llvm.used contains a list of pointers to named values which the
compiler, assembler, and linker are required to treat as if there is a
reference that they cannot see. Ensure that the symbols are preserved
by adding an explicit -include reference to the linker command.
Details
- Reviewers
rnk
Diff Detail
- Repository
- rL LLVM
Event Timeline
Duplicating this in the ARM and X86 AsmPrinters is lame. Maybe we should hoist the COFF-specific handling up to the next level? I'm going to look into doing that for -export flags.
Cool, look at rL322788.
BTW, afterwards this is a great opportunity to fix this bug:
template <typename T> struct Foo { static int x; }; int f(); template <typename T> int Foo<T>::x = f(); template struct Foo<int>;
MSVC emits "/include:?x@?$Foo@H@@2HA" to make sure that x survives dead stripping. Once we have this llvm.used functionality, we have an easy IR-only way to get that /include directive.
Awesome; I was thinking about doing that as a follow up. I'll hoist this into that new layer. Completely agree on the fixing the emission after this infrastructure is in place. I can't believe that we never implemented this.
This doesn't seem like it will do the right thing if the global has internal linkage. Do we care about that case? I guess we could handle it by emitting dummy ABSOLUTE relocations from a non-COMDAT section to the section or symbol that we want to preserve.
Patch is missing context.
lib/CodeGen/AsmPrinter/AsmPrinter.cpp | ||
---|---|---|
1459 ↗ | (On Diff #130689) | Add a comment about why internal symbols are ignored? |
Maybe test a vectorcallcc function to test that we're using the GlobalValue overload of getNameWithPrefix.