1
1
mirror of https://github.com/rui314/mold.git synced 2024-09-22 10:27:48 +03:00

DSO symbol aliases

This commit is contained in:
Rui Ueyama 2020-11-25 20:35:04 +09:00
parent 278f93d26f
commit f053716009
6 changed files with 32 additions and 14 deletions

11
main.cc
View File

@ -435,8 +435,17 @@ static void scan_rels() {
if (sym->flags & Symbol::NEEDS_TLSLD)
out::got->add_tlsld_symbol(sym);
if (sym->flags & Symbol::NEEDS_COPYREL)
if (sym->flags & Symbol::NEEDS_COPYREL) {
out::copyrel->add_symbol(sym);
assert(sym->file->is_dso);
for (Symbol *alias : ((SharedFile *)sym->file)->find_aliases(sym)) {
assert(alias->copyrel_offset == -1 ||
alias->copyrel_offset == sym->copyrel_offset);
alias->copyrel_offset = sym->copyrel_offset;
out::dynsym->add_symbol(alias);
}
}
}
}

1
mold.h
View File

@ -765,6 +765,7 @@ public:
void parse();
void resolve_symbols();
ArrayRef<Symbol *> find_aliases(Symbol *sym);
StringRef soname;

View File

@ -518,7 +518,7 @@ void ObjectFile::handle_undefined_weak_symbols() {
sym.visibility = esym.getVisibility();
sym.esym = &esym;
sym.is_undef_weak = true;
sym.is_imported = !config.is_static;
sym.is_imported = false;
if (UNLIKELY(sym.traced))
message("trace: " + toString(this) + ": unresolved weak symbol " + sym.name);
@ -706,3 +706,11 @@ std::string toString(InputFile *file) {
return obj->name;
return (obj->archive_name + ":" + obj->name).str();
}
ArrayRef<Symbol *> SharedFile::find_aliases(Symbol *sym) {
assert(sym->file == this);
auto [begin, end] = std::equal_range(
symbols.begin(), symbols.end(), sym,
[&](Symbol *a, Symbol *b) { return a->value < b->value; });
return ArrayRef<Symbol *>(&*begin, end - begin);
}

View File

@ -658,6 +658,10 @@ MergedSection::get_instance(StringRef name, u64 flags, u32 type) {
void CopyrelSection::add_symbol(Symbol *sym) {
assert(sym->is_imported);
if (sym->copyrel_offset != -1)
return;
sym->copyrel_offset = align_to(shdr.sh_size, shdr.sh_addralign);
shdr.sh_size += sym->esym->st_size;
symbols.push_back(sym);

View File

@ -18,17 +18,17 @@
// CHECK: 0x0000000000000001 (NEEDED) Shared library: [libc.so.6]
// CHECK: 0x0000000000000001 (NEEDED) Shared library: [ld-linux-x86-64.so.2]
// CHECK: 0x0000000000000007 (RELA) 0x2001c8
// CHECK: 0x0000000000000008 (RELASZ) 96 (bytes)
// CHECK: 0x0000000000000008 (RELASZ) 24 (bytes)
// CHECK: 0x0000000000000009 (RELAENT) 24 (bytes)
// CHECK: 0x0000000000000017 (JMPREL) 0x2001b0
// CHECK: 0x0000000000000002 (PLTRELSZ) 24 (bytes)
// CHECK: 0x0000000000000003 (PLTGOT) 0x202028
// CHECK: 0x0000000000000014 (PLTREL) RELA
// CHECK: 0x0000000000000006 (SYMTAB) 0x200228
// CHECK: 0x0000000000000006 (SYMTAB) 0x2001e0
// CHECK: 0x000000000000000b (SYMENT) 24 (bytes)
// CHECK: 0x0000000000000005 (STRTAB) 0x2002b8
// CHECK: 0x000000000000000a (STRSZ) 140 (bytes)
// CHECK: 0x0000000000000004 (HASH) 0x200344
// CHECK: 0x0000000000000005 (STRTAB) 0x200228
// CHECK: 0x000000000000000a (STRSZ) 71 (bytes)
// CHECK: 0x0000000000000004 (HASH) 0x200270
// CHECK: 0x0000000000000019 (INIT_ARRAY) 0x2021d0
// CHECK: 0x000000000000001b (INIT_ARRAYSZ) 8 (bytes)
// CHECK: 0x000000000000001a (FINI_ARRAY) 0x2021c8
@ -41,11 +41,8 @@
// DYNAMIC: Symbol table for image:
// DYNAMIC: Num Buc: Value Size Type Bind Vis Ndx Name
// DYNAMIC: 3 1: 0000000000000000 0 NOTYPE WEAK DEFAULT UND _ITM_registerTMCloneTable
// DYNAMIC: 2 1: 0000000000000000 0 NOTYPE WEAK DEFAULT UND _ITM_deregisterTMCloneTab
// DYNAMIC: 5 2: 0000000000000000 204 FUNC GLOBAL DEFAULT UND printf
// DYNAMIC: 1 3: 0000000000000000 0 NOTYPE WEAK DEFAULT UND __gmon_start__
// DYNAMIC: 4 4: 0000000000000000 483 FUNC GLOBAL DEFAULT UND __libc_start_main
// DYNAMIC: 1 1: 0000000000000000 483 FUNC GLOBAL DEFAULT UND __libc_start_main
// DYNAMIC: 2 2: 0000000000000000 204 FUNC GLOBAL DEFAULT UND printf
.globl main
main:

View File

@ -23,7 +23,6 @@
// GOTPLT: 0x00202038 00000000 00000000 16102000 00000000 .......... .....
// RUN: objdump -d -j .plt %t.exe | FileCheck --check-prefix=PLT %s
// PLT: Disassembly of section .plt:
// PLT: 0000000000201000 <printf@plt-0x10>:
// PLT: 201000: ff 35 2a 10 00 00 pushq 0x102a(%rip) # 202030 <_GLOBAL_OFFSET_TABLE_+0x8>
// PLT: 201006: ff 25 2c 10 00 00 jmpq *0x102c(%rip) # 202038 <_GLOBAL_OFFSET_TABLE_+0x10>
@ -31,7 +30,7 @@
// PLT: 0000000000201010 <printf@plt>:
// PLT: 201010: ff 25 2a 10 00 00 jmpq *0x102a(%rip) # 202040 <printf>
// PLT: 201016: 68 00 00 00 00 pushq $0x0
// PLT: 20101b: e9 e0 ff ff ff jmpq 201000 <_IO_stdin_used+0xac8>
// PLT: 20101b: e9 e0 ff ff ff jmpq 201000 <_IO_stdin_used+0xbb8>
.text
.globl main