[PATCH] D30889: [ELF] Fix error reporting for eh_frame and other synthetic sections

Eugene Leviant via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 13 05:53:51 PDT 2017


evgeny777 created this revision.
evgeny777 added a project: lld.

Such sections don't belong to any specific file, so getLocation<ELFT>() will crash for them. One of possible cases is 
out of range relocation in .eh_frame section


Repository:
  rL LLVM

https://reviews.llvm.org/D30889

Files:
  ELF/InputSection.cpp
  test/ELF/linkerscript/eh-frame-reloc-out-of-range.s


Index: test/ELF/linkerscript/eh-frame-reloc-out-of-range.s
===================================================================
--- test/ELF/linkerscript/eh-frame-reloc-out-of-range.s
+++ test/ELF/linkerscript/eh-frame-reloc-out-of-range.s
@@ -0,0 +1,27 @@
+## Check that error is correctly reported when .eh_frame reloc
+## is out of range
+
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
+# RUN: echo "PHDRS { eh PT_LOAD; text PT_LOAD; }  \
+# RUN:       SECTIONS { . = 0x10000; \
+# RUN:         .eh_frame_hdr : { *(.eh_frame_hdr*) } : eh \
+# RUN:         .eh_frame : { *(.eh_frame) } : eh \
+# RUN:         . = 0xF00000000; \
+# RUN:         .text : { *(.text*) } : text \
+# RUN:       }" > %t.script
+# RUN: not ld.lld %t.o -T %t.script -o %t 2>&1 | FileCheck %s
+
+# CHECK: error: {{.*}}:(.eh_frame+0x20): relocation R_X86_64_PC32 out of range
+
+	.text
+  .globl _start
+_start:
+	.cfi_startproc
+  .cfi_lsda 0, _ex
+  nop
+	.cfi_endproc
+
+  .data
+_ex:
+  .word 0
Index: ELF/InputSection.cpp
===================================================================
--- ELF/InputSection.cpp
+++ ELF/InputSection.cpp
@@ -172,6 +172,11 @@
 // Returns a source location string. Used to construct an error message.
 template <class ELFT>
 std::string InputSectionBase::getLocation(uint64_t Offset) {
+  // We don't have file for synthetic sections.
+  if (getFile<ELFT>() == nullptr)
+    return (Config->OutputFile + ":(" + Name + "+0x" + utohexstr(Offset) + ")")
+        .str();
+
   // First check if we can get desired values from debugging information.
   std::string LineInfo = getFile<ELFT>()->getLineInfo(this, Offset);
   if (!LineInfo.empty())


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D30889.91544.patch
Type: text/x-patch
Size: 1695 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170313/fa8aa3d4/attachment.bin>


More information about the llvm-commits mailing list