1
1
mirror of https://github.com/rui314/mold.git synced 2024-11-11 16:58:12 +03:00

Export symbols from executables

This commit is contained in:
Rui Ueyama 2021-02-21 00:23:53 +09:00
parent 9814405864
commit d8381f7e74
4 changed files with 17 additions and 5 deletions

View File

@ -360,6 +360,13 @@ static void scan_rels() {
// Exit if there was a relocation that refers an undefined symbol.
Error::checkpoint();
// Export symbols referenced by DSOs.
tbb::parallel_for_each(out::dsos, [&](SharedFile *file) {
for (Symbol *sym : file->undefs)
if (sym->file && !sym->file->is_dso)
sym->flags |= NEEDS_DYNSYM;
});
// Aggregate dynamic symbols to a single vector.
std::vector<InputFile *> files;
append(files, out::objs);

1
mold.h
View File

@ -977,6 +977,7 @@ public:
std::string_view soname;
std::vector<std::string_view> version_strings;
std::vector<Symbol *> undefs;
private:
std::string_view get_soname();

View File

@ -874,15 +874,18 @@ void SharedFile::parse() {
vers = get_data<u16>(*sec);
for (i64 i = first_global; i < esyms.size(); i++) {
if (!esyms[i].is_defined())
continue;
if (!vers.empty() && (vers[i] >> 15) == 1)
continue;
std::string_view name = symbol_strtab.data() + esyms[i].st_name;
elf_syms.push_back(&esyms[i]);
versyms.push_back(vers.empty() ? 1 : vers[i]);
symbols.push_back(Symbol::intern(name));
if (esyms[i].is_defined()) {
elf_syms.push_back(&esyms[i]);
versyms.push_back(vers.empty() ? 1 : vers[i]);
symbols.push_back(Symbol::intern(name));
} else {
undefs.push_back(Symbol::intern(name));
}
}
static Counter counter("dso_syms");

View File

@ -18,5 +18,6 @@ x:
EOF
../mold -o $t/exe $t/a.o $t/b.so
readelf --dyn-syms $t/exe | grep -q expfn
echo OK