Skip to content

Commit

Permalink
Do not optimize absolute symbols in DSOs
Browse files Browse the repository at this point in the history
  • Loading branch information
rui314 committed Feb 1, 2024
1 parent 91a88ee commit 7f8d77d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 26 deletions.
20 changes: 2 additions & 18 deletions elf/passes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1783,20 +1783,6 @@ void parse_symbol_version(Context<E> &ctx) {
});
}

namespace {
template <typename E>
inline bool should_import_absolute_sym(const Symbol<E> *sym) {
#ifdef __sun
// On illumos, symbols with shndx=SHN_ABS and st_value=0 are special
// and should be imported.
return sym->value == 0;
#else
(void)sym;
return false;
#endif
}
} // anonymous namespace

template <typename E>
void compute_import_export(Context<E> &ctx) {
Timer t(ctx, "compute_import_export");
Expand Down Expand Up @@ -1837,10 +1823,8 @@ void compute_import_export(Context<E> &ctx) {
for (Symbol<E> *sym : file->get_global_syms()) {
// If we are using a symbol in a DSO, we need to import it.
if (sym->file && sym->file->is_dso) {
if (!sym->is_absolute() || should_import_absolute_sym(sym)) {
std::scoped_lock lock(sym->mu);
sym->is_imported = true;
}
std::scoped_lock lock(sym->mu);
sym->is_imported = true;
continue;
}

Expand Down
9 changes: 1 addition & 8 deletions test/elf/shared-abs-sym.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,5 @@ $CC -fPIC -c -o $t/d.o $t/c.c
$CC -B. -o $t/exe1 -pie $t/d.o $t/b.so
$QEMU $t/exe1 | grep -q 'foo=0x3'

nm -D $t/exe1 > $t/log1
! grep -q foo $t/log1 || false

$CC -fPIC -c -o $t/e.o $t/c.c
$CC -B. -o $t/exe2 -no-pie $t/e.o $t/b.so
$CC -B. -o $t/exe2 -no-pie $t/d.o $t/b.so
$QEMU $t/exe2 | grep -q 'foo=0x3'

nm -D $t/exe2 > $t/log2
! grep -q foo $t/log2 || false

0 comments on commit 7f8d77d

Please sign in to comment.