[PATCH] 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
Mon Oct 3 03:50:26 PDT 2016


grimar updated this revision to Diff 73258.
grimar added a comment.

- Addressed review comments.


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,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
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) +
+              " 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:


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D25083.73258.patch
Type: text/x-patch
Size: 1036 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161003/49770afa/attachment.bin>


More information about the llvm-commits mailing list