[lld] r320437 - [ELF] Change default output section type to SHT_NOBITS
Jake Ehrlich via llvm-commits
llvm-commits at lists.llvm.org
Mon Dec 11 15:25:27 PST 2017
Author: jakehehrlich
Date: Mon Dec 11 15:25:27 2017
New Revision: 320437
URL: http://llvm.org/viewvc/llvm-project?rev=320437&view=rev
Log:
[ELF] Change default output section type to SHT_NOBITS
When an output section has no byte commands and has no input sections then it
would be ideal if the type of the section is SHT_NOBITS so that the file can
take up less space. This change sets the default type of of output sections to
SHT_NOBITS instead of SHT_PROGBITS to allow this. This required some minor test
changes (which double as tests for this new behavior) but extend-pt-load.s had
be changed in a non-trivial way. Since it seems to me that the point of the
test is to point out the consequences of how flags are assigned to output
sections that don't have input sections I changed the test to work and still
show how the memsize of the executable segment was changed.
Differential Revision: https://reviews.llvm.org/D41082
Modified:
lld/trunk/ELF/LinkerScript.cpp
lld/trunk/ELF/OutputSections.cpp
lld/trunk/test/ELF/linkerscript/arm-exidx-order.s
lld/trunk/test/ELF/linkerscript/extend-pt-load.s
lld/trunk/test/ELF/linkerscript/merge-sections.s
lld/trunk/test/ELF/linkerscript/symbol-only-flags.s
lld/trunk/test/ELF/linkerscript/symbol-only.s
Modified: lld/trunk/ELF/LinkerScript.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.cpp?rev=320437&r1=320436&r2=320437&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.cpp (original)
+++ lld/trunk/ELF/LinkerScript.cpp Mon Dec 11 15:25:27 2017
@@ -87,7 +87,7 @@ OutputSection *LinkerScript::createOutpu
// There was a forward reference.
Sec = SecRef;
} else {
- Sec = make<OutputSection>(Name, SHT_PROGBITS, 0);
+ Sec = make<OutputSection>(Name, SHT_NOBITS, 0);
if (!SecRef)
SecRef = Sec;
}
Modified: lld/trunk/ELF/OutputSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.cpp?rev=320437&r1=320436&r2=320437&view=diff
==============================================================================
--- lld/trunk/ELF/OutputSections.cpp (original)
+++ lld/trunk/ELF/OutputSections.cpp Mon Dec 11 15:25:27 2017
@@ -312,6 +312,8 @@ template <class ELFT> void OutputSection
Sections.push_back(IS);
}
}
+ if (isa<ByteCommand>(Base) && Type == SHT_NOBITS)
+ Type = SHT_PROGBITS;
}
if (Flags & SHF_LINK_ORDER) {
Modified: lld/trunk/test/ELF/linkerscript/arm-exidx-order.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/arm-exidx-order.s?rev=320437&r1=320436&r2=320437&view=diff
==============================================================================
--- lld/trunk/test/ELF/linkerscript/arm-exidx-order.s (original)
+++ lld/trunk/test/ELF/linkerscript/arm-exidx-order.s Mon Dec 11 15:25:27 2017
@@ -9,7 +9,7 @@
# CHECK: Section {
# CHECK: Index:
# CHECK: Name: .foo
-# CHECK-NEXT: Type: SHT_PROGBITS
+# CHECK-NEXT: Type: SHT_NOBITS
# CHECK-NEXT: Flags [
# CHECK-NEXT: SHF_ALLOC
# CHECK-NEXT: ]
Modified: lld/trunk/test/ELF/linkerscript/extend-pt-load.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/extend-pt-load.s?rev=320437&r1=320436&r2=320437&view=diff
==============================================================================
--- lld/trunk/test/ELF/linkerscript/extend-pt-load.s (original)
+++ lld/trunk/test/ELF/linkerscript/extend-pt-load.s Mon Dec 11 15:25:27 2017
@@ -33,18 +33,17 @@
# RUN: .hash : { } \
# RUN: .dynstr : { } \
# RUN: .text : { *(.text) } \
-# RUN: . = ALIGN(0x1000); \
-# RUN: bar : { HIDDEN(bar_sym = .); } \
+# RUN: bar : { . = ALIGN(0x1000); } \
# RUN: .data.rel.ro : { *(.data.rel.ro) } \
# RUN: }" > %t.script
# RUN: ld.lld --hash-style=sysv -o %t2 --script %t.script %t.o -shared
# RUN: llvm-readobj --elf-output-style=GNU -l -s %t2 | FileCheck --check-prefix=CHECK2 %s
# CHECK2: .text PROGBITS 00000000000001bc 0001bc 000001 00 AX
-# CHECK2-NEXT: bar PROGBITS 0000000000001000 001000 000000 00 AX
+# CHECK2-NEXT: bar NOBITS 00000000000001bd 0001bd 000e43 00 AX
# CHECK2-NEXT: .data.rel.ro PROGBITS 0000000000001000 001000 000001 00 WA
-# CHECK2: LOAD 0x000000 0x0000000000000000 0x0000000000000000 0x001000 0x001000 R E
+# CHECK2: LOAD 0x000000 0x0000000000000000 0x0000000000000000 0x0001bd 0x001000 R E
# CHECK2-NEXT: LOAD 0x001000 0x0000000000001000 0x0000000000001000 0x000068 0x000068 RW
# If the current behavior becomes a problem we should consider just moving the commands out
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=320437&r1=320436&r2=320437&view=diff
==============================================================================
--- lld/trunk/test/ELF/linkerscript/merge-sections.s (original)
+++ lld/trunk/test/ELF/linkerscript/merge-sections.s Mon Dec 11 15:25:27 2017
@@ -36,7 +36,7 @@
# RUN: llvm-readobj -s -t %t2 | FileCheck %s --check-prefix=GC
# GC: Name: .foo
-# GC-NEXT: Type: SHT_PROGBITS
+# GC-NEXT: Type: SHT_NOBITS
# GC-NEXT: Flags [
# GC-NEXT: SHF_ALLOC
# GC-NEXT: ]
Modified: lld/trunk/test/ELF/linkerscript/symbol-only-flags.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/symbol-only-flags.s?rev=320437&r1=320436&r2=320437&view=diff
==============================================================================
--- lld/trunk/test/ELF/linkerscript/symbol-only-flags.s (original)
+++ lld/trunk/test/ELF/linkerscript/symbol-only-flags.s Mon Dec 11 15:25:27 2017
@@ -10,7 +10,7 @@
# CHECK: Section {
# CHECK: Index:
# CHECK: Name: .foo
-# CHECK-NEXT: Type: SHT_PROGBITS
+# CHECK-NEXT: Type: SHT_NOBITS
# CHECK-NEXT: Flags [
# CHECK-NEXT: SHF_ALLOC
# CHECK-NEXT: SHF_WRITE
Modified: lld/trunk/test/ELF/linkerscript/symbol-only.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/symbol-only.s?rev=320437&r1=320436&r2=320437&view=diff
==============================================================================
--- lld/trunk/test/ELF/linkerscript/symbol-only.s (original)
+++ lld/trunk/test/ELF/linkerscript/symbol-only.s Mon Dec 11 15:25:27 2017
@@ -12,7 +12,7 @@
# CHECK: Sections:
# CHECK-NEXT: Idx Name Size Address
# CHECK-NEXT: 0 00000000 0000000000000000
-# CHECK: abc 00000000 [[ADDR:[0-9a-f]*]] DATA
+# CHECK: abc 00000000 [[ADDR:[0-9a-f]*]] BSS
# CHECK-NEXT: bar 00000000 0000000000001000 DATA
# CHECK: SYMBOL TABLE:
More information about the llvm-commits
mailing list