mirror of
https://github.com/rui314/mold.git
synced 2024-10-04 16:48:04 +03:00
Refactor
This commit is contained in:
parent
d0ab7d9e17
commit
0542a2254b
@ -1092,14 +1092,14 @@ void ObjectFile<E>::compute_symtab(Context<E> &ctx) {
|
||||
|
||||
template <typename E>
|
||||
void ObjectFile<E>::write_symtab(Context<E> &ctx) {
|
||||
u8 *symtab_base = ctx.buf + ctx.symtab->shdr.sh_offset;
|
||||
ElfSym<E> *symtab_base = (ElfSym<E> *)(ctx.buf + ctx.symtab->shdr.sh_offset);
|
||||
i64 symtab_idx;
|
||||
|
||||
u8 *strtab_base = ctx.buf + ctx.strtab->shdr.sh_offset;
|
||||
i64 strtab_off = strtab_offset;
|
||||
i64 symtab_off;
|
||||
|
||||
auto write_sym = [&](Symbol<E> &sym) {
|
||||
ElfSym<E> &esym = *(ElfSym<E> *)(symtab_base + symtab_off);
|
||||
symtab_off += sizeof(esym);
|
||||
ElfSym<E> &esym = symtab_base[symtab_idx++];
|
||||
|
||||
esym = sym.esym();
|
||||
esym.st_name = strtab_off;
|
||||
@ -1122,14 +1122,14 @@ void ObjectFile<E>::write_symtab(Context<E> &ctx) {
|
||||
strtab_off += sym.name().size() + 1;
|
||||
};
|
||||
|
||||
symtab_off = local_symtab_offset;
|
||||
symtab_idx = local_symtab_idx;
|
||||
for (i64 i = 1; i < this->first_global; i++) {
|
||||
Symbol<E> &sym = *this->symbols[i];
|
||||
if (sym.write_to_symtab)
|
||||
write_sym(sym);
|
||||
}
|
||||
|
||||
symtab_off = global_symtab_offset;
|
||||
symtab_idx = global_symtab_idx;
|
||||
for (i64 i = this->first_global; i < this->elf_syms.size(); i++) {
|
||||
Symbol<E> &sym = *this->symbols[i];
|
||||
if (sym.file == this && sym.write_to_symtab)
|
||||
|
@ -1007,8 +1007,8 @@ public:
|
||||
u64 num_dynrel = 0;
|
||||
u64 reldyn_offset = 0;
|
||||
|
||||
u64 local_symtab_offset = 0;
|
||||
u64 global_symtab_offset = 0;
|
||||
u64 local_symtab_idx = 0;
|
||||
u64 global_symtab_idx = 0;
|
||||
u64 num_local_symtab = 0;
|
||||
u64 num_global_symtab = 0;
|
||||
u64 strtab_offset = 0;
|
||||
|
@ -458,26 +458,21 @@ void DynstrSection<E>::copy_buf(Context<E> &ctx) {
|
||||
|
||||
template <typename E>
|
||||
void SymtabSection<E>::update_shdr(Context<E> &ctx) {
|
||||
this->shdr.sh_size = sizeof(ElfSym<E>);
|
||||
i64 nsyms = 1;
|
||||
|
||||
for (ObjectFile<E> *file : ctx.objs) {
|
||||
file->local_symtab_offset = this->shdr.sh_size;
|
||||
this->shdr.sh_size += file->num_local_symtab * sizeof(ElfSym<E>);
|
||||
file->local_symtab_idx = nsyms;
|
||||
nsyms += file->num_local_symtab;
|
||||
}
|
||||
|
||||
for (ObjectFile<E> *file : ctx.objs) {
|
||||
file->global_symtab_offset = this->shdr.sh_size;
|
||||
this->shdr.sh_size += file->num_global_symtab * sizeof(ElfSym<E>);
|
||||
file->global_symtab_idx = nsyms;
|
||||
nsyms += file->num_global_symtab;
|
||||
}
|
||||
|
||||
this->shdr.sh_info = ctx.objs[0]->global_symtab_offset / sizeof(ElfSym<E>);
|
||||
this->shdr.sh_info = ctx.objs[0]->global_symtab_idx;
|
||||
this->shdr.sh_link = ctx.strtab->shndx;
|
||||
|
||||
if (this->shdr.sh_size == sizeof(ElfSym<E>))
|
||||
this->shdr.sh_size = 0;
|
||||
|
||||
static Counter counter("symtab");
|
||||
counter += this->shdr.sh_size / sizeof(ElfSym<E>);
|
||||
this->shdr.sh_size = (nsyms == 1) ? 0 : nsyms * sizeof(ElfSym<E>);
|
||||
}
|
||||
|
||||
template <typename E>
|
||||
|
Loading…
Reference in New Issue
Block a user