[PATCH v3] libtraceevent: avoid racing recursive builds of both libraries

Cao Ruichuang <[email protected]> Mon, 1 Jun 2026 16:20:24 +0800
Newsgroups org.kernel.vger.linux-trace-devel
Message-ID <[email protected]>
A top-level parallel build currently starts separate recursive makes for
libtraceevent.a and libtraceevent.so. Both sub-makes rebuild the same
object files in the same output directory, which can corrupt the .o files
and make the final link fail with file format errors.

The src/Makefile already has the static library depend on the shared
library before running objcopy. Reflect that dependency at the top level
too by also making the static library target depend on the shared library
target. This serializes parallel top-level requests for both libraries
while preserving the shared-before-static build order and the existing
forced static-library recursive make.

This fixes the object-file race seen when top-level parallel builds
request both libraries, for example via `make -j8 libs` or
`make -j8 libtraceevent.a libtraceevent.so`.

Link: https://bugzilla.kernel.org/show_bug.cgi?id=217428
Assisted-by: Codex:gpt-5.5
Signed-off-by: Cao Ruichuang <[email protected]>
---
Changes in v3:
- Follow Steven's review and make the top-level static library target
  depend on the shared library target, matching src/Makefile's dependency
  direction.
- Preserve the existing forced static-library recursive make while
  serializing parallel top-level requests shared-before-static.

Tested on x86_64 Linux with GNU Make 4.3, GCC 11.5.0, and GNU objcopy
2.35.2:
- make -j8 libs
- make -j8 libtraceevent.a libtraceevent.so
- 20 iterations of: make clean && make -j8 libs
- 10 iterations of: make clean && make -j8 libtraceevent.a libtraceevent.so
- make -j8
- make -j8 test

 Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Makefile b/Makefile
index e1a10a0..d1ceaee 100644
--- a/Makefile
+++ b/Makefile
@@ -208,7 +208,7 @@ libtraceevent.so: $(bdir) $(LIBTRACEEVENT_SHARED)
 
 libs: libtraceevent.a libtraceevent.so
 
-$(LIBTRACEEVENT_STATIC): force
+$(LIBTRACEEVENT_STATIC): force $(LIBTRACEEVENT_SHARED)
 	$(Q)$(call descend,$(src)/src,$@)
 
 $(LIBTRACEEVENT_SHARED): force
-- 
2.39.5 (Apple Git-154)