Created attachment 902113 [details] environment Build fails with -O3 in CFLAGS: libbpf.c: In function ‘bpf_map__init_kern_struct_ops’: libbpf.c:1109:18: error: ‘mod_btf’ may be used uninitialized [-Werror=maybe-uninitialized] 1109 | kern_btf = mod_btf ? mod_btf->btf : obj->btf_vmlinux; | ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ libbpf.c:1094:28: note: ‘mod_btf’ was declared here 1094 | struct module_btf *mod_btf; | ^~~~~~~ In function ‘find_struct_ops_kern_types’, inlined from ‘bpf_map__init_kern_struct_ops’ at libbpf.c:1102:8: libbpf.c:982:21: error: ‘btf’ may be used uninitialized [-Werror=maybe-uninitialized] 982 | kern_type = btf__type_by_id(btf, kern_type_id); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ libbpf.c: In function ‘bpf_map__init_kern_struct_ops’: libbpf.c:967:21: note: ‘btf’ was declared here 967 | struct btf *btf; | ^~~ It builds correctly with -O2.
Created attachment 902114 [details] build.log
-O3 is discouraged from regular usage. See red text: https://wiki.gentoo.org/wiki/GCC_optimization#-O >Warning >Using -O3 may cause some packages to break either during the compilation or misbehave at runtime, although -O3 retains standard conformance, hence any breakage is either undefined behaviour in the application, or (very rarely) a compiler bug.
(In reply to Reva Denis from comment #2) -O3 is fine even if people should use it with caution and it's a valid bug (albeit a false positive). I'm going to handle it.
*** Bug 939140 has been marked as a duplicate of this bug. ***
a quick fix is to assign NULL to mod_btf (line 1094) and btf (line 967) as default value.
Sent https://lore.kernel.org/bpf/f6962729197ae7cdf4f6d1512625bd92f2322d31.1725630494.git.sam@gentoo.org/T/#u upstream.
(In reply to Luigi 'Comio' Mantellini from comment #5) > a quick fix is to assign NULL to mod_btf (line 1094) and btf (line 967) as > default value. jinx :)
6.10.9 builds with -O3
(In reply to Emanuele Torre from comment #8) > 6.10.9 builds with -O3 Yes, my patch was included in it. https://gitweb.gentoo.org/proj/linux-patches.git/commit/?h=6.10&id=e6e998f862f051598cd9b9c6cdcb7ad1f9f16d65