[PATCH] gbuild: LinkTarget: only re-link libraries if exported symbo...

Michael Stahl (via Code Review) gerrit at gerrit.libreoffice.org
Mon Apr 8 02:03:20 PDT 2013


Hi,

I have submitted a patch for review:

    https://gerrit.libreoffice.org/3272

To pull it, you can do:

    git pull ssh://gerrit.libreoffice.org:29418/core refs/changes/72/3272/1

gbuild: LinkTarget: only re-link libraries if exported symbols change

Write out the exported symbols of a Library to a "libfoo.so.exports"
file, which is only touched when linking if the exported symbols
actually change, and let dependent LinkTargets depend on this
exports file instead of the library itself, for faster rebuilds.

Thnans to Ami Fischman of Chromium for the idea.

Change-Id: Ie4b5da0853140709e517028b514800b044527e61
---
M solenv/gbuild/LinkTarget.mk
M solenv/gbuild/platform/android.mk
M solenv/gbuild/platform/com_GCC_class.mk
M solenv/gbuild/platform/com_MSC_class.mk
M solenv/gbuild/platform/macosx.mk
M solenv/gbuild/platform/solaris.mk
M solenv/gbuild/platform/unxgcc.mk
7 files changed, 54 insertions(+), 1 deletion(-)



diff --git a/solenv/gbuild/LinkTarget.mk b/solenv/gbuild/LinkTarget.mk
index 46952c8..f1e4097 100644
--- a/solenv/gbuild/LinkTarget.mk
+++ b/solenv/gbuild/LinkTarget.mk
@@ -402,6 +402,7 @@
 		$(call gb_LinkTarget_get_headers_target,$*) \
 		$(call gb_LinkTarget_get_external_headers_target,$*) \
 		$(call gb_LinkTarget_get_objects_list,$*) \
+		$(call gb_LinkTarget_get_target,$*).exports \
 		$(DLLTARGET) \
 		$(AUXTARGETS)) && \
 		cat $${RESPONSEFILE} /dev/null | xargs -n 200 rm -fr && \
@@ -441,6 +442,14 @@
 mv $${TEMPFILE} $(call gb_LinkTarget_get_objects_list,$(2))
 
 endef
+
+# Target for the .exports of the shared library, to speed up incremental build.
+# This deliberately does nothing if the file exists; the file is actually
+# written in gb_LinkTarget__command_dynamiclink.
+# Put this pattern rule here so it overrides the one below.
+# (this is rather ugly: because of % the functions cannot be used)
+$(call gb_LinkTarget_get_target,Library/%.exports) : $(gb_Library_OUTDIRLOCATION)/%
+	$(if $(wildcard $@),true,touch $@)
 
 # If object files from this library are merged, create just empty file
 $(call gb_LinkTarget_get_target,%) : $(call gb_LinkTarget_get_headers_target,%) $(gb_Helper_MISCDUMMY)
@@ -832,7 +841,10 @@
 
 $(call gb_LinkTarget_get_target,$(1)) : LINKED_LIBS += $(3)
 
-$(call gb_LinkTarget_get_target,$(1)) : $(foreach lib,$(3),$(call gb_Library_get_target,$(lib)))
+# depend on the exports of the library, not on the library itself
+# for faster incremental builds when the ABI is unchanged
+$(call gb_LinkTarget_get_target,$(1)) : \
+	$(foreach lib,$(3),$(call gb_Library_get_exports_target,$(lib)))
 $(call gb_LinkTarget_get_external_headers_target,$(1)) : \
 	$(foreach lib,$(2),$(call gb_Library_get_headers_target,$(lib)))
 
diff --git a/solenv/gbuild/platform/android.mk b/solenv/gbuild/platform/android.mk
index 1f4bf81..7dc95b8 100644
--- a/solenv/gbuild/platform/android.mk
+++ b/solenv/gbuild/platform/android.mk
@@ -52,6 +52,14 @@
 		$(LIBS) \
 		$(patsubst lib%.a,-l%,$(patsubst lib%.so,-l%,$(foreach lib,$(LINKED_LIBS),$(call gb_Library_get_filename,$(lib))))) \
 		-o $(1))
+	$(if $(filter Library,$(TARGETTYPE)),\
+		$(NM) --extern-only --dynamic --format=posix $(1) \
+			| cut -d' ' -f1-2 | grep -v U$$ \
+			> $(1).exports.tmp && \
+		if cmp -s $(1).exports.tmp $(1).exports; \
+			then rm $(1).exports.tmp; \
+			else mv $(1).exports.tmp $(1).exports; touch -r $(1) $(1).exports; \
+		fi)
 endef
 
 ifeq ($(DISABLE_DYNLOADING),TRUE)
diff --git a/solenv/gbuild/platform/com_GCC_class.mk b/solenv/gbuild/platform/com_GCC_class.mk
index c8a8d33..4f30a50 100644
--- a/solenv/gbuild/platform/com_GCC_class.mk
+++ b/solenv/gbuild/platform/com_GCC_class.mk
@@ -240,6 +240,10 @@
 		)
 endef
 
