[PATCH] D42977: Don't set dso_local flag in LTO resolutions for absolute symbols defined in ELF objects

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


This revision was not accepted when it landed; it landed in state "Needs Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rL324435: Don't set dso_local flag in LTO resolutions for absolute symbols defined in ELF (authored by dmikulin, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D42977?vs=133096&id=133115#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D42977

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


Index: lld/trunk/ELF/LTO.cpp
===================================================================
--- lld/trunk/ELF/LTO.cpp
+++ lld/trunk/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);
Index: lld/trunk/test/ELF/lto/Inputs/absolute.s
===================================================================
--- lld/trunk/test/ELF/lto/Inputs/absolute.s
+++ lld/trunk/test/ELF/lto/Inputs/absolute.s
@@ -0,0 +1,2 @@
+.globl blah
+ blah = 0xdeadbeef
Index: lld/trunk/test/ELF/lto/abs-resol.ll
===================================================================
--- lld/trunk/test/ELF/lto/abs-resol.ll
+++ lld/trunk/test/ELF/lto/abs-resol.ll
@@ -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
+}


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D42977.133115.patch
Type: text/x-patch
Size: 1824 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180207/f509389c/attachment.bin>


More information about the llvm-commits mailing list