Skip to content

Commit

Permalink
allow-multiple-definitions should completely suppress errors instead …
Browse files Browse the repository at this point in the history
…of making them warnings.

We found that when you pass --allow-multiple-definitions or `-z muldefs`
to GNU linkers, they don't complain about duplicate symbols at all. They
don't even print out warnings on it. We emit warnings in that case.
If you pass --fatal-warnings, that difference results in a link failure.

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

llvm-svn: 327920
  • Loading branch information
rui314 committed Mar 19, 2018
1 parent 6738960 commit 048a669
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
17 changes: 7 additions & 10 deletions lld/ELF/SymbolTable.cpp
Expand Up @@ -410,20 +410,17 @@ Symbol *SymbolTable::addCommon(StringRef N, uint64_t Size, uint32_t Alignment,
return S;
}

static void warnOrError(const Twine &Msg) {
if (Config->AllowMultipleDefinition)
warn(Msg);
else
error(Msg);
}

static void reportDuplicate(Symbol *Sym, InputFile *NewFile) {
warnOrError("duplicate symbol: " + toString(*Sym) + "\n>>> defined in " +
toString(Sym->File) + "\n>>> defined in " + toString(NewFile));
if (!Config->AllowMultipleDefinition)
error("duplicate symbol: " + toString(*Sym) + "\n>>> defined in " +
toString(Sym->File) + "\n>>> defined in " + toString(NewFile));
}

static void reportDuplicate(Symbol *Sym, InputFile *NewFile,
InputSectionBase *ErrSec, uint64_t ErrOffset) {
if (Config->AllowMultipleDefinition)
return;

Defined *D = cast<Defined>(Sym);
if (!D->Section || !ErrSec) {
reportDuplicate(Sym, NewFile);
Expand All @@ -450,7 +447,7 @@ static void reportDuplicate(Symbol *Sym, InputFile *NewFile,
if (!Src2.empty())
Msg += Src2 + "\n>>> ";
Msg += Obj2;
warnOrError(Msg);
error(Msg);
}

Symbol *SymbolTable::addRegular(StringRef Name, uint8_t StOther, uint8_t Type,
Expand Down
8 changes: 4 additions & 4 deletions lld/test/ELF/allow-multiple-definition.s
Expand Up @@ -4,13 +4,13 @@
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/allow-multiple-definition.s -o %t2
# RUN: not ld.lld %t1 %t2 -o %t3
# RUN: not ld.lld --allow-multiple-definition --no-allow-multiple-definition %t1 %t2 -o %t3
# RUN: ld.lld --allow-multiple-definition %t1 %t2 -o %t3
# RUN: ld.lld --allow-multiple-definition %t2 %t1 -o %t4
# RUN: ld.lld --allow-multiple-definition --fatal-warnings %t1 %t2 -o %t3
# RUN: ld.lld --allow-multiple-definition --fatal-warnings %t2 %t1 -o %t4
# RUN: llvm-objdump -d %t3 | FileCheck %s
# RUN: llvm-objdump -d %t4 | FileCheck -check-prefix=REVERT %s

# RUN: ld.lld -z muldefs %t1 %t2 -o %t3
# RUN: ld.lld -z muldefs %t2 %t1 -o %t4
# 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 -d %t3 | FileCheck %s
# RUN: llvm-objdump -d %t4 | FileCheck -check-prefix=REVERT %s

Expand Down

0 comments on commit 048a669

Please sign in to comment.