[lld] r297711 - [ELF] Fix error reporting for synthetic sections

Eugene Leviant via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 14 01:33:46 PDT 2017


Author: evgeny777
Date: Tue Mar 14 03:33:45 2017
New Revision: 297711

URL: http://llvm.org/viewvc/llvm-project?rev=297711&view=rev
Log:
[ELF] Fix error reporting for synthetic sections

Synthetic sections don't belong to any input file, but still they
are input sections. Whenever problem occurs with relocations in
these sections lld crashes in error reporting, trying to print
input file name.

Differential revision: https://reviews.llvm.org/D30889

Added:
    lld/trunk/test/ELF/linkerscript/eh-frame-reloc-out-of-range.s
Modified:
    lld/trunk/ELF/InputSection.cpp

Modified: lld/trunk/ELF/InputSection.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.cpp?rev=297711&r1=297710&r2=297711&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.cpp (original)
+++ lld/trunk/ELF/InputSection.cpp Tue Mar 14 03:33:45 2017
@@ -172,6 +172,11 @@ InputSectionBase *InputSectionBase::getL
 // 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())

Added: lld/trunk/test/ELF/linkerscript/eh-frame-reloc-out-of-range.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/eh-frame-reloc-out-of-range.s?rev=297711&view=auto
==============================================================================
--- lld/trunk/test/ELF/linkerscript/eh-frame-reloc-out-of-range.s (added)
+++ lld/trunk/test/ELF/linkerscript/eh-frame-reloc-out-of-range.s Tue Mar 14 03:33:45 2017
@@ -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




More information about the llvm-commits mailing list