[lld] r251454 - [elf2] Don't allocate VA space for TLS NOBITS sections.
Michael J. Spencer via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 27 14:22:55 PDT 2015
Author: mspencer
Date: Tue Oct 27 16:22:54 2015
New Revision: 251454
URL: http://llvm.org/viewvc/llvm-project?rev=251454&view=rev
Log:
[elf2] Don't allocate VA space for TLS NOBITS sections.
Differential Revision: http://reviews.llvm.org/D13838
Added:
lld/trunk/test/elf2/tls.s
Modified:
lld/trunk/ELF/Writer.cpp
Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=251454&r1=251453&r2=251454&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Tue Oct 27 16:22:54 2015
@@ -611,6 +611,15 @@ static uint32_t toPhdrFlags(uint64_t Fla
return Ret;
}
+template <class ELFT>
+static bool consumesVirtualAddressSpace(OutputSectionBase<ELFT> *Sec) {
+ return (Sec->getFlags() & SHF_ALLOC) &&
+ // Don't allocate VA space for TLS NOBITS sections. The PT_TLS PHDR is
+ // responsible for allocating space for them, not the PT_LOAD that
+ // contains the TLS initialization image.
+ !((Sec->getFlags() & SHF_TLS) && Sec->getType() == SHT_NOBITS);
+}
+
// Visits all sections to create PHDRs and to assign incremental,
// non-overlapping addresses to output sections.
template <class ELFT> void Writer<ELFT>::assignAddresses() {
@@ -659,7 +668,7 @@ template <class ELFT> void Writer<ELFT>:
}
}
- if (Sec->getFlags() & SHF_ALLOC) {
+ if (consumesVirtualAddressSpace<ELFT>(Sec)) {
VA = RoundUpToAlignment(VA, Sec->getAlign());
Sec->setVA(VA);
VA += Sec->getSize();
Added: lld/trunk/test/elf2/tls.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/tls.s?rev=251454&view=auto
==============================================================================
--- lld/trunk/test/elf2/tls.s (added)
+++ lld/trunk/test/elf2/tls.s Tue Oct 27 16:22:54 2015
@@ -0,0 +1,93 @@
+// REQUIRES: x86
+// RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
+// RUN: ld.lld2 %t -o %tout
+// RUN: llvm-readobj -sections -program-headers %tout | FileCheck %s
+
+.global _start
+_start:
+
+ .section .tbss,"awT", at nobits
+ .long 0
+
+ .section .tdata,"awT", at progbits
+ .long 1
+
+ .section .thread_bss,"awT", at nobits
+ .long 0
+
+ .section .thread_data,"awT", at progbits
+ .long 2
+
+// CHECK: Name: .tdata
+// CHECK-NEXT: Type: SHT_PROGBITS
+// CHECK-NEXT: Flags [
+// CHECK-NEXT: SHF_ALLOC
+// CHECK-NEXT: SHF_TLS
+// CHECK-NEXT: SHF_WRITE
+// CHECK-NEXT: ]
+// CHECK-NEXT: Address:
+// CHECK-NEXT: Offset:
+// CHECK-NEXT: Size: 4
+// CHECK-NEXT: Link:
+// CHECK-NEXT: Info:
+// CHECK-NEXT: AddressAlignment:
+// CHECK-NEXT: EntrySize:
+// CHECK-NEXT: }
+// CHECK-NEXT: Section {
+// CHECK-NEXT: Index:
+// CHECK-NEXT: Name: .thread_data
+// CHECK-NEXT: Type: SHT_PROGBITS
+// CHECK-NEXT: Flags [
+// CHECK-NEXT: SHF_ALLOC
+// CHECK-NEXT: SHF_TLS
+// CHECK-NEXT: SHF_WRITE
+// CHECK-NEXT: ]
+// CHECK-NEXT: Address:
+// CHECK-NEXT: Offset:
+// CHECK-NEXT: Size: 4
+// CHECK-NEXT: Link:
+// CHECK-NEXT: Info:
+// CHECK-NEXT: AddressAlignment:
+// CHECK-NEXT: EntrySize:
+// CHECK-NEXT: }
+// CHECK-NEXT: Section {
+// CHECK-NEXT: Index:
+// CHECK-NEXT: Name: .tbss
+// CHECK-NEXT: Type: SHT_NOBITS
+// CHECK-NEXT: Flags [
+// CHECK-NEXT: SHF_ALLOC
+// CHECK-NEXT: SHF_TLS
+// CHECK-NEXT: SHF_WRITE
+// CHECK-NEXT: ]
+// CHECK-NEXT: Address:
+// CHECK-NEXT: Offset:
+// CHECK-NEXT: Size: 4
+// CHECK-NEXT: Link:
+// CHECK-NEXT: Info:
+// CHECK-NEXT: AddressAlignment:
+// CHECK-NEXT: EntrySize:
+// CHECK-NEXT: }
+// CHECK-NEXT: Section {
+// CHECK-NEXT: Index:
+// CHECK-NEXT: Name: .thread_bss
+// CHECK-NEXT: Type: SHT_NOBITS
+// CHECK-NEXT: Flags [
+// CHECK-NEXT: SHF_ALLOC
+// CHECK-NEXT: SHF_TLS
+// CHECK-NEXT: SHF_WRITE
+// CHECK-NEXT: ]
+// CHECK-NEXT: Address:
+// CHECK-NEXT: Offset:
+// CHECK-NEXT: Size: 4
+
+// Check that the TLS NOBITS sections weren't added to the R/W PT_LOAD's size.
+
+// CHECK: ProgramHeaders [
+// CHECK: Type: PT_LOAD
+// CHECK: Type: PT_LOAD
+// CHECK: FileSize: 8
+// CHECK-NEXT: MemSize: 8
+// CHECK-NEXT: Flags [
+// CHECK-NEXT: PF_R
+// CHECK-NEXT: PF_W
+// CHECK-NEXT: ]
More information about the llvm-commits
mailing list