Don't set dso_local flag in LTO resolutions for absolute symbols defined in ELF
objects, it confuses codegen into generating pc-rel relocations for those
symbols, which leads to linker errors.
Differential Revision: https://reviews.llvm.org/D42977
llvm-svn: 324435
diff --git a/lld/ELF/LTO.cpp b/lld/ELF/LTO.cpp
index 3710bef..098e842 100644
--- a/lld/ELF/LTO.cpp
+++ b/lld/ELF/LTO.cpp
@@ -154,8 +154,14 @@
R.VisibleToRegularObj = Config->Relocatable || Sym->IsUsedInRegularObj ||
(R.Prevailing && Sym->includeInDynsym()) ||
UsedStartStop.count(ObjSym.getSectionName());
+ const auto *DR = dyn_cast<Defined>(Sym);
R.FinalDefinitionInLinkageUnit =
- Sym->isDefined() && (IsExecutable || Sym->Visibility != STV_DEFAULT);
+ (IsExecutable || Sym->Visibility != STV_DEFAULT) && DR &&
+ // Skip absolute symbols from ELF objects, otherwise PC-rel relocations
+ // will be generated by for them, triggering linker errors.
+ // Symbol section is always null for bitcode symbols, hence the check
+ // for isElf().
+ !(Sym->File && Sym->File->isElf() && DR->Section == nullptr);
if (R.Prevailing)
undefine(Sym);