mirror of
https://github.com/rui314/mold.git
synced 2024-09-21 09:57:18 +03:00
Do not add unreferenced DSO symbols to .dynsym
This commit is contained in:
parent
508702b18b
commit
ccd27807aa
@ -417,11 +417,9 @@ void scan_rels(Context<E> &ctx) {
|
||||
|
||||
tbb::parallel_for((i64)0, (i64)files.size(), [&](i64 i) {
|
||||
for (Symbol<E> *sym : files[i]->symbols) {
|
||||
if (sym->file != files[i])
|
||||
continue;
|
||||
if (sym->is_imported || sym->is_exported)
|
||||
if (!files[i]->is_dso && (sym->is_imported || sym->is_exported))
|
||||
sym->flags |= NEEDS_DYNSYM;
|
||||
if (sym->flags)
|
||||
if (sym->file == files[i] && sym->flags)
|
||||
vec[i].push_back(sym);
|
||||
}
|
||||
});
|
||||
|
@ -18,17 +18,17 @@ EOF
|
||||
clang -fuse-ld=`pwd`/../mold -o $t/exe $t/a.o
|
||||
readelf -a $t/exe > $t/log
|
||||
|
||||
grep -Pq '\(INIT\)\s+0x233010' $t/log
|
||||
grep -Pq '\(FINI\)\s+0x233000' $t/log
|
||||
grep -Pq '0000000000233010\s+0 FUNC GLOBAL HIDDEN \d+ _init$' $t/log
|
||||
grep -Pq '0000000000233000\s+0 FUNC GLOBAL HIDDEN \d+ _fini$' $t/log
|
||||
grep -Pq '\(INIT\)\s+0x201010' $t/log
|
||||
grep -Pq '\(FINI\)\s+0x201000' $t/log
|
||||
grep -Pq '0000000000201010\s+0 FUNC GLOBAL HIDDEN \d+ _init$' $t/log
|
||||
grep -Pq '0000000000201000\s+0 FUNC GLOBAL HIDDEN \d+ _fini$' $t/log
|
||||
|
||||
clang -fuse-ld=`pwd`/../mold -o $t/exe $t/a.o -Wl,-init,init -Wl,-fini,fini
|
||||
readelf -a $t/exe > $t/log
|
||||
|
||||
grep -Pq '\(INIT\)\s+0x233119' $t/log
|
||||
grep -Pq '\(FINI\)\s+0x23311a' $t/log
|
||||
grep -Pq '0000000000233119\s+0 NOTYPE GLOBAL DEFAULT \d+ init$' $t/log
|
||||
grep -Pq '000000000023311a\s+0 NOTYPE GLOBAL DEFAULT \d+ fini$' $t/log
|
||||
grep -Pq '\(INIT\)\s+0x201119' $t/log
|
||||
grep -Pq '\(FINI\)\s+0x20111a' $t/log
|
||||
grep -Pq '0000000000201119\s+0 NOTYPE GLOBAL DEFAULT \d+ init$' $t/log
|
||||
grep -Pq '000000000020111a\s+0 NOTYPE GLOBAL DEFAULT \d+ fini$' $t/log
|
||||
|
||||
echo OK
|
||||
|
@ -6,10 +6,12 @@ t=$(pwd)/tmp/$(basename -s .sh $0)
|
||||
mkdir -p $t
|
||||
|
||||
cat <<EOF | clang -fPIC -c -o $t/a.o -x assembler -
|
||||
.globl fn1, fn2
|
||||
.globl fn1, fn2, fn3
|
||||
fn1:
|
||||
call fn2@PLT
|
||||
ret
|
||||
fn3:
|
||||
nop
|
||||
EOF
|
||||
|
||||
clang -shared -fuse-ld=`pwd`/../mold -o $t/b.so $t/a.o
|
||||
@ -17,7 +19,7 @@ clang -shared -fuse-ld=`pwd`/../mold -o $t/b.so $t/a.o
|
||||
readelf --dyn-syms $t/b.so > $t/log
|
||||
|
||||
grep -q '0000000000000000 0 NOTYPE GLOBAL DEFAULT UND fn2' $t/log
|
||||
grep -q '000000000003311c 0 NOTYPE GLOBAL DEFAULT 15 fn1' $t/log
|
||||
grep -q '000000000000111c 0 NOTYPE GLOBAL DEFAULT 15 fn1' $t/log
|
||||
|
||||
cat <<EOF | clang -fPIC -c -o $t/c.o -xc -
|
||||
#include <stdio.h>
|
||||
@ -36,5 +38,6 @@ EOF
|
||||
|
||||
clang -fuse-ld=`pwd`/../mold -o $t/exe $t/c.o $t/b.so
|
||||
$t/exe | grep -q hello
|
||||
! readelf --symbols $t/exe | grep -q fn3 || false
|
||||
|
||||
echo OK
|
||||
|
Loading…
Reference in New Issue
Block a user