1
1
mirror of https://github.com/rui314/mold.git synced 2024-09-21 18:08:01 +03:00

Fill .rela.dyn even if there's no .got

This commit is contained in:
Rui Ueyama 2021-07-16 15:33:51 +09:00
parent c44fa6172b
commit cce1cb353f
2 changed files with 35 additions and 27 deletions

1
mold.h
View File

@ -559,6 +559,7 @@ public:
}
void update_shdr(Context<E> &ctx) override;
void copy_buf(Context<E> &ctx) override;
void sort(Context<E> &ctx);
i64 relcount = 0;

View File

@ -256,6 +256,10 @@ void RelDynSection<E>::update_shdr(Context<E> &ctx) {
// .rel.dyn contents are filled by GotSection::copy_buf(Context<E> &ctx) and
// InputSection::apply_reloc_alloc().
i64 offset = ctx.got->get_reldyn_size(ctx);
offset += ctx.dynbss->symbols.size() * sizeof(ElfRel<E>);
offset += ctx.dynbss_relro->symbols.size() * sizeof(ElfRel<E>);
for (ObjectFile<E> *file : ctx.objs) {
file->reldyn_offset = offset;
offset += file->num_dynrel * sizeof(ElfRel<E>);
@ -263,6 +267,36 @@ void RelDynSection<E>::update_shdr(Context<E> &ctx) {
this->shdr.sh_size = offset;
}
template <typename E>
static ElfRel<E> reloc(u64 offset, u32 type, u32 sym, i64 addend = 0);
template <>
ElfRel<X86_64> reloc<X86_64>(u64 offset, u32 type, u32 sym, i64 addend) {
return {offset, type, sym, addend};
}
template <>
ElfRel<I386> reloc<I386>(u64 offset, u32 type, u32 sym, i64 addend) {
return {(u32)offset, type, sym};
}
template <>
ElfRel<AARCH64> reloc<AARCH64>(u64 offset, u32 type, u32 sym, i64 addend) {
return {offset, type, sym, addend};
}
template <typename E>
void RelDynSection<E>::copy_buf(Context<E> &ctx) {
ElfRel<E> *rel =
(ElfRel<E> *)(ctx.buf + this->shdr.sh_offset + ctx.got->get_reldyn_size(ctx));
for (Symbol<E> *sym : ctx.dynbss->symbols)
*rel++ = reloc<E>(sym->get_addr(ctx), E::R_COPY, sym->get_dynsym_idx(ctx));
for (Symbol<E> *sym : ctx.dynbss_relro->symbols)
*rel++ = reloc<E>(sym->get_addr(ctx), E::R_COPY, sym->get_dynsym_idx(ctx));
}
template <typename E>
void RelDynSection<E>::sort(Context<E> &ctx) {
Timer t(ctx, "sort_dynamic_relocs");
@ -758,30 +792,9 @@ i64 GotSection<E>::get_reldyn_size(Context<E> &ctx) const {
if (tlsld_idx != -1)
n++;
n += ctx.dynbss->symbols.size();
n += ctx.dynbss_relro->symbols.size();
return n * sizeof(ElfRel<E>);
}
template <typename E>
static ElfRel<E> reloc(u64 offset, u32 type, u32 sym, i64 addend = 0);
template <>
ElfRel<X86_64> reloc<X86_64>(u64 offset, u32 type, u32 sym, i64 addend) {
return {offset, type, sym, addend};
}
template <>
ElfRel<I386> reloc<I386>(u64 offset, u32 type, u32 sym, i64 addend) {
return {(u32)offset, type, sym};
}
template <>
ElfRel<AARCH64> reloc<AARCH64>(u64 offset, u32 type, u32 sym, i64 addend) {
return {offset, type, sym, addend};
}
// Fill .got and .rel.dyn.
template <typename E>
void GotSection<E>::copy_buf(Context<E> &ctx) {
@ -839,12 +852,6 @@ void GotSection<E>::copy_buf(Context<E> &ctx) {
if (tlsld_idx != -1)
*rel++ = reloc<E>(get_tlsld_addr(ctx), E::R_DTPMOD, 0);
for (Symbol<E> *sym : ctx.dynbss->symbols)
*rel++ = reloc<E>(sym->get_addr(ctx), E::R_COPY, sym->get_dynsym_idx(ctx));
for (Symbol<E> *sym : ctx.dynbss_relro->symbols)
*rel++ = reloc<E>(sym->get_addr(ctx), E::R_COPY, sym->get_dynsym_idx(ctx));
}
template <typename E>