[elf2] Fix R_X86_64_TPOFF32 handling.

For x86-64 the initial executable TLS block is placed directly before the
thread specific data register so compilers can directly access it via
R_X86_64_TPOFF32. Generate the correct (negative) offset for this case.

llvm-svn: 252131
This commit is contained in:
Michael J. Spencer 2015-11-05 02:00:35 +00:00
parent 776e4a7da7
commit 6c34eff536
4 changed files with 11 additions and 6 deletions

View File

@ -372,6 +372,7 @@ template <class ELFT> struct Out {
static SymbolTableSection<ELFT> *DynSymTab;
static SymbolTableSection<ELFT> *SymTab;
static uintX_t TlsInitImageVA;
static size_t TlsInitImageAlignedSize;
};
template <class ELFT> DynamicSection<ELFT> *Out<ELFT>::Dynamic;
@ -392,6 +393,7 @@ template <class ELFT> StringTableSection<ELFT> *Out<ELFT>::StrTab;
template <class ELFT> SymbolTableSection<ELFT> *Out<ELFT>::DynSymTab;
template <class ELFT> SymbolTableSection<ELFT> *Out<ELFT>::SymTab;
template <class ELFT> typename Out<ELFT>::uintX_t Out<ELFT>::TlsInitImageVA;
template <class ELFT> size_t Out<ELFT>::TlsInitImageAlignedSize;
} // namespace elf2
} // namespace lld

View File

@ -340,7 +340,7 @@ void X86_64TargetInfo::relocateOne(uint8_t *Loc, uint8_t *BufEnd, uint32_t Type,
write32le(Loc, SA);
break;
case R_X86_64_TPOFF32:
write32le(Loc, SA);
write32le(Loc, SA - Out<llvm::object::ELF64LE>::TlsInitImageAlignedSize);
break;
default:
error("unrecognized reloc " + Twine(Type));

View File

@ -740,8 +740,11 @@ template <class ELFT> void Writer<ELFT>::assignAddresses() {
}
}
if (TlsPhdr.p_vaddr)
if (TlsPhdr.p_vaddr) {
Phdrs[++PhdrIdx] = TlsPhdr;
Out<ELFT>::TlsInitImageAlignedSize =
RoundUpToAlignment(TlsPhdr.p_memsz, TlsPhdr.p_align);
}
// Add an entry for .dynamic.
if (isOutputDynamic()) {

View File

@ -164,7 +164,7 @@ d:
// DIS: Disassembly of section .text:
// DIS-NEXT: _start:
// DIS-NEXT: 11000: {{.+}} movl %fs:8, %eax
// DIS-NEXT: 11008: {{.+}} movl %fs:0, %eax
// DIS-NEXT: 11010: {{.+}} movl %fs:12, %eax
// DIS-NEXT: 11018: {{.+}} movl %fs:4, %eax
// DIS-NEXT: 11000: {{.+}} movl %fs:-8, %eax
// DIS-NEXT: 11008: {{.+}} movl %fs:-16, %eax
// DIS-NEXT: 11010: {{.+}} movl %fs:-4, %eax
// DIS-NEXT: 11018: {{.+}} movl %fs:-12, %eax