[ELF] -r: don't define _TLS_MODULE_BASE_
_TLS_MODULE_BASE_ is supposed to be defined by the final link. Defining it in a relocatable link may render the final link value incorrect. GNU ld i386/x86-64 have the same issue: https://sourceware.org/bugzilla/show_bug.cgi?id=29820
This commit is contained in:
parent
2ec79afd89
commit
8610cb0460
|
@ -1862,7 +1862,6 @@ template <class ELFT> void Writer<ELFT>::finalizeSections() {
|
|||
addOptionalRegular("__global_pointer$", sec ? sec : Out::elfHeader, 0x800,
|
||||
STV_DEFAULT);
|
||||
}
|
||||
}
|
||||
|
||||
if (config->emachine == EM_386 || config->emachine == EM_X86_64) {
|
||||
// On targets that support TLSDESC, _TLS_MODULE_BASE_ is defined in such a
|
||||
|
@ -1870,20 +1869,21 @@ template <class ELFT> void Writer<ELFT>::finalizeSections() {
|
|||
//
|
||||
// 1) Without relaxation: it produces a dynamic TLSDESC relocation that
|
||||
// computes 0.
|
||||
// 2) With LD->LE relaxation: _TLS_MODULE_BASE_@tpoff = 0 (lowest address in
|
||||
// the TLS block).
|
||||
// 2) With LD->LE relaxation: _TLS_MODULE_BASE_@tpoff = 0 (lowest address
|
||||
// in the TLS block).
|
||||
//
|
||||
// 2) is special cased in @tpoff computation. To satisfy 1), we define it as
|
||||
// an absolute symbol of zero. This is different from GNU linkers which
|
||||
// 2) is special cased in @tpoff computation. To satisfy 1), we define it
|
||||
// as an absolute symbol of zero. This is different from GNU linkers which
|
||||
// define _TLS_MODULE_BASE_ relative to the first TLS section.
|
||||
Symbol *s = symtab.find("_TLS_MODULE_BASE_");
|
||||
if (s && s->isUndefined()) {
|
||||
s->resolve(Defined{/*file=*/nullptr, StringRef(), STB_GLOBAL, STV_HIDDEN,
|
||||
STT_TLS, /*value=*/0, 0,
|
||||
s->resolve(Defined{/*file=*/nullptr, StringRef(), STB_GLOBAL,
|
||||
STV_HIDDEN, STT_TLS, /*value=*/0, 0,
|
||||
/*section=*/nullptr});
|
||||
ElfSym::tlsModuleBase = cast<Defined>(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!config->relocatable) {
|
||||
llvm::TimeTraceScope timeScope("Finalize .eh_frame");
|
||||
|
|
|
@ -32,6 +32,14 @@
|
|||
# LE-NEXT: movl %fs:-8(%rax), %edx
|
||||
# LE-NEXT: addl %fs:-4(%rax), %edx
|
||||
|
||||
# RUN: ld.lld -r %t.o -o %t.ro
|
||||
# RUN: llvm-readelf -s %t.ro | FileCheck --check-prefix=RELOCATABLE %s
|
||||
# RUN: ld.lld %t.ro -o %t
|
||||
# RUN: llvm-readelf -r %t | FileCheck --check-prefix=NOREL %s
|
||||
# RUN: llvm-objdump --no-print-imm-hex -d --no-show-raw-insn %t | FileCheck --check-prefix=LE %s
|
||||
|
||||
# RELOCATABLE: 0000000000000000 0 TLS GLOBAL DEFAULT UND _TLS_MODULE_BASE_
|
||||
|
||||
leaq _TLS_MODULE_BASE_@tlsdesc(%rip), %rax
|
||||
call *_TLS_MODULE_BASE_@tlscall(%rax)
|
||||
movl %fs:a@dtpoff(%rax), %edx
|
||||
|
|
Loading…
Reference in New Issue