[RFC PATCH v2 05/30] scripts: Add min_eh_frame build-time .eh_frame minifier

bot+bpf-ci at kernel.org bot+bpf-ci at kernel.org
Tue Nov 24 23:06:28 PST 2026


> scripts: Add min_eh_frame build-time .eh_frame minifier

TL;DR: Nits only, none described as bugs, in scripts/min_eh_frame.c: use a
named enum instead of bare rule numbers (which differ from the kernel's), and
share the duplicated register-rule and cleanup code.

> diff --git a/scripts/min_eh_frame.c b/scripts/min_eh_frame.c
> new file mode 100644
> index 000000000000..55b07b11c635
> --- /dev/null
> +++ b/scripts/min_eh_frame.c

[ ... ]

> +static bool rows_equal(const struct min_row *a, const struct min_row *b)
> +{

[ ... ]

> +	if ((a->fp_rule == 1 || a->fp_rule == 2 || a->fp_rule == 4) &&
> +	    a->fp_off != b->fp_off)
> +		return false;
> +	if ((a->ra_rule == 1 || a->ra_rule == 4) &&
> +	    a->ra_off != b->ra_off)
> +		return false;

This isn't a bug, but would a small local enum for the rule and CFA-kind
codes make rows_equal() and the restore paths easier to check?

struct min_row documents fp_rule as 0=same, 1=cfa_off, 2=fp_off, 3=undef,
4=sp_off, and these bare numbers are tested about 38 times in the file.

The kernel interpreter in include/linux/unwind_dwarf_cfi.h numbers the same
concepts differently (DWARF_CFI_RULE_SP_OFFSET is 3 and
DWARF_CFI_RULE_UNDEFINED is 4), so "fp_rule == 4" means different things on
each side.  Matching the dwarf_cfi_rule numbering would avoid that.

[ ... ]

> +				if (reg == arch->fp_reg) {
> +					row.fp_rule = 1;
> +					row.fp_off = off;
> +				} else if (reg == cie->ra_reg) {
> +					row.ra_rule = 1;
> +					row.ra_off = off;
> +				} else {
> +					row.sp_rule = 1;
> +					row.sp_off = off;
> +				}

This isn't a bug, but could these fp/ra/sp assignment blocks share a small
helper, along the lines of cfi_apply_reg_rule() in kernel/unwind/dwarf_cfi.c?

The same ladder appears in minify_insns() for DW_CFA_offset_extended,
DW_CFA_offset_extended_sf, DW_CFA_GNU_negative_offset_extended,
DW_CFA_undefined and DW_CFA_same_value, differing only in the rule value
and offset.  The restore paths (DW_CFA_restore and DW_CFA_restore_extended)
repeat a similar three-way copy from cie_base, which cfi_restore_reg() covers
on the kernel side.

[ ... ]

> +	free(anchors.data);
> +	free(cies);
> +	free(sorted_relas);
> +	free(out_eh.data);
> +	free(out_relas);
> +	return 0;
> +
> +bail:
> +	/* Leave unusual/hand-crafted .eh_frame untouched rather than failing build */
> +	free(anchors.data);
> +	free(cies);
> +	free(sorted_relas);
> +	free(out_eh.data);
> +	free(out_relas);
> +	return 0;

This isn't a bug, but since the success path and bail: free the same buffers
and both return 0, could the success path fall through to a single cleanup
label, with a ret variable for the -1 case, as minify_insns() does?

process_elf64() has a third copy of the same five frees in the record-length
error path, which returns -1.  The FDE branch also repeats
"free(rmaps); free(min_fde_insns.data); free(fde_rec.data); goto bail;" three
times.


---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md

CI run summary: https://github.com/kernel-patches/bpf/actions/runs/45561209846


More information about the linux-riscv mailing list