Skip to content

Commit

Permalink
Avoid reading data from .plt
Browse files Browse the repository at this point in the history
  • Loading branch information
rui314 committed Aug 23, 2023
1 parent ac20d87 commit 51fec5f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
12 changes: 6 additions & 6 deletions elf/arch-ppc64v1.cc
Original file line number Diff line number Diff line change
Expand Up @@ -72,22 +72,22 @@ void write_plt_header(Context<E> &ctx, u8 *buf) {
0x7d88'02a6, // mflr r12
0x429f'0005, // bcl 20, 31, 4 // obtain PC
0x7d68'02a6, // mflr r11
0xe84b'0024, // ld r2,36(r11)
0x7d88'03a6, // mtlr r12
0x7d62'5a14, // add r11,r2,r11
0x3d6b'0000, // addis r11, r11, GOTPLT_OFFSET@ha
0x396b'0000, // addi r11, r11, GOTPLT_OFFSET@lo
0xe98b'0000, // ld r12,0(r11)
0xe84b'0008, // ld r2,8(r11)
0x7d89'03a6, // mtctr r12
0xe96b'0010, // ld r11,16(r11)
0x4e80'0420, // bctr
// .quad .got.plt - .plt - 8
0x0000'0000,
0x0000'0000,
};

static_assert(sizeof(insn) == E::plt_hdr_size);
memcpy(buf, insn, sizeof(insn));
*(ub64 *)(buf + 44) = ctx.gotplt->shdr.sh_addr - ctx.plt->shdr.sh_addr - 8;

i64 val = ctx.gotplt->shdr.sh_addr - ctx.plt->shdr.sh_addr - 8;
*(ub32 *)(buf + 16) |= higha(val);
*(ub32 *)(buf + 20) |= lo(val);
}

template <>
Expand Down
2 changes: 1 addition & 1 deletion elf/elf.h
Original file line number Diff line number Diff line change
Expand Up @@ -2149,7 +2149,7 @@ struct PPC64 {
struct PPC64V1 : PPC64 {
static constexpr std::string_view target_name = "ppc64v1";
static constexpr bool is_le = false;
static constexpr u32 plt_hdr_size = 52;
static constexpr u32 plt_hdr_size = 44;
static constexpr u32 pltgot_size = 0;
static constexpr u32 thunk_hdr_size = 0;
static constexpr u32 thunk_size = 28;
Expand Down

0 comments on commit 51fec5f

Please sign in to comment.