path: root/solenv/gbuild
diff options
authorLuboš Luňák <>2019-06-22 21:17:56 +0200
committerLuboš Luňák <>2020-01-18 14:56:37 +0100
commita0323937ff4b36594e26b5c1a143af188c75abfc (patch)
treec72205ba55e37fe8bdc934b52097dd8074cbac13 /solenv/gbuild
parent68c934c08401d1edbd89746dd0d554d7fc80665b (diff)
support Clang's -fmodules-codegen/debuginfo options for PCH building
These (starting with my patches for Clang-to-be-10) allowing emitting debuginfo and functions into a dedicated object file, so that all the normal compilations using the PCH can skip those, thus saving the time. The debuginfo option seems to always be worth it. The codegen option is more tricky, it doesn't seem to be worth it for optimized builds (optimizing all the functions in that one object file costs too much). This requires also using --Wl,--gc-sections . The reason is that the object file contains all template instances instantiated from the PCH, so that they can be shared, but the template instance may come from another library or use a private symbol from that library. For example the std::unique_ptr<ScInterpreterContext> in ScInterpreterContextPool in the header refers to ScInterpreterContext dtor. But even though both these classes are private, the header gets used also by scfilt, because there it is included by document.hxx because of a private ScDocument data member. So even though nothing in scfilt uses ScInterpreterContext, the PCH object file will refer to it. Fortunately that template instance itself is not used by scfilt, so --gc-sections will remove it. Change-Id: I2a06ebcc4dd4175424b3a72ab3ebcaf2ac3ee295 Reviewed-on: Tested-by: Jenkins Reviewed-by: Luboš Luňák <>
Diffstat (limited to 'solenv/gbuild')
1 files changed, 15 insertions, 1 deletions
diff --git a/solenv/gbuild/platform/ b/solenv/gbuild/platform/
index 2ec7a66f3e25..f40d315b1c3b 100644
--- a/solenv/gbuild/platform/
+++ b/solenv/gbuild/platform/
@@ -89,8 +89,22 @@ gb_PrecompiledHeader_EXT := .gch
# Clang supports building extra object file where it puts code that would be shared by all users of the PCH.
-# Unlike with MSVC it is built as a separate step.
+# Unlike with MSVC it is built as a separate step. The relevant options are used only when generating the PCH
+# and when creating the PCH's object file, normal compilations using the PCH do not need extra options.
gb_PrecompiledHeader_pch_with_obj = $(BUILDING_PCH_WITH_OBJ)
+# If using Clang's PCH extra object, we may need to strip unused sections, otherwise inline and template functions
+# emitted in that object may in some cases cause unresolved references to private symbols in other libraries.
+gb_LinkTarget_LDFLAGS += -Wl,--gc-sections
+gb_PrecompiledHeader_pch_with_obj += -ffunction-sections -fdata-sections
+# Enable generating more shared code and debuginfo in the PCH object file.
+gb_PrecompiledHeader_pch_with_obj += $(PCH_MODULES_DEBUGINFO)
+# -fmodules-codegen appears to be worth it only if not optimizing, otherwise optimizing all the functions emitted
+# in the PCH object file may take way too long, especially given that many of those may get thrown away
+gb_PrecompiledHeader_pch_with_obj += $(PCH_MODULES_CODEGEN)
# This is for MSVC's object file built directly as a side-effect of building the PCH.
gb_PrecompiledHeader_get_objectfile =