libperf: fix parallel build race with header install
Subsystems (2)
PATCH 1/1 libperf: fix parallel build race with header install
When perf is built with high parallelism (-j128), there is a race condition between the install_headers and libperf.a targets in the libperf sub-build. Both are invoked as targets of a single make invocation from Makefile.perf:
$(MAKE) -C $(LIBPERF_DIR) ... $@ install_headers
The perf tool's exported CFLAGS includes -I$(LIBPERF_OUTPUT)/include which points to the header install destination. The coreutils install command creates the destination file (truncated) before writing content. If the compiler runs between file creation and content write, it includes an empty header, causing incomplete type and missing prototype errors in the libperf source files.
Fix this by making the libperf compilation target depend on install_headers, ensuring all headers are fully installed before any source files are compiled.
--- tools/lib/perf/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/lib/perf/Makefile +1 -1
@@ -99,7 +99,7 @@ $(LIBAPI)-clean: $(call QUIET_CLEAN, libapi) $(Q)$(MAKE) -C $(LIB_DIR) O=$(OUTPUT) clean >/dev/null -$(LIBPERF_IN): FORCE +$(LIBPERF_IN): install_headers FORCE $(Q)$(MAKE) $(build)=libperf $(LIBPERF_A): $(LIBPERF_IN)
Signature · 1 line
2.50.1 (Apple Git-155)
[email protected]
AI reviewSashiko AI review found 1 potential issue(s): - [Medium] The patch breaks standalone compilation of `libperf` for unprivileged users and improperly pollutes the host filesystem for root users. --
Sashiko AI review found 1 potential issue(s):
- [Medium] The patch breaks standalone compilation of libperf for unprivileged users and improperly pollutes the host filesystem for root users. --
commit 208fe5b88e547b876734f4625a046aecb0847770
Author: Gaurav Sharma <[email protected]>
libperf: fix parallel build race with header install
This commit attempts to fix a race condition between the install_headers and libperf.a targets when building with high parallelism. It does this by making the libperf compilation target depend on install_headers.
Quoted 3 lines
tools/lib/perf/Makefile +0
-0
[ ... ]
tools/lib/perf/Makefile $(LIBAPI)-clean: · line 103
Quoted 7 lines
tools/lib/perf/Makefile +1
-1@@ -99,7 +99,7 @@ $(LIBAPI)-clean: $(call QUIET_CLEAN, libapi) $(Q)$(MAKE) -C $(LIB_DIR) O=$(OUTPUT) clean >/dev/null -$(LIBPERF_IN): FORCE +$(LIBPERF_IN): install_headers FORCE $(Q)$(MAKE) $(build)=libperf
Does this break standalone compilation of libperf for unprivileged users?
In a standalone build (e.g., make -C tools/lib/perf), variables like DESTDIR and prefix default to empty strings. Because of this, it appears that INSTALL_HDRS_PFX will evaluate to the absolute path /include/perf.
Won't forcing a standard compilation to execute system-level installation steps abort the build with a 'Permission denied' error for unprivileged users? For root users, will this unexpectedly write to /include/perf and pollute the host's root filesystem outside of an explicit make install phase?
Would it be better to serialize the install_headers and compilation targets in the caller (tools/perf/Makefile.perf) rather than within the library's local build rules?
Serializing these targets in Makefile.perf would also resolve identical pre-existing parallel build races in libapi, libbpf, libsubcmd, and libsymbol which are not covered by this change.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Ian Rogers
reviewerQuoted 15 lines · Gaurav Sharma
When perf is built with high parallelism (-j128), there is a race condition between the
install_headersand libperf.a targets in the libperf sub-build. Both are invoked as targets of a single make invocation from Makefile.perf:$(MAKE) -C $(LIBPERF_DIR) ... $@ install_headersThe perf tool's exported CFLAGS includes -I$(LIBPERF_OUTPUT)/include which points to the header install destination. The coreutils install command creates the destination file (truncated) before writing content. If the compiler runs between file creation and content write, it includes an empty header, causing incomplete type and missing prototype errors in the libperf source files.
Quoted 7 lines
Fix this by making the libperf compilation target depend on
install_headers, ensuring all headers are fully installed before any source files are compiled.Fixes 91009a3a9913 ("perf build: Install libperf locally when building")Signed-off-by Gaurav Sharma <[email protected]>
I believe this was addressed by:
https://web.git.kernel.org/pub/scm/linux/kernel/git/perf/perf-tools-next.git/commit/tools/lib/perf/Makefile?h=perf-tools-next&id=8c5b40678c63be6b85f1c2dc8c8b89d632faf988
Thanks,
Ian
Quoted 20 lines
--- tools/lib/perf/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tools/lib/perf/Makefile +1
-2@@ -99,7 +99,7 @@ $(LIBAPI)-clean: $(call QUIET_CLEAN, libapi) $(Q)$(MAKE) -C $(LIB_DIR) O=$(OUTPUT) clean >/dev/null -$(LIBPERF_IN): FORCE +$(LIBPERF_IN): install_headers FORCE $(Q)$(MAKE) $(build)=libperf $(LIBPERF_A): $(LIBPERF_IN) --2.50.1 (Apple Git-155)