[PATCH] D29968: Handle .eh_frame pointing to discarded section in -r

Rafael Ávila de Espíndola via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 14 14:49:23 PST 2017


rafael created this revision.

https://reviews.llvm.org/D29968

Files:
  ELF/InputSection.cpp
  test/ELF/relocatable-eh-frame.s


Index: test/ELF/relocatable-eh-frame.s
===================================================================
--- /dev/null
+++ test/ELF/relocatable-eh-frame.s
@@ -0,0 +1,15 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
+# RUN: ld.lld -r %t.o %t.o -o %t
+# RUN: llvm-readobj -r %t | FileCheck %s
+
+# CHECK:      Relocations [
+# CHECK-NEXT:   Section ({{.*}}) .rela.eh_frame {
+# CHECK-NEXT:     0x20 R_X86_64_PC32 .foo 0x0
+# CHECK-NEXT:     0x0 R_X86_64_NONE - 0x0
+# CHECK-NEXT:   }
+# CHECK-NEXT: ]
+
+.section .foo,"aG", at progbits,bar,comdat
+.cfi_startproc
+.cfi_endproc
Index: ELF/InputSection.cpp
===================================================================
--- ELF/InputSection.cpp
+++ ELF/InputSection.cpp
@@ -241,9 +241,20 @@
       // section. This means we have to update the addend. That is
       // trivial for Elf_Rela, but for Elf_Rel we have to write to the
       // section data. We do that by adding to the Relocation vector.
+
+      // .eh_frame is horribly special and can reference discarded sections. To
+      // avoid having to parse and recreate .eh_frame, we just replace any
+      // relocation in it pointing to discarded sections with R_*_NONE, which
+      // hopefully creates a frame that is ignored at runtime.
+      InputSectionBase<ELFT> *Section =
+          cast<DefinedRegular<ELFT>>(Body).Section;
+      if (Section == &InputSection<ELFT>::Discarded) {
+        P->setSymbolAndType(0, 0, false);
+        continue;
+      }
+
       if (Config->Rela) {
-        P->r_addend += Body.getVA<ELFT>() -
-                       cast<DefinedRegular<ELFT>>(Body).Section->OutSec->Addr;
+        P->r_addend += Body.getVA<ELFT>() - Section->OutSec->Addr;
       } else if (Config->Relocatable) {
         const uint8_t *BufLoc = RelocatedSection->Data.begin() + Rel.r_offset;
         uint64_t Implicit = Target->getImplicitAddend(BufLoc, Type);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D29968.88449.patch
Type: text/x-patch
Size: 1927 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170214/9de97fc1/attachment.bin>


More information about the llvm-commits mailing list