Skip to content

Commit acdba09

Browse files
committed
[ELF] Change duplicate symbol errors to use errorOrWarn
so that --noinhibit-exec downgrades the error to a warning, which matches GNU ld. Most recoverable errors should use errorOrWarn.
1 parent c7d947f commit acdba09

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

lld/ELF/Symbols.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -539,8 +539,8 @@ void elf::reportDuplicate(const Symbol &sym, const InputFile *newFile,
539539
if (!d->section && !errSec && errOffset && d->value == errOffset)
540540
return;
541541
if (!d->section || !errSec) {
542-
error("duplicate symbol: " + toString(sym) + "\n>>> defined in " +
543-
toString(sym.file) + "\n>>> defined in " + toString(newFile));
542+
errorOrWarn("duplicate symbol: " + toString(sym) + "\n>>> defined in " +
543+
toString(sym.file) + "\n>>> defined in " + toString(newFile));
544544
return;
545545
}
546546

@@ -564,7 +564,7 @@ void elf::reportDuplicate(const Symbol &sym, const InputFile *newFile,
564564
if (!src2.empty())
565565
msg += src2 + "\n>>> ";
566566
msg += obj2;
567-
error(msg);
567+
errorOrWarn(msg);
568568
}
569569

570570
void Symbol::checkDuplicate(const Defined &other) const {

lld/test/ELF/allow-multiple-definition.s

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
# RUN: llvm-objdump --no-print-imm-hex -d %t3 | FileCheck %s
1010
# RUN: llvm-objdump --no-print-imm-hex -d %t4 | FileCheck --check-prefix=REVERT %s
1111

12+
# RUN: ld.lld --noinhibit-exec %t2 %t1 -o /dev/null 2>&1 | FileCheck %s --check-prefix=WARN
13+
# WARN: warning: duplicate symbol: _bar
14+
1215
# RUN: ld.lld -z muldefs --fatal-warnings %t1 %t2 -o %t3
1316
# RUN: ld.lld -z muldefs --fatal-warnings %t2 %t1 -o %t4
1417
# RUN: llvm-objdump --no-print-imm-hex -d %t3 | FileCheck %s

0 commit comments

Comments
 (0)