Skip to content

Commit

Permalink
[ELF] Always set _GLOBAL_OFFSET_TABLE_ to the beginning of .got
Browse files Browse the repository at this point in the history
Previously, we set the address of `_GLOBAL_OFFSET_TABLE_` to `.got.plt`
on i386 and x86-64 and to `.got` on other targets. But it looks like
this special treament of x86 isn't necessary. The x86-64 psABI said
that the symbol can even be in the middle of `.got` (*1). If `.got.plt`
is missing, GNU linker set it to `.got`.

This commit unconditionally set the symbol value to `.got`.

(*1) x86-64 psABI 1.0 p.77: "The symbol _GLOBAL_OFFSET_TABLE_ may
reside in the middle of the .got section, allowing both negative and
non-negative offsets into the array of addresses."
  • Loading branch information
rui314 committed Mar 3, 2022
1 parent 8714b78 commit eb79859
Showing 1 changed file with 1 addition and 6 deletions.
7 changes: 1 addition & 6 deletions elf/passes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1323,12 +1323,7 @@ void fix_synthetic_symbols(Context<E> &ctx) {
start(ctx._DYNAMIC, ctx.dynamic);

// _GLOBAL_OFFSET_TABLE_
if (E::e_machine == EM_X86_64 || E::e_machine == EM_386)
start(ctx._GLOBAL_OFFSET_TABLE_, ctx.gotplt);
else if (E::e_machine == EM_AARCH64 || E::e_machine == EM_RISCV)
start(ctx._GLOBAL_OFFSET_TABLE_, ctx.got);
else
unreachable();
start(ctx._GLOBAL_OFFSET_TABLE_, ctx.got);

// __GNU_EH_FRAME_HDR
start(ctx.__GNU_EH_FRAME_HDR, ctx.eh_frame_hdr);
Expand Down

0 comments on commit eb79859

Please sign in to comment.