Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/arch-arm32.cc
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ static Thunk<E> &get_reachable_thunk(OutputSection<E> &osec, u64 addr) {
template <>
void InputSection<E>::apply_reloc_alloc(Context<E> &ctx, u8 *base) {
std::span<const ElfRel<E>> rels = get_rels(ctx);
RelocationsStats rels_stats;

for (i64 i = 0; i < rels.size(); i++) {
const ElfRel<E> &rel = rels[i];
Expand All @@ -305,6 +306,8 @@ void InputSection<E>::apply_reloc_alloc(Context<E> &ctx, u8 *base) {
u64 GOT = ctx.got->shdr.sh_addr;

auto check = [&](i64 val, i64 lo, i64 hi) {
if (ctx.arg.stats)
update_relocation_stats(rels_stats, i, val, lo, hi);
check_range(ctx, i, val, lo, hi);
};

Expand Down Expand Up @@ -549,6 +552,8 @@ void InputSection<E>::apply_reloc_alloc(Context<E> &ctx, u8 *base) {
Error(ctx) << *this << ": unknown relocation: " << rel;
}
}
if (ctx.arg.stats)
save_relocation_stats<E>(ctx, *this, rels_stats);
}

template <>
Expand Down
11 changes: 10 additions & 1 deletion src/arch-arm64.cc
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ static bool is_add(u8 *loc) {
template <>
void InputSection<E>::apply_reloc_alloc(Context<E> &ctx, u8 *base) {
std::span<const ElfRel<E>> rels = get_rels(ctx);
RelocationsStats rels_stats;

for (i64 i = 0; i < rels.size(); i++) {
const ElfRel<E> &rel = rels[i];
Expand All @@ -154,14 +155,15 @@ void InputSection<E>::apply_reloc_alloc(Context<E> &ctx, u8 *base) {

Symbol<E> &sym = *file.symbols[rel.r_sym];
u8 *loc = base + rel.r_offset;

u64 S = sym.get_addr(ctx);
u64 A = rel.r_addend;
u64 P = get_addr() + rel.r_offset;
u64 G = sym.get_got_idx(ctx) * sizeof(Word<E>);
u64 GOT = ctx.got->shdr.sh_addr;

auto check = [&](i64 val, i64 lo, i64 hi) {
if (ctx.arg.stats)
update_relocation_stats(rels_stats, i, val, lo, hi);
check_range(ctx, i, val, lo, hi);
};

Expand Down Expand Up @@ -431,11 +433,14 @@ void InputSection<E>::apply_reloc_alloc(Context<E> &ctx, u8 *base) {
unreachable();
}
}
if (ctx.arg.stats)
save_relocation_stats<E>(ctx, *this, rels_stats);
}

template <>
void InputSection<E>::apply_reloc_nonalloc(Context<E> &ctx, u8 *base) {
std::span<const ElfRel<E>> rels = get_rels(ctx);
RelocationsStats rels_stats;

for (i64 i = 0; i < rels.size(); i++) {
const ElfRel<E> &rel = rels[i];
Expand All @@ -453,6 +458,8 @@ void InputSection<E>::apply_reloc_nonalloc(Context<E> &ctx, u8 *base) {
u64 A = frag ? frag_addend : (i64)rel.r_addend;

auto check = [&](i64 val, i64 lo, i64 hi) {
if (ctx.arg.stats)
update_relocation_stats(rels_stats, i, val, lo, hi);
check_range(ctx, val, i, lo, hi);
};

Expand All @@ -473,6 +480,8 @@ void InputSection<E>::apply_reloc_nonalloc(Context<E> &ctx, u8 *base) {
break;
}
}
if (ctx.arg.stats)
save_relocation_stats<E>(ctx, *this, rels_stats);
}

template <>
Expand Down
10 changes: 10 additions & 0 deletions src/arch-i386.cc
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ static u32 relax_tlsdesc_to_le(u8 *loc) {
template <>
void InputSection<E>::apply_reloc_alloc(Context<E> &ctx, u8 *base) {
std::span<const ElfRel<E>> rels = get_rels(ctx);
RelocationsStats rels_stats;

for (i64 i = 0; i < rels.size(); i++) {
const ElfRel<E> &rel = rels[i];
Expand All @@ -295,6 +296,8 @@ void InputSection<E>::apply_reloc_alloc(Context<E> &ctx, u8 *base) {
u64 GOT = ctx.got->shdr.sh_addr;

auto check = [&](i64 val, i64 lo, i64 hi) {
if (ctx.arg.stats)
update_relocation_stats(rels_stats, i, val, lo, hi);
check_range(ctx, i, val, lo, hi);
};

Expand Down Expand Up @@ -430,11 +433,14 @@ void InputSection<E>::apply_reloc_alloc(Context<E> &ctx, u8 *base) {
unreachable();
}
}
if (ctx.arg.stats)
save_relocation_stats<E>(ctx, *this, rels_stats);
}

template <>
void InputSection<E>::apply_reloc_nonalloc(Context<E> &ctx, u8 *base) {
std::span<const ElfRel<E>> rels = get_rels(ctx);
RelocationsStats rels_stats;

for (i64 i = 0; i < rels.size(); i++) {
const ElfRel<E> &rel = rels[i];
Expand All @@ -453,6 +459,8 @@ void InputSection<E>::apply_reloc_nonalloc(Context<E> &ctx, u8 *base) {
u64 GOT = ctx.got->shdr.sh_addr;

auto check = [&](i64 val, i64 lo, i64 hi) {
if (ctx.arg.stats)
update_relocation_stats(rels_stats, i, val, lo, hi);
check_range(ctx, val, i, lo, hi);
};

Expand Down Expand Up @@ -501,6 +509,8 @@ void InputSection<E>::apply_reloc_nonalloc(Context<E> &ctx, u8 *base) {
unreachable();
}
}
if (ctx.arg.stats)
save_relocation_stats<E>(ctx, *this, rels_stats);
}

template <>
Expand Down
5 changes: 5 additions & 0 deletions src/arch-loongarch.cc
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ void InputSection<E>::apply_reloc_alloc(Context<E> &ctx, u8 *base) {
std::span<RelocDelta> deltas = extra.r_deltas;
i64 k = 0;
u8 *buf = (u8 *)contents.data();
RelocationsStats rels_stats;

for (i64 i = 0; i < rels.size(); i++) {
const ElfRel<E> &rel = rels[i];
Expand Down Expand Up @@ -326,6 +327,8 @@ void InputSection<E>::apply_reloc_alloc(Context<E> &ctx, u8 *base) {
};

auto check_branch = [&](i64 val, i64 lo, i64 hi) {
if (ctx.arg.stats)
update_relocation_stats(rels_stats, i, val, lo, hi);
check(val, lo, hi);
if (val & 0b11)
Error(ctx) << *this << ": misaligned symbol " << sym
Expand Down Expand Up @@ -652,6 +655,8 @@ void InputSection<E>::apply_reloc_alloc(Context<E> &ctx, u8 *base) {
unreachable();
}
}
if (ctx.arg.stats)
save_relocation_stats<E>(ctx, *this, rels_stats);
}

template <>
Expand Down
5 changes: 5 additions & 0 deletions src/arch-m68k.cc
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ void EhFrameSection<E>::apply_eh_reloc(Context<E> &ctx, const ElfRel<E> &rel,
template <>
void InputSection<E>::apply_reloc_alloc(Context<E> &ctx, u8 *base) {
std::span<const ElfRel<E>> rels = get_rels(ctx);
RelocationsStats rels_stats;

for (i64 i = 0; i < rels.size(); i++) {
const ElfRel<E> &rel = rels[i];
Expand All @@ -93,6 +94,8 @@ void InputSection<E>::apply_reloc_alloc(Context<E> &ctx, u8 *base) {
u64 GOT = ctx.got->shdr.sh_addr;

auto check = [&](i64 val, i64 lo, i64 hi) {
if (ctx.arg.stats)
update_relocation_stats(rels_stats, i, val, lo, hi);
check_range(ctx, i, val, lo, hi);
};

Expand Down Expand Up @@ -204,6 +207,8 @@ void InputSection<E>::apply_reloc_alloc(Context<E> &ctx, u8 *base) {
unreachable();
}
}
if (ctx.arg.stats)
save_relocation_stats<E>(ctx, *this, rels_stats);
}

template <>
Expand Down
10 changes: 10 additions & 0 deletions src/arch-ppc64v1.cc
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ void EhFrameSection<E>::apply_eh_reloc(Context<E> &ctx, const ElfRel<E> &rel,
template <>
void InputSection<E>::apply_reloc_alloc(Context<E> &ctx, u8 *base) {
std::span<const ElfRel<E>> rels = get_rels(ctx);
RelocationsStats rels_stats;

for (i64 i = 0; i < rels.size(); i++) {
const ElfRel<E> &rel = rels[i];
Expand All @@ -170,6 +171,8 @@ void InputSection<E>::apply_reloc_alloc(Context<E> &ctx, u8 *base) {
u64 TOC = ctx.extra.TOC->value;

auto check = [&](i64 val, i64 lo, i64 hi) {
if (ctx.arg.stats)
update_relocation_stats(rels_stats, i, val, lo, hi);
check_range(ctx, i, val, lo, hi);
};

Expand Down Expand Up @@ -276,11 +279,14 @@ void InputSection<E>::apply_reloc_alloc(Context<E> &ctx, u8 *base) {
unreachable();
}
}
if (ctx.arg.stats)
save_relocation_stats<E>(ctx, *this, rels_stats);
}

template <>
void InputSection<E>::apply_reloc_nonalloc(Context<E> &ctx, u8 *base) {
std::span<const ElfRel<E>> rels = get_rels(ctx);
RelocationsStats rels_stats;

for (i64 i = 0; i < rels.size(); i++) {
const ElfRel<E> &rel = rels[i];
Expand All @@ -298,6 +304,8 @@ void InputSection<E>::apply_reloc_nonalloc(Context<E> &ctx, u8 *base) {
u64 A = frag ? frag_addend : (i64)rel.r_addend;

auto check = [&](i64 val, i64 lo, i64 hi) {
if (ctx.arg.stats)
update_relocation_stats(rels_stats, i, val, lo, hi);
check_range(ctx, val, i, lo, hi);
};

Expand All @@ -320,6 +328,8 @@ void InputSection<E>::apply_reloc_nonalloc(Context<E> &ctx, u8 *base) {
<< rel;
}
}
if (ctx.arg.stats)
save_relocation_stats<E>(ctx, *this, rels_stats);
}

template <>
Expand Down
5 changes: 5 additions & 0 deletions src/arch-ppc64v2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@ void InputSection<E>::apply_reloc_alloc(Context<E> &ctx, u8 *base) {
template <>
void InputSection<E>::apply_reloc_nonalloc(Context<E> &ctx, u8 *base) {
std::span<const ElfRel<E>> rels = get_rels(ctx);
RelocationsStats rels_stats;

for (i64 i = 0; i < rels.size(); i++) {
const ElfRel<E> &rel = rels[i];
Expand All @@ -362,6 +363,8 @@ void InputSection<E>::apply_reloc_nonalloc(Context<E> &ctx, u8 *base) {
u64 A = frag ? frag_addend : (i64)rel.r_addend;

auto check = [&](i64 val, i64 lo, i64 hi) {
if (ctx.arg.stats)
update_relocation_stats(rels_stats, i, val, lo, hi);
check_range(ctx, i, val, lo, hi);
};

Expand All @@ -384,6 +387,8 @@ void InputSection<E>::apply_reloc_nonalloc(Context<E> &ctx, u8 *base) {
<< rel;
}
}
if (ctx.arg.stats)
save_relocation_stats<E>(ctx, *this, rels_stats);
}

template <>
Expand Down
5 changes: 5 additions & 0 deletions src/arch-riscv.cc
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ void InputSection<E>::apply_reloc_alloc(Context<E> &ctx, u8 *base) {
std::span<RelocDelta> deltas = extra.r_deltas;
i64 k = 0;
u8 *buf = (u8 *)contents.data();
RelocationsStats rels_stats;

for (i64 i = 0; i < rels.size(); i++) {
const ElfRel<E> &rel = rels[i];
Expand Down Expand Up @@ -298,6 +299,8 @@ void InputSection<E>::apply_reloc_alloc(Context<E> &ctx, u8 *base) {
u64 GOT = ctx.got->shdr.sh_addr;

auto check = [&](i64 val, i64 lo, i64 hi) {
if (ctx.arg.stats)
update_relocation_stats(rels_stats, i, val, lo, hi);
check_range(ctx, i, val, lo, hi);
};

Expand Down Expand Up @@ -642,6 +645,8 @@ void InputSection<E>::apply_reloc_alloc(Context<E> &ctx, u8 *base) {
unreachable();
}
}
if (ctx.arg.stats)
save_relocation_stats<E>(ctx, *this, rels_stats);
}

template <>
Expand Down
10 changes: 10 additions & 0 deletions src/arch-s390x.cc
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ void EhFrameSection<E>::apply_eh_reloc(Context<E> &ctx, const ElfRel<E> &rel,
template <>
void InputSection<E>::apply_reloc_alloc(Context<E> &ctx, u8 *base) {
std::span<const ElfRel<E>> rels = get_rels(ctx);
RelocationsStats rels_stats;

for (i64 i = 0; i < rels.size(); i++) {
const ElfRel<E> &rel = rels[i];
Expand All @@ -131,6 +132,8 @@ void InputSection<E>::apply_reloc_alloc(Context<E> &ctx, u8 *base) {
u64 GOT = ctx.got->shdr.sh_addr;

auto check = [&](i64 val, i64 lo, i64 hi) {
if (ctx.arg.stats)
update_relocation_stats(rels_stats, i, val, lo, hi);
check_range(ctx, i, val, lo, hi);
};

Expand Down Expand Up @@ -330,11 +333,14 @@ void InputSection<E>::apply_reloc_alloc(Context<E> &ctx, u8 *base) {
unreachable();
}
}
if (ctx.arg.stats)
save_relocation_stats<E>(ctx, *this, rels_stats);
}

template <>
void InputSection<E>::apply_reloc_nonalloc(Context<E> &ctx, u8 *base) {
std::span<const ElfRel<E>> rels = get_rels(ctx);
RelocationsStats rels_stats;

for (i64 i = 0; i < rels.size(); i++) {
const ElfRel<E> &rel = rels[i];
Expand All @@ -352,6 +358,8 @@ void InputSection<E>::apply_reloc_nonalloc(Context<E> &ctx, u8 *base) {
u64 A = frag ? frag_addend : (i64)rel.r_addend;

auto check = [&](i64 val, i64 lo, i64 hi) {
if (ctx.arg.stats)
update_relocation_stats(rels_stats, i, val, lo, hi);
check_range(ctx, val, i, lo, hi);
};

Expand All @@ -376,6 +384,8 @@ void InputSection<E>::apply_reloc_nonalloc(Context<E> &ctx, u8 *base) {
Fatal(ctx) << *this << ": apply_reloc_nonalloc: " << rel;
}
}
if (ctx.arg.stats)
save_relocation_stats<E>(ctx, *this, rels_stats);
}

template <>
Expand Down
10 changes: 10 additions & 0 deletions src/arch-sparc64.cc
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ void EhFrameSection<E>::apply_eh_reloc(Context<E> &ctx, const ElfRel<E> &rel,
template <>
void InputSection<E>::apply_reloc_alloc(Context<E> &ctx, u8 *base) {
std::span<const ElfRel<E>> rels = get_rels(ctx);
RelocationsStats rels_stats;

for (i64 i = 0; i < rels.size(); i++) {
const ElfRel<E> &rel = rels[i];
Expand All @@ -154,6 +155,8 @@ void InputSection<E>::apply_reloc_alloc(Context<E> &ctx, u8 *base) {
u64 GOT = ctx.got->shdr.sh_addr;

auto check = [&](i64 val, i64 lo, i64 hi) {
if (ctx.arg.stats)
update_relocation_stats(rels_stats, i, val, lo, hi);
check_range(ctx, i, val, lo, hi);
};

Expand Down Expand Up @@ -446,11 +449,14 @@ void InputSection<E>::apply_reloc_alloc(Context<E> &ctx, u8 *base) {
unreachable();
}
}
if (ctx.arg.stats)
save_relocation_stats<E>(ctx, *this, rels_stats);
}

template <>
void InputSection<E>::apply_reloc_nonalloc(Context<E> &ctx, u8 *base) {
std::span<const ElfRel<E>> rels = get_rels(ctx);
RelocationsStats rels_stats;

for (i64 i = 0; i < rels.size(); i++) {
const ElfRel<E> &rel = rels[i];
Expand All @@ -468,6 +474,8 @@ void InputSection<E>::apply_reloc_nonalloc(Context<E> &ctx, u8 *base) {
u64 A = frag ? frag_addend : (i64)rel.r_addend;

auto check = [&](i64 val, i64 lo, i64 hi) {
if (ctx.arg.stats)
update_relocation_stats(rels_stats, i, val, lo, hi);
check_range(ctx, val, i, lo, hi);
};

Expand All @@ -494,6 +502,8 @@ void InputSection<E>::apply_reloc_nonalloc(Context<E> &ctx, u8 *base) {
Fatal(ctx) << *this << ": apply_reloc_nonalloc: " << rel;
}
}
if (ctx.arg.stats)
save_relocation_stats<E>(ctx, *this, rels_stats);
}

template <>
Expand Down
Loading