[PATCH] [Request, 13 lines] D25083: [ELF] - Do not crash if symbol type set to TLS when there is no tls sections.

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 30 02:18:46 PDT 2016


grimar created this revision.
grimar added reviewers: ruiu, rafael, davide.
grimar added subscribers: llvm-commits, grimar, evgeny777.

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.


https://reviews.llvm.org/D25083

Files:
  ELF/Symbols.cpp
  test/ELF/invalid/Inputs/tls-symbol.elf
  test/ELF/invalid/tls-symbol.s


Index: test/ELF/invalid/tls-symbol.s
===================================================================
--- test/ELF/invalid/tls-symbol.s
+++ test/ELF/invalid/tls-symbol.s
@@ -0,0 +1,7 @@
+# REQUIRES: x86
+
+## tls-symbol.elf does not have TLS sections, but type
+## of one of the symbol is broken and set to STT_TLS.
+# RUN: not ld.lld %S/Inputs/tls-symbol.elf \
+# RUN:   -o %t 2>&1 | FileCheck %s
+# CHECK: no PT_TLS program header found when met STT_TLS symbol
Index: ELF/Symbols.cpp
===================================================================
--- ELF/Symbols.cpp
+++ ELF/Symbols.cpp
@@ -59,8 +59,12 @@
       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) +
+              ": no PT_TLS program header found when met STT_TLS symbol");
       return VA - Out<ELFT>::TlsPhdr->p_vaddr;
+    }
     return VA;
   }
   case SymbolBody::DefinedCommonKind:


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D25083.73013.patch
Type: text/x-patch
Size: 1094 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160930/298be0a1/attachment.bin>


More information about the llvm-commits mailing list