[TargetMachine] Drop implied dso_local for definitions in ELF static … · llvm/llvm-project@2047c10 · GitHub was to clean up llvm::TargetMachine::shouldAssumeDSOLocal
. For Clang, that code is unneeded because Clang sets dso_local llvm-project/CodeGenModule.cpp at main · llvm/llvm-project · GitHub
I am thinking whether [TargetMachine] Drop implied dso_local for definitions in ELF static … · llvm/llvm-project@2047c10 · GitHub should be reverted (or be replaced with if (RM == Reloc::Static && !GV->isDeclarationForLinker()) return true
) as a workaround before IR producers set dso_local properly.
But for Rust, it'd be nice to explicitly set dso_local like Clang.
About dso_local in LLVM IR, it was introduced to model "whether references to a function/global variable (either definition or declaration) can be assumed to be resolved within the linkage unit".
On ELF, STV_DEFAULT STB_GLOBAL/STB_WEAK
symbols are preemptible (interposable) for a shared object (ld -shared
). Such -fpic produced symbols are modeled with dso_preemptable
. (Yes, "preemptible" is used more frequently than "preemptable" in ELF)
On COFF, only extern_weak
or dllimport
GlobalValue
s can be dso_preemptable
.
On Mach-O, the current rule is
if (TT.isOSBinFormatMachO()) {
if (RM == llvm::Reloc::Static)
return true;
return GV->isStrongDefinitionForLinker();
}
It'd be nice if someone can clarify whether the GV->isStrongDefinitionForLinker()
condition can be generalized to !GV->isDeclaractionForLinker
in non-static relocation models (llc -relocation-model=pic
or llc -relocation-model=dynamic-no-pic
) If yes, dso_local can be set on definitions of all linkage types in these binary formats, and the emitted IR can be made very similar for COFF/ELF/Mach-O.