Skip to content

Commit a633dab

Browse files
Yonghong SongAlexei Starovoitov
authored andcommitted
selftests/bpf: Fix RELEASE build failure with gcc14
With gcc14, when building with RELEASE=1, I hit four below compilation failure: Error 1: In file included from test_loader.c:6: test_loader.c: In function ‘run_subtest’: test_progs.h:194:17: error: ‘retval’ may be used uninitialized in this function [-Werror=maybe-uninitialized] 194 | fprintf(stdout, ##format); \ | ^~~~~~~ test_loader.c:958:13: note: ‘retval’ was declared here 958 | int retval, err, i; | ^~~~~~ The uninitialized var 'retval' actually could cause incorrect result. Error 2: In function ‘test_fd_array_cnt’: prog_tests/fd_array.c:71:14: error: ‘btf_id’ may be used uninitialized in this function [-Werror=maybe-uninitialized] 71 | fd = bpf_btf_get_fd_by_id(id); | ^~~~~~~~~~~~~~~~~~~~~~~~ prog_tests/fd_array.c:302:15: note: ‘btf_id’ was declared here 302 | __u32 btf_id; | ^~~~~~ Changing ASSERT_GE to ASSERT_EQ can fix the compilation error. Otherwise, there is no functionality change. Error 3: prog_tests/tailcalls.c: In function ‘test_tailcall_hierarchy_count’: prog_tests/tailcalls.c:1402:23: error: ‘fentry_data_fd’ may be used uninitialized in this function [-Werror=maybe-uninitialized] 1402 | err = bpf_map_lookup_elem(fentry_data_fd, &i, &val); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The code is correct. The change intends to silence gcc errors. Error 4: (this error only happens on arm64) In file included from prog_tests/log_buf.c:4: prog_tests/log_buf.c: In function ‘bpf_prog_load_log_buf’: ./test_progs.h:390:22: error: ‘log_buf’ may be used uninitialized [-Werror=maybe-uninitialized] 390 | int ___err = libbpf_get_error(___res); \ | ^~~~~~~~~~~~~~~~~~~~~~~~ prog_tests/log_buf.c:158:14: note: in expansion of macro ‘ASSERT_OK_PTR’ 158 | if (!ASSERT_OK_PTR(log_buf, "log_buf_alloc")) | ^~~~~~~~~~~~~ In file included from selftests/bpf/tools/include/bpf/bpf.h:32, from ./test_progs.h:36: selftests/bpf/tools/include/bpf/libbpf_legacy.h:113:17: note: by argument 1 of type ‘const void *’ to ‘libbpf_get_error’ declared here 113 | LIBBPF_API long libbpf_get_error(const void *ptr); | ^~~~~~~~~~~~~~~~ Adding a pragma to disable maybe-uninitialized fixed the issue. Signed-off-by: Yonghong Song <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent f66b4aa commit a633dab

File tree

4 files changed

+9
-5
lines changed

4 files changed

+9
-5
lines changed

tools/testing/selftests/bpf/prog_tests/fd_array.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ static void check_fd_array_cnt__referenced_btfs(void)
312312

313313
/* btf should still exist when original file descriptor is closed */
314314
err = get_btf_id_by_fd(extra_fds[0], &btf_id);
315-
if (!ASSERT_GE(err, 0, "get_btf_id_by_fd"))
315+
if (!ASSERT_EQ(err, 0, "get_btf_id_by_fd"))
316316
goto cleanup;
317317

318318
Close(extra_fds[0]);

tools/testing/selftests/bpf/prog_tests/log_buf.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
#include "test_log_buf.skel.h"
88
#include "bpf_util.h"
99

10+
#if !defined(__clang__)
11+
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
12+
#endif
13+
1014
static size_t libbpf_log_pos;
1115
static char libbpf_log_buf[1024 * 1024];
1216
static bool libbpf_log_error;

tools/testing/selftests/bpf/prog_tests/tailcalls.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1195,7 +1195,7 @@ static void test_tailcall_hierarchy_count(const char *which, bool test_fentry,
11951195
bool test_fexit,
11961196
bool test_fentry_entry)
11971197
{
1198-
int err, map_fd, prog_fd, main_data_fd, fentry_data_fd, fexit_data_fd, i, val;
1198+
int err, map_fd, prog_fd, main_data_fd, fentry_data_fd = 0, fexit_data_fd = 0, i, val;
11991199
struct bpf_object *obj = NULL, *fentry_obj = NULL, *fexit_obj = NULL;
12001200
struct bpf_link *fentry_link = NULL, *fexit_link = NULL;
12011201
struct bpf_program *prog, *fentry_prog;

tools/testing/selftests/bpf/test_loader.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,9 +1103,9 @@ void run_subtest(struct test_loader *tester,
11031103
}
11041104
}
11051105

1106-
do_prog_test_run(bpf_program__fd(tprog), &retval,
1107-
bpf_program__type(tprog) == BPF_PROG_TYPE_SYSCALL ? true : false);
1108-
if (retval != subspec->retval && subspec->retval != POINTER_VALUE) {
1106+
err = do_prog_test_run(bpf_program__fd(tprog), &retval,
1107+
bpf_program__type(tprog) == BPF_PROG_TYPE_SYSCALL ? true : false);
1108+
if (!err && retval != subspec->retval && subspec->retval != POINTER_VALUE) {
11091109
PRINT_FAIL("Unexpected retval: %d != %d\n", retval, subspec->retval);
11101110
goto tobj_cleanup;
11111111
}

0 commit comments

Comments
 (0)