[PATCH] D44601: LLD: Avoid segfault with --emit-relocs
Domagoj Stolfa via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 19 20:33:51 PDT 2018
dstolfa updated this revision to Diff 139070.
dstolfa added a comment.
I believe that this fully fixes the issue. It adds a check for `Config->Relocatable` and checks for `OutsecName` correctly.
All tests pass.
https://reviews.llvm.org/D44601
Files:
ELF/LinkerScript.cpp
ELF/Writer.cpp
test/ELF/emit-relocs-eh-frame.s
Index: test/ELF/emit-relocs-eh-frame.s
===================================================================
--- /dev/null
+++ test/ELF/emit-relocs-eh-frame.s
@@ -0,0 +1,17 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t1.o
+# RUN: ld.lld --emit-relocs %t1.o -o %t
+# RUN: llvm-readobj -r %t | FileCheck %s
+
+# CHECK: Relocations [
+# CHECK-NEXT: Section {{.*}} .rela.eh_frame {
+# CHECK-NEXT: 0x{{.*}} R_X86_64_PC32 .text 0x0
+# CHECK-NEXT: }
+# CHECK-NEXT: ]
+
+.globl _start
+.text
+_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 S->Name;
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
@@ -555,6 +555,9 @@
// other REL[A] sections created by linker itself.
if (!isa<SyntheticSection>(IS) &&
(IS->Type == SHT_REL || IS->Type == SHT_RELA)) {
+ if (!Config->Relocatable &&
+ OutsecName.find(".eh_frame") != std::string::npos)
+ return createSection(IS, OutsecName);
auto *Sec = cast<InputSection>(IS);
OutputSection *Out = Sec->getRelocatedSection()->getOutputSection();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D44601.139070.patch
Type: text/x-patch
Size: 1597 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180320/07fdee41/attachment.bin>
More information about the llvm-commits
mailing list