mirror of
https://github.com/rui314/mold.git
synced 2024-10-26 21:20:46 +03:00
[ELF] Handle GNU-unique symbols as if they were weak
https://github.com/rui314/mold/issues/524
This commit is contained in:
parent
86f3130e44
commit
c4850273c7
@ -819,12 +819,22 @@ static u64 get_rank(InputFile<E> *file, const ElfSym<E> &esym, bool is_lazy) {
|
||||
return (5 << 24) + file->priority;
|
||||
}
|
||||
|
||||
// GCC creates symbols in COMDATs with STB_GNU_UNIQUE instead of
|
||||
// STB_WEAK if it was configured to do so at build time or the
|
||||
// -fgnu-unique flag was given. In order to to not select a
|
||||
// GNU_UNIQUE symbol in a discarded COMDAT section, we treat it as
|
||||
// if it were weak.
|
||||
//
|
||||
// It looks like STB_GNU_UNIQUE is not a popular option anymore and
|
||||
// often disabled by default though.
|
||||
bool is_weak = (esym.st_bind == STB_WEAK || esym.st_bind == STB_GNU_UNIQUE);
|
||||
|
||||
if (file->is_dso || is_lazy) {
|
||||
if (esym.st_bind == STB_WEAK)
|
||||
if (is_weak)
|
||||
return (4 << 24) + file->priority;
|
||||
return (3 << 24) + file->priority;
|
||||
}
|
||||
if (esym.st_bind == STB_WEAK)
|
||||
if (is_weak)
|
||||
return (2 << 24) + file->priority;
|
||||
return (1 << 24) + file->priority;
|
||||
}
|
||||
|
@ -711,9 +711,12 @@ void check_duplicate_symbols(Context<E> &ctx) {
|
||||
const ElfSym<E> &esym = file->elf_syms[i];
|
||||
Symbol<E> &sym = *file->symbols[i];
|
||||
|
||||
// Skip if our symbol is undef or weak
|
||||
// Skip if our symbol is undef or weak. We handle GNU-unique
|
||||
// symbols as if they were weak so that this logic is consistent
|
||||
// with get_rank() in input-files.cc.
|
||||
if (sym.file == file || sym.file == ctx.internal_obj ||
|
||||
esym.is_undef() || esym.is_common() || (esym.st_bind == STB_WEAK))
|
||||
esym.is_undef() || esym.is_common() || (esym.st_bind == STB_WEAK) ||
|
||||
(esym.st_bind == STB_GNU_UNIQUE))
|
||||
continue;
|
||||
|
||||
// Skip if our symbol is in a dead section. In most cases, the
|
||||
|
Loading…
Reference in New Issue
Block a user