[PATCH] D44601: LLD: Avoid segfault with --emit-relocs

Domagoj Stolfa via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Mar 18 18:23:56 PDT 2018


dstolfa updated this revision to Diff 138876.
dstolfa added a comment.

Bump the diff to reflect things that @arichardson has helped me find.

The relocations are still not checked in the test itself because it's not clear what the section number should be yet (I'm getting different outputs from different linkers at the moment).

This diff removes the unnecessary duplicate runs that are checked by `emit-relocs.s` already and renames `emit-relocs-freebsd.s` to `emit-relocs-eh.s` as the breakage is not unique to FreeBSD. It does not provide a correct fix yet and still just works around the issue by simply ignoring the problematic entries.


Repository:
  rLLD LLVM Linker

https://reviews.llvm.org/D44601

Files:
  ELF/LinkerScript.cpp
  ELF/Writer.cpp
  test/ELF/emit-relocs-eh.s


Index: test/ELF/emit-relocs-eh.s
===================================================================
--- /dev/null
+++ test/ELF/emit-relocs-eh.s
@@ -0,0 +1,20 @@
+# REQUIRES: x86
+# RUN: llvm-mc -triple=x86_64-unknown-freebsd -filetype=obj %s -o %t1.o
+# RUN: ld.lld %t1.o --emit-relocs -o %t
+# RUN: llvm-readobj -t -r -s %t | FileCheck %s
+
+# CHECK:        Section {
+# CHECK:          Index: 2
+# CHECK-NEXT:     Name: .text
+# CHECK-NEXT:     Type: SHT_PROGBITS
+# CHECK-NEXT:     Flags [
+# CHECK-NEXT:       SHF_ALLOC
+# CHECK-NEXT:       SHF_EXECINSTR
+# CHECK-NEXT:     ]
+
+.text
+.globl _start
+_start:
+.cfi_startproc
+  nop
+.cfi_endproc
Index: ELF/Writer.cpp
===================================================================
--- ELF/Writer.cpp
+++ ELF/Writer.cpp
@@ -98,6 +98,8 @@
       !isa<SyntheticSection>(S)) {
     OutputSection *Out =
         cast<InputSection>(S)->getRelocatedSection()->getOutputSection();
+    if (!Out)
+      return "";
     if (S->Type == SHT_RELA)
       return Saver.save(".rela" + Out->Name);
     return Saver.save(".rel" + Out->Name);
Index: ELF/LinkerScript.cpp
===================================================================
--- ELF/LinkerScript.cpp
+++ ELF/LinkerScript.cpp
@@ -636,6 +636,8 @@
       continue;
 
     StringRef Name = getOutputSectionName(S);
+    if (Name == "")
+      continue;
 
     if (Config->OrphanHandling == OrphanHandlingPolicy::Error)
       error(toString(S) + " is being placed in '" + Name + "'");


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D44601.138876.patch
Type: text/x-patch
Size: 1490 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180319/1032be0c/attachment.bin>


More information about the llvm-commits mailing list