Re: [PATCH dwarves 4/4] btf_encoder: Prefer strong function definitions for BTF generation
Yonghong Song <[email protected]>
| Newsgroups | org.kernel.vger.dwarves,org.kernel.vger.bpf |
|---|---|
| Message-ID | <[email protected]> |
On 1/13/26 5:13 AM, Alan Maguire wrote: > From: Matt Bobrowski <[email protected]> > > Currently, when a function has both a weak and a strong definition > across different compilation units (CUs), the BTF encoder arbitrarily > selects one to generate the BTF entry. This selection fundamentally is > dependent on the order in which pahole processes the CUs. > > This indifference often leads to a mismatch where the generated BTF > reflects the weak definition's prototype, even though the linker > selected the strong definition for the final vmlinux binary. > > A notable example described in [0] involving function > bpf_lsm_mmap_file(). Both weak and strong definitions exist, > distinguished only by parameter names (e.g., file vs > file__nullable). While the strong definition is linked into the > vmlinux object, the generated BTF contained the prototype for the weak > definition. This causes issues for BPF verifier (e.g., __nullable > annotation semantics), or tools relying on accurate type information. > > To fix this, ensure the BTF encoder selects the function definition > corresponding to the actual code linked into the binary. This is > achieved by comparing the DWARF function address (DW_AT_low_pc) with > the ELF symbol address (st_value). Only the DWARF entry for the strong > definition will match the final resolved ELF symbol address. > > [0] https://lore.kernel.org/all/[email protected]/ > > Link: https://lore.kernel.org/all/[email protected]/ > Signed-off-by: Matt Bobrowski <[email protected]> Acked-by: Yonghong Song <[email protected]>