mirror of
https://github.com/rui314/mold.git
synced 2024-09-22 02:20:51 +03:00
Export more symbols from executable if they could overwrite dso syms
This commit is contained in:
parent
9c784ce735
commit
a715197be4
2
mold.h
2
mold.h
@ -1012,7 +1012,7 @@ public:
|
||||
|
||||
std::string_view soname;
|
||||
std::vector<std::string_view> version_strings;
|
||||
std::vector<Symbol<E> *> undefs;
|
||||
std::vector<Symbol<E> *> globals;
|
||||
std::vector<const ElfSym<E> *> elf_syms;
|
||||
|
||||
private:
|
||||
|
@ -1241,10 +1241,9 @@ void SharedFile<E>::parse(Context<E> &ctx) {
|
||||
for (i64 i = first_global; i < esyms.size(); i++) {
|
||||
std::string_view name = symbol_strtab.data() + esyms[i].st_name;
|
||||
|
||||
if (!esyms[i].is_defined()) {
|
||||
undefs.push_back(Symbol<E>::intern(ctx, name));
|
||||
globals.push_back(Symbol<E>::intern(ctx, name));
|
||||
if (esyms[i].is_undef())
|
||||
continue;
|
||||
}
|
||||
|
||||
if (vers.empty()) {
|
||||
elf_syms.push_back(&esyms[i]);
|
||||
|
@ -553,9 +553,12 @@ void compute_import_export(Context<E> &ctx) {
|
||||
// Export symbols referenced by DSOs.
|
||||
if (!ctx.arg.shared) {
|
||||
tbb::parallel_for_each(ctx.dsos, [&](SharedFile<E> *file) {
|
||||
for (Symbol<E> *sym : file->undefs)
|
||||
if (sym->file && !sym->file->is_dso && sym->visibility != STV_HIDDEN)
|
||||
for (Symbol<E> *sym : file->globals) {
|
||||
if (sym->file && !sym->file->is_dso && sym->visibility != STV_HIDDEN) {
|
||||
std::lock_guard lock(sym->mu);
|
||||
sym->is_exported = true;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -6,19 +6,25 @@ t=$(pwd)/tmp/$(basename -s .sh $0)
|
||||
mkdir -p $t
|
||||
|
||||
cat <<EOF | cc -o $t/a.o -c -x assembler -
|
||||
.globl _start, expfn
|
||||
.globl _start, expfn1, expfn2
|
||||
_start:
|
||||
expfn:
|
||||
nop
|
||||
expfn1:
|
||||
nop
|
||||
expfn2:
|
||||
nop
|
||||
EOF
|
||||
|
||||
cat <<EOF | cc -shared -o $t/b.so -x assembler -
|
||||
.globl x
|
||||
.globl x, expfn1, expfn2
|
||||
x:
|
||||
call expfn@PLT
|
||||
call expfn1@PLT
|
||||
expfn2:
|
||||
nop
|
||||
EOF
|
||||
|
||||
../mold -o $t/exe $t/a.o $t/b.so
|
||||
readelf --dyn-syms $t/exe | grep -q expfn
|
||||
readelf --dyn-syms $t/exe | grep -q expfn2
|
||||
readelf --dyn-syms $t/exe | grep -q expfn1
|
||||
|
||||
echo OK
|
||||
|
Loading…
Reference in New Issue
Block a user