mirror of
https://github.com/rui314/mold.git
synced 2024-08-17 00:40:36 +03:00
Handle STT_COMMON as a synonym for STT_OBJECT
This commit is contained in:
parent
81b714c4f3
commit
4396784dbd
@ -1063,6 +1063,17 @@ void check_symbol_types(Context<E> &ctx) {
|
||||
append(files, ctx.objs);
|
||||
append(files, ctx.dsos);
|
||||
|
||||
auto canonicalize = [](u32 ty) -> u32 {
|
||||
switch (ty) {
|
||||
case STT_GNU_IFUNC:
|
||||
return STT_FUNC;
|
||||
case STT_COMMON:
|
||||
return STT_OBJECT;
|
||||
default:
|
||||
return ty;
|
||||
}
|
||||
};
|
||||
|
||||
tbb::parallel_for_each(files.begin(), files.end(), [&](InputFile<E> *file) {
|
||||
for (i64 i = file->first_global; i < file->elf_syms.size(); i++) {
|
||||
Symbol<E> &sym = *file->symbols[i];
|
||||
@ -1072,15 +1083,14 @@ void check_symbol_types(Context<E> &ctx) {
|
||||
const ElfSym<E> &esym1 = sym.esym();
|
||||
const ElfSym<E> &esym2 = file->elf_syms[i];
|
||||
|
||||
u32 ty1 = (esym1.st_type == STT_GNU_IFUNC) ? (u32)STT_FUNC : esym1.st_type;
|
||||
u32 ty2 = (esym2.st_type == STT_GNU_IFUNC) ? (u32)STT_FUNC : esym2.st_type;
|
||||
|
||||
if (ty1 != STT_NOTYPE && ty2 != STT_NOTYPE && ty1 != ty2)
|
||||
if (esym1.st_type != STT_NOTYPE && esym2.st_type != STT_NOTYPE &&
|
||||
canonicalize(esym1.st_type) != canonicalize(esym2.st_type)) {
|
||||
Warn(ctx) << "symbol type mismatch: " << sym << '\n'
|
||||
<< ">>> defined in " << *sym.file << " as "
|
||||
<< stt_to_string<E>(esym1.st_type) << '\n'
|
||||
<< ">>> defined in " << *file << " as "
|
||||
<< stt_to_string<E>(esym2.st_type);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
26
test/elf/stt-common.sh
Executable file
26
test/elf/stt-common.sh
Executable file
@ -0,0 +1,26 @@
|
||||
#!/bin/bash
|
||||
. $(dirname $0)/common.inc
|
||||
|
||||
cat <<EOF | $CC -fcommon -xc -c -o $t/a.o - -Wa,--elf-stt-common=yes 2> /dev/null || skip
|
||||
int foo;
|
||||
int bar;
|
||||
int baz = 42;
|
||||
EOF
|
||||
|
||||
cat <<EOF | $CC -fcommon -xc -c -o $t/b.o - -Wa,--elf-stt-common=yes
|
||||
#include <stdio.h>
|
||||
|
||||
int foo;
|
||||
int bar = 5;
|
||||
int baz;
|
||||
|
||||
int main() {
|
||||
printf("%d %d %d\n", foo, bar, baz);
|
||||
}
|
||||
EOF
|
||||
|
||||
$CC -B. -o $t/exe $t/a.o $t/b.o -Wl,--fatal-warnings
|
||||
$QEMU $t/exe | grep -q '0 5 42'
|
||||
|
||||
readelf --sections $t/exe > $t/log
|
||||
grep -q '.common .*NOBITS' $t/log
|
Loading…
Reference in New Issue
Block a user