diff --git a/lld/ELF/InputSection.cpp b/lld/ELF/InputSection.cpp index cf34a814fed415..a7bb9bd47299e2 100644 --- a/lld/ELF/InputSection.cpp +++ b/lld/ELF/InputSection.cpp @@ -682,6 +682,8 @@ static int64_t getTlsTpOffset(const Symbol &s) { // before TP. The alignment padding is added so that (TP - padding - // p_memsz) is congruent to p_vaddr modulo p_align. PhdrEntry *tls = ctx.tlsPhdr; + if (!tls) // Reported an error in getSymVA + return 0; switch (config->emachine) { // Variant 1. case EM_ARM: diff --git a/lld/ELF/Symbols.cpp b/lld/ELF/Symbols.cpp index 4e1ae819b86fad..13fc6dc0dd572a 100644 --- a/lld/ELF/Symbols.cpp +++ b/lld/ELF/Symbols.cpp @@ -119,9 +119,11 @@ static uint64_t getSymVA(const Symbol &sym, int64_t addend) { // after sections are finalized. (e.g. Measuring the size of .rela.dyn // for Android relocation packing requires knowing TLS symbol addresses // during section finalization.) - if (!ctx.tlsPhdr || !ctx.tlsPhdr->firstSec) - fatal(toString(d.file) + - " has an STT_TLS symbol but doesn't have an SHF_TLS section"); + if (!ctx.tlsPhdr || !ctx.tlsPhdr->firstSec) { + errorOrWarn(toString(d.file) + + " has an STT_TLS symbol but doesn't have a PT_TLS segment"); + return 0; + } return va - ctx.tlsPhdr->firstSec->addr; } return va; diff --git a/lld/test/ELF/invalid/tls-symbol.s b/lld/test/ELF/invalid/tls-symbol.s index 3f371d406e1f2f..1af1e783d1f5b4 100644 --- a/lld/test/ELF/invalid/tls-symbol.s +++ b/lld/test/ELF/invalid/tls-symbol.s @@ -4,7 +4,7 @@ # RUN: yaml2obj %s -o %t.o # RUN: not ld.lld %t.o -o /dev/null 2>&1 | FileCheck %s -# CHECK: has an STT_TLS symbol but doesn't have an SHF_TLS section +# CHECK: has an STT_TLS symbol but doesn't have a PT_TLS segment --- !ELF FileHeader: diff --git a/lld/test/ELF/linkerscript/phdrs-no-tls.test b/lld/test/ELF/linkerscript/phdrs-no-tls.test index 1d5d726b6c9e10..0d374beaf8eee8 100644 --- a/lld/test/ELF/linkerscript/phdrs-no-tls.test +++ b/lld/test/ELF/linkerscript/phdrs-no-tls.test @@ -2,9 +2,11 @@ # REQUIRES: x86 # RUN: rm -rf %t && split-file %s %t && cd %t # RUN: llvm-mc -filetype=obj -triple=x86_64 a.s -o a.o -# RUN: not ld.lld -T a.lds a.o --noinhibit-exec 2>&1 | FileCheck %s --implicit-check-not=warning: +# RUN: not ld.lld -T a.lds a.o +# RUN: ld.lld -T a.lds a.o --noinhibit-exec 2>&1 | FileCheck %s --implicit-check-not=warning: -# CHECK: error: a.o has an STT_TLS symbol but doesn't have an SHF_TLS section +# CHECK: warning: a.o has an STT_TLS symbol but doesn't have a PT_TLS segment +# CHECK-NEXT: warning: a.o has an STT_TLS symbol but doesn't have a PT_TLS segment #--- a.lds PHDRS {