From 6da1e8c50c9a3a8943f8c3fc5b1b135a7554d876 Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Thu, 1 Apr 2021 01:16:17 +0900 Subject: [PATCH] wip --- output_chunks.cc | 15 +++++++++++---- test/i386-hello-static.sh | 2 +- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/output_chunks.cc b/output_chunks.cc index c8a966da..2bb54736 100644 --- a/output_chunks.cc +++ b/output_chunks.cc @@ -728,16 +728,22 @@ void GotSection::copy_buf(Context &ctx) { template void GotPltSection::copy_buf(Context &ctx) { typename E::word *buf = (typename E::word *)(ctx.buf + this->shdr.sh_offset); + memset(buf, 0, this->shdr.sh_size); // The first slot of .got.plt points to _DYNAMIC, as requested by // the x86-64 psABI. The second and the third slots are reserved by // the psABI. buf[0] = ctx.dynamic ? ctx.dynamic->shdr.sh_addr : 0; - buf[1] = 0; - buf[2] = 0; - for (Symbol *sym : ctx.plt->symbols) + for (Symbol *sym : ctx.plt->symbols) { + if (sym->get_type() == STT_GNU_IFUNC) { + if (E::rel_type == SHT_REL) + buf[sym->gotplt_idx] = sym->input_section->get_addr() + sym->value; + continue; + } + buf[sym->gotplt_idx] = sym->get_plt_addr(ctx) + 6; + } } template @@ -801,8 +807,8 @@ void RelPltSection::copy_buf(Context &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; + u64 r_sym = 0; u32 r_addend = 0; if (sym->get_type() == STT_GNU_IFUNC) { @@ -810,6 +816,7 @@ void RelPltSection::copy_buf(Context &ctx) { r_addend = sym->input_section->get_addr() + sym->value; } else { r_type = E::R_JUMP_SLOT; + r_sym = sym->dynsym_idx; } ElfRel *rel = buf + relplt_idx++; diff --git a/test/i386-hello-static.sh b/test/i386-hello-static.sh index 84a6c214..65aae3f5 100755 --- a/test/i386-hello-static.sh +++ b/test/i386-hello-static.sh @@ -15,6 +15,6 @@ int main() { EOF clang -fuse-ld=`pwd`/../mold -m32 -o $t/exe $t/a.o -static -# $t/exe | grep -q 'Hello world' +$t/exe | grep -q 'Hello world' echo OK