[lld] r358981 - [ELF] Change default output section type to SHT_PROGBITS
Andrew Ng via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 23 05:38:53 PDT 2019
Author: anng
Date: Tue Apr 23 05:38:52 2019
New Revision: 358981
URL: http://llvm.org/viewvc/llvm-project?rev=358981&view=rev
Log:
[ELF] Change default output section type to SHT_PROGBITS
This fixes an issue where a symbol only section at the start of a
PT_LOAD segment, causes incorrect alignment of the file offset for the
start of the segment which results in the output of an invalid ELF.
SHT_PROGBITS was the default output section type in the past.
Differential Revision: https://reviews.llvm.org/D60131
Added:
lld/trunk/test/ELF/linkerscript/symbol-only-align.test
Modified:
lld/trunk/ELF/LinkerScript.cpp
lld/trunk/test/ELF/linkerscript/arm-exidx-order.test
lld/trunk/test/ELF/linkerscript/extend-pt-load2.test
lld/trunk/test/ELF/linkerscript/merge-sections.s
lld/trunk/test/ELF/linkerscript/orphan-phdrs.s
lld/trunk/test/ELF/linkerscript/symbol-only-flags.test
Modified: lld/trunk/ELF/LinkerScript.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.cpp?rev=358981&r1=358980&r2=358981&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.cpp (original)
+++ lld/trunk/ELF/LinkerScript.cpp Tue Apr 23 05:38:52 2019
@@ -86,7 +86,7 @@ OutputSection *LinkerScript::createOutpu
// There was a forward reference.
Sec = SecRef;
} else {
- Sec = make<OutputSection>(Name, SHT_NOBITS, 0);
+ Sec = make<OutputSection>(Name, SHT_PROGBITS, 0);
if (!SecRef)
SecRef = Sec;
}
Modified: lld/trunk/test/ELF/linkerscript/arm-exidx-order.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/arm-exidx-order.test?rev=358981&r1=358980&r2=358981&view=diff
==============================================================================
--- lld/trunk/test/ELF/linkerscript/arm-exidx-order.test (original)
+++ lld/trunk/test/ELF/linkerscript/arm-exidx-order.test Tue Apr 23 05:38:52 2019
@@ -13,7 +13,7 @@ SECTIONS {
# CHECK: Section {
# CHECK: Index:
# CHECK: Name: .foo
-# CHECK-NEXT: Type: SHT_NOBITS
+# CHECK-NEXT: Type: SHT_PROGBITS
# CHECK-NEXT: Flags [
# CHECK-NEXT: SHF_ALLOC
# CHECK-NEXT: ]
Modified: lld/trunk/test/ELF/linkerscript/extend-pt-load2.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/extend-pt-load2.test?rev=358981&r1=358980&r2=358981&view=diff
==============================================================================
--- lld/trunk/test/ELF/linkerscript/extend-pt-load2.test (original)
+++ lld/trunk/test/ELF/linkerscript/extend-pt-load2.test Tue Apr 23 05:38:52 2019
@@ -17,8 +17,8 @@ SECTIONS {
}
# CHECK: .text PROGBITS 00000000000001bc 0001bc 000001 00 AX
-# CHECK-NEXT: bar NOBITS 00000000000001bd 0001bd 000e43 00 AX
+# CHECK-NEXT: bar PROGBITS 00000000000001bd 0001bd 000e43 00 AX
# CHECK-NEXT: .data.rel.ro PROGBITS 0000000000001000 001000 000001 00 WA
-# CHECK: LOAD 0x000000 0x0000000000000000 0x0000000000000000 0x0001bd 0x001000 R E
+# CHECK: LOAD 0x000000 0x0000000000000000 0x0000000000000000 0x001000 0x001000 R E
# CHECK-NEXT: LOAD 0x001000 0x0000000000001000 0x0000000000001000 0x000068 0x000068 RW
Modified: lld/trunk/test/ELF/linkerscript/merge-sections.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/merge-sections.s?rev=358981&r1=358980&r2=358981&view=diff
==============================================================================
--- lld/trunk/test/ELF/linkerscript/merge-sections.s (original)
+++ lld/trunk/test/ELF/linkerscript/merge-sections.s Tue Apr 23 05:38:52 2019
@@ -35,7 +35,7 @@
# RUN: llvm-readobj -s -t %t2 | FileCheck %s --check-prefix=GC
# GC: Name: .foo
-# GC-NEXT: Type: SHT_NOBITS
+# GC-NEXT: Type: SHT_PROGBITS
# GC-NEXT: Flags [
# GC-NEXT: SHF_ALLOC
# GC-NEXT: ]
Modified: lld/trunk/test/ELF/linkerscript/orphan-phdrs.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/orphan-phdrs.s?rev=358981&r1=358980&r2=358981&view=diff
==============================================================================
--- lld/trunk/test/ELF/linkerscript/orphan-phdrs.s (original)
+++ lld/trunk/test/ELF/linkerscript/orphan-phdrs.s Tue Apr 23 05:38:52 2019
@@ -23,13 +23,13 @@
# CHECK: Segment Sections
# CHECK-NEXT: .text .orphan
-# CHECK-NEXT: .rw
+# CHECK-NEXT: .empty .rw
-.section .text, "ax"
+.section .text,"ax"
ret
-.section .rw, "aw"
+.section .rw,"aw"
.quad 0
-.section .orphan, "ax"
+.section .orphan,"ax"
ret
Added: lld/trunk/test/ELF/linkerscript/symbol-only-align.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/symbol-only-align.test?rev=358981&view=auto
==============================================================================
--- lld/trunk/test/ELF/linkerscript/symbol-only-align.test (added)
+++ lld/trunk/test/ELF/linkerscript/symbol-only-align.test Tue Apr 23 05:38:52 2019
@@ -0,0 +1,35 @@
+# REQUIRES: x86
+# RUN: echo '.text; ret; .data; .quad 0' > %t.s
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %t.s -o %t.o
+# RUN: ld.lld -o %t --script %s %t.o -shared
+# RUN: llvm-readobj -elf-output-style=GNU -s -t -l %t | FileCheck %s
+
+PHDRS {
+ text PT_LOAD FLAGS(0x5);
+ data PT_LOAD FLAGS(0x6);
+}
+
+SECTIONS {
+ . = SIZEOF_HEADERS;
+ .text : { *(.text) } : text
+ . = ALIGN(CONSTANT(MAXPAGESIZE));
+ foo : { __start_foo = .; *(foo); __end_foo = .; } : data
+ .data : { *(.data) }
+ .dynamic : { *(.dynamic) }
+}
+
+## Check that foo, the symbol only section, has the expected aligned address and
+## file offset. Also check that the section's symbols and the data segment's
+## offset and addresses match.
+
+# CHECK: Section Headers
+# CHECK: foo PROGBITS 0000000000[[ADDR:[0-9a-f]*]] [[ADDR]]
+# CHECK-NEXT: .data PROGBITS 0000000000[[ADDR]] [[ADDR]]
+
+# CHECK: Symbol table
+# CHECK: 0000000000[[ADDR]] 0 NOTYPE GLOBAL DEFAULT {{[0-9]+}} __start_foo
+# CHECK: 0000000000[[ADDR]] 0 NOTYPE GLOBAL DEFAULT {{[0-9]+}} __end_foo
+
+# CHECK: Program Headers
+# CHECK: LOAD
+# CHECK-NEXT: LOAD 0x[[ADDR]] 0x0000000000[[ADDR]] 0x0000000000[[ADDR]]
Modified: lld/trunk/test/ELF/linkerscript/symbol-only-flags.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/symbol-only-flags.test?rev=358981&r1=358980&r2=358981&view=diff
==============================================================================
--- lld/trunk/test/ELF/linkerscript/symbol-only-flags.test (original)
+++ lld/trunk/test/ELF/linkerscript/symbol-only-flags.test Tue Apr 23 05:38:52 2019
@@ -14,7 +14,7 @@ SECTIONS {
# CHECK: Section {
# CHECK: Index:
# CHECK: Name: .foo
-# CHECK-NEXT: Type: SHT_NOBITS
+# CHECK-NEXT: Type: SHT_PROGBITS
# CHECK-NEXT: Flags [
# CHECK-NEXT: SHF_ALLOC
# CHECK-NEXT: SHF_WRITE
More information about the llvm-commits
mailing list