Skip to content

Commit b6448a0

Browse files
committed
[ELF] Change "no PT_TLS" error to use errorOrWarn
so that --noinhibit-exec downgrades the error to a warning, which helps debugging when `PHDRS` is specified without `PT_TLS`. Also update the message to make it accurate: STT_TLS may exist in the absence of PT_TLS. In addition, invoking `exitLld(1)` (through `fatal`) is problematic (#66974): When a thread is `exitLld(1)`, triggering `llvm_shutdown`, another thread may be at `relocateAlloc`, accessing `sec.relocs()` which got destroyed(tampered?), leading to incorrect `llvm_unreachable("invalid expression")`.
1 parent e26b42c commit b6448a0

File tree

4 files changed

+12
-6
lines changed

4 files changed

+12
-6
lines changed

lld/ELF/InputSection.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,8 @@ static int64_t getTlsTpOffset(const Symbol &s) {
682682
// before TP. The alignment padding is added so that (TP - padding -
683683
// p_memsz) is congruent to p_vaddr modulo p_align.
684684
PhdrEntry *tls = ctx.tlsPhdr;
685+
if (!tls) // Reported an error in getSymVA
686+
return 0;
685687
switch (config->emachine) {
686688
// Variant 1.
687689
case EM_ARM:

lld/ELF/Symbols.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,11 @@ static uint64_t getSymVA(const Symbol &sym, int64_t addend) {
119119
// after sections are finalized. (e.g. Measuring the size of .rela.dyn
120120
// for Android relocation packing requires knowing TLS symbol addresses
121121
// during section finalization.)
122-
if (!ctx.tlsPhdr || !ctx.tlsPhdr->firstSec)
123-
fatal(toString(d.file) +
124-
" has an STT_TLS symbol but doesn't have an SHF_TLS section");
122+
if (!ctx.tlsPhdr || !ctx.tlsPhdr->firstSec) {
123+
errorOrWarn(toString(d.file) +
124+
" has an STT_TLS symbol but doesn't have a PT_TLS segment");
125+
return 0;
126+
}
125127
return va - ctx.tlsPhdr->firstSec->addr;
126128
}
127129
return va;

lld/test/ELF/invalid/tls-symbol.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# RUN: yaml2obj %s -o %t.o
55
# RUN: not ld.lld %t.o -o /dev/null 2>&1 | FileCheck %s
66

7-
# CHECK: has an STT_TLS symbol but doesn't have an SHF_TLS section
7+
# CHECK: has an STT_TLS symbol but doesn't have a PT_TLS segment
88

99
--- !ELF
1010
FileHeader:

lld/test/ELF/linkerscript/phdrs-no-tls.test

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
# REQUIRES: x86
33
# RUN: rm -rf %t && split-file %s %t && cd %t
44
# RUN: llvm-mc -filetype=obj -triple=x86_64 a.s -o a.o
5-
# RUN: not ld.lld -T a.lds a.o --noinhibit-exec 2>&1 | FileCheck %s --implicit-check-not=warning:
5+
# RUN: not ld.lld -T a.lds a.o
6+
# RUN: ld.lld -T a.lds a.o --noinhibit-exec 2>&1 | FileCheck %s --implicit-check-not=warning:
67

7-
# CHECK: error: a.o has an STT_TLS symbol but doesn't have an SHF_TLS section
8+
# CHECK: warning: a.o has an STT_TLS symbol but doesn't have a PT_TLS segment
9+
# CHECK-NEXT: warning: a.o has an STT_TLS symbol but doesn't have a PT_TLS segment
810

911
#--- a.lds
1012
PHDRS {

0 commit comments

Comments
 (0)