Re: [PATCH dwarves v4 2/2] pahole: Inject kfunc decl tags into BTF

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sun, 2024-02-04 at 11:40 -0700, Daniel Xu wrote:
[...]
> +static int btf_encoder__tag_kfuncs(struct btf_encoder *encoder)
> +{
> +	const char *filename = encoder->filename;
> +	struct gobuffer btf_kfunc_ranges = {};
> +	struct gobuffer btf_funcs = {};
> +	Elf_Scn *symscn = NULL;
> +	int symbols_shndx = -1;
> +	int fd = -1, err = -1;
> +	int idlist_shndx = -1;
> +	Elf_Scn *scn = NULL;
> +	size_t idlist_addr;
> +	Elf_Data *symbols;
> +	Elf_Data *idlist;
> +	size_t strtabidx;
> +	Elf *elf = NULL;
> +	GElf_Shdr shdr;
> +	size_t strndx;
> +	char *secname;
> +	int nr_syms;
> +	int i = 0;

Note: when compiled in Release mode (e.g. using buildcmd.sh from the repo)
there is a number of false-positive warnings reported by GCC 13.2.1:

$ ./buildcmd.sh
...
In function ‘is_sym_kfunc_set’,
    inlined from ‘btf_encoder__tag_kfuncs’ at /home/eddy/work/dwarves-fork/btf_encoder.c:1639:8,
    inlined from ‘btf_encoder__encode’ at /home/eddy/work/dwarves-fork/btf_encoder.c:1724:29:
/home/eddy/work/dwarves-fork/btf_encoder.c:1395:29: warning: ‘idlist_addr’ may be used uninitialized [-Wmaybe-uninitialized]
 1395 |         off = sym->st_value - idlist_addr;
      |               ~~~~~~~~~~~~~~^~~~~~~~~~~~~
/home/eddy/work/dwarves-fork/btf_encoder.c: In function ‘btf_encoder__encode’:
/home/eddy/work/dwarves-fork/btf_encoder.c:1538:16: note: ‘idlist_addr’ was declared here
 1538 |         size_t idlist_addr;
      |                ^~~~~~~~~~~
In function ‘btf_encoder__tag_kfuncs’,
    inlined from ‘btf_encoder__encode’ at /home/eddy/work/dwarves-fork/btf_encoder.c:1724:29:

Same thing is reported for:
- btf_encoder.c:1630:22: warning: ‘symbols’ may be used uninitialized
- btf_encoder.c:1385:15: warning: ‘idlist’ may be used uninitialized
- btf_encoder.c:1638:24: warning: ‘strtabidx’ may be used uninitialized

GCC does not figure out that the variables above are guarded by -1 checks below.

[...]
> +	while ((scn = elf_nextscn(elf, scn)) != NULL) {
[...]
> +		if (shdr.sh_type == SHT_SYMTAB) {
> +			symbols_shndx = i;
> +			symscn = scn;
> +			symbols = data;
> +			strtabidx = shdr.sh_link;
> +		} else if (!strcmp(secname, BTF_IDS_SECTION)) {
> +			idlist_shndx = i;
> +			idlist_addr = shdr.sh_addr;
> +			idlist = data;
> +		}
> +	}
> +
> +	/* Cannot resolve symbol or .BTF_ids sections. Nothing to do. */
> +	if (symbols_shndx == -1 || idlist_shndx == -1) {
> +		err = 0;
> +		goto out;
> +	}
[...]





[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux