[PATCH] D25232: [ELF] Do not join input sections when linker creates relocatable object file (-r option)
Eugene Leviant via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 4 05:03:18 PDT 2016
evgeny777 created this revision.
evgeny777 added reviewers: ruiu, rafael.
evgeny777 added subscribers: grimar, ikudrin, llvm-commits.
evgeny777 set the repository for this revision to rL LLVM.
evgeny777 added a project: lld.
When -r option is used lld may end up creating malformed object file. The simplest example is an input file having following sections
.text._init SHT_PROGBITS
.text._fini SHT_PROGBITS
.rela.text._init SHT_RELA
.rela.text._fini SHT_RELA
Given input above lld will produce object file with two relocation sections for a single section .text. If you then pass this file as an input for GNU ld, you'll get error 'File not recognized: bad value'
Repository:
rL LLVM
https://reviews.llvm.org/D25232
Files:
ELF/Writer.cpp
test/ELF/relocatable-sections.s
Index: test/ELF/relocatable-sections.s
===================================================================
--- test/ELF/relocatable-sections.s
+++ test/ELF/relocatable-sections.s
@@ -0,0 +1,30 @@
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t1.o
+# RUN: ld.lld -r %t1.o -o %t
+# RUN: llvm-objdump -section-headers %t | FileCheck %s
+
+# CHECK: .text
+# CHECK-NEXT: .text._init
+# CHECK-NEXT: .text._fini
+# CHECK-NEXT: .rela.text
+# CHECK-NEXT: .rela.text._init
+# CHECK-NEXT: .rela.text._fini
+
+.globl _start
+_start:
+ call foo
+ nop
+
+.section .xxx,"a"
+ .quad 0
+
+.section .text._init,"ax"
+ .quad .xxx
+foo:
+ call bar
+ nop
+
+
+.section .text._fini,"ax"
+ .quad .xxx
+bar:
+ nop
Index: ELF/Writer.cpp
===================================================================
--- ELF/Writer.cpp
+++ ELF/Writer.cpp
@@ -92,6 +92,9 @@
template <class ELFT>
StringRef elf::getOutputSectionName(InputSectionBase<ELFT> *S) {
StringRef Name = S->Name;
+ if (Config->Relocatable)
+ return Name;
+
for (StringRef V :
{".text.", ".rodata.", ".data.rel.ro.", ".data.", ".bss.",
".init_array.", ".fini_array.", ".ctors.", ".dtors.", ".tbss.",
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D25232.73456.patch
Type: text/x-patch
Size: 1194 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161004/af6f4508/attachment.bin>
More information about the llvm-commits
mailing list