[ELF] - Do not crash if symbol type set to TLS when there is no tls sections.

id_000021,sig_11,src_000002,op_flip1,pos_92 from PR30540

does not have TLS sections, but type
of one of the symbol is broken and set to STT_TLS,
what resulted in a crash. Patch fixes crash.

DIfferential revision: https://reviews.llvm.org/D25083

llvm-svn: 283198
This commit is contained in:
George Rimar 2016-10-04 08:52:51 +00:00
parent 0c82561c4c
commit 6a3b154aab
3 changed files with 10 additions and 1 deletions

View File

@ -59,8 +59,12 @@ static typename ELFT::uint getSymVA(const SymbolBody &Body,
Addend = 0;
}
uintX_t VA = (SC->OutSec ? SC->OutSec->getVA() : 0) + SC->getOffset(Offset);
if (D.isTls() && !Config->Relocatable)
if (D.isTls() && !Config->Relocatable) {
if (!Out<ELFT>::TlsPhdr)
fatal(getFilename(D.File) +
" has a STT_TLS symbol but doesn't have a PT_TLS section");
return VA - Out<ELFT>::TlsPhdr->p_vaddr;
}
return VA;
}
case SymbolBody::DefinedCommonKind:

Binary file not shown.

View File

@ -0,0 +1,5 @@
# REQUIRES: x86
## The test file contains a STT_TLS symbol but has no TLS section.
# RUN: not ld.lld %S/Inputs/tls-symbol.elf -o %t 2>&1 | FileCheck %s
# CHECK: has a STT_TLS symbol but doesn't have a PT_TLS section