From adcccbeeef6e9b0f9f84bd0a5976debade53534e Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Tue, 30 Mar 2021 21:13:04 +0900 Subject: [PATCH] wip --- output_chunks.cc | 48 +++++++++++++++--------------------------------- 1 file changed, 15 insertions(+), 33 deletions(-) diff --git a/output_chunks.cc b/output_chunks.cc index 1dedb79c..aab9d273 100644 --- a/output_chunks.cc +++ b/output_chunks.cc @@ -703,12 +703,12 @@ void GotSection::copy_buf(Context &ctx) { for (Symbol *sym : tlsdesc_syms) *rel++ = reloc(sym->get_tlsdesc_addr(ctx), R_X86_64_TLSDESC, - sym->dynsym_idx, 0); + sym->dynsym_idx, 0); for (Symbol *sym : gottpoff_syms) { if (sym->is_imported) *rel++ = reloc(sym->get_gottpoff_addr(ctx), R_X86_64_TPOFF64, - sym->dynsym_idx, 0); + sym->dynsym_idx, 0); else buf[sym->gottpoff_idx] = sym->get_addr(ctx) - ctx.tls_end; } @@ -821,46 +821,28 @@ void RelPltSection::update_shdr(Context &ctx) { this->shdr.sh_link = ctx.dynsym->shndx; } -template <> -void RelPltSection::copy_buf(Context &ctx) { - ElfRel *buf = (ElfRel *)(ctx.buf + this->shdr.sh_offset); +template +void RelPltSection::copy_buf(Context &ctx) { + ElfRel *buf = (ElfRel *)(ctx.buf + this->shdr.sh_offset); memset(buf, 0, this->shdr.sh_size); i64 relplt_idx = 0; - for (Symbol *sym : ctx.plt->symbols) { - ElfRel &rel = buf[relplt_idx++]; - memset(&rel, 0, sizeof(rel)); - rel.r_sym = sym->dynsym_idx; - rel.r_offset = sym->get_gotplt_addr(ctx); + for (Symbol *sym : ctx.plt->symbols) { + u64 r_offset = sym->get_gotplt_addr(ctx); + u64 r_sym = sym->dynsym_idx; + u32 r_type = 0; + u32 r_addend = 0; if (sym->get_type() == STT_GNU_IFUNC) { - rel.r_type = R_X86_64_IRELATIVE; - rel.r_addend = sym->input_section->get_addr() + sym->value; + r_type = R_X86_64_IRELATIVE; + r_addend = sym->input_section->get_addr() + sym->value; } else { - rel.r_type = R_X86_64_JUMP_SLOT; + r_type = R_X86_64_JUMP_SLOT; } - } -} -template <> -void RelPltSection::copy_buf(Context &ctx) { - ElfRel *buf = (ElfRel *)(ctx.buf + this->shdr.sh_offset); - memset(buf, 0, this->shdr.sh_size); - - i64 relplt_idx = 0; - - for (Symbol *sym : ctx.plt->symbols) { - ElfRel &rel = buf[relplt_idx++]; - memset(&rel, 0, sizeof(rel)); - rel.r_sym = sym->dynsym_idx; - rel.r_offset = sym->get_gotplt_addr(ctx); - - if (sym->get_type() == STT_GNU_IFUNC) { - rel.r_type = R_386_IRELATIVE; - } else { - rel.r_type = R_386_JUMP_SLOT; - } + ElfRel *rel = buf + relplt_idx++; + *rel = reloc(r_offset, r_type, r_sym, r_addend); } }