At optimization level -O2 or higher in gcc, static functions may be optimized such that they have suffixes like .isra.0, .constprop.0 etc. These represent - constant propagation (.constprop.0); - interprocedural scalar replacement of aggregates, removal of unused parameters and replacement of parameters passed by reference by parameters passed by value (.isra.0) See [1] for details. Currently BTF encoding does not handle such optimized functions that get renamed with a "." suffix such as ".isra.0", ".constprop.0". This is safer because such suffixes can often indicate parameters have been optimized out. This series addresses this by matching a function to a suffixed version ("foo" matching "foo.isra.0") while ensuring that the function signature does not contain optimized-out parameters. Note that if the function is found ("foo") it will be preferred, only falling back to "foo.isra.0" if lookup of the function fails. Addition to BTF is skipped if the function has optimized-out parameters, since the expected function signature will not match. BTF encoding does not include the "."-suffix to be consistent with DWARF. In addition, the kernel currently does not allow a "." suffix in a BTF function name. A problem with this approach however is that BTF carries out the encoding process in parallel across multiple CUs, and sometimes a function has optimized-out parameters in one CU but not others; we see this for NF_HOOK.constprop.0 for example. So in order to determine if the function has optimized-out parameters in any CU, its addition is not carried out until we have processed all CUs and are about to merge BTF. At this point we know if any such optimizations have occurred. Patches 1-4 handle the optimized-out parameter identification and matching "."-suffixed functions with the original function to facilitate BTF encoding. Patch 5 addresses a related problem - it is entirely possible for a static function of the same name to exist in different CUs with different function signatures. Because BTF does not currently encode any information that would help disambiguate which BTF function specification matches which static function (in the case of multiple different function signatures), it is best to eliminate such functions from BTF for now. The same mechanism that is used to compare static "."-suffixed functions is re-used for the static function comparison. A superficial comparison of number of parameters/parameter names is done to see if such representations are consistent, and if inconsistent prototypes are observed, the function is flagged for exclusion from BTF. When these methods are combined - the additive encoding of "."-suffixed functions and the subtractive elimination of functions with inconsistent parameters - we see a small overall increase in the number of functions in vmlinux BTF, from 49538 to 50083. It turns out that the inconsistent prototype checking will actually eliminate some of the suffix matches also, for cases where the DWARF representation of a function differs across CUs, but not via the abstract origin late DWARF references showing optimized-out parameters that we check for in patch 1. [1] https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html Alan Maguire (5): dwarves: help dwarf loader spot functions with optimized-out parameters btf_encoder: refactor function addition into dedicated btf_encoder__add_func btf_encoder: child encoders should have a reference to parent encoder btf_encoder: represent "."-suffixed optimized functions (".isra.0") in BTF btf_encoder: skip BTF encoding of static functions with inconsistent prototypes btf_encoder.c | 357 +++++++++++++++++++++++++++++++++++++++++++++++++-------- btf_encoder.h | 2 +- dwarf_loader.c | 76 +++++++++++- dwarves.h | 5 +- pahole.c | 7 +- 5 files changed, 390 insertions(+), 57 deletions(-) -- 1.8.3.1