[UPDATE] This patch
- lowers @llvm.global_dtors by adding @llvm.global_ctors functions which register the destructors with __cxa_atexit.
- impements @llvm.global_ctors with wasm start functions and linker metadata
See here for more background.
Paths
| Differential D40759
[WebAssembly] Implement @llvm.global_ctors and @llvm.global_dtors ClosedPublic Authored by sunfish on Dec 1 2017, 5:09 PM.
Details
Diff Detail
Event TimelineComment Actions Updated patch:
sunfish retitled this revision from [WebAssembly] Experiment with lowering @llvm.global_dtors to [WebAssembly] Lower @llvm.global_dtors.Dec 3 2017, 7:06 AM sunfish retitled this revision from [WebAssembly] Lower @llvm.global_dtors to [WebAssembly] Implement @llvm.global_ctors and @llvm.global_dtors.Dec 7 2017, 5:12 AM Comment Actions How would you feel about landing a simplified version of this change that doesn't use the start section (i.e. always put start functions in the metadata)? Seems a little strange to special case the single start function. Also, I like the idea of letting the linker decide if/when to switch to using the start section (for now anyway). Comment Actions I'd like to land this soon if possible (sans the start section if possible) so I start working on the lld side. This revision is now accepted and ready to land.Dec 13 2017, 12:13 PM Comment Actions Omitting the start section part for now is ok with me. It should be sufficient to just remove the Priority == UINT16_MAX special cases. I'm also adding comments for a few minor issues in the patch that I thought of. The COMDAT thing would be nice to do now so that we don't have to coordinate adding it in the future. I won't be able to land anything this week, so I'm ok if you want to land this without the start section parts right now.
Comment Actions I've implemented the Musl side of this change. It was pretty simple really, I've just added the following to crt1.o, which is pulled in by the default link-line: extern void __init_libc(char **envp, char *pn); __attribute__((constructor(1))) void __libc_ctor() { __init_libc((char**)&__wasm_init_data.envp0, (char*)__wasm_init_data.argv0); } It sounds like Sam is working on the LLD-side of this change, to actually use the init-data section to synthesise an entrypoint. I look forward to testing with it!
Comment Actions I landed a modified version of this change in rL320774. I assume its OK to close this now.
Revision Contents
Diff 125936 include/llvm/BinaryFormat/Wasm.h
include/llvm/CodeGen/TargetLoweringObjectFileImpl.h
lib/CodeGen/TargetLoweringObjectFileImpl.cpp
lib/MC/WasmObjectWriter.cpp
lib/Object/WasmObjectFile.cpp
lib/Target/WebAssembly/CMakeLists.txt
lib/Target/WebAssembly/WebAssembly.h
lib/Target/WebAssembly/WebAssemblyLowerGlobalDtors.cpp
lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
test/CodeGen/WebAssembly/lower-global-dtors.ll
test/MC/WebAssembly/init-fini-array.ll
|
We should reserve room here for an optional COMDAT symbol too. For now, it's probably sufficient to just stub it out with a encodeULEB128(0, getStream()).