[lld] r295322 - Fix crash with -emit-relocs -shared.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 16 06:23:44 PST 2017


Author: rafael
Date: Thu Feb 16 08:23:43 2017
New Revision: 295322

URL: http://llvm.org/viewvc/llvm-project?rev=295322&view=rev
Log:
Fix crash with -emit-relocs -shared.

The code to handle the input SHT_REL/SHT_RELA sections was getting
confused with the linker generated relocation sections.

Added:
    lld/trunk/test/ELF/emit-relocs-shared.s
Modified:
    lld/trunk/ELF/OutputSections.cpp

Modified: lld/trunk/ELF/OutputSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.cpp?rev=295322&r1=295321&r2=295322&view=diff
==============================================================================
--- lld/trunk/ELF/OutputSections.cpp (original)
+++ lld/trunk/ELF/OutputSections.cpp Thu Feb 16 08:23:43 2017
@@ -119,10 +119,14 @@ template <class ELFT> void OutputSection
   if (!Config->copyRelocs() || (Type != SHT_RELA && Type != SHT_REL))
     return;
 
+  InputSection<ELFT> *First = Sections[0];
+  if (isa<SyntheticSection<ELFT>>(First))
+    return;
+
   this->Link = In<ELFT>::SymTab->OutSec->SectionIndex;
   // sh_info for SHT_REL[A] sections should contain the section header index of
   // the section to which the relocation applies.
-  InputSectionBase<ELFT> *S = Sections[0]->getRelocatedSection();
+  InputSectionBase<ELFT> *S = First->getRelocatedSection();
   this->Info = S->OutSec->SectionIndex;
 }
 

Added: lld/trunk/test/ELF/emit-relocs-shared.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/emit-relocs-shared.s?rev=295322&view=auto
==============================================================================
--- lld/trunk/test/ELF/emit-relocs-shared.s (added)
+++ lld/trunk/test/ELF/emit-relocs-shared.s Thu Feb 16 08:23:43 2017
@@ -0,0 +1,16 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
+# RUN: ld.lld --emit-relocs %t.o -o %t.so -shared
+# RUN: llvm-readobj -r %t.so | FileCheck %s
+
+.data
+.quad foo
+
+# CHECK:      Relocations [
+# CHECK-NEXT:   Section (4) .rela.dyn {
+# CHECK-NEXT:     0x1000 R_X86_64_64 foo 0x0
+# CHECK-NEXT:   }
+# CHECK-NEXT:   Section (8) .rela.data {
+# CHECK-NEXT:     0x1000 R_X86_64_64 foo 0x0
+# CHECK-NEXT:   }
+# CHECK-NEXT: ]




More information about the llvm-commits mailing list