Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WebAssembly] Use WebAssembly custom sections in C/C++ source files #54552

Closed
nokotan opened this issue Mar 25, 2022 · 3 comments
Closed

[WebAssembly] Use WebAssembly custom sections in C/C++ source files #54552

nokotan opened this issue Mar 25, 2022 · 3 comments

Comments

@nokotan
Copy link
Contributor

nokotan commented Mar 25, 2022

All global variables, including ones that have section attribute __attribute__((section("<section-name>"))), are located in WebAssembly data sections.

I know that this behavior is required to compatibility of other platforms, and that this is great solution because all data in WebAssembly custom section cannot be loaded into a linear memory.

If you want to embed some metadata into WebAssembly, file scope inline assembly can be used.

__asm(
  ".section .custom_section.my_section,\"G\",@,abc123\n"
  ".ascii \"my_section is here!\"\n"
);

I want global variables, attributed __attribute__((section(".custom_section.*"))) and never read and written in the program, to be located into WebAssembly custom section.
This may be solution candidate of that llvm-cov is useless with WebAssembly because llvm-cov currently expects that llvm-cov specific sections are located in WebAssembly custom section. (emscripten-core/emscripten#13046)

@llvmbot
Copy link
Member

llvmbot commented Mar 25, 2022

@llvm/issue-subscribers-backend-webassembly

@sbc100
Copy link
Collaborator

sbc100 commented Mar 25, 2022

Anther solution the llvm-cov problem is to update the way libObject handles data segments. As of today the individual data segments are not listed as separate in ObjectFile::sections()... but I think they they should be. I've got a discussion started here but I've made much progress recently: WebAssembly/tool-conventions#138

The idea is that when you build with -fdata-sections and/or -ffunction-sections you expected the resulting tools to display one section per symbol.. but today we don't do that with wasm.. which I think its bug.

@nokotan
Copy link
Contributor Author

nokotan commented Apr 6, 2022

Now I agree with It could be better way that writing data segment metadata into wasm binary, like WasmWriter::writeSectionContent(_, WasmYAML::LinkingSection) does, when -fdata-sections specified than directly write data segments into wasm custom section.

Originally I hoped this feature in order to use writing wasm-bindgen's metadata in C/C++ source files, which currently leads me to preprocessors macro hell... It won't be a good wasm-JavaScript bindings generation tool for C/C++ unlike emscripten's webidl binder or wit-bindgen.

@nokotan nokotan closed this as completed Apr 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants