For MachO, lower .llvm.global_dtors into .llvm_global_ctors with
__cxa_atexit calls to avoid emitting the deprecated __mod_term_func.
Reuse the existing WebAssemblyLowerGlobalDtors.cpp to accomplish this.
Paths
| Differential D121327
Lower `@llvm.global_dtors` using `__cxa_atexit` on MachO ClosedPublic Authored by yln on Mar 9 2022, 1:07 PM.
Details Summary For MachO, lower .llvm.global_dtors into .llvm_global_ctors with Reuse the existing WebAssemblyLowerGlobalDtors.cpp to accomplish this.
Diff Detail
Event TimelineComment Actions I wanted to check in to get your feedback on the overall approach while I am working on adding tests for the behavior change. On Darwin (MachO really) we want to transition away from the deprecated __mod_term_funcs section (relevant: D45578). However, currently @llvm.global_dtors, i.e., llvm::appendToGlobalDtors callers, are lowered to it. Comment Actions The overall approach here makes sense to me. The tests test/CodeGen/WebAssembly/global_dtors.ll and test/CodeGen/WebAssembly/lower-global-dtors.ll cover the main interesting corner cases that we've hit with this pass; they currently have wasm targets and wasm-specific CHECK lines, but could likely be ported to other targets. Comment Actions @yln I like the approach here as it solves problem for all of LLVM, not just ASan specifically :). This is better than what I was going to do originally. I think the only missing there here are some tests. Comment Actions Make pass compatible with new pass manager to ease testing with opt. Add and adapt tests. Add documentation. Make clang-format happy.
This revision is now accepted and ready to land.Mar 11 2022, 11:04 AM delcypher added inline comments.
Comment Actions Add support for an escape hatch to fallback to the old behavior: via Clang driver flag Comment Actions @sunfish
Comment Actions
Yes, the change looks good to me! yln added inline comments.
This revision was landed with ongoing or failed builds.Mar 14 2022, 5:51 PM Closed by commit rG9c542a5a4e1b: Lower `@llvm.global_dtors` using `__cxa_atexit` on MachO (authored by yln). · Explain Why This revision was automatically updated to reflect the committed changes. yln marked an inline comment as done. Comment Actions Hi @yln, the test you added llvm/test/Transforms/LowerGlobalDestructors/lower-global-dtors.ll is failing on some bots, e.g. https://lab.llvm.org/buildbot/#/builders/139/builds/18527 (builder llvm-clang-x86_64-sie-ubuntu-fast). Please can you take a look? Comment Actions @yln I've reverted your commit at rG7262eacd41997d7ca262d83367e28998662c1b21 to try and get the buildbots green again Comment Actions Thanks for pointing out the test failure and reverting the change. I see this failure: : 'RUN: at line 1'; /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/opt -lower-global-dtors -S < /home/buildbot/buildbot-root/llvm-project/llvm/test/Transforms/LowerGlobalDestructors/lower-global-dtors.ll | /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/FileCheck /home/buildbot/buildbot-root/llvm-project/llvm/test/Transforms/LowerGlobalDestructors/lower-global-dtors.ll --implicit-check-not=llvm.global_dtors : 'RUN: at line 2'; /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/opt -passes=lower-global-dtors -S < /home/buildbot/buildbot-root/llvm-project/llvm/test/Transforms/LowerGlobalDestructors/lower-global-dtors.ll | /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/FileCheck /home/buildbot/buildbot-root/llvm-project/llvm/test/Transforms/LowerGlobalDestructors/lower-global-dtors.ll --implicit-check-not=llvm.global_dtors -- Exit Code: 2 Command Output (stderr): -- opt: Unknown command line argument '-lower-global-dtors'. Try: '/home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/build/bin/opt --help' opt: Did you mean '--join-globalcopies'? This looks like my changes are not sufficiently registering the pass for opt on every platform, but so far I haven't found anything that is obviously wrong/missing. Do you know who I can reach out to help me with "pass registration"? Comment Actions
FYI - you could have continued to use this phab for review, it makes it easier to compare the changes you've made
Revision Contents
Diff 415273 clang/lib/CodeGen/BackendUtil.cpp
llvm/docs/Passes.rst
llvm/include/llvm/CodeGen/CommandFlags.h
llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h
llvm/include/llvm/InitializePasses.h
llvm/include/llvm/LinkAllPasses.h
llvm/include/llvm/Target/TargetOptions.h
llvm/include/llvm/Transforms/Instrumentation/AddressSanitizerOptions.hllvm/include/llvm/Transforms/Utils.h
llvm/include/llvm/Transforms/Utils/LowerGlobalDtors.h
llvm/lib/CodeGen/CodeGen.cpp
llvm/lib/CodeGen/CommandFlags.cpp
llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
llvm/lib/CodeGen/TargetPassConfig.cpp
llvm/lib/Passes/PassBuilder.cpp
llvm/lib/Passes/PassRegistry.def
llvm/lib/Target/WebAssembly/CMakeLists.txt
llvm/lib/Target/WebAssembly/WebAssembly.h
llvm/lib/Target/WebAssembly/WebAssemblyLowerGlobalDtors.cpp
llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
llvm/lib/Transforms/Utils/CMakeLists.txt
llvm/lib/Transforms/Utils/LowerGlobalDtors.cpp
llvm/test/CodeGen/ARM/ctors_dtors.ll
llvm/test/CodeGen/X86/2011-08-29-InitOrder.ll
llvm/test/Transforms/LowerGlobalDestructors/lower-global-dtors.ll
|
clang-format not found in user’s local PATH; not linting file.