mk: link core to library archive instead of .o file

Do not link base and core libraries into on large relocatable .o file,
which is linked later to core - causing long link times. Create an
independent library archive out of the base and core libraries that can
be linked faster.

issue #4027
This commit is contained in:
Sebastian Sumpf
2021-02-19 15:23:49 +01:00
committed by Norman Feske
parent 64165d829e
commit f68e655312
16 changed files with 49 additions and 33 deletions

View File

@ -1,27 +1,43 @@
TARGET ?= core
CORE_OBJ ?= core.o
CORE_LIB ?= core.a
$(TARGET):
@true
ifneq ($(INSTALL_DIR),)
ifneq ($(DEBUG_DIR),)
$(TARGET): $(INSTALL_DIR)/$(CORE_OBJ) $(DEBUG_DIR)/$(CORE_OBJ)
$(TARGET): $(INSTALL_DIR)/$(CORE_LIB) $(DEBUG_DIR)/$(CORE_LIB)
$(CORE_OBJ).stripped: $(CORE_OBJ)
$(VERBOSE)$(STRIP) --strip-debug -o $@ $<
$(CORE_LIB).stripped: $(CORE_LIB)
$(VERBOSE)$(STRIP) --strip-unneeded -o $@ $<
$(INSTALL_DIR)/$(CORE_OBJ) : $(CORE_OBJ).stripped
$(VERBOSE)ln -sf $(CURDIR)/$< $(INSTALL_DIR)/$(CORE_OBJ)
$(INSTALL_DIR)/$(CORE_LIB) : $(CORE_LIB).stripped
$(VERBOSE)ln -sf $(CURDIR)/$< $(INSTALL_DIR)/$(CORE_LIB)
$(DEBUG_DIR)/$(CORE_OBJ) : $(CORE_OBJ)
$(VERBOSE)ln -sf $(CURDIR)/$< $(DEBUG_DIR)/$(CORE_OBJ)
$(DEBUG_DIR)/$(CORE_LIB) : $(CORE_LIB)
$(VERBOSE)ln -sf $(CURDIR)/$< $(DEBUG_DIR)/$(CORE_LIB)
endif
endif
.PHONY: $(CORE_OBJ)
$(CORE_OBJ):
$(VERBOSE)$(LD) $(LD_MARCH) -u _start --whole-archive -r $(LINK_ITEMS) $(LIBCXX_GCC) -o $@
#
# Create an archive from base and core archive objects, this archive is
# later linked to core. This gives better performance than the old way where we
# would link the archives into a relocatable object file (ld -r) that in turn
# was linked to core - leading to a large object file with many relocations
# causing long link times (especially on base-hw)
#
# We create the archive by piping an MRI script to ar -M
# "create " - create library
# "addlib" - add $(LINK_ITEMS)
# "save" - save and overwrite library
.PHONY: $(CORE_LIB)
$(CORE_LIB):
$(VERBOSE)(echo "create $@"; \
echo -e "$(addprefix \naddlib ,$(LINK_ITEMS))"; \
echo "save"; \
echo "end"; \
) | $(AR) -M
clean cleanall:
$(VERBOSE)rm -f $(CORE_OBJ) $(CORE_OBJ).stripped
$(VERBOSE)rm -f $(CORE_LIB) $(CORE_LIB).stripped