]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libsanitizer: parallelize subdir builds
authorHarmen Stoppels <me@harmenstoppels.nl>
Thu, 23 Jul 2026 09:57:42 +0000 (11:57 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Thu, 23 Jul 2026 09:57:42 +0000 (11:57 +0200)
Automake normally builds subdirectories sequentially, which makes the
libsanitizer builds effectively sequential as there is little parallelism per
subdirectory. This patch replaces the all-recursive loop with an explicit
dependency graph: asan and hwasan depend on lsan, while others just need
sanitizer_common.

Exposing this DAG to make raises the CPU load from 2.3 to 3.7, yielding a
roughly 30% reduction in build time on multi-core machines.

libsanitizer/ChangeLog:

* Makefile.am: Override all-recursive and define explicit
DAG dependencies for all-* targets to enable parallel builds.
* Makefile.in: Regenerate.

Signed-off-by: Harmen Stoppels <me@harmenstoppels.nl>
Reviewed-by: Jakub Jelinek <jakub@redhat.com>
libsanitizer/Makefile.am
libsanitizer/Makefile.in

index 53e20bdac2c5c43b55845a982377ab5688d50a4c..2e3245c8d87199faf79f1575e1fa0187f5b36d83 100644 (file)
@@ -26,6 +26,30 @@ endif
 if HWASAN_SUPPORTED
 SUBDIRS += hwasan
 endif
+
+# Override all-recursive and explicitly define the dependency graph
+# to increase parallelism during the build.
+
+all-sanitizer_common all-interception all-libbacktrace:
+       +cd $(@:all-%=%) && $(MAKE) $(AM_MAKEFLAGS) all
+
+SANITIZER_BASE_DEPS = all-sanitizer_common
+if !USING_MAC_INTERPOSE
+SANITIZER_BASE_DEPS += all-interception
+endif
+if LIBBACKTRACE_SUPPORTED
+SANITIZER_BASE_DEPS += all-libbacktrace
+endif
+
+all-lsan all-ubsan all-tsan: $(SANITIZER_BASE_DEPS)
+       +cd $(@:all-%=%) && $(MAKE) $(AM_MAKEFLAGS) all
+
+all-asan all-hwasan: $(SANITIZER_BASE_DEPS) all-lsan
+       +cd $(@:all-%=%) && $(MAKE) $(AM_MAKEFLAGS) all
+
+all-recursive: $(SUBDIRS:%=all-%)
+
+.PHONY: $(SUBDIRS:%=all-%)
 endif
 
 ## Force DIST_SUBDIRS so that make distclean works
index fa6fe9e26a3ea88e4cd98158dabd80e2ba066556..280e45cdbe49d8f963ef234a9080135191bce464 100644 (file)
@@ -98,6 +98,8 @@ target_triplet = @target@
 @LIBBACKTRACE_SUPPORTED_TRUE@@SANITIZER_SUPPORTED_TRUE@am__append_3 = libbacktrace
 @SANITIZER_SUPPORTED_TRUE@@TSAN_SUPPORTED_TRUE@am__append_4 = tsan
 @HWASAN_SUPPORTED_TRUE@@SANITIZER_SUPPORTED_TRUE@am__append_5 = hwasan
+@SANITIZER_SUPPORTED_TRUE@@USING_MAC_INTERPOSE_FALSE@am__append_6 = all-interception
+@LIBBACKTRACE_SUPPORTED_TRUE@@SANITIZER_SUPPORTED_TRUE@am__append_7 = all-libbacktrace
 subdir = .
 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
 am__aclocal_m4_deps = $(top_srcdir)/../config/acx.m4 \
@@ -370,6 +372,8 @@ nodist_saninclude_HEADERS = $(am__append_1)
 @SANITIZER_SUPPORTED_TRUE@SUBDIRS = sanitizer_common $(am__append_2) \
 @SANITIZER_SUPPORTED_TRUE@     $(am__append_3) lsan asan ubsan \
 @SANITIZER_SUPPORTED_TRUE@     $(am__append_4) $(am__append_5)
+@SANITIZER_SUPPORTED_TRUE@SANITIZER_BASE_DEPS = all-sanitizer_common \
+@SANITIZER_SUPPORTED_TRUE@     $(am__append_6) $(am__append_7)
 DIST_SUBDIRS = $(SUBDIRS)
 gcc_version := $(shell @get_gcc_base_ver@ $(top_srcdir)/../gcc/BASE-VER)
 
@@ -765,6 +769,22 @@ uninstall-am: uninstall-nodist_sanincludeHEADERS \
 .PRECIOUS: Makefile
 
 
+# Override all-recursive and explicitly define the dependency graph
+# to increase parallelism during the build.
+
+@SANITIZER_SUPPORTED_TRUE@all-sanitizer_common all-interception all-libbacktrace:
+@SANITIZER_SUPPORTED_TRUE@     +cd $(@:all-%=%) && $(MAKE) $(AM_MAKEFLAGS) all
+
+@SANITIZER_SUPPORTED_TRUE@all-lsan all-ubsan all-tsan: $(SANITIZER_BASE_DEPS)
+@SANITIZER_SUPPORTED_TRUE@     +cd $(@:all-%=%) && $(MAKE) $(AM_MAKEFLAGS) all
+
+@SANITIZER_SUPPORTED_TRUE@all-asan all-hwasan: $(SANITIZER_BASE_DEPS) all-lsan
+@SANITIZER_SUPPORTED_TRUE@     +cd $(@:all-%=%) && $(MAKE) $(AM_MAKEFLAGS) all
+
+@SANITIZER_SUPPORTED_TRUE@all-recursive: $(SUBDIRS:%=all-%)
+
+@SANITIZER_SUPPORTED_TRUE@.PHONY: $(SUBDIRS:%=all-%)
+
 # GNU Make needs to see an explicit $(MAKE) variable in the command it
 # runs to enable its job server during parallel builds.  Hence the
 # comments below.