tools build: Fix arm64 unistd.h dependency
v4 cover tools build: Fix arm64 unistd.h dependency
The perf build includes arm64's unistd.h, but its dependent header unistd_64.h is missing.
As suggested by Arnd in [1]:
"I would suggest using the same method across all architectures:
either we figure out how to use the generated headers on all of them (including x86, which uses yet another method), or we just stick with the old asm-generic/unistd.h copy and use that on arm64 as well."
A dynamic approach (e.g., make headers_install) may be explored later to generate headers for tools, but that will need consensus from the tools maintainers. In the meantime, this series provides a quick fix by using the asm-generic/unistd.h copy for arm64.
---
Changes in v4:
- Updated commit log in patch 01 to avoid confusion (James).
- Link to v3: https://lore.kernel.org/r/[email protected]
Changes in v3:
- Changed to include asm-generic/unistd.h copy (Arnd).
- Removed check due to divergence between the kernel and tools.
- Link to v2: https://lore.kernel.org/r/[email protected]
Changes in v2:
- Added a consistency check (Ian).
- Rebased on the latest perf-tools-next.
- Link to v1: https://lore.kernel.org/r/[email protected]
---
Leo Yan (3):
tools headers: Go back to include asm-generic/unistd.h for arm64 Revert "perf tools: Fix arm64 build by generating unistd_64.h" tools headers: Don't check arm64's unistd.h
tools/arch/arm64/include/uapi/asm/unistd.h | 24 +++++++++++++++++++++++- tools/lib/perf/Makefile | 14 ++------------ tools/perf/Makefile.config | 1 - tools/perf/check-headers.sh | 1 - 4 files changed, 25 insertions(+), 15 deletions(-)
---
base-commit: cbd41c6d4c26c161a2b0e70ad411d3885ff13507
change-id: 20251203-perf_fix_syscall_header-e280fa931d44
Best regards,
Signature · 1 line
Leo Yan <[email protected]>
PATCH v4 1/3 tools headers: Go back to include asm-generic/unistd.h for arm64
The header unistd.h is included under Arm64's uAPI folder (see tools/arch/arm64/include/uapi/asm/), but it does not include its dependent header unistd_64.h. The intention is for unistd_64.h to be generated dynamically using scripts/Makefile.asm-headers.
However, this dynamic approach causes problems because the header is not available early enough, even though it is widely included throughout tools. Using the perf build as an example:
1) Feature detection: Perf first runs feature tests.
The BPF feature program test-bpf.c includes unistd.h. Since unistd_64.h has not been generated yet, the program fails to build, and the BPF feature ends up being disabled.
2) libperf build:
The libperf Makefile later generates unistd_64.h on the fly, so libperf itself builds successfully.
3) Final perf build:
Although the perf binary can build successfully using the generated header, we never get a chance to build BPF skeleton programs, because BPF support was already disabled earlier.
Restore to include asm-generic/unistd.h for fixing the issue. This aligns with most architectures (x86 is a special case that keeps unistd_32.h/unistd_64.h for its particular syscall numbers) and ensures the header is available from the start.
--- tools/arch/arm64/include/uapi/asm/unistd.h | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-)
tools/arch/arm64/include/uapi/asm/unistd.h +23 -1
@@ -1,2 +1,24 @@/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ -#include <asm/unistd_64.h> +/* +* Copyright (C) 2012 ARM Ltd. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#define __ARCH_WANT_RENAMEAT +#define __ARCH_WANT_NEW_STAT +#define __ARCH_WANT_SET_GET_RLIMIT +#define __ARCH_WANT_TIME32_SYSCALLS +#define __ARCH_WANT_MEMFD_SECRET + +#include <asm-generic/unistd.h>
Signature · 1 line
2.34.1
PATCH v4 2/3 Revert "perf tools: Fix arm64 build by generating unistd_64.h"
In reply to Leo YanThis reverts:
commit 8988c4b91945 ("perf tools: Fix in-source libperf build") commit bfb713ea53c7 ("perf tools: Fix arm64 build by generating unistd_64.h")
Since we now have a static unistd_64.h for the arm64 build, there is no need to generate unistd_64.h in libperf. Revert all patches related to generating unistd_64.h.
--- tools/lib/perf/Makefile | 14 ++------------ tools/perf/Makefile.config | 1 - 2 files changed, 2 insertions(+), 13 deletions(-)
tools/lib/perf/Makefile +2 -12
@@ -42,7 +42,6 @@ libdir_relative_SQ = $(subst ','\'',$(libdir_relative)) TEST_ARGS := $(if $(V),-v) INCLUDES = \ --I$(OUTPUT)arch/$(SRCARCH)/include/generated/uapi \ -I$(srctree)/tools/lib/perf/include \ -I$(srctree)/tools/lib/ \ -I$(srctree)/tools/include \
@@ -100,16 +99,7 @@ $(LIBAPI)-clean: $(call QUIET_CLEAN, libapi) $(Q)$(MAKE) -C $(LIB_DIR) O=$(OUTPUT) clean >/dev/null -uapi-asm := $(OUTPUT)arch/$(SRCARCH)/include/generated/uapi/asm -ifeq ($(SRCARCH),arm64) - syscall-y := $(uapi-asm)/unistd_64.h -endif -uapi-asm-generic: - $(if $(syscall-y),\ - $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.asm-headers obj=$(uapi-asm) \ - generic=include/uapi/asm-generic $(syscall-y),) - -$(LIBPERF_IN): uapi-asm-generic FORCE +$(LIBPERF_IN): FORCE $(Q)$(MAKE) $(build)=libperf $(LIBPERF_A): $(LIBPERF_IN)
@@ -130,7 +120,7 @@ all: fixdep clean: $(LIBAPI)-clean $(call QUIET_CLEAN, libperf) $(RM) $(LIBPERF_A) \ *.o *~ *.a *.so *.so.$(VERSION) *.so.$(LIBPERF_VERSION) .*.d .*.cmd tests/*.o LIBPERF-CFLAGS $(LIBPERF_PC) \ - $(TESTS_STATIC) $(TESTS_SHARED) $(syscall-y) + $(TESTS_STATIC) $(TESTS_SHARED) TESTS_IN = tests-in.o
tools/perf/Makefile.config +0 -1
@@ -64,7 +64,6 @@ include $(srctree)/tools/scripts/Makefile.arch $(call detected_var,SRCARCH) CFLAGS += -I$(OUTPUT)arch/$(SRCARCH)/include/generated -CFLAGS += -I$(OUTPUT)libperf/arch/$(SRCARCH)/include/generated/uapi # Additional ARCH settings for ppc ifeq ($(SRCARCH),powerpc)
Signature · 1 line
2.34.1
PATCH v4 3/3 tools headers: Don't check arm64's unistd.h
In reply to Leo YanThe arm64 unistd.h in tools now diverges from the kernel header. Comparing the two headers is pointless, remove the check.
--- tools/perf/check-headers.sh | 1 - 1 file changed, 1 deletion(-)
tools/perf/check-headers.sh +0 -1
@@ -54,7 +54,6 @@ declare -a FILES=( "arch/s390/include/uapi/asm/kvm.h" "arch/s390/include/uapi/asm/sie.h" "arch/arm64/include/uapi/asm/kvm.h" - "arch/arm64/include/uapi/asm/unistd.h" "arch/alpha/include/uapi/asm/errno.h" "arch/mips/include/asm/errno.h" "arch/mips/include/uapi/asm/errno.h"
Signature · 1 line
2.34.1
Quoted 10 lines · Leo Yan
The perf build includes arm64's
unistd.h, but its dependent headerunistd_64.his missing.As suggested by Arnd in [1]:
"I would suggest using the same method across all architectures:
either we figure out how to use the generated headers on all of them (including x86, which uses yet another method), or we just stick with the oldasm-generic/unistd.hcopy and use that on arm64 as well."
Quoted 5 lines
A dynamic approach (e.g., make
headers_install) may be explored later to generate headers for tools, but that will need consensus from the tools maintainers. In the meantime, this series provides a quick fix by using theasm-generic/unistd.hcopy for arm64.
BPF feature detection is fixed on Arm with this change. And the make headers_install idea sounds good for later.
Quoted 34 lines
Signed-off-by Leo Yan <[email protected]>---
Changes in v4:
- Updated commit log in patch 01 to avoid confusion (James).
- Link to v3: https://lore.kernel.org/r/[email protected]Changes in v3:
- Changed to includeasm-generic/unistd.hcopy (Arnd).
- Removed check due to divergence between the kernel and tools.
- Link to v2: https://lore.kernel.org/r/[email protected]Changes in v2:
- Added a consistency check (Ian).
- Rebased on the latest perf-tools-next.
- Link to v1: https://lore.kernel.org/r/[email protected]---
Leo Yan (3):
tools headers: Go back to includeasm-generic/unistd.hfor arm64 Revert "perf tools: Fix arm64 build by generatingunistd_64.h" tools headers: Don't check arm64'sunistd.htools/arch/arm64/include/uapi/asm/unistd.h | 24 +++++++++++++++++++++++- tools/lib/perf/Makefile | 14 ++------------ tools/perf/Makefile.config | 1 - tools/perf/check-headers.sh | 1 - 4 files changed, 25 insertions(+), 15 deletions(-)---
base-commit:cbd41c6d4c26c161a2b0e70ad411d3885ff13507
change-id: 20251203-perf_fix_syscall_header-e280fa931d44Best regards,