Skip to content

Commit

Permalink
[ELF] Change duplicate symbol errors to use errorOrWarn
Browse files Browse the repository at this point in the history
so that --noinhibit-exec downgrades the error to a warning, which
matches GNU ld. Most recoverable errors should use errorOrWarn.
MaskRay committed Mar 27, 2024
1 parent c7d947f commit acdba09
Showing 2 changed files with 6 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lld/ELF/Symbols.cpp
Original file line number Diff line number Diff line change
@@ -539,8 +539,8 @@ void elf::reportDuplicate(const Symbol &sym, const InputFile *newFile,
if (!d->section && !errSec && errOffset && d->value == errOffset)
return;
if (!d->section || !errSec) {
error("duplicate symbol: " + toString(sym) + "\n>>> defined in " +
toString(sym.file) + "\n>>> defined in " + toString(newFile));
errorOrWarn("duplicate symbol: " + toString(sym) + "\n>>> defined in " +
toString(sym.file) + "\n>>> defined in " + toString(newFile));
return;
}

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

void Symbol::checkDuplicate(const Defined &other) const {
3 changes: 3 additions & 0 deletions lld/test/ELF/allow-multiple-definition.s
Original file line number Diff line number Diff line change
@@ -9,6 +9,9 @@
# RUN: llvm-objdump --no-print-imm-hex -d %t3 | FileCheck %s
# RUN: llvm-objdump --no-print-imm-hex -d %t4 | FileCheck --check-prefix=REVERT %s

# RUN: ld.lld --noinhibit-exec %t2 %t1 -o /dev/null 2>&1 | FileCheck %s --check-prefix=WARN
# WARN: warning: duplicate symbol: _bar

# RUN: ld.lld -z muldefs --fatal-warnings %t1 %t2 -o %t3
# RUN: ld.lld -z muldefs --fatal-warnings %t2 %t1 -o %t4
# RUN: llvm-objdump --no-print-imm-hex -d %t3 | FileCheck %s

0 comments on commit acdba09

Please sign in to comment.