Re: [PATCH v2 5/6] objtool: list `noreturn` Rust functions

From: Peter Zijlstra
Date: Thu Jul 25 2024 - 04:34:27 EST


On Wed, Jul 24, 2024 at 08:35:49PM +0100, Gary Guo wrote:
> > @@ -202,10 +216,30 @@ static bool __dead_end_function(struct objtool_file *file, struct symbol *func,
> > if (!func)
> > return false;
> >
> > - if (func->bind == STB_GLOBAL || func->bind == STB_WEAK)
> > + if (func->bind == STB_GLOBAL || func->bind == STB_WEAK) {
> > + /*
> > + * Rust standard library functions.
> > + *
> > + * These are just heuristics -- we do not control the precise symbol
> > + * name, due to the crate disambiguators (which depend on the compiler)
> > + * as well as changes to the source code itself between versions.
> > + */
> > + if (!strncmp(func->name, "_R", 2) &&
> > + (str_ends_with(func->name, "_4core6option13unwrap_failed") ||
> > + str_ends_with(func->name, "_4core6result13unwrap_failed") ||
> > + str_ends_with(func->name, "_4core9panicking5panic") ||
> > + str_ends_with(func->name, "_4core9panicking9panic_fmt") ||
> > + str_ends_with(func->name, "_4core9panicking14panic_explicit") ||
> > + str_ends_with(func->name, "_4core9panicking18panic_bounds_check") ||
> > + strstr(func->name, "_4core9panicking11panic_const24panic_const_") ||
> > + (strstr(func->name, "_4core5slice5index24slice_") &&
> > + str_ends_with(func->name, "_fail"))))
> > + return true;
> > +

Perhaps add a helper function: is_rust_noreturn() or somesuch.

> I wonder if we should use dwarf for this. There's DW_AT_noreturn which
> tells us exactly what we want. This would also remove the need for the
> hardcoded C symbol list. I do recognise that debug info is not required
> for objtool though...

I think the slightly longer term plan here was to have noreturn.h
generated from a DWARF build but still included verbatim in the objtool
source, such that it works even on regular builds.

(and can be augmented where the compilers are being 'funny')

It's just that nobody has had time to implement this... you fancy giving
this a stab?