[lld] r324435 - Don't set dso_local flag in LTO resolutions for absolute symbols defined in ELF

Dmitry Mikulin via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 6 16:49:51 PST 2018


Author: dmikulin
Date: Tue Feb  6 16:49:51 2018
New Revision: 324435

URL: http://llvm.org/viewvc/llvm-project?rev=324435&view=rev
Log:
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

Added:
    lld/trunk/test/ELF/lto/Inputs/absolute.s
    lld/trunk/test/ELF/lto/abs-resol.ll
Modified:
    lld/trunk/ELF/LTO.cpp

Modified: lld/trunk/ELF/LTO.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LTO.cpp?rev=324435&r1=324434&r2=324435&view=diff
==============================================================================
--- lld/trunk/ELF/LTO.cpp (original)
+++ lld/trunk/ELF/LTO.cpp Tue Feb  6 16:49:51 2018
@@ -154,8 +154,14 @@ void BitcodeCompiler::add(BitcodeFile &F
     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);

Added: lld/trunk/test/ELF/lto/Inputs/absolute.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/lto/Inputs/absolute.s?rev=324435&view=auto
==============================================================================
--- lld/trunk/test/ELF/lto/Inputs/absolute.s (added)
+++ lld/trunk/test/ELF/lto/Inputs/absolute.s Tue Feb  6 16:49:51 2018
@@ -0,0 +1,2 @@
+.globl blah
+ blah = 0xdeadbeef

Added: lld/trunk/test/ELF/lto/abs-resol.ll
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/lto/abs-resol.ll?rev=324435&view=auto
==============================================================================
--- lld/trunk/test/ELF/lto/abs-resol.ll (added)
+++ lld/trunk/test/ELF/lto/abs-resol.ll Tue Feb  6 16:49:51 2018
@@ -0,0 +1,14 @@
+; REQUIRES: x86
+
+; RUN: llvm-as %s -o %t.o
+; RUN: llvm-mc -triple=x86_64-pc-linux %p/Inputs/absolute.s -o %t2.o -filetype=obj
+; RUN: ld.lld %t.o %t2.o -o %t.out -pie
+
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+ at blah = external global i8, align 1
+
+define i8* @_start() {
+ ret i8* @blah
+}




More information about the llvm-commits mailing list