1
1
mirror of https://github.com/rui314/mold.git synced 2024-09-22 10:27:48 +03:00
This commit is contained in:
Rui Ueyama 2021-03-29 16:02:12 +09:00
parent c8531418de
commit 4821453ba3
4 changed files with 51 additions and 51 deletions

View File

@ -340,7 +340,7 @@ void InputSection::apply_reloc_alloc(Context &ctx, u8 *base) {
break;
}
case R_TLSLD:
write(ctx.got->get_tlsld_addr() + A - P);
write(ctx.got->get_tlsld_addr(ctx) + A - P);
break;
case R_TLSLD_RELAX_LE: {
// Relax LD to LE

22
main.cc
View File

@ -568,29 +568,29 @@ static void scan_rels() {
// Assign offsets in additional tables for each dynamic symbol.
for (Symbol *sym : flatten(vec)) {
if (sym->flags & NEEDS_DYNSYM)
ctx.dynsym->add_symbol(sym);
ctx.dynsym->add_symbol(ctx, sym);
if (sym->flags & NEEDS_GOT)
ctx.got->add_got_symbol(sym);
ctx.got->add_got_symbol(ctx, sym);
if (sym->flags & NEEDS_PLT) {
if (sym->flags & NEEDS_GOT)
ctx.pltgot->add_symbol(sym);
ctx.pltgot->add_symbol(ctx, sym);
else
ctx.plt->add_symbol(sym);
ctx.plt->add_symbol(ctx, sym);
}
if (sym->flags & NEEDS_GOTTPOFF)
ctx.got->add_gottpoff_symbol(sym);
ctx.got->add_gottpoff_symbol(ctx, sym);
if (sym->flags & NEEDS_TLSGD)
ctx.got->add_tlsgd_symbol(sym);
ctx.got->add_tlsgd_symbol(ctx, sym);
if (sym->flags & NEEDS_TLSDESC)
ctx.got->add_tlsdesc_symbol(sym);
ctx.got->add_tlsdesc_symbol(ctx, sym);
if (sym->flags & NEEDS_TLSLD)
ctx.got->add_tlsld();
ctx.got->add_tlsld(ctx);
if (sym->flags & NEEDS_COPYREL) {
assert(sym->file->is_dso);
@ -606,7 +606,7 @@ static void scan_rels() {
alias->has_copyrel = true;
alias->value = sym->value;
alias->copyrel_readonly = sym->copyrel_readonly;
ctx.dynsym->add_symbol(alias);
ctx.dynsym->add_symbol(ctx, alias);
}
}
}
@ -1283,7 +1283,7 @@ int main(int argc, char **argv) {
// Sort .dynsym contents. Beyond this point, no symbol will be
// added to .dynsym.
ctx.dynsym->sort_symbols();
ctx.dynsym->sort_symbols(ctx);
// Fill .gnu.version_d section contents.
fill_verdef();
@ -1310,7 +1310,7 @@ int main(int argc, char **argv) {
return chunk->kind == OutputChunk::REGULAR &&
chunk->name == ".eh_frame";
});
ctx.eh_frame->construct();
ctx.eh_frame->construct(ctx);
}
// Now that we have computed sizes for all sections and assigned

24
mold.h
View File

@ -410,18 +410,18 @@ public:
shdr.sh_addralign = GOT_SIZE;
}
void add_got_symbol(Symbol *sym);
void add_gottpoff_symbol(Symbol *sym);
void add_tlsgd_symbol(Symbol *sym);
void add_tlsdesc_symbol(Symbol *sym);
void add_tlsld();
void add_got_symbol(Context &ctx, Symbol *sym);
void add_gottpoff_symbol(Context &ctx, Symbol *sym);
void add_tlsgd_symbol(Context &ctx, Symbol *sym);
void add_tlsdesc_symbol(Context &ctx, Symbol *sym);
void add_tlsld(Context &ctx);
u64 get_tlsld_addr() const {
u64 get_tlsld_addr(Context &ctx) const {
assert(tlsld_idx != -1);
return shdr.sh_addr + tlsld_idx * GOT_SIZE;
}
i64 get_reldyn_size() const;
i64 get_reldyn_size(Context &ctx) const;
void copy_buf(Context &ctx) override;
std::vector<Symbol *> got_syms;
@ -452,7 +452,7 @@ public:
shdr.sh_addralign = 16;
}
void add_symbol(Symbol *sym);
void add_symbol(Context &ctx, Symbol *sym);
void copy_buf(Context &ctx) override;
std::vector<Symbol *> symbols;
@ -467,7 +467,7 @@ public:
shdr.sh_addralign = 8;
}
void add_symbol(Symbol *sym);
void add_symbol(Context &ctx, Symbol *sym);
void copy_buf(Context &ctx) override;
std::vector<Symbol *> symbols;
@ -579,8 +579,8 @@ public:
shdr.sh_addralign = 8;
}
void add_symbol(Symbol *sym);
void sort_symbols();
void add_symbol(Context &ctx, Symbol *sym);
void sort_symbols(Context &ctx);
void update_shdr(Context &ctx) override;
void copy_buf(Context &ctx) override;
@ -659,7 +659,7 @@ public:
shdr.sh_addralign = 8;
}
void construct();
void construct(Context &ctx);
void copy_buf(Context &ctx) override;
u64 get_addr(const Symbol &sym);

