[lld] r291765 - [ELF] - Do not crash if user section has name equal to one of synthetic sections.

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 12 05:00:33 PST 2017


Author: grimar
Date: Thu Jan 12 07:00:31 2017
New Revision: 291765

URL: http://llvm.org/viewvc/llvm-project?rev=291765&view=rev
Log:
[ELF] - Do not crash if user section has name equal to one of synthetic sections.

Previously we just crashed when had user defined
section .shstrtab, for example. Which name equals to synthetic one,
but have different type.

Testcase reveals an issue.

Differential revision: https://reviews.llvm.org/D28559

Added:
    lld/trunk/test/ELF/incompatible-section-types2.s
Modified:
    lld/trunk/ELF/InputSection.cpp

Modified: lld/trunk/ELF/InputSection.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.cpp?rev=291765&r1=291764&r2=291765&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.cpp (original)
+++ lld/trunk/ELF/InputSection.cpp Thu Jan 12 07:00:31 2017
@@ -36,7 +36,10 @@ using namespace lld::elf;
 // Returns a string to construct an error message.
 template <class ELFT>
 std::string lld::toString(const InputSectionBase<ELFT> *Sec) {
-  return (Sec->getFile()->getName() + ":(" + Sec->Name + ")").str();
+  // File can absent if section is synthetic.
+  std::string FileName =
+      Sec->getFile() ? Sec->getFile()->getName() : "<internal>";
+  return (FileName + ":(" + Sec->Name + ")").str();
 }
 
 template <class ELFT>

Added: lld/trunk/test/ELF/incompatible-section-types2.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/incompatible-section-types2.s?rev=291765&view=auto
==============================================================================
--- lld/trunk/test/ELF/incompatible-section-types2.s (added)
+++ lld/trunk/test/ELF/incompatible-section-types2.s Thu Jan 12 07:00:31 2017
@@ -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 <internal>:(.shstrtab)
+
+.section .shstrtab,""
+.short 20




More information about the llvm-commits mailing list