gb_LTOFLAGS: use -flto=jobserver instead of fixed $(PARALLELISM)

fixed PARALLELISM causes explosion of jobs, especially when machines
wtih many cores/threads. A make wtih PARALLELISM=16 would launch up to
16 linker invocations that by themselves would also do their linking
with a parallelism of 16, causing load of over 100 and very likely
exhausting all memory bringing the system to a crawl or cause OOM kills.

for a command to be able to communicate with make's jobserver, it must
be part of a submake called with $(MAKE) or the command from the rule
needs to be prefixed with the + character.
While our gbuild stuff is a submake call, it only is that submake that
uses the PARALLELISM flags determined by configure, so that is not
sufficient for jobserver usage by the the lto linker.

Change-Id: I46ec4760c1a8623195700b8cb16f7deafeb1111e
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/144593
Tested-by: Jenkins
Reviewed-by: Christian Lohmaier <lohmaier+LibreOffice@googlemail.com>
diff --git a/solenv/gbuild/platform/com_GCC_defs.mk b/solenv/gbuild/platform/com_GCC_defs.mk
index 7a2066a..6eeda2f 100644
--- a/solenv/gbuild/platform/com_GCC_defs.mk
+++ b/solenv/gbuild/platform/com_GCC_defs.mk
@@ -197,8 +197,8 @@ ifeq (,$(index,iOS MACOSX,$(OS)))
gb_LTOPLUGINFLAGS := --plugin $(if $(LD_PLUGIN),$(LD_PLUGIN),LLVMgold.so)
endif
else
# use first element of the PARALLELISM, to allow values like "12 -l 14" to specify load limits
gb_LTOFLAGS := -flto=$(if $(filter-out 0,$(PARALLELISM)),$(firstword $(PARALLELISM)),auto) -fuse-linker-plugin -O2
# use parallelism based on make's job handling
gb_LTOFLAGS := -flto=jobserver -fuse-linker-plugin -O2
# clang does not support -flto=<number>
gb_CLANG_LTOFLAGS := -flto=thin
endif
diff --git a/solenv/gbuild/platform/unxgcc.mk b/solenv/gbuild/platform/unxgcc.mk
index 5e971bd..461d1f0 100644
--- a/solenv/gbuild/platform/unxgcc.mk
+++ b/solenv/gbuild/platform/unxgcc.mk
@@ -134,7 +134,7 @@ $(if $(call gb_LinkTarget__WantLock,$2), \
   $(gb_LinkTarget__cmd_lockfile) -r -1 $(gb_LinkTarget__Lock) ;  \
   echo "$(call gb_Output_announce_str,$(2): got link lock at $$(date -u),$(true),LNK,5)" ; \
)
	$(if $(filter EMSCRIPTEN,$(OS)),unset PYTHONWARNINGS ;) \
	+$(if $(filter EMSCRIPTEN,$(OS)),unset PYTHONWARNINGS ;) \
$(call gb_Helper_abbreviate_dirs,\
	$(if $(call gb_LinkTarget__NeedsCxxLinker),$(or $(T_CXX),$(gb_CXX)) $(gb_CXX_LINKFLAGS),$(or $(T_CC),$(gb_CC))) \
		$(if $(filter Library CppunitTest,$(TARGETTYPE)),$(gb_Library_TARGETTYPEFLAGS)) \