Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
rui314 committed Sep 14, 2024
1 parent 63d990e commit e7e4132
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 20 deletions.
16 changes: 1 addition & 15 deletions src/input-sections.cc
Original file line number Diff line number Diff line change
Expand Up @@ -101,18 +101,6 @@ void InputSection<E>::copy_contents(Context<E> &ctx, u8 *buf) {
}
}

template <typename E>
static bool
is_relr_reloc(Context<E> &ctx, InputSection<E> &isec, const ElfRel<E> &rel) {
if (ctx.arg.pack_dyn_relocs_relr &&
rel.r_offset % sizeof(Word<E>) == 0) {
const ElfShdr<E> &shdr = isec.shdr();
return !(shdr.sh_flags & SHF_EXECINSTR) &&
shdr.sh_addralign % sizeof(Word<E>) == 0;
}
return false;
}

typedef enum : u8 { NONE, ERROR, COPYREL, PLT, CPLT } Action;

template <typename E>
Expand All @@ -124,12 +112,10 @@ static void do_action(Context<E> &ctx, Action action, InputSection<E> &isec,
case ERROR:
Error(ctx) << isec << ": " << rel << " relocation at offset 0x"
<< std::hex << rel.r_offset << " against symbol `"
<< sym << "' can not be used; recompile with "
<< (sym.is_absolute() ? "-fno-PIC" : "-fPIC");
<< sym << "' can not be used; recompile with -fPIC";
break;
case COPYREL:
// Create a copy relocation
assert(sym.is_imported);
sym.flags |= NEEDS_COPYREL;
break;
case PLT:
Expand Down
2 changes: 1 addition & 1 deletion src/mold.h
Original file line number Diff line number Diff line change
Expand Up @@ -2614,7 +2614,7 @@ inline bool InputSection<E>::icf_removed() const {
template <typename E>
std::pair<SectionFragment<E> *, i64>
MergeableSection<E>::get_fragment(i64 offset) {
std::vector<u32> &vec = frag_offsets;
std::span<u32> vec = frag_offsets;
auto it = std::upper_bound(vec.begin(), vec.end(), offset);
i64 idx = it - 1 - vec.begin();
return {fragments[idx], offset - vec[idx]};
Expand Down
9 changes: 5 additions & 4 deletions src/output-chunks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -995,29 +995,30 @@ void OutputSection<E>::write_to(Context<E> &ctx, u8 *buf, ElfRel<E> *rel) {
for (AbsRel<E> &r : abs_rels) {
Word<E> *loc = (Word<E> *)(buf + r.isec->offset + r.offset);
u64 addr = this->shdr.sh_addr + r.isec->offset + r.offset;
Symbol<E> &sym = *r.sym;

switch (r.kind) {
case ABS_REL_NONE:
case ABS_REL_RELR:
*loc = r.sym->get_addr(ctx) + r.addend;
*loc = sym.get_addr(ctx) + r.addend;
break;
case ABS_REL_BASEREL: {
u64 val = r.sym->get_addr(ctx) + r.addend;
u64 val = sym.get_addr(ctx) + r.addend;
*rel++ = ElfRel<E>(addr, E::R_RELATIVE, 0, val);
if (ctx.arg.apply_dynamic_relocs)
*loc = val;
break;
}
case ABS_REL_IFUNC:
if constexpr (supports_ifunc<E>) {
u64 val = r.sym->get_addr(ctx, NO_PLT) + r.addend;
u64 val = sym.get_addr(ctx, NO_PLT) + r.addend;
*rel++ = ElfRel<E>(addr, E::R_IRELATIVE, 0, val);
if (ctx.arg.apply_dynamic_relocs)
*loc = val;
}
break;
case ABS_REL_DYNREL:
*rel++ = ElfRel<E>(addr, E::R_ABS, r.sym->get_dynsym_idx(ctx), r.addend);
*rel++ = ElfRel<E>(addr, E::R_ABS, sym.get_dynsym_idx(ctx), r.addend);
if (ctx.arg.apply_dynamic_relocs)
*loc = r.addend;
break;
Expand Down

0 comments on commit e7e4132

Please sign in to comment.