1
1
mirror of https://github.com/rui314/mold.git synced 2024-09-22 02:20:51 +03:00

Add -warn-common

This commit is contained in:
Rui Ueyama 2021-03-24 01:13:45 +09:00
parent 802f4229c2
commit 4519f8660c
4 changed files with 35 additions and 1 deletions

View File

@ -290,6 +290,10 @@ void parse_nonpositional_args(std::span<std::string_view> args,
} else if (read_flag(args, "stats")) {
config.stats = true;
Counter::enabled = true;
} else if (read_flag(args, "warn-common")) {
config.warn_common = true;
} else if (read_flag(args, "no-warn-common")) {
config.warn_common = false;
} else if (read_z_flag(args, "now")) {
config.z_now = true;
} else if (read_z_flag(args, "execstack")) {

1
mold.h
View File

@ -89,6 +89,7 @@ struct Config {
bool strip_all = false;
bool strip_debug = false;
bool trace = false;
bool warn_common = false;
bool z_copyreloc = true;
bool z_defs = false;
bool z_delete = true;

View File

@ -848,8 +848,11 @@ void ObjectFile::convert_common_symbols() {
continue;
Symbol *sym = symbols[i];
if (sym->file != this)
if (sym->file != this) {
if (config.warn_common)
SyncOut() << *this << ": " << "multiple common symbols: " << *sym;
continue;
}
assert(sym->esym->st_value);

26
test/warn-common.sh Executable file
View File

@ -0,0 +1,26 @@
#!/bin/bash
set -e
cd $(dirname $0)
echo -n "Testing $(basename -s .sh $0) ... "
t=$(pwd)/tmp/$(basename -s .sh $0)
mkdir -p $t
cat <<EOF | clang -fcommon -c -xc -o $t/a.o -
int foo;
EOF
cat <<EOF | clang -fcommon -c -xc -o $t/b.o -
int foo;
int main() {
return 0;
}
EOF
clang -fuse-ld=`pwd`/../mold -o $t/exe $t/a.o $t/b.o
! fgrep -q 'multiple common symbols' $t/log
clang -fuse-ld=`pwd`/../mold -o $t/exe $t/a.o $t/b.o -Wl,-warn-common >& $t/log
fgrep -q 'multiple common symbols' $t/log
echo OK