perf parse-events: Include errno.h before kernel headers
PATCH 1/1 perf parse-events: Include errno.h before kernel headers
Building perf against uClibc fails in config_term_common():
util/parse-events.c:954:30: error: 'ERANGE' undeclared
The kernel headers included before errno.h pull in asm/errno.h. uClibc's bits/errno.h undefines EDOM, EILSEQ and ERANGE before including linux/errno.h, but the kernel header include guards prevent these macros from being defined again.
Include errno.h before the kernel headers so ERANGE remains defined.
--- tools/perf/util/parse-events.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/parse-events.c +1 -1
@@ -1,10 +1,10 @@// SPDX-License-Identifier: GPL-2.0 +#include <errno.h> #include <linux/hw_breakpoint.h> #include <linux/err.h> #include <linux/list_sort.h> #include <linux/zalloc.h> #include <dirent.h> -#include <errno.h> #include <sys/ioctl.h> #include <sys/param.h> #include "cpumap.h"
Signature · 1 line
2.53.0
[email protected]
AI reviewSashiko has reviewed this patch and found no issues.
Quoted 9 lines
Building perf against uClibc fails in
config_term_common():
util/parse-events.c:954:30: error: 'ERANGE' undeclaredThe kernel headers included before
errno.hpull inasm/errno.h. uClibc'sbits/errno.hundefines EDOM, EILSEQ and ERANGE before includinglinux/errno.h, but the kernel header include guards prevent these macros from being defined again.
Quoted 4 lines
Include
errno.hbefore the kernel headers so ERANGE remains defined.Fixes 6b9c0261b3fb ("perf record: Add ratio-to-prev term")Signed-off-by Florian Fainelli <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Quoted 23 lines · Florian Fainelli
Building perf against uClibc fails in
config_term_common():util/parse-events.c:954:30: error: 'ERANGE' undeclaredThe kernel headers included before
errno.hpull inasm/errno.h. uClibc'sbits/errno.hundefines EDOM, EILSEQ and ERANGE before includinglinux/errno.h, but the kernel header include guards prevent these macros from being defined again.Include
errno.hbefore the kernel headers so ERANGE remains defined.Fixes 6b9c0261b3fb ("perf record: Add ratio-to-prev term")Signed-off-by Florian Fainelli <[email protected]>--- tools/perf/util/parse-events.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tools/perf/util/parse-events.c +0
-0@@ -1,10 +1,10 @@// SPDX-License-Identifier: GPL-2.0
tools/perf/util/parse-events.c line 10
Quoted 10 lines
tools/perf/util/parse-events.c +1
-1+#include <errno.h> #include <linux/hw_breakpoint.h> #include <linux/err.h> #include <linux/list_sort.h> #include <linux/zalloc.h> #include <dirent.h> -#include <errno.h> #include <sys/ioctl.h> #include <sys/param.h> #include "cpumap.h"
This seems like a bug in uClibc, if it undefs something but then includes a header to re-define it that it expects hasn't already been included. But I suppose even if you fixed it we'd still need some kind of workaround for older versions.
There's another workaround that is slightly less fragile and doesn't have to be applied every time linux/err.h is included in this order. If you change the asm/errno.h include in tools/include/linux/err.h to errno.h then the libc one will always be processed first. It probably makes sense for the userspace copy of the header to use a libc errno anyway.
But maybe it's just as hacky as this fix.
Either way:
Quoted 6 lines · James Clark
On 26/10/2026 17:48, Florian Fainelli wrote:
But maybe it's just as hacky as this fix.Either way:
Reviewed-by James Clark <[email protected]>
Thanks, applied for v7.4.
- Arnaldo