Commit 682732fe authored by Ben Walker's avatar Ben Walker Committed by Konrad Sztyber
Browse files

build: Respect -j make option for LTO jobs



We previously used -flto=auto, which attempts to connect to the current
make jobserver to query how many jobs to use. If it can't connect, it
falls back to using the number of CPU cores. GCC itself uses make to run
these LTO jobs.

Since we use make to invoke gcc, and gcc then invokes make, this is a
RECURSIVE make call. In order for the inner-make to find the jobserver
we need to ensure we've done the correct set up for recursive make,
which means prepending the "+" symbol to the line that calls GCC.

We also change from -flto=auto to -flto=jobserver. If it can't find the
job server, it will now produce an error and default to just 1 core.
This is a more sensible behavior than silently failing and defaulting to
all cores, which can lock up build systems.

Change-Id: I4d05a815dbc71f695abb93f208136f741a28118f
Signed-off-by: default avatarBen Walker <ben@nvidia.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/24652


Community-CI: Mellanox Build Bot
Reviewed-by: default avatarJim Harris <jim.harris@samsung.com>
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarKonrad Sztyber <konrad.sztyber@intel.com>
parent 30afc277
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -97,8 +97,8 @@ COMMON_CFLAGS += -Werror
endif

ifeq ($(CONFIG_LTO),y)
COMMON_CFLAGS += -flto=auto
LDFLAGS += -flto=auto
COMMON_CFLAGS += -flto=jobserver
LDFLAGS += -flto=jobserver
else
COMMON_CFLAGS += -fno-lto
LDFLAGS += -fno-lto
@@ -409,11 +409,11 @@ endif

# Link $(OBJS) and $(LIBS) into $@ (app)
LINK_C=\
	$(Q)echo "  LINK $(notdir $@)"; \
	$(Q)+echo "  LINK $(notdir $@)"; \
	$(CC) -o $@ $(CFLAGS) $(LDFLAGS) $(OBJS) $(LIBS) $(ENV_LDFLAGS) $(SYS_LIBS)

LINK_CXX=\
	$(Q)echo "  LINK $(notdir $@)"; \
	$(Q)+echo "  LINK $(notdir $@)"; \
	$(CXX) -o $@ $(CXXFLAGS) $(LDFLAGS) $(OBJS) $(LIBS) $(ENV_LDFLAGS) $(SYS_LIBS)

# Provide function to ease build of a shared lib