[PATCH] D24967: [ELF] - Fixed linkage error when using -g --gc-sections together.

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 27 09:04:27 PDT 2016


This revision was automatically updated to reflect the committed changes.
Closed by commit rL282495: [ELF] - Fixed linkage error when using -g --gc-sections together. (authored by grimar).

Changed prior to commit:
  https://reviews.llvm.org/D24967?vs=72656&id=72665#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D24967

Files:
  lld/trunk/ELF/MarkLive.cpp
  lld/trunk/test/ELF/debug-gc.s

Index: lld/trunk/ELF/MarkLive.cpp
===================================================================
--- lld/trunk/ELF/MarkLive.cpp
+++ lld/trunk/ELF/MarkLive.cpp
@@ -64,13 +64,20 @@
   return Rel.r_addend;
 }
 
+template <class ELFT> static bool IsAlloc(InputSectionBase<ELFT> &Sec) {
+  return (&Sec != &InputSection<ELFT>::Discarded) &&
+         (Sec.getSectionHdr()->sh_flags & SHF_ALLOC);
+}
+
 template <class ELFT, class RelT>
 static ResolvedReloc<ELFT> resolveReloc(InputSectionBase<ELFT> &Sec,
                                         RelT &Rel) {
   SymbolBody &B = Sec.getFile()->getRelocTargetSym(Rel);
   auto *D = dyn_cast<DefinedRegular<ELFT>>(&B);
   if (!D || !D->Section)
     return {nullptr, 0};
+  if (!IsAlloc<ELFT>(Sec) && IsAlloc<ELFT>(*D->Section))
+    return {nullptr, 0};
   typename ELFT::uint Offset = D->Value;
   if (D->isSection())
     Offset += getAddend(Sec, Rel);
@@ -208,8 +215,7 @@
       return;
     R.Sec->Live = true;
     if (InputSection<ELFT> *S = dyn_cast<InputSection<ELFT>>(R.Sec))
-      if (S->getSectionHdr()->sh_flags & SHF_ALLOC)
-        Q.push_back(S);
+      Q.push_back(S);
   };
 
   auto MarkSymbol = [&](const SymbolBody *Sym) {
Index: lld/trunk/test/ELF/debug-gc.s
===================================================================
--- lld/trunk/test/ELF/debug-gc.s
+++ lld/trunk/test/ELF/debug-gc.s
@@ -0,0 +1,24 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
+# RUN: ld.lld %t.o -o %t1 --gc-sections
+# RUN: llvm-objdump -s %t1 | FileCheck %s
+
+# CHECK:      Contents of section .debug_str:
+# CHECK-NEXT:  0000 41414100 42424200   AAA.BBB.
+# CHECK:      Contents of section .debug_info:
+# CHECK-NEXT:  0000 00000000 04000000
+
+.globl _start
+_start:
+
+.section .debug_str,"MS", at progbits,1
+.Linfo_string0:
+  .asciz "AAA"
+.Linfo_string1:
+  .asciz "BBB"
+.Linfo_string2:
+  .asciz "ムムム"
+  
+.section  .debug_info,"", at progbits
+  .long .Linfo_string0
+  .long .Linfo_string1


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D24967.72665.patch
Type: text/x-patch
Size: 1999 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160927/970f89f1/attachment.bin>


More information about the llvm-commits mailing list