[PATCH] D44601: LLD: Avoid segfault on FreeBSD with --emit-relocs
Domagoj Stolfa via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sat Mar 17 13:53:22 PDT 2018
dstolfa updated this revision to Diff 138827.
dstolfa added a comment.
Generate a minimal test case for the breakage. It seems like the root cause of this are the cfi sections.
Repository:
rLLD LLVM Linker
https://reviews.llvm.org/D44601
Files:
ELF/LinkerScript.cpp
ELF/Writer.cpp
test/ELF/emit-relocs-freebsd.s
Index: test/ELF/emit-relocs-freebsd.s
===================================================================
--- /dev/null
+++ test/ELF/emit-relocs-freebsd.s
@@ -0,0 +1,68 @@
+# 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 single dash form.
+# RUN: ld.lld -emit-relocs %t1.o -o %t1
+# RUN llvm-read-obj -t -r -s %t1 | FileCheck %s
+
+## Check alias.
+# RUN: ld.lld -q %t1.o -o %t2
+# RUN: llvm-readobj -t -r -s %t2 | 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: ]
+# CHECK: Relocations [
+# CHECK-NEXT: ]
+# CHECK-NEXT: Symbols [
+# CHECK-NEXT: Symbol {
+# CHECK-NEXT: Name:
+# CHECK-NEXT: Value: 0x0
+# CHECK-NEXT: Size: 0
+# CHECK-NEXT: Binding: Local
+# CHECK-NEXT: Type: None
+# CHECK-NEXT: Other: 0
+# CHECK-NEXT: Section: Undefined
+# CHECK-NEXT: }
+# CHECK-NEXT: Symbol {
+# CHECK-NEXT: Name:
+# CHECK-NEXT: Value: 0x201000
+# CHECK-NEXT: Size: 0
+# CHECK-NEXT: Binding: Local
+# CHECK-NEXT: Type: Section
+# CHECK-NEXT: Other: 0
+# CHECK-NEXT: Section: .text
+# CHECK-NEXT: }
+# CHECK-NEXT: Symbol {
+# CHECK-NEXT: Name:
+# CHECK-NEXT: Value: 0x0
+# CHECK-NEXT: Size: 0
+# CHECK-NEXT: Binding: Local
+# CHECK-NEXT: Type: Section
+# CHECK-NEXT: Other: 0
+# CHECK-NEXT: Section: .comment
+# CHECK-NEXT: }
+# CHECK-NEXT: Symbol {
+# CHECK-NEXT: Name: _start
+# CHECK-NEXT: Value: 0x201000
+# CHECK-NEXT: Size: 0
+# CHECK-NEXT: Binding: Global
+# CHECK-NEXT: Type: None
+# CHECK-NEXT: Other: 0
+# CHECK-NEXT: Section: .text
+# CHECK-NEXT: }
+# 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
@@ -628,6 +628,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.138827.patch
Type: text/x-patch
Size: 2931 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180317/f0b0f451/attachment.bin>
More information about the llvm-commits
mailing list