[lld] r262650 - [ELF] - Do not allow .bss to occupy the file space when producing relocatable output
George Rimar via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 3 12:24:14 PST 2016
Author: grimar
Date: Thu Mar 3 14:24:14 2016
New Revision: 262650
URL: http://llvm.org/viewvc/llvm-project?rev=262650&view=rev
Log:
[ELF] - Do not allow .bss to occupy the file space when producing relocatable output
When generating relocatable output SHT_NOBITS sections
were still occupy the file space.
Differential revision: http://reviews.llvm.org/D17857
Added:
lld/trunk/test/ELF/relocatable-bss.s
Modified:
lld/trunk/ELF/Writer.cpp
lld/trunk/test/ELF/relocatable.s
Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=262650&r1=262649&r2=262650&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Thu Mar 3 14:24:14 2016
@@ -1327,9 +1327,11 @@ template <class ELFT> void Writer<ELFT>:
Out<ELFT>::ElfHeader->setSize(sizeof(Elf_Ehdr));
uintX_t FileOff = 0;
for (OutputSectionBase<ELFT> *Sec : OutputSections) {
- FileOff = alignTo(FileOff, Sec->getAlign());
+ if (Sec->getType() != SHT_NOBITS)
+ FileOff = alignTo(FileOff, Sec->getAlign());
Sec->setFileOffset(FileOff);
- FileOff += Sec->getSize();
+ if (Sec->getType() != SHT_NOBITS)
+ FileOff += Sec->getSize();
}
SectionHeaderOff = alignTo(FileOff, sizeof(uintX_t));
FileSize = SectionHeaderOff + getNumSections() * sizeof(Elf_Shdr);
Added: lld/trunk/test/ELF/relocatable-bss.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/relocatable-bss.s?rev=262650&view=auto
==============================================================================
--- lld/trunk/test/ELF/relocatable-bss.s (added)
+++ lld/trunk/test/ELF/relocatable-bss.s Thu Mar 3 14:24:14 2016
@@ -0,0 +1,40 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t1.o
+# RUN: ld.lld -r %t1.o -o %t
+# RUN: llvm-readobj -file-headers -sections -program-headers -symbols -r %t | FileCheck %s
+
+## We check here that .bss does not occupy the space in file.
+## If it would, the SectionHeaderOffset would have offset about 5 megabytes.
+# CHECK: ElfHeader {
+# CHECK-NEXT: Ident {
+# CHECK-NEXT: Magic: (7F 45 4C 46)
+# CHECK-NEXT: Class: 64-bit
+# CHECK-NEXT: DataEncoding: LittleEndian
+# CHECK-NEXT: FileVersion: 1
+# CHECK-NEXT: OS/ABI: SystemV
+# CHECK-NEXT: ABIVersion: 0
+# CHECK-NEXT: Unused: (00 00 00 00 00 00 00)
+# CHECK-NEXT: }
+# CHECK-NEXT: Type: Relocatable
+# CHECK-NEXT: Machine: EM_X86_64
+# CHECK-NEXT: Version:
+# CHECK-NEXT: Entry:
+# CHECK-NEXT: ProgramHeaderOffset:
+# CHECK-NEXT: SectionHeaderOffset: 0xA8
+# CHECK-NEXT: Flags [
+# CHECK-NEXT: ]
+# CHECK-NEXT: HeaderSize:
+# CHECK-NEXT: ProgramHeaderEntrySize:
+# CHECK-NEXT: ProgramHeaderCount:
+# CHECK-NEXT: SectionHeaderEntrySize:
+# CHECK-NEXT: SectionHeaderCount:
+# CHECK-NEXT: StringTableSectionIndex:
+# CHECK-NEXT: }
+
+.text
+.globl _start;
+_start:
+ nop
+
+.bss
+ .space 5242880
Modified: lld/trunk/test/ELF/relocatable.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/relocatable.s?rev=262650&r1=262649&r2=262650&view=diff
==============================================================================
--- lld/trunk/test/ELF/relocatable.s (original)
+++ lld/trunk/test/ELF/relocatable.s Thu Mar 3 14:24:14 2016
@@ -30,7 +30,7 @@
# CHECK-NEXT: Version: 1
# CHECK-NEXT: Entry: 0x0
# CHECK-NEXT: ProgramHeaderOffset: 0x0
-# CHECK-NEXT: SectionHeaderOffset: 0x2D8
+# CHECK-NEXT: SectionHeaderOffset: 0x2C0
# CHECK-NEXT: Flags [
# CHECK-NEXT: ]
# CHECK-NEXT: HeaderSize: 64
More information about the llvm-commits
mailing list