perf: workaround the error cased by maybe-uninitialized warning
PATCH 1/1 perf: workaround the error cased by maybe-uninitialized warning
When enable DEBUG_BUILD, the perf build failed by the following error:
libbpf.c:727:36: error: 'data' may be used uninitialized in this function [-Werror=maybe-uninitialized]
This is ok until Khem commit a patch in oe-core:
16643b03227466e2c80a24c2d079fe36e89553c1
This commit import "-Og" option to "DEBUG_OPTIMIZATION", result in this error.
Actually, the warning was misinformation. We explore the code in libbpf.c:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/tools/lib/bpf/libbpf.c#n640
--------------------------------------------------------------------------
if (scn)
data = elf_getdata(scn, NULL);
if (!scn || !data) {
pr_warning("failed to get Elf_Data from map section %d\n",
obj->efile.maps_shndx);
return -EINVAL;
}
......
using data...
......--------------------------------------------------------------------------
If the 'scn' was not null, the data will be initialized. if the data was null, the function will return -EINVAL, so the data must be not null, but compiler can't see it in 'if' code block, so treat it as 'maybe-uninitialized'.
--- meta/recipes-kernel/perf/perf.bb | 1 + 1 file changed, 1 insertion(+)
meta/recipes-kernel/perf/perf.bb +1 -0
@@ -271,3 +271,4 @@ FILES_${PN}-perl = "${libexecdir}/perf-core/scripts/perl" INHIBIT_PACKAGE_DEBUG_SPLIT="1" +DEBUG_OPTIMIZATION_append = " -Wno-error=maybe-uninitialized"
Signature · 1 line
2.7.4
Quoted 35 lines · Dengke Du
When enable
DEBUG_BUILD, the perf build failed by the following error:
libbpf.c:727:36: error: 'data' may be used uninitialized in this function [-Werror=maybe-uninitialized]
This is ok until Khem commit a patch in oe-core:16643b03227466e2c80a24c2d079fe36e89553c1This commit import "-Og" option to "
DEBUG_OPTIMIZATION", result in this error.Actually, the warning was misinformation. We explore the code in
libbpf.c:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/tools/lib/bpf/libbpf.c#n640
--------------------------------------------------------------------------if (scn) data = elf_getdata(scn, NULL); if (!scn || !data) { pr_warning("failed to get Elf_Data from map section %d\n", obj->efile.maps_shndx); return -EINVAL; } ...... using data... ......--------------------------------------------------------------------------
If the 'scn' was not null, the data will be initialized. if the data was null, the function will return-EINVAL, so the data must be not null, but compiler can't see it in 'if' code block, so treat it as 'maybe-uninitialized'.Signed-off-by Dengke Du <[email protected]>--- meta/recipes-kernel/perf/perf.bb | 1 + 1 file changed, 1 insertion(+)meta/recipes-kernel/perf/perf.bb +0
-0
meta/recipes-kernel/perf/perf.bb FILES_${PN}-perl = "${libexecdir}/perf-core/scripts/perl" · line 274
Quoted 4 lines
meta/recipes-kernel/perf/perf.bb +1
-0@@ -271,3 +271,4 @@ FILES_${PN}-perl = "${libexecdir}/perf-core/scripts/perl" INHIBIT_PACKAGE_DEBUG_SPLIT="1" +DEBUG_OPTIMIZATION_append = " -Wno-error=maybe-uninitialized"
I was thinking that this would be applied globally, but I think doing it on need bases is
a better approach so this looks ok to me.
Quoted 38 lines · Khem Raj
Quoted 37 lines · Dengke Du
When enable
DEBUG_BUILD, the perf build failed by the following error:
libbpf.c:727:36: error: 'data' may be used uninitialized in this function [-Werror=maybe-uninitialized]
This is ok until Khem commit a patch in oe-core:16643b03227466e2c80a24c2d079fe36e89553c1This commit import "-Og" option to "
DEBUG_OPTIMIZATION", result in this error.Actually, the warning was misinformation. We explore the code in
libbpf.c:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/tools/lib/bpf/libbpf.c#n640
--------------------------------------------------------------------------if (scn) data = elf_getdata(scn, NULL); if (!scn || !data) { pr_warning("failed to get Elf_Data from map section %d\n", obj->efile.maps_shndx); return -EINVAL; } ...... using data... ......--------------------------------------------------------------------------
If the 'scn' was not null, the data will be initialized. if the data was null, the function will return-EINVAL, so the data must be not null, but compiler can't see it in 'if' code block, so treat it as 'maybe-uninitialized'.Signed-off-by Dengke Du <[email protected]>--- meta/recipes-kernel/perf/perf.bb | 1 + 1 file changed, 1 insertion(+)meta/recipes-kernel/perf/perf.bb +0
-0@@ -271,3 +271,4 @@ FILES_${PN}-perl = "${libexecdir}/perf-core/scripts/perl"
Quoted 5 lines
meta/recipes-kernel/perf/perf.bb FILES_${PN}-perl = "${libexecdir}/perf-core/scripts/perl" · line 274
Quoted 2 lines
meta/recipes-kernel/perf/perf.bb +1
-0INHIBIT_PACKAGE_DEBUG_SPLIT="1" +DEBUG_OPTIMIZATION_append = " -Wno-error=maybe-uninitialized"I was thinking that this would be applied globally, but I think doing it on need bases is a better approach so this looks ok to me.
so this commit should be merged.
I don't see it in master[-next] yet so this is a reminder to the busy, hard-working gatekeepers. :)
../Randy
Quoted 1 line
Signature · 2 lines
# Randy MacLeod # Wind River Linux