mirror of
https://github.com/rui314/mold.git
synced 2024-09-22 02:20:51 +03:00
Change how to handle --unresolved-symbols=ignore
Previously, we turned unresolved undefined symbols into dynamic symbols. This patch changed the behavior so that such symbols are turned into non-dynamic absolute symbols with value zero. This change is needed by Gentoo's dev-libs/wayland-protocols-1.21 package.
This commit is contained in:
parent
04f82b4b13
commit
9519e4ce20
11
main.cc
11
main.cc
@ -450,11 +450,18 @@ int do_main(int argc, char **argv) {
|
||||
// Convert weak symbols to absolute symbols with value 0.
|
||||
convert_undefined_weak_symbols(ctx);
|
||||
|
||||
// If we do not handle undefined symbols as errors, such symbols
|
||||
// are converted to absolute symbols with value 0.
|
||||
if (ctx.arg.unresolved_symbols != UnresolvedKind::ERROR) {
|
||||
tbb::parallel_for_each(ctx.objs, [&](ObjectFile<E> *file) {
|
||||
file->ignore_unresolved_symbols(ctx);
|
||||
});
|
||||
}
|
||||
|
||||
// If we are linking a .so file, remaining undefined symbols does
|
||||
// not cause a linker error. Instead, they are treated as if they
|
||||
// were imported symbols.
|
||||
if ((ctx.arg.shared && !ctx.arg.z_defs) ||
|
||||
ctx.arg.unresolved_symbols != UnresolvedKind::ERROR) {
|
||||
if (ctx.arg.shared && !ctx.arg.z_defs) {
|
||||
Timer t(ctx, "claim_unresolved_symbols");
|
||||
tbb::parallel_for_each(ctx.objs, [&](ObjectFile<E> *file) {
|
||||
file->claim_unresolved_symbols(ctx);
|
||||
|
1
mold.h
1
mold.h
@ -935,6 +935,7 @@ public:
|
||||
void convert_undefined_weak_symbols(Context<E> &ctx);
|
||||
void resolve_comdat_groups();
|
||||
void eliminate_duplicate_comdat_groups();
|
||||
void ignore_unresolved_symbols(Context<E> &ctx);
|
||||
void claim_unresolved_symbols(Context<E> &ctx);
|
||||
void scan_relocations(Context<E> &ctx);
|
||||
void convert_common_symbols(Context<E> &ctx);
|
||||
|
@ -934,6 +934,34 @@ void ObjectFile<E>::eliminate_duplicate_comdat_groups() {
|
||||
}
|
||||
}
|
||||
|
||||
template <typename E>
|
||||
void ObjectFile<E>::ignore_unresolved_symbols(Context<E> &ctx) {
|
||||
if (!this->is_alive)
|
||||
return;
|
||||
|
||||
for (i64 i = first_global; i < this->symbols.size(); i++) {
|
||||
const ElfSym<E> &esym = elf_syms[i];
|
||||
Symbol<E> &sym = *this->symbols[i];
|
||||
if (esym.is_defined())
|
||||
continue;
|
||||
|
||||
std::lock_guard lock(sym.mu);
|
||||
if (sym.sym_idx == -1 || sym.is_undef()) {
|
||||
if (sym.file && sym.file->priority < this->priority)
|
||||
continue;
|
||||
if (ctx.arg.unresolved_symbols == UnresolvedKind::WARN)
|
||||
Warn(ctx) << "undefined symbol: " << *this << ": " << sym;
|
||||
|
||||
sym.file = this;
|
||||
sym.input_section = nullptr;
|
||||
sym.value = 0;
|
||||
sym.sym_idx = i;
|
||||
sym.is_imported = false;
|
||||
sym.is_exported = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <typename E>
|
||||
void ObjectFile<E>::claim_unresolved_symbols(Context<E> &ctx) {
|
||||
if (!this->is_alive)
|
||||
@ -942,7 +970,6 @@ void ObjectFile<E>::claim_unresolved_symbols(Context<E> &ctx) {
|
||||
for (i64 i = first_global; i < this->symbols.size(); i++) {
|
||||
const ElfSym<E> &esym = elf_syms[i];
|
||||
Symbol<E> &sym = *this->symbols[i];
|
||||
|
||||
if (esym.is_defined())
|
||||
continue;
|
||||
|
||||
@ -951,8 +978,6 @@ void ObjectFile<E>::claim_unresolved_symbols(Context<E> &ctx) {
|
||||
if (sym.file && sym.file->priority < this->priority)
|
||||
continue;
|
||||
|
||||
if (ctx.arg.unresolved_symbols == UnresolvedKind::WARN)
|
||||
Warn(ctx) << "undefined symbol: " << *this << ": " << sym;
|
||||
sym.file = this;
|
||||
sym.value = 0;
|
||||
sym.sym_idx = i;
|
||||
|
@ -17,6 +17,8 @@ cmd="clang -fuse-ld=`pwd`/../mold -o $t/exe $t/a.o"
|
||||
|
||||
$cmd -Wl,-unresolved-symbols=ignore-all
|
||||
|
||||
! readelf --dyn-syms $t/exe | grep -w foo || false
|
||||
|
||||
$cmd -Wl,-unresolved-symbols=report-all -Wl,--warn-unresolved-symbols 2>&1 | \
|
||||
grep -q 'undefined.*foo'
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user