libtraceevent: avoid racing recursive builds of both libraries
PATCH 1/1 libtraceevent: avoid racing recursive builds of both libraries
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.
Make the default libs target descend into src/ only once and build the shared library plus static archive from the same sub-make. Keep the individual top-level library targets unchanged for direct use.
This reliably fixes repeated make -j8 and make -j8 libs failures in a Linux VM, where the unfixed tree reproduces the race within a few runs.
--- Makefile | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
Makefile +4 -3
@@ -183,9 +183,9 @@ build := -f $(srctree)/build/Makefile.build dir=. obj LIB_TARGET := libtraceevent.so libtraceevent.a -CMD_TARGETS = $(LIB_TARGET) $(PKG_CONFIG_FILE) +CMD_TARGETS = libs $(PKG_CONFIG_FILE) -TARGETS = $(CMD_TARGETS) +TARGETS = $(LIB_TARGET) $(PKG_CONFIG_FILE) all: all_cmd plugins
@@ -206,7 +206,8 @@ all_cmd: $(CMD_TARGETS) libtraceevent.a: $(bdir) $(LIBTRACEEVENT_STATIC) libtraceevent.so: $(bdir) $(LIBTRACEEVENT_SHARED) -libs: libtraceevent.a libtraceevent.so +libs: $(bdir) force + $(Q)$(call descend,$(src)/src,libtraceevent.so $(LIBTRACEEVENT_STATIC)) $(LIBTRACEEVENT_STATIC): force $(Q)$(call descend,$(src)/src,$@)
Signature · 1 line
2.39.5 (Apple Git-154)
PATCH v2 1/1 libtraceevent: avoid racing recursive builds of both libraries
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 builds libtraceevent.so as part of the libtraceevent.a target. Reflect that at the top level too by making the shared library target depend on the static library target, so parallel requests for either or both libraries funnel through a single recursive make.
This fixes repeated make -j8, make -j8 libs, and make -j8 libtraceevent.a libtraceevent.so failures in a Linux VM, where the unfixed tree reproduces the race within a few runs.
--- Makefile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
Makefile +1 -2
@@ -211,8 +211,7 @@ libs: libtraceevent.a libtraceevent.so $(LIBTRACEEVENT_STATIC): force $(Q)$(call descend,$(src)/src,$@) -$(LIBTRACEEVENT_SHARED): force - $(Q)$(call descend,$(src)/src,libtraceevent.so) +$(LIBTRACEEVENT_SHARED): $(LIBTRACEEVENT_STATIC) $(bdir)/libtraceevent.so: $(bdir)/libtraceevent.so.$(EP_VERSION) @ln -sf $(<F) $@
Signature · 1 line
2.39.5 (Apple Git-154)
On Mon, 6 Apr 2026 14:28:55 +0800
CaoRuichuang <[email protected]> wrote:
Sorry for the late reply, I've been quite busy on the kernel side of things.
Quoted 26 lines
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/
Makefilealready builds libtraceevent.so as part of the libtraceevent.a target. Reflect that at the top level too by making the shared library target depend on the static library target, so parallel requests for either or both libraries funnel through a single recursive make.This fixes repeated
make -j8,make -j8 libs, andmake -j8 libtraceevent.a libtraceevent.sofailures in a Linux VM, where the unfixed tree reproduces the race within a few runs.Signed-off-by CaoRuichuang <[email protected]>--- Makefile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)Makefile +0
-0
Makefile libs: libtraceevent.a libtraceevent.so · line 214
Quoted 6 lines
Makefile +1
-2@@ -211,8 +211,7 @@ libs: libtraceevent.a libtraceevent.so $(LIBTRACEEVENT_STATIC): force $(Q)$(call descend,$(src)/src,$@) -$(LIBTRACEEVENT_SHARED): force - $(Q)$(call descend,$(src)/src,libtraceevent.so) +$(LIBTRACEEVENT_SHARED): $(LIBTRACEEVENT_STATIC)
As you state in the change log, "Makefile already builds libtraceevent.so as part of the libtraceevent.a target", wouldn't that mean the above should be:
$(LIBTRACEEVENT_STATIC): $(LIBTRACEEVENT_SHARED)
$(LIBTRACEEVENT_SHARED): force
$(Q)$(call descend,$(src)/src,libtraceevent.so)
??
BTW, thanks for working on this. Sorry I couldn't get to it earlier.
-- Steve
Quoted 3 lines
Makefile +0
-0$(bdir)/libtraceevent.so: $(bdir)/libtraceevent.so.$(EP_VERSION) @ln -sf $(<F) $@
PATCH v3 1/1 libtraceevent: avoid racing recursive builds of both libraries
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.
---
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(-)
Makefile +1 -1
@@ -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
Signature · 1 line
2.39.5 (Apple Git-154)
Quoted 12 lines · On Mon, 1 Jun 2026 16:20:24 +0800 Cao Ruichuang <[email protected]> wrote:
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.
Quoted 7 lines
This fixes the object-file race seen when top-level parallel builds request both libraries, for example via
make -j8 libsormake -j8 libtraceevent.a libtraceevent.so.Assisted-by Codex:gpt-5.5Signed-off-by Cao Ruichuang <[email protected]>
Thanks for the updates.
For future version updates, please start a new email thread and do not reply to the old one. It makes it easier to manage for maintainers.
Also, the tracing code uses capital letters to start subjects:
[PATCH v3] libtraceevent: Avoid racing recursive builds of both libraries
Quoted 2 lines
---
Changes in v3:
In order to still keep the trail of versions, you can use lore with the Message-ID of the previous email version:
Changes since v2: https://lore.kernel.org/all/[email protected]/
If all looks good, I'll go ahead and apply your patches.
Thanks again,
-- Steve
Quoted 31 lines
- 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_64Linux 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 testMakefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)Makefile +1
-1@@ -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