+define gb_Library_get_exports_target
+$(call gb_LinkTarget_get_target,$(call gb_Library_get_linktargetname,$(1))).exports
+endef
+
 # YaccTarget class
 
 ifeq ($(ANCIENT_BISON),YES)
diff --git a/solenv/gbuild/platform/com_MSC_class.mk b/solenv/gbuild/platform/com_MSC_class.mk
index 55aff01..2575aa1 100755
--- a/solenv/gbuild/platform/com_MSC_class.mk
+++ b/solenv/gbuild/platform/com_MSC_class.mk
@@ -351,6 +351,11 @@
 $(patsubst $(1):%,%,$(filter $(1):%,$(gb_Library_DLLFILENAMES)))
 endef
 
+# this is nerfed, it just points to the library to disable the .exports
+define gb_Library_get_exports_target
+$(call gb_LinkTarget_get_target,$(call gb_Library_get_linktargetname,$(1)))
+endef
+
 
 # StaticLibrary class
 
diff --git a/solenv/gbuild/platform/macosx.mk b/solenv/gbuild/platform/macosx.mk
index 970d6bd..6c0284f 100644
--- a/solenv/gbuild/platform/macosx.mk
+++ b/solenv/gbuild/platform/macosx.mk
@@ -163,6 +163,14 @@
 	$(if $(MACOSX_CODESIGNING_IDENTITY), \
 		$(if $(filter Executable,$(TARGETTYPE)), \
 			codesign --identifier=$(MACOSX_BUNDLE_IDENTIFIER).$(notdir $(1)) --sign $(MACOSX_CODESIGNING_IDENTITY) $(1) &&)) \
+	$(if $(filter Library,$(TARGETTYPE)),\
+		otool -l $(1) | grep -A 5 LC_ID_DYLIB > $(1).exports.tmp && \
+		$(NM) -g -P $(1) | cut -d' ' -f1-2 | grep -v U$$ \
+			>> $(1).exports.tmp && \
+		if cmp -s $(1).exports.tmp $(1).exports; \
+			then rm $(1).exports.tmp; \
+			else mv $(1).exports.tmp $(1).exports; touch -r $(1) $(1).exports; \
+		fi &&) \
 	:)
 endef
 
diff --git a/solenv/gbuild/platform/solaris.mk b/solenv/gbuild/platform/solaris.mk
index 037a1a1..bf4d848 100644
--- a/solenv/gbuild/platform/solaris.mk
+++ b/solenv/gbuild/platform/solaris.mk
@@ -199,6 +199,14 @@
 		$(LIBS) \
 		$(patsubst lib%.a,-l%,$(patsubst lib%.so,-l%,$(foreach lib,$(LINKED_LIBS),$(call gb_Library_get_filename,$(lib))))) \
 		-o $(1))
+	$(if $(filter Library,$(TARGETTYPE)),\
+		$(NM) --extern-only --dynamic --format=posix $(1) \
+			| cut -d' ' -f1-2 | grep -v U$$ \
+			> $(1).exports.tmp && \
+		if cmp -s $(1).exports.tmp $(1).exports; \
+			then rm $(1).exports.tmp; \
+			else mv $(1).exports.tmp $(1).exports; touch -r $(1) $(1).exports; \
+		fi)
 endef
 
 define gb_LinkTarget__command_staticlink
diff --git a/solenv/gbuild/platform/unxgcc.mk b/solenv/gbuild/platform/unxgcc.mk
index 14f5882..b2f9e70 100644
--- a/solenv/gbuild/platform/unxgcc.mk
+++ b/solenv/gbuild/platform/unxgcc.mk
@@ -202,6 +202,14 @@
 		$(patsubst lib%.a,-l%,$(patsubst lib%.so,-l%,$(foreach lib,$(LINKED_LIBS),$(call gb_Library_get_filename,$(lib))))) \
 		-o $(if $(SOVERSION),$(1).$(SOVERSION),$(1)))
 	$(if $(SOVERSION),ln -sf $(notdir $(1)).$(SOVERSION) $(1))
+	$(if $(filter Library,$(TARGETTYPE)),\
+		$(NM) --extern-only --dynamic --format=posix $(1) \
+			| cut -d' ' -f1-2 | grep -v U$$ \
+			> $(1).exports.tmp && \
+		if cmp -s $(1).exports.tmp $(1).exports; \
+			then rm $(1).exports.tmp; \
+			else mv $(1).exports.tmp $(1).exports; touch -r $(1) $(1).exports; \
+		fi)
 endef
 
 define gb_LinkTarget__command_staticlink

-- 
To view, visit https://gerrit.libreoffice.org/3272
To unsubscribe, visit https://gerrit.libreoffice.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie4b5da0853140709e517028b514800b044527e61
Gerrit-PatchSet: 1
Gerrit-Project: core
Gerrit-Branch: master
Gerrit-Owner: Michael Stahl <mstahl at redhat.com>



More information about the LibreOffice mailing list