[ELF] Fix nullptr dereference when creating an error message for a synthetic section.

Differential Revision: https://reviews.llvm.org/D34752

llvm-svn: 307162
This commit is contained in:
Sean Eveson 2017-07-05 14:55:43 +00:00
parent ef7aff507b
commit d54759b236
2 changed files with 13 additions and 1 deletions

View File

@ -276,7 +276,9 @@ template <class ELFT> std::string InputSectionBase::getSrcMsg(uint64_t Offset) {
template <class ELFT> std::string InputSectionBase::getObjMsg(uint64_t Off) { template <class ELFT> std::string InputSectionBase::getObjMsg(uint64_t Off) {
// Synthetic sections don't have input files. // Synthetic sections don't have input files.
elf::ObjectFile<ELFT> *File = getFile<ELFT>(); elf::ObjectFile<ELFT> *File = getFile<ELFT>();
std::string Filename = File ? File->getName() : "(internal)"; if (!File)
return ("(internal):(" + Name + "+0x" + utohexstr(Off) + ")").str();
std::string Filename = File->getName();
std::string Archive; std::string Archive;
if (!File->ArchiveName.empty()) if (!File->ArchiveName.empty())

View File

@ -0,0 +1,10 @@
// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
// RUN: cd %S
// RUN: not ld.lld %t.o --format=binary duplicated-synthetic-sym.s -o %t.elf 2>&1 | FileCheck %s
// CHECK: duplicate symbol: _binary_duplicated_synthetic_sym_s_start
// CHECK: defined at (internal):(.data+0x0)
.globl _binary_duplicated_synthetic_sym_s_start
_binary_duplicated_synthetic_sym_s_start:
.long 0