Skip to content

Commit fb8910a

Browse files
jeromemarchandekyooo
authored andcommitted
tools/javaobjnew: Use MIN macro instead of min function
The function min() is called among the arguments of bpf_probe_read_user(). Depending on kernel version, the expansion of the macro may emmit a fake function that prevent the compilation of the BPF code. Replace the min() function by the MIN() macro to solve the issue. This is safe since both members of the comparison are unsigned integer. Solves the following error: /virtual/main.c:48:36: error: cannot call non-static helper function 48 | bpf_probe_read_user(&key.name, min(sizeof(key.name), (size_t)length), (void *)classptr); | ^ include/linux/minmax.h:129:19: note: expanded from macro 'min' 129 | #define min(x, y) __careful_cmp(min, x, y) | ^ include/linux/minmax.h:105:2: note: expanded from macro '__careful_cmp' 105 | __careful_cmp_once(op, x, y, __UNIQUE_ID(x_), __UNIQUE_ID(y_)) | ^ include/linux/minmax.h:100:2: note: expanded from macro '__careful_cmp_once' 100 | BUILD_BUG_ON_MSG(!__types_ok(x,y,ux,uy), \ | ^ note: (skipping 2 expansions in backtrace; use -fmacro-backtrace-limit=0 to see all) include/linux/compiler_types.h:418:2: note: expanded from macro '_compiletime_assert' 418 | __compiletime_assert(condition, msg, prefix, suffix) | ^ include/linux/compiler_types.h:411:4: note: expanded from macro '__compiletime_assert' 411 | prefix ## suffix(); \ | ^ <scratch space>:91:1: note: expanded from here 91 | __compiletime_assert_317 | ^ 1 error generated. Traceback (most recent call last): File "/usr/share/bcc/tools/lib/uobjnew", line 178, in <module> bpf = BPF(text=program, usdt_contexts=[usdt]) File "/usr/lib/python3.9/site-packages/bcc/__init__.py", line 507, in __init__ raise Exception("Failed to compile BPF module %s" % (src_file or "<text>")) Exception: Failed to compile BPF module <text> Signed-off-by: Jerome Marchand <[email protected]>
1 parent c351210 commit fb8910a

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

tools/lib/uobjnew.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@
9292
#
9393
elif language == "java":
9494
program += """
95+
#ifndef MIN
96+
#define MIN(x, y) ((x) < (y) ? (x) : (y))
97+
#endif
9598
int alloc_entry(struct pt_regs *ctx) {
9699
struct key_t key = {};
97100
struct val_t *valp, zero = {};
@@ -100,7 +103,7 @@
100103
bpf_usdt_readarg(2, ctx, &classptr);
101104
bpf_usdt_readarg(3, ctx, &length);
102105
bpf_usdt_readarg(4, ctx, &size);
103-
bpf_probe_read_user(&key.name, min(sizeof(key.name), (size_t)length), (void *)classptr);
106+
bpf_probe_read_user(&key.name, MIN(sizeof(key.name), (size_t)length), (void *)classptr);
104107
valp = allocs.lookup_or_try_init(&key, &zero);
105108
if (valp) {
106109
valp->total_size += size;

0 commit comments

Comments
 (0)