tools/javaobjnew: Use MIN macro instead of min function #5406
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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();
| ^
: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
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 ""))
Exception: Failed to compile BPF module