Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the extra statistics of relative relocations in large binaries #1375

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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 @@ -253,6 +253,7 @@ static bool is_jump_reachable(i64 val) {
template <>
void InputSection<E>::apply_reloc_alloc(Context<E> &ctx, u8 *base) {
std::span<const ElfRel<E>> rels = get_rels(ctx);
RelocationsStats rels_stats;

auto get_tls_trampoline_addr = [&, i = 0](u64 addr) mutable {
for (; i < output_section->thunks.size(); i++) {
Expand All @@ -273,6 +274,8 @@ void InputSection<E>::apply_reloc_alloc(Context<E> &ctx, u8 *base) {
u8 *loc = base + rel.r_offset;

auto check = [&](i64 val, i64 lo, i64 hi) {
if (ctx.arg.stats)
update_relocation_stats(rels_stats, i, val, lo, hi);
if (val < lo || hi <= val)
Error(ctx) << *this << ": relocation " << rel << " against "
<< sym << " out of range: " << val << " is not in ["
Expand Down Expand Up @@ -532,6 +535,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
10 changes: 10 additions & 0 deletions 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 @@ -156,6 +157,8 @@ void InputSection<E>::apply_reloc_alloc(Context<E> &ctx, u8 *base) {
u8 *loc = base + rel.r_offset;

auto check = [&](i64 val, i64 lo, i64 hi) {
if (ctx.arg.stats)
update_relocation_stats(rels_stats, i, val, lo, hi);
if (val < lo || hi <= val)
Error(ctx) << *this << ": relocation " << rel << " against "
<< sym << " out of range: " << val << " is not in ["
Expand Down Expand Up @@ -434,11 +437,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 @@ -449,6 +455,8 @@ void InputSection<E>::apply_reloc_nonalloc(Context<E> &ctx, u8 *base) {
u8 *loc = base + rel.r_offset;

auto check = [&](i64 val, i64 lo, i64 hi) {
if (ctx.arg.stats)
update_relocation_stats(rels_stats, i, val, lo, hi);
if (val < lo || hi <= val)
Error(ctx) << *this << ": relocation " << rel << " against "
<< sym << " out of range: " << val << " is not in ["
Expand Down Expand Up @@ -481,6 +489,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 @@ -285,6 +285,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) {
u8 *loc = base + rel.r_offset;

auto check = [&](i64 val, i64 lo, i64 hi) {
if (ctx.arg.stats)
update_relocation_stats(rels_stats, i, val, lo, hi);
if (val < lo || hi <= val)
Error(ctx) << *this << ": relocation " << rel << " against "
<< sym << " out of range: " << val << " is not in ["
Expand Down Expand Up @@ -435,11 +438,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 @@ -450,6 +456,8 @@ void InputSection<E>::apply_reloc_nonalloc(Context<E> &ctx, u8 *base) {
u8 *loc = base + rel.r_offset;

auto check = [&](i64 val, i64 lo, i64 hi) {
if (ctx.arg.stats)
update_relocation_stats(rels_stats, i, val, lo, hi);
if (val < lo || hi <= val)
Error(ctx) << *this << ": relocation " << rel << " against "
<< sym << " out of range: " << val << " is not in ["
Expand Down Expand Up @@ -509,6 +517,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 @@ -265,6 +265,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;

auto get_r_delta = [&](i64 idx) {
return extra.r_deltas.empty() ? 0 : extra.r_deltas[idx];
Expand All @@ -284,6 +285,8 @@ void InputSection<E>::apply_reloc_alloc(Context<E> &ctx, u8 *base) {
u8 *loc = base + r_offset;

auto check = [&](i64 val, i64 lo, i64 hi) {
if (ctx.arg.stats)
update_relocation_stats(rels_stats, i, val, lo, hi);
if (val < lo || hi <= val)
Error(ctx) << *this << ": relocation " << rel << " against "
<< sym << " out of range: " << val << " is not in ["
Expand Down Expand Up @@ -657,6 +660,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 @@ -87,6 +88,8 @@ void InputSection<E>::apply_reloc_alloc(Context<E> &ctx, u8 *base) {
u8 *loc = base + rel.r_offset;

auto check = [&](i64 val, i64 lo, i64 hi) {
if (ctx.arg.stats)
update_relocation_stats(rels_stats, i, val, lo, hi);
if (val < lo || hi <= val)
Error(ctx) << *this << ": relocation " << rel << " against "
<< sym << " out of range: " << val << " is not in ["
Expand Down Expand Up @@ -207,6 +210,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 @@ -163,6 +164,8 @@ void InputSection<E>::apply_reloc_alloc(Context<E> &ctx, u8 *base) {
u8 *loc = base + rel.r_offset;

auto check = [&](i64 val, i64 lo, i64 hi) {
if (ctx.arg.stats)
update_relocation_stats(rels_stats, i, val, lo, hi);
if (val < lo || hi <= val)
Error(ctx) << *this << ": relocation " << rel << " against "
<< sym << " out of range: " << val << " is not in ["
Expand Down Expand Up @@ -279,11 +282,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 @@ -294,6 +300,8 @@ void InputSection<E>::apply_reloc_nonalloc(Context<E> &ctx, u8 *base) {
u8 *loc = base + rel.r_offset;

auto check = [&](i64 val, i64 lo, i64 hi) {
if (ctx.arg.stats)
update_relocation_stats(rels_stats, i, val, lo, hi);
if (val < lo || hi <= val)
Error(ctx) << *this << ": relocation " << rel << " against "
<< sym << " out of range: " << val << " is not in ["
Expand Down Expand Up @@ -328,6 +336,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 @@ -344,6 +344,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 @@ -354,6 +355,8 @@ void InputSection<E>::apply_reloc_nonalloc(Context<E> &ctx, u8 *base) {
u8 *loc = base + rel.r_offset;

auto check = [&](i64 val, i64 lo, i64 hi) {
if (ctx.arg.stats)
update_relocation_stats(rels_stats, i, val, lo, hi);
if (val < lo || hi <= val)
Error(ctx) << *this << ": relocation " << rel << " against "
<< sym << " out of range: " << val << " is not in ["
Expand Down Expand Up @@ -388,6 +391,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 @@ -208,6 +208,7 @@ static inline bool is_hi20(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;
u64 GP = ctx.__global_pointer ? ctx.__global_pointer->get_addr(ctx) : 0;

auto get_r_delta = [&](i64 idx) {
Expand All @@ -225,6 +226,8 @@ void InputSection<E>::apply_reloc_alloc(Context<E> &ctx, u8 *base) {
u8 *loc = base + r_offset;

auto check = [&](i64 val, i64 lo, i64 hi) {
if (ctx.arg.stats)
update_relocation_stats(rels_stats, i, val, lo, hi);
if (val < lo || hi <= val)
Error(ctx) << *this << ": relocation " << rel << " against "
<< sym << " out of range: " << val << " is not in ["
Expand Down Expand Up @@ -620,6 +623,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 @@ -125,6 +126,8 @@ void InputSection<E>::apply_reloc_alloc(Context<E> &ctx, u8 *base) {
u8 *loc = base + rel.r_offset;

auto check = [&](i64 val, i64 lo, i64 hi) {
if (ctx.arg.stats)
update_relocation_stats(rels_stats, i, val, lo, hi);
if (val < lo || hi <= val)
Error(ctx) << *this << ": relocation " << rel << " against "
<< sym << " out of range: " << val << " is not in ["
Expand Down Expand Up @@ -323,11 +326,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 @@ -338,6 +344,8 @@ void InputSection<E>::apply_reloc_nonalloc(Context<E> &ctx, u8 *base) {
u8 *loc = base + rel.r_offset;

auto check = [&](i64 val, i64 lo, i64 hi) {
if (ctx.arg.stats)
update_relocation_stats(rels_stats, i, val, lo, hi);
if (val < lo || hi <= val)
Error(ctx) << *this << ": relocation " << rel << " against "
<< sym << " out of range: " << val << " is not in ["
Expand Down Expand Up @@ -372,6 +380,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 @@ -141,6 +141,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 @@ -151,6 +152,8 @@ void InputSection<E>::apply_reloc_alloc(Context<E> &ctx, u8 *base) {
u8 *loc = base + rel.r_offset;

auto check = [&](i64 val, i64 lo, i64 hi) {
if (ctx.arg.stats)
update_relocation_stats(rels_stats, i, val, lo, hi);
if (val < lo || hi <= val)
Error(ctx) << *this << ": relocation " << rel << " against "
<< sym << " out of range: " << val << " is not in ["
Expand Down Expand Up @@ -452,11 +455,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 @@ -467,6 +473,8 @@ void InputSection<E>::apply_reloc_nonalloc(Context<E> &ctx, u8 *base) {
u8 *loc = base + rel.r_offset;

auto check = [&](i64 val, i64 lo, i64 hi) {
if (ctx.arg.stats)
update_relocation_stats(rels_stats, i, val, lo, hi);
if (val < lo || hi <= val)
Error(ctx) << *this << ": relocation " << rel << " against "
<< sym << " out of range: " << val << " is not in ["
Expand Down Expand Up @@ -505,6 +513,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
Loading