@@ -146,6 +146,7 @@ static bool is_add(u8 *loc) {
146146template <>
147147void InputSection<E>::apply_reloc_alloc(Context<E> &ctx, u8 *base) {
148148 std::span<const ElfRel<E>> rels = get_rels (ctx);
149+ RelocationsStats rels_stats;
149150
150151 for (i64 i = 0 ; i < rels.size (); i++) {
151152 const ElfRel<E> &rel = rels[i];
@@ -154,14 +155,15 @@ void InputSection<E>::apply_reloc_alloc(Context<E> &ctx, u8 *base) {
154155
155156 Symbol<E> &sym = *file.symbols [rel.r_sym ];
156157 u8 *loc = base + rel.r_offset ;
157-
158158 u64 S = sym.get_addr (ctx);
159159 u64 A = rel.r_addend ;
160160 u64 P = get_addr () + rel.r_offset ;
161161 u64 G = sym.get_got_idx (ctx) * sizeof (Word<E>);
162162 u64 GOT = ctx.got ->shdr .sh_addr ;
163163
164164 auto check = [&](i64 val, i64 lo, i64 hi) {
165+ if (ctx.arg .stats )
166+ update_relocation_stats (rels_stats, i, val, lo, hi);
165167 check_range (ctx, i, val, lo, hi);
166168 };
167169
@@ -431,11 +433,14 @@ void InputSection<E>::apply_reloc_alloc(Context<E> &ctx, u8 *base) {
431433 unreachable ();
432434 }
433435 }
436+ if (ctx.arg .stats )
437+ save_relocation_stats<E>(ctx, *this , rels_stats);
434438}
435439
436440template <>
437441void InputSection<E>::apply_reloc_nonalloc(Context<E> &ctx, u8 *base) {
438442 std::span<const ElfRel<E>> rels = get_rels (ctx);
443+ RelocationsStats rels_stats;
439444
440445 for (i64 i = 0 ; i < rels.size (); i++) {
441446 const ElfRel<E> &rel = rels[i];
@@ -453,6 +458,8 @@ void InputSection<E>::apply_reloc_nonalloc(Context<E> &ctx, u8 *base) {
453458 u64 A = frag ? frag_addend : (i64 )rel.r_addend ;
454459
455460 auto check = [&](i64 val, i64 lo, i64 hi) {
461+ if (ctx.arg .stats )
462+ update_relocation_stats (rels_stats, i, val, lo, hi);
456463 check_range (ctx, val, i, lo, hi);
457464 };
458465
@@ -473,6 +480,8 @@ void InputSection<E>::apply_reloc_nonalloc(Context<E> &ctx, u8 *base) {
473480 break ;
474481 }
475482 }
483+ if (ctx.arg .stats )
484+ save_relocation_stats<E>(ctx, *this , rels_stats);
476485}
477486
478487template <>
0 commit comments