Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 939106 - sys-kernel/gentoo-kernel-bin-6.10.7: build fails with -O3
Summary: sys-kernel/gentoo-kernel-bin-6.10.7: build fails with -O3
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal
Assignee: Distribution Kernel Project
URL:
Whiteboard:
Keywords:
: 939140 (view as bug list)
Depends on:
Blocks:
 
Reported: 2024-09-05 10:24 UTC by Emanuele Torre
Modified: 2024-10-05 13:40 UTC (History)
4 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
environment (environment,103.08 KB, text/plain)
2024-09-05 10:24 UTC, Emanuele Torre
Details
build.log (build.log,99.59 KB, text/x-log)
2024-09-05 10:24 UTC, Emanuele Torre
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Emanuele Torre 2024-09-05 10:24:03 UTC
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.
Comment 1 Emanuele Torre 2024-09-05 10:24:24 UTC
Created attachment 902114 [details]
build.log
Comment 2 Reva Denis 2024-09-05 14:19:22 UTC
-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.
Comment 3 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2024-09-05 14:26:25 UTC
(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.
Comment 4 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2024-09-05 19:21:55 UTC
*** Bug 939140 has been marked as a duplicate of this bug. ***
Comment 5 Luigi 'Comio' Mantellini 2024-09-06 13:46:57 UTC
a quick fix is to assign NULL to mod_btf (line 1094) and btf (line 967) as default value.
Comment 7 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2024-09-06 13:49:42 UTC
(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 :)
Comment 8 Emanuele Torre 2024-09-08 17:23:08 UTC
6.10.9 builds with -O3
Comment 9 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2024-09-08 17:26:15 UTC
(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