[PATCH] D28559: [ELF] - Do not crash if user section has name equal to one of synthetic sections.

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 11 04:54:46 PST 2017


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

Previously we just crashed when had user defined
section .shstrtab, for example. Which name equals to synthetic one.
Testcase reveals an issue.


https://reviews.llvm.org/D28559

Files:
  ELF/InputSection.cpp
  test/ELF/incompatible-section-types2.s


Index: test/ELF/incompatible-section-types2.s
===================================================================
--- test/ELF/incompatible-section-types2.s
+++ test/ELF/incompatible-section-types2.s
@@ -0,0 +1,7 @@
+// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
+// RUN: not ld.lld %t.o -o %t 2>&1 | FileCheck %s
+
+// CHECK: error: Section has different type from others with the same name '.shstrtab'
+
+.section .shstrtab,""
+.short 20
Index: ELF/InputSection.cpp
===================================================================
--- ELF/InputSection.cpp
+++ ELF/InputSection.cpp
@@ -35,6 +35,9 @@
 // Returns a string to construct an error message.
 template <class ELFT>
 std::string lld::toString(const InputSectionBase<ELFT> *Sec) {
+  // File can absent if section is synthetic.
+  if (!Sec->getFile())
+    return ("'" + Sec->Name + "'").str();
   return (Sec->getFile()->getName() + ":(" + Sec->Name + ")").str();
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D28559.83961.patch
Type: text/x-patch
Size: 951 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170111/a67ab2c6/attachment.bin>


More information about the llvm-commits mailing list