[PATCH] D26201: [ELF/GC] Fix pending references to garbage collected sections

Davide Italiano via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 1 09:54:46 PDT 2016


davide created this revision.
davide added reviewers: rafael, Bigcheese, phosek.
davide added a subscriber: llvm-commits.

The example reported in https://llvm.org/bugs/show_bug.cgi?id=30793 shows a case where gc reclaims a SHF_TLS section, but it doesn't recliam the section containing the debug info for it. This is, anyway, expected, as we do not reclaim non-alloc sections during the garbage collection phase (and this is not going to change anytime soon, at least this is what I gathered last I talked with Rafael about it).
So, we end up with a pending reference, thinking that the input was invalid (which is not true, as it's GC that removed the SH_TLS section, and therefore didn't create the PT_TLS *segment* for it). In cases like this, just assign a VA of zero at relocaiton time instead of error'ing out (this is what gold does as well, FWIW).


https://reviews.llvm.org/D26201

Files:
  ELF/InputSection.cpp
  test/ELF/gc-debuginfo-tls.s


Index: test/ELF/gc-debuginfo-tls.s
===================================================================
--- /dev/null
+++ test/ELF/gc-debuginfo-tls.s
@@ -0,0 +1,28 @@
+# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
+# RUN: ld.lld %t.o --gc-sections -shared -o %t1
+# RUN: ld.lld %t.o -shared -o %t2
+# RUN: llvm-readobj -symbols %t1 | FileCheck %s --check-prefix=GC
+# RUN: llvm-readobj -symbols %t2 | FileCheck %s --check-prefix=NOGC
+
+# NOGC: Symbol {
+# NOGC:   Name: .tbss
+# NOGC:   Value: 0x1000
+# NOGC:   Size: 0
+# NOGC:   Binding: Local
+# NOGC:   Type: TLS
+# NOGC:   Other: 0
+# NOGC:   Section: .tbss
+# NOGC: }
+
+# GC-NOT: tbss
+
+      .file   1 "patatino.cpp"
+      .globl  main
+main:
+      .loc    1 2 0
+      .cfi_startproc
+      .cfi_endproc
+      .cfi_startproc
+      .cfi_endproc
+      .section        .tbss,"awT", at nobits
+      .long 0
Index: ELF/InputSection.cpp
===================================================================
--- ELF/InputSection.cpp
+++ ELF/InputSection.cpp
@@ -407,8 +407,12 @@
     }
 
     uintX_t AddrLoc = this->OutSec->getVA() + Offset;
-    uint64_t SymVA = SignExtend64<sizeof(uintX_t) * 8>(
-        getSymVA<ELFT>(Type, Addend, AddrLoc, Sym, R_ABS));
+    uint64_t SymVA;
+    if (Sym.isTls() && !Out<ELFT>::TlsPhdr)
+      SymVA = 0;
+    else
+      SymVA = SignExtend64<sizeof(uintX_t) * 8>(
+          getSymVA<ELFT>(Type, Addend, AddrLoc, Sym, R_ABS));
     Target->relocateOne(BufLoc, Type, SymVA);
   }
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D26201.76583.patch
Type: text/x-patch
Size: 1495 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161101/8177cc5d/attachment.bin>


More information about the llvm-commits mailing list