View File

@ -211,7 +211,7 @@ void RelDynSection::update_shdr(Context &ctx) {
// .rel.dyn contents are filled by GotSection::copy_buf(Context &ctx) and
// InputSection::apply_reloc_alloc().
i64 offset = ctx.got->get_reldyn_size();
i64 offset = ctx.got->get_reldyn_size(ctx);
for (ObjectFile *file : ctx.objs) {
file->reldyn_offset = offset;
offset += file->num_dynrel * sizeof(ElfRela);
@ -331,21 +331,21 @@ void SymtabSection::copy_buf(Context &ctx) {
});
}
static bool has_init_array() {
static bool has_init_array(Context &ctx) {
for (OutputChunk *chunk : ctx.chunks)
if (chunk->shdr.sh_type == SHT_INIT_ARRAY)
return true;
return false;
}
static bool has_fini_array() {
static bool has_fini_array(Context &ctx) {
for (OutputChunk *chunk : ctx.chunks)
if (chunk->shdr.sh_type == SHT_FINI_ARRAY)
return true;
return false;
}
static std::vector<u64> create_dynamic_section() {
static std::vector<u64> create_dynamic_section(Context &ctx) {
std::vector<u64> vec;
auto define = [&](u64 tag, u64 val) {
@ -393,13 +393,13 @@ static std::vector<u64> create_dynamic_section() {
define(DT_STRSZ, ctx.dynstr->shdr.sh_size);
}
if (has_init_array()) {
if (has_init_array(ctx)) {
define(DT_INIT_ARRAY, ctx.__init_array_start->value);
define(DT_INIT_ARRAYSZ,
ctx.__init_array_end->value - ctx.__init_array_start->value);
}
if (has_fini_array()) {
if (has_fini_array(ctx)) {
define(DT_FINI_ARRAY, ctx.__fini_array_start->value);
define(DT_FINI_ARRAYSZ,
ctx.__fini_array_end->value - ctx.__fini_array_start->value);
@ -463,12 +463,12 @@ void DynamicSection::update_shdr(Context &ctx) {
if (!ctx.arg.shared && ctx.dsos.empty())
return;
shdr.sh_size = create_dynamic_section().size() * 8;
shdr.sh_size = create_dynamic_section(ctx).size() * 8;
shdr.sh_link = ctx.dynstr->shndx;
}
void DynamicSection::copy_buf(Context &ctx) {
std::vector<u64> contents = create_dynamic_section();
std::vector<u64> contents = create_dynamic_section(ctx);
assert(shdr.sh_size == contents.size() * sizeof(contents[0]));
write_vector(ctx.buf + shdr.sh_offset, contents);
}
@ -551,50 +551,50 @@ void OutputSection::copy_buf(Context &ctx) {
});
}
void GotSection::add_got_symbol(Symbol *sym) {
void GotSection::add_got_symbol(Context &ctx, Symbol *sym) {
assert(sym->got_idx == -1);
sym->got_idx = shdr.sh_size / GOT_SIZE;
shdr.sh_size += GOT_SIZE;
got_syms.push_back(sym);
if (sym->is_imported)
ctx.dynsym->add_symbol(sym);
ctx.dynsym->add_symbol(ctx, sym);
}
void GotSection::add_gottpoff_symbol(Symbol *sym) {
void GotSection::add_gottpoff_symbol(Context &ctx, Symbol *sym) {
assert(sym->gottpoff_idx == -1);
sym->gottpoff_idx = shdr.sh_size / GOT_SIZE;
shdr.sh_size += GOT_SIZE;
gottpoff_syms.push_back(sym);
if (sym->is_imported)
ctx.dynsym->add_symbol(sym);
ctx.dynsym->add_symbol(ctx, sym);
}
void GotSection::add_tlsgd_symbol(Symbol *sym) {
void GotSection::add_tlsgd_symbol(Context &ctx, Symbol *sym) {
assert(sym->tlsgd_idx == -1);
sym->tlsgd_idx = shdr.sh_size / GOT_SIZE;
shdr.sh_size += GOT_SIZE * 2;
tlsgd_syms.push_back(sym);
ctx.dynsym->add_symbol(sym);
ctx.dynsym->add_symbol(ctx, sym);
}
void GotSection::add_tlsdesc_symbol(Symbol *sym) {
void GotSection::add_tlsdesc_symbol(Context &ctx, Symbol *sym) {
assert(sym->tlsdesc_idx == -1);
sym->tlsdesc_idx = shdr.sh_size / GOT_SIZE;
shdr.sh_size += GOT_SIZE * 2;
tlsdesc_syms.push_back(sym);
ctx.dynsym->add_symbol(sym);
ctx.dynsym->add_symbol(ctx, sym);
}
void GotSection::add_tlsld() {
void GotSection::add_tlsld(Context &ctx) {
if (tlsld_idx != -1)
return;
tlsld_idx = shdr.sh_size / GOT_SIZE;
shdr.sh_size += GOT_SIZE * 2;
}
i64 GotSection::get_reldyn_size() const {
i64 GotSection::get_reldyn_size(Context &ctx) const {
i64 n = 0;
for (Symbol *sym : got_syms)
if (sym->is_imported || (ctx.arg.pic && sym->is_relative()))
@ -651,7 +651,7 @@ void GotSection::copy_buf(Context &ctx) {
}
if (tlsld_idx != -1)
*rel++ = {get_tlsld_addr(), R_X86_64_DTPMOD64, 0, 0};
*rel++ = {get_tlsld_addr(ctx), R_X86_64_DTPMOD64, 0, 0};
for (Symbol *sym : ctx.dynbss->symbols)
*rel++ = {sym->get_addr(), R_X86_64_COPY, sym->dynsym_idx, 0};
@ -675,7 +675,7 @@ void GotPltSection::copy_buf(Context &ctx) {
buf[sym->gotplt_idx] = sym->get_plt_addr() + 6;
}
void PltSection::add_symbol(Symbol *sym) {
void PltSection::add_symbol(Context &ctx, Symbol *sym) {
assert(sym->plt_idx == -1);
assert(sym->got_idx == -1);
@ -691,7 +691,7 @@ void PltSection::add_symbol(Symbol *sym) {
sym->gotplt_idx = ctx.gotplt->shdr.sh_size / GOT_SIZE;
ctx.gotplt->shdr.sh_size += GOT_SIZE;
ctx.relplt->shdr.sh_size += sizeof(ElfRela);
ctx.dynsym->add_symbol(sym);
ctx.dynsym->add_symbol(ctx, sym);
}
void PltSection::copy_buf(Context &ctx) {
@ -724,7 +724,7 @@ void PltSection::copy_buf(Context &ctx) {
}
}
void PltGotSection::add_symbol(Symbol *sym) {
void PltGotSection::add_symbol(Context &ctx, Symbol *sym) {
assert(sym->plt_idx == -1);
assert(sym->got_idx != -1);
@ -773,7 +773,7 @@ void RelPltSection::copy_buf(Context &ctx) {
}
}
void DynsymSection::add_symbol(Symbol *sym) {
void DynsymSection::add_symbol(Context &ctx, Symbol *sym) {
if (symbols.empty())
symbols.push_back({});
@ -783,7 +783,7 @@ void DynsymSection::add_symbol(Symbol *sym) {
symbols.push_back(sym);
}
void DynsymSection::sort_symbols() {
void DynsymSection::sort_symbols(Context &ctx) {
Timer t("sort_dynsyms");
struct T {
@ -822,7 +822,7 @@ void DynsymSection::sort_symbols() {
ctx.gnu_hash->num_buckets = num_globals / ctx.gnu_hash->LOAD_FACTOR + 1;
ctx.gnu_hash->symoffset = first_global - vec.begin();
tbb::parallel_for_each(first_global, vec.end(), [](T &x) {
tbb::parallel_for_each(first_global, vec.end(), [&](T &x) {
x.hash = gnu_hash(x.sym->name) % ctx.gnu_hash->num_buckets;
});
@ -1102,7 +1102,7 @@ void MergedSection::copy_buf(Context &ctx) {
});
}
void EhFrameSection::construct() {
void EhFrameSection::construct(Context &ctx) {
// Remove dead FDEs and assign them offsets within their corresponding
// CIE group.
tbb::parallel_for((i64)0, (i64)ctx.objs.size(), [&](i64 i) {
@ -1312,7 +1312,7 @@ void DynbssSection::add_symbol(Context &ctx, Symbol *sym) {
sym->has_copyrel = true;
shdr.sh_size += sym->esym->st_size;
symbols.push_back(sym);
ctx.dynsym->add_symbol(sym);
ctx.dynsym->add_symbol(ctx, sym);
}
void VersymSection::update_shdr(Context &ctx) {