Skip to content

Commit

Permalink
[ELF][x86] Always create .got.plt
Browse files Browse the repository at this point in the history
glibc's -static-pie implementation expect that _GLOBAL_OFFSET_TABLE_
is at the beginning of .got.plt, as it uses the address of _DYNAMIC
which is stored at _GLOBAL_OFFSET_TABLE_[0].

In this patch, we always create .got.plt for x86-64 and i386.
  • Loading branch information
rui314 committed Apr 4, 2022
1 parent 615a24d commit 0884f27
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
1 change: 1 addition & 0 deletions elf/mold.h
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,7 @@ class GotPltSection : public Chunk<E> {
this->shdr.sh_type = SHT_PROGBITS;
this->shdr.sh_flags = SHF_ALLOC | SHF_WRITE;
this->shdr.sh_addralign = E::word_size;
this->shdr.sh_size = E::word_size * 3;
}

void copy_buf(Context<E> &ctx) override;
Expand Down
4 changes: 1 addition & 3 deletions elf/output-chunks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1161,10 +1161,8 @@ template <typename E>
void PltSection<E>::add_symbol(Context<E> &ctx, Symbol<E> *sym) {
assert(!sym->has_plt(ctx));

if (this->shdr.sh_size == 0) {
if (this->shdr.sh_size == 0)
this->shdr.sh_size = ctx.plt_hdr_size;
ctx.gotplt->shdr.sh_size = E::word_size * 3;
}

sym->set_plt_idx(ctx, symbols.size());
this->shdr.sh_size += ctx.plt_size;
Expand Down
5 changes: 4 additions & 1 deletion elf/passes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1391,7 +1391,10 @@ void fix_synthetic_symbols(Context<E> &ctx) {
start(ctx._DYNAMIC, ctx.dynamic);

// _GLOBAL_OFFSET_TABLE_
start(ctx._GLOBAL_OFFSET_TABLE_, ctx.got);
if constexpr (std::is_same_v<E, X86_64> || std::is_same_v<E, I386>)
start(ctx._GLOBAL_OFFSET_TABLE_, ctx.gotplt);
else
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 0884f27

Please sign in to comment.