From: Martin Storsjö Date: Wed, 18 Dec 2019 21:58:51 +0000 (+0200) Subject: [LLD] [COFF] Fix reporting duplicate errors for absolute symbols X-Git-Tag: llvmorg-11-init~1770 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=29d8c27c65289d1ed370861ff75f309a689a22cb;p=platform%2Fupstream%2Fllvm.git [LLD] [COFF] Fix reporting duplicate errors for absolute symbols Previously this caused crashes in the reportDuplicate method. A DefinedAbsolute doesn't have any InputFile attached to it, so we can't report the file for the original symbol. We could add an InputFile argument to SymbolTable::addAbsolute only for the sake of error reporting, but even then it'd be assymetrical, only pointing out the file containing the new conflicting definition, not the original one. Differential Revision: https://reviews.llvm.org/D71679 --- diff --git a/lld/COFF/SymbolTable.cpp b/lld/COFF/SymbolTable.cpp index 302b05b..e6f9d70 100644 --- a/lld/COFF/SymbolTable.cpp +++ b/lld/COFF/SymbolTable.cpp @@ -545,6 +545,8 @@ static std::string getSourceLocationObj(ObjFile *file, SectionChunk *sc, static std::string getSourceLocation(InputFile *file, SectionChunk *sc, uint32_t offset, StringRef name) { + if (!file) + return ""; if (auto *o = dyn_cast(file)) return getSourceLocationObj(o, sc, offset, name); if (auto *b = dyn_cast(file)) @@ -566,7 +568,7 @@ void SymbolTable::reportDuplicate(Symbol *existing, InputFile *newFile, llvm::raw_string_ostream os(msg); os << "duplicate symbol: " << toString(*existing); - DefinedRegular *d = cast(existing); + DefinedRegular *d = dyn_cast(existing); if (d && isa(d->getFile())) { os << getSourceLocation(d->getFile(), d->getChunk(), d->getValue(), existing->getName()); diff --git a/lld/test/COFF/duplicate-absolute.s b/lld/test/COFF/duplicate-absolute.s new file mode 100644 index 0000000..0d7e0d3 --- /dev/null +++ b/lld/test/COFF/duplicate-absolute.s @@ -0,0 +1,14 @@ +// REQUIRES: x86 +// RUN: llvm-mc -triple x86_64-windows-msvc -filetype obj -o %t.obj %s +// RUN: echo -e ".globl myabsolute\nmyabsolute = 0" > %t.dupl.s +// RUN: llvm-mc -triple x86_64-windows-msvc -filetype obj -o %t.dupl.obj %t.dupl.s +// RUN: not lld-link /out:%t.exe %t.obj %t.dupl.obj 2>&1 | FileCheck %s + +// CHECK: error: duplicate symbol: myabsolute + +.globl myabsolute +myabsolute = 0 + +.globl entry +entry: + ret