Don't allocate space for SHT_NOBITS sections.

llvm-svn: 246480
This commit is contained in:
Rafael Espindola 2015-08-31 20:23:57 +00:00
parent 742fd989b5
commit 058f343246
2 changed files with 39 additions and 1 deletions

View File

@ -63,6 +63,7 @@ public:
uintX_t getFlags() { return Header.sh_flags; }
uintX_t getFileOff() { return Header.sh_offset; }
uintX_t getAlign() { return Header.sh_addralign; }
uint32_t getType() { return Header.sh_type; }
virtual void finalize() {}
virtual void writeTo(uint8_t *Buf) = 0;
@ -449,7 +450,8 @@ template <class ELFT> void Writer<ELFT>::assignAddresses() {
VA += RoundUpToAlignment(Size, Align);
}
Sec->setFileOffset(FileOff);
FileOff += RoundUpToAlignment(Size, Align);
if (Sec->getType() != SHT_NOBITS)
FileOff += RoundUpToAlignment(Size, Align);
}
// Regular sections.

36
lld/test/elf2/bss.s Normal file
View File

@ -0,0 +1,36 @@
// RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
// RUN: lld -flavor gnu2 %t -o %t2
// RUN: llvm-readobj -sections %t2 | FileCheck %s
// REQUIRES: x86
// Test that bss takes no space on disk.
// CHECK: Name: .bss
// CHECK-NEXT: Type: SHT_NOBITS
// CHECK-NEXT: Flags [
// CHECK-NEXT: SHF_ALLOC
// CHECK-NEXT: SHF_WRITE
// CHECK-NEXT: ]
// CHECK-NEXT: Address: 0x1000
// CHECK-NEXT: Offset: 0x1000
// CHECK-NEXT: Size: 4
// CHECK-NEXT: Link: 0
// CHECK-NEXT: Info: 0
// CHECK-NEXT: AddressAlignment: 4
// CHECK-NEXT: EntrySize: 0
// CHECK-NEXT: }
// CHECK-NEXT: Section {
// CHECK-NEXT: Index:
// CHECK-NEXT: Name:
// CHECK-NEXT: Type:
// CHECK-NEXT: Flags [
// CHECK-NEXT: ]
// CHECK-NEXT: Address:
// CHECK-NEXT: Offset: 0x1000
.global _start
_start:
.bss
.zero 4