[ELF] TBSS section has to be special cased so that it doesnot occupy memory space
llvm-svn: 183815
This commit is contained in:
parent
6f63001879
commit
d5ff08ca5f
|
@ -581,8 +581,13 @@ template <class ELFT> void DefaultLayout<ELFT>::assignSectionsToSegments() {
|
|||
int64_t lookupSectionFlag = msi->flags();
|
||||
if (!(lookupSectionFlag & llvm::ELF::SHF_WRITE))
|
||||
lookupSectionFlag &= ~llvm::ELF::SHF_EXECINSTR;
|
||||
|
||||
// Merge string sections into Data segment itself
|
||||
lookupSectionFlag &= ~(llvm::ELF::SHF_STRINGS | llvm::ELF::SHF_MERGE);
|
||||
|
||||
// Merge the TLS section into the DATA segment itself
|
||||
lookupSectionFlag &= ~(llvm::ELF::SHF_TLS);
|
||||
|
||||
Segment<ELFT> *segment;
|
||||
// We need a seperate segment for sections that dont have
|
||||
// the segment type to be PT_LOAD
|
||||
|
|
|
@ -30,6 +30,9 @@
|
|||
|
||||
namespace lld {
|
||||
namespace elf {
|
||||
|
||||
template <typename ELFT> class DefaultLayout;
|
||||
|
||||
/// \brief A segment can be divided into segment slices
|
||||
/// depending on how the segments can be split
|
||||
template<class ELFT>
|
||||
|
@ -496,8 +499,13 @@ template <class ELFT> void Segment<ELFT>::assignVirtualAddress(uint64_t &addr) {
|
|||
}
|
||||
if (isTLSSegment)
|
||||
tlsStartAddr += section->memSize();
|
||||
addr += section->memSize();
|
||||
section->setMemSize(addr - section->virtualAddr());
|
||||
section->setMemSize(addr + section->memSize() - section->virtualAddr());
|
||||
// TBSS section is special that it doesnot contribute to memory of any
|
||||
// segment, If we see a tbss section, dont add memory size to addr
|
||||
// The fileOffset is automatically taken care of since TBSS section does
|
||||
// not endup using file size
|
||||
if (section->order() != DefaultLayout<ELFT>::ORDER_TBSS)
|
||||
addr += section->memSize();
|
||||
}
|
||||
slice->setMemSize(addr - slice->virtualAddr());
|
||||
}
|
||||
|
|
Binary file not shown.
|
@ -0,0 +1,8 @@
|
|||
__thread int tls0 = 0;
|
||||
__thread int tls1 = 0;
|
||||
__thread int tls2 = 1;
|
||||
__thread int tls3 = 2;
|
||||
|
||||
int main() {
|
||||
return tls0 + tls1 + tls2;
|
||||
}
|
|
@ -10,8 +10,6 @@ CHECK: LOAD
|
|||
CHECK: flags r-x
|
||||
CHECK: LOAD
|
||||
CHECK: flags rw-
|
||||
CHECK: LOAD
|
||||
CHECK: flags rw-
|
||||
CHECK: DYNAMIC
|
||||
CHECK: flags r--
|
||||
CHECK: TLS
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
# This tests verifies that TLS variables have correct offsets
|
||||
# and that TBSS doesnot occupy memory
|
||||
RUN: lld -flavor gnu -target x86_64-linux %p/Inputs/tlsAddr.x86-64 -static \
|
||||
RUN: -o %t --noinhibit-exec
|
||||
RUN: llvm-objdump -section-headers %t | FileCheck -check-prefix=CHECKADDR %s
|
||||
|
||||
CHECKADDR: 8 .data 00000000 0000000000401008 DATA
|
Loading…
Reference in New Issue