1
1
mirror of https://github.com/rui314/mold.git synced 2024-11-13 09:39:13 +03:00

[ELF] Fix -exclude_libs option

This commit is contained in:
Rui Ueyama 2021-12-10 17:27:44 +09:00
parent e394fa73d4
commit 10a318d5ba
3 changed files with 33 additions and 1 deletions

View File

@ -796,6 +796,8 @@ void parse_nonpositional_args(Context<E> &ctx,
if (ctx.arg.output.empty())
ctx.arg.output = "a.out";
ctx.arg.undefined.push_back(ctx.arg.entry);
// TLSDESC relocs must be always relaxed for statically-linked
// executables even if -no-relax is given. It is because a
// statically-linked executable doesn't contain a tranpoline

View File

@ -888,7 +888,11 @@ ObjectFile<E>::mark_live_objects(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];
merge_visibility(ctx, sym, exclude_libs ? STV_HIDDEN : esym.st_visibility);
u8 visibility = esym.st_visibility;
if (esym.is_defined() && exclude_libs)
visibility = STV_HIDDEN;
merge_visibility(ctx, sym, visibility);
if (sym.traced) {
if (esym.is_defined())

26
test/elf/exclude-libs3.sh Executable file
View File

@ -0,0 +1,26 @@
#!/bin/bash
set -e
cd $(dirname $0)
mold=`pwd`/../../mold
echo -n "Testing $(basename -s .sh $0) ... "
t=$(pwd)/../../out/test/elf/$(basename -s .sh $0)
mkdir -p $t
cat <<EOF | clang -xc -c -o $t/a.o -
void foo();
void bar() { foo(); }
EOF
rm -f $t/b.a
ar crs $t/b.a $t/a.o
cat <<EOF | clang -xc -c -o $t/c.o -
void bar();
void foo() { bar(); }
EOF
clang -fuse-ld=$mold -shared -o $t/d.so $t/c.o $t/b.a -Wl,-exclude-libs=ALL
readelf --dyn-syms $t/d.so > $t/log
fgrep -q foo $t/log
echo OK