From 983fe0f10f2afbd8e42b2e3c8912898d205fb6b5 Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Fri, 13 Jan 2023 21:06:19 +0800 Subject: [PATCH] Refactor --- elf/arch-i386.cc | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/elf/arch-i386.cc b/elf/arch-i386.cc index 706fc6ffe9..41d77a1291 100644 --- a/elf/arch-i386.cc +++ b/elf/arch-i386.cc @@ -204,27 +204,22 @@ static u32 relax_got32x(u8 *loc) { // Relax GD to LE static void relax_gd_to_le(u8 *loc, ElfRel rel, u64 val) { + static const u8 insn[] = { + 0x65, 0xa1, 0, 0, 0, 0, // mov %gs:0, %eax + 0x81, 0xc0, 0, 0, 0, 0, // add $tp_offset, %eax + }; + switch (rel.r_type) { case R_386_PLT32: - case R_386_PC32: { - static const u8 insn[] = { - 0x65, 0xa1, 0, 0, 0, 0, // mov %gs:0, %eax - 0x81, 0xc0, 0, 0, 0, 0, // add $tp_offset, %eax - }; + case R_386_PC32: memcpy(loc - 3, insn, sizeof(insn)); *(ul32 *)(loc + 5) = val; break; - } case R_386_GOT32: - case R_386_GOT32X: { - static const u8 insn[] = { - 0x65, 0xa1, 0, 0, 0, 0, // mov %gs:0, %eax - 0x81, 0xc0, 0, 0, 0, 0, // add $tp_offset, %eax - }; + case R_386_GOT32X: memcpy(loc - 2, insn, sizeof(insn)); *(ul32 *)(loc + 6) = val; break; - } default: unreachable(); }