1
1
mirror of https://github.com/rui314/mold.git synced 2024-11-11 05:46:58 +03:00
This commit is contained in:
Rui Ueyama 2021-03-29 23:50:19 +09:00
parent 7f8f6627ea
commit a82e3314e0
5 changed files with 30 additions and 26 deletions

View File

@ -113,10 +113,10 @@ collect_root_set(Context<E> &ctx) {
});
// Add sections referenced by root symbols.
enqueue_symbol(Symbol<E>::intern(ctx.arg.entry));
enqueue_symbol(Symbol<E>::intern(ctx, ctx.arg.entry));
for (std::string_view name : ctx.arg.undefined)
enqueue_symbol(Symbol<E>::intern(name));
enqueue_symbol(Symbol<E>::intern(ctx, name));
// .eh_frame consists of variable-length records called CIE and FDE
// records, and they are a unit of inclusion or exclusion.

12
main.cc
View File

@ -275,7 +275,7 @@ static void resolve_obj_symbols(Context<E> &ctx) {
roots.push_back(file);
for (std::string_view name : ctx.arg.undefined)
if (InputFile<E> *file = Symbol<E>::intern(name)->file)
if (InputFile<E> *file = Symbol<E>::intern(ctx, name)->file)
if (!file->is_alive.exchange(true) && !file->is_dso)
roots.push_back((ObjectFile<E> *)file);
@ -634,7 +634,7 @@ static void apply_version_script(Context<E> &ctx) {
if (!elem.is_extern_cpp &&
elem.pattern.find('*') == elem.pattern.npos) {
Symbol<E>::intern(elem.pattern)->ver_idx = elem.ver_idx;
Symbol<E>::intern(ctx, elem.pattern)->ver_idx = elem.ver_idx;
continue;
}
@ -1038,8 +1038,10 @@ static void fix_synthetic_symbols(Context<E> &ctx) {
// __start_ and __stop_ symbols
for (OutputChunk<E> *chunk : ctx.chunks) {
if (is_c_identifier(chunk->name)) {
start(Symbol<E>::intern_alloc("__start_" + std::string(chunk->name)), chunk);
stop(Symbol<E>::intern_alloc("__stop_" + std::string(chunk->name)), chunk);
std::string *sym1 = new std::string("__start_" + std::string(chunk->name));
std::string *sym2 = new std::string("__stop_" + std::string(chunk->name));
start(Symbol<E>::intern(ctx, *sym1), chunk);
stop(Symbol<E>::intern(ctx, *sym2), chunk);
}
}
}
@ -1185,7 +1187,7 @@ int do_main(int argc, char **argv) {
}
for (std::string_view arg : ctx.arg.trace_symbol)
Symbol<E>::intern(arg)->traced = true;
Symbol<E>::intern(ctx, arg)->traced = true;
// Parse input files
{

22
mold.h
View File

@ -132,17 +132,11 @@ public:
Symbol(std::string_view name) : name(name) {}
Symbol(const Symbol<E> &other) : name(other.name) {}
static Symbol<E> *intern(std::string_view key, std::string_view name) {
static ConcurrentMap<Symbol> map;
return map.insert(key, {name});
}
static Symbol<E> *intern(Context<E> &ctx, std::string_view key,
std::string_view name);
static Symbol<E> *intern(std::string_view name) {
return intern(name, name);
}
static Symbol<E> *intern_alloc(std::string name) {
return intern(*new std::string(name));
static Symbol<E> *intern(Context<E> &ctx, std::string_view name) {
return intern(ctx, name, name);
}
inline u64 get_addr(Context<E> &ctx) const;
@ -1448,6 +1442,14 @@ inline u64 next_power_of_two(u64 val) {
return (u64)1 << (64 - __builtin_clzl(val - 1));
}
template <typename E>
Symbol<E> *Symbol<E>::intern(Context<E> &ctx, std::string_view key,
std::string_view name) {
static ConcurrentMap<Symbol> map;
return map.insert(key, {name});
}
template <typename E>
inline bool Symbol<E>::is_alive() const {
if (frag)

View File

@ -439,7 +439,7 @@ void ObjectFile<E>::initialize_symbols(Context<E> &ctx) {
symvers[i - first_global] = ver.data();
}
this->symbols[i] = Symbol<E>::intern(key, name);
this->symbols[i] = Symbol<E>::intern(ctx, key, name);
if (esym.is_common())
has_common_symbol = true;
@ -1028,7 +1028,7 @@ ObjectFile<E>::ObjectFile(Context<E> &ctx) {
esym.st_visibility = visibility;
esyms->push_back(esym);
Symbol<E> *sym = Symbol<E>::intern(name);
Symbol<E> *sym = Symbol<E>::intern(ctx, name);
this->symbols.push_back(sym);
return sym;
};
@ -1122,14 +1122,14 @@ void SharedFile<E>::parse(Context<E> &ctx) {
std::string_view name = symbol_strtab.data() + esyms[i].st_name;
if (!esyms[i].is_defined()) {
undefs.push_back(Symbol<E>::intern(name));
undefs.push_back(Symbol<E>::intern(ctx, name));
continue;
}
if (vers.empty()) {
elf_syms.push_back(&esyms[i]);
versyms.push_back(VER_NDX_GLOBAL);
this->symbols.push_back(Symbol<E>::intern(name));
this->symbols.push_back(Symbol<E>::intern(ctx, name));
} else {
u16 ver = vers[i] & ~VERSYM_HIDDEN;
if (ver == VER_NDX_LOCAL)
@ -1141,12 +1141,12 @@ void SharedFile<E>::parse(Context<E> &ctx) {
elf_syms.push_back(&esyms[i]);
versyms.push_back(ver);
this->symbols.push_back(Symbol<E>::intern(mangled, name));
this->symbols.push_back(Symbol<E>::intern(ctx, mangled, name));
if (!(vers[i] & VERSYM_HIDDEN)) {
elf_syms.push_back(&esyms[i]);
versyms.push_back(ver);
this->symbols.push_back(Symbol<E>::intern(name));
this->symbols.push_back(Symbol<E>::intern(ctx, name));
}
}
}

View File

@ -32,7 +32,7 @@ void OutputEhdr<E>::copy_buf(Context<E> &ctx) {
hdr.e_machine = EM_X86_64;
hdr.e_version = EV_CURRENT;
if (!ctx.arg.entry.empty())
hdr.e_entry = Symbol<E>::intern(ctx.arg.entry)->get_addr(ctx);
hdr.e_entry = Symbol<E>::intern(ctx, ctx.arg.entry)->get_addr(ctx);
hdr.e_phoff = ctx.phdr->shdr.sh_offset;
hdr.e_shoff = ctx.shdr->shdr.sh_offset;
hdr.e_ehsize = sizeof(ElfEhdr<E>);
@ -453,9 +453,9 @@ static std::vector<u64> create_dynamic_section(Context<E> &ctx) {
define(DT_VERDEFNUM, ctx.verdef->shdr.sh_info);
}
if (Symbol<E> *sym = Symbol<E>::intern(ctx.arg.init); sym->file)
if (Symbol<E> *sym = Symbol<E>::intern(ctx, ctx.arg.init); sym->file)
define(DT_INIT, sym->get_addr(ctx));
if (Symbol<E> *sym = Symbol<E>::intern(ctx.arg.fini); sym->file)
if (Symbol<E> *sym = Symbol<E>::intern(ctx, ctx.arg.fini); sym->file)
define(DT_FINI, sym->get_addr(ctx));
if (ctx.hash)