From df3498769bf3937c456a9ae5fcd69064d96c4833 Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Fri, 13 Nov 2020 13:39:29 +0900 Subject: [PATCH] temporary --- main.cc | 2 -- mold.h | 6 ++---- output_chunks.cc | 7 +++++++ test/plt.s | 17 +++++++++++------ 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/main.cc b/main.cc index 271b04a9..1b502905 100644 --- a/main.cc +++ b/main.cc @@ -417,8 +417,6 @@ static void write_got(u8 *buf, ArrayRef files) { u8 *dynsym_buf = buf + out::dynsym->shdr.sh_offset; u8 *dynstr_buf = buf + out::dynstr->shdr.sh_offset; - memset(buf + out::gotplt->shdr.sh_offset, 0, out::gotplt->shdr.sh_size); - tbb::parallel_for_each(files, [&](ObjectFile *file) { u32 dynstr_offset = file->dynstr_offset; diff --git a/mold.h b/mold.h index b50ac25e..c3fbe6c1 100644 --- a/mold.h +++ b/mold.h @@ -340,16 +340,14 @@ public: class GotPltSection : public OutputChunk { public: GotPltSection() : OutputChunk(SYNTHETIC) { - this->name = ".gotplt"; + this->name = ".got.plt"; shdr.sh_type = llvm::ELF::SHT_PROGBITS; shdr.sh_flags = llvm::ELF::SHF_ALLOC | llvm::ELF::SHF_WRITE; shdr.sh_addralign = GOT_SIZE; shdr.sh_size = GOT_SIZE * 3; } - void initialize(u8 *buf) override { - memset(buf + shdr.sh_offset, 0, GOT_SIZE * 3); - } + void initialize(u8 *buf) override; }; class PltSection : public OutputChunk { diff --git a/output_chunks.cc b/output_chunks.cc index 5e9263c9..06a828ae 100644 --- a/output_chunks.cc +++ b/output_chunks.cc @@ -71,6 +71,13 @@ bool OutputSection::empty() const { return true; } +void GotPltSection::initialize(u8 *buf) { + u8 *base = buf + shdr.sh_offset; + memset(base, 0, shdr.sh_size); + if (out::dynamic) + *(u64 *)base = out::dynamic->shdr.sh_addr; +} + void PltSection::initialize(u8 *buf) { const u8 data[] = { 0xff, 0x35, 0, 0, 0, 0, // pushq GOTPLT+8(%rip) diff --git a/test/plt.s b/test/plt.s index 5291e820..aed207ba 100644 --- a/test/plt.s +++ b/test/plt.s @@ -11,13 +11,18 @@ // RUN: /lib/x86_64-linux-gnu/ld-linux-x86-64.so.2 // RUN: readelf --sections %t.exe | FileCheck --check-prefix=SECTIONS %s -// SECTIONS: [19] .gotplt PROGBITS 0000000000202058 00002058 -// SECTIONS: 0000000000000028 0000000000000000 WA 0 0 8 +// SECTIONS: [19] .got.plt PROGBITS 0000000000202058 00002058 +// SECTIONS: 0000000000000028 0000000000000000 WA 0 0 8 +// SECTIONS: [20] .dynamic DYNAMIC 0000000000202080 00002080 +// SECTIONS: 0000000000000130 0000000000000010 WA 9 0 8 -// RUN: objdump -d -j .plt %t.exe | FileCheck %s -// CHECK: 2011a8: ff 35 b2 0e 00 00 pushq 0xeb2(%rip) # 202060 -// CHECK: 2011ae: ff 25 b4 0e 00 00 jmpq *0xeb4(%rip) # 202068 -// CHECK: 2011b4: 0f 1f 40 00 nopl 0x0(%rax) +// RUN: readelf -x .got.plt %t.exe | FileCheck --check-prefix=GOTPLT %s +// GOTPLT: 0x00202058 80202000 00000000 00000000 00000000 + +// RUN: objdump -d -j .plt %t.exe | FileCheck --check-prefix=PLT %s +// PLT: 2011a8: ff 35 b2 0e 00 00 pushq 0xeb2(%rip) # 202060 +// PLT: 2011ae: ff 25 b4 0e 00 00 jmpq *0xeb4(%rip) # 202068 +// PLT: 2011b4: 0f 1f 40 00 nopl 0x0(%rax) .globl main main: