wasi-libc icon indicating copy to clipboard operation
wasi-libc copied to clipboard

Generation user-defined custom section

Open mikevoronov opened this issue 3 years ago • 2 comments

(this probably doesn't belong here, but I couldn't find better repo to raise it on)

Are there any example of generation user-defined custom sections? I tried smth like this

const unsigned char __FCE_SDK_VERSION[]
    __attribute__((__section__(".custom_section.__fce_sdk_version"))) 
    = "0.5.0";

but resulted Wasm binary doesn't contain new custom section with this name. I tried both with --no-gc-sections. Then checked emitted llvm that didn't contain wasm.custom_sections attribute.

I also checked llvm/clang source (and corresponding code inside rustc) and it seems that this isn't implemented in the clang frontend.

mikevoronov avatar Mar 13 '21 09:03 mikevoronov

This is a clang issue rather than a libc issue, I'm not an expert on clang but maybe @sbc100 can point you in the right direction?

pchickey avatar Mar 18 '21 16:03 pchickey

It looks like support for user defined custom sections is only implemented in https://reviews.llvm.org/D45297. However there is no support for this at the clang / C / C++ layer. Using this feature would require a frontend that supports it, or writing llvm assembly or bitcode directly.

(The reason this is not easy in C/C++ is that in C/C++ that language kind of assumes everything has an address. Things in custom sections don't have addresses because they are not in linear memory.).

sbc100 avatar Mar 18 '21 16:03 sbc100