From f68e655312b72e1a42bbca9a5733ac9c96d6bc28 Mon Sep 17 00:00:00 2001 From: Sebastian Sumpf Date: Fri, 19 Feb 2021 15:23:49 +0100 Subject: [PATCH] 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 --- repos/base-fiasco/src/core/fiasco/target.mk | 2 +- repos/base-foc/src/core/foc/target.mk | 2 +- repos/base-hw/src/core/hw/target.mk | 2 +- repos/base-nova/src/core/nova/target.mk | 2 +- repos/base-okl4/src/core/okl4/target.mk | 2 +- .../src/core/pistachio/target.mk | 2 +- repos/base-sel4/src/core/sel4/target.mk | 2 +- repos/base/src/core/target.inc | 40 +++++++++++++------ tool/run/boot_dir/fiasco | 2 +- tool/run/boot_dir/foc | 2 +- tool/run/boot_dir/hw | 10 ++--- tool/run/boot_dir/nova | 6 +-- tool/run/boot_dir/okl4 | 2 +- tool/run/boot_dir/pistachio | 2 +- tool/run/boot_dir/sel4 | 2 +- tool/run/run | 2 +- 16 files changed, 49 insertions(+), 33 deletions(-) diff --git a/repos/base-fiasco/src/core/fiasco/target.mk b/repos/base-fiasco/src/core/fiasco/target.mk index 873c08063a..edc4ca67c5 100644 --- a/repos/base-fiasco/src/core/fiasco/target.mk +++ b/repos/base-fiasco/src/core/fiasco/target.mk @@ -1,4 +1,4 @@ LIBS := core-fiasco -CORE_OBJ := core-fiasco.o +CORE_LIB := core-fiasco.a include $(BASE_DIR)/src/core/target.inc diff --git a/repos/base-foc/src/core/foc/target.mk b/repos/base-foc/src/core/foc/target.mk index 72e551dec2..de70b41877 100644 --- a/repos/base-foc/src/core/foc/target.mk +++ b/repos/base-foc/src/core/foc/target.mk @@ -2,6 +2,6 @@ include $(REP_DIR)/etc/board.conf TARGET := foc-$(BOARD) LIBS := core-foc -CORE_OBJ := core-foc-$(BOARD).o +CORE_LIB := core-foc-$(BOARD).a include $(BASE_DIR)/src/core/target.inc diff --git a/repos/base-hw/src/core/hw/target.mk b/repos/base-hw/src/core/hw/target.mk index 1b06d322a9..f72891de7d 100644 --- a/repos/base-hw/src/core/hw/target.mk +++ b/repos/base-hw/src/core/hw/target.mk @@ -1,6 +1,6 @@ BOARD ?= unknown TARGET := core_hw_$(BOARD) LIBS := core-hw-$(BOARD) -CORE_OBJ := core-hw-$(BOARD).o +CORE_LIB := core-hw-$(BOARD).a include $(BASE_DIR)/src/core/target.inc diff --git a/repos/base-nova/src/core/nova/target.mk b/repos/base-nova/src/core/nova/target.mk index 878bcfbee9..d7e6b2df9e 100644 --- a/repos/base-nova/src/core/nova/target.mk +++ b/repos/base-nova/src/core/nova/target.mk @@ -1,4 +1,4 @@ LIBS := core-nova -CORE_OBJ := core-nova.o +CORE_LIB := core-nova.a include $(BASE_DIR)/src/core/target.inc diff --git a/repos/base-okl4/src/core/okl4/target.mk b/repos/base-okl4/src/core/okl4/target.mk index d8ca78befb..9439e615bb 100644 --- a/repos/base-okl4/src/core/okl4/target.mk +++ b/repos/base-okl4/src/core/okl4/target.mk @@ -1,4 +1,4 @@ LIBS := core-okl4 -CORE_OBJ := core-okl4.o +CORE_LIB := core-okl4.a include $(BASE_DIR)/src/core/target.inc diff --git a/repos/base-pistachio/src/core/pistachio/target.mk b/repos/base-pistachio/src/core/pistachio/target.mk index b2e6e32a8b..68868bd829 100644 --- a/repos/base-pistachio/src/core/pistachio/target.mk +++ b/repos/base-pistachio/src/core/pistachio/target.mk @@ -1,4 +1,4 @@ LIBS := core-pistachio -CORE_OBJ := core-pistachio.o +CORE_LIB := core-pistachio.a include $(BASE_DIR)/src/core/target.inc diff --git a/repos/base-sel4/src/core/sel4/target.mk b/repos/base-sel4/src/core/sel4/target.mk index 9af0b717dc..20c39b383d 100644 --- a/repos/base-sel4/src/core/sel4/target.mk +++ b/repos/base-sel4/src/core/sel4/target.mk @@ -1,4 +1,4 @@ LIBS := core-sel4 -CORE_OBJ := core-sel4.o +CORE_LIB := core-sel4.a include $(BASE_DIR)/src/core/target.inc diff --git a/repos/base/src/core/target.inc b/repos/base/src/core/target.inc index 98a25ffcdc..dc84272914 100644 --- a/repos/base/src/core/target.inc +++ b/repos/base/src/core/target.inc @@ -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 diff --git a/tool/run/boot_dir/fiasco b/tool/run/boot_dir/fiasco index 9601d8e1cb..4f1e510c77 100644 --- a/tool/run/boot_dir/fiasco +++ b/tool/run/boot_dir/fiasco @@ -1,5 +1,5 @@ proc binary_name_ld_lib_so { } { return "ld-fiasco.lib.so" } -proc binary_name_core_o { } { return "core-fiasco.o" } +proc binary_name_core_a { } { return "core-fiasco.a" } proc binary_name_timer { } { return "fiasco_timer_drv" } proc kernel_files { } { return { fiasco sigma0-fiasco bootstrap-fiasco } } diff --git a/tool/run/boot_dir/foc b/tool/run/boot_dir/foc index 8c9c2dba57..cbd20ea74d 100644 --- a/tool/run/boot_dir/foc +++ b/tool/run/boot_dir/foc @@ -1,5 +1,5 @@ proc binary_name_ld_lib_so { } { return "ld-foc.lib.so" } -proc binary_name_core_o { } { return "core-foc-[board].o" } +proc binary_name_core_a { } { return "core-foc-[board].a" } proc binary_name_timer { } { return "foc_timer_drv" } proc kernel_files { } { return { foc sigma0-foc bootstrap-foc } } diff --git a/tool/run/boot_dir/hw b/tool/run/boot_dir/hw index 51ee88a7a8..6507413ab3 100644 --- a/tool/run/boot_dir/hw +++ b/tool/run/boot_dir/hw @@ -1,5 +1,5 @@ proc binary_name_ld_lib_so { } { return "ld-hw.lib.so" } -proc binary_name_core_o { } { return "core-hw.o" } +proc binary_name_core_a { } { return "core-hw.a" } proc binary_name_timer { } { return "hw_timer_drv" } @@ -49,14 +49,14 @@ proc run_boot_dir {binaries} { set ld_arg "" if {![file exists [run_dir]/genode/ld.lib.so]} { set ld_arg lib/ld/hw } - if {![file exists [run_dir]/genode/core-hw-[board].o]} { set core_arg core/hw } + if {![file exists [run_dir]/genode/core-hw-[board].a]} { set core_arg core/hw } if {![file exists [run_dir]/genode/bootstrap-hw-[board].o]} { set bootstrap_arg bootstrap/hw } set build_args "$bootstrap_arg $core_arg $ld_arg" if {[llength $build_args]} { build $build_args } if {$ld_arg != ""} { file copy -force bin/ld-hw.lib.so [run_dir]/genode/ld.lib.so } - if {$core_arg != ""} { file copy -force bin/core-hw-[board].o [run_dir]/genode/ } + if {$core_arg != ""} { file copy -force bin/core-hw-[board].a [run_dir]/genode/ } if {$bootstrap_arg != ""} { file copy -force bin/bootstrap-hw-[board].o [run_dir]/genode/ } # @@ -68,12 +68,12 @@ proc run_boot_dir {binaries} { puts "core link address is [core_link_address]" - set core_obj core-hw-[board].o + set core_obj core-hw-[board].a set bootstrap_obj bootstrap-hw-[board].o # create core and bootstrap binary without modules for debugging if {[file exists debug/core-hw-[board].o]} { - build_core debug/core-hw-[board].o {} [run_dir].core [core_link_address] + build_core debug/core-hw-[board].a {} [run_dir].core [core_link_address] build_core [run_dir]/genode/$bootstrap_obj {} [run_dir].bootstrap [bootstrap_link_address] } diff --git a/tool/run/boot_dir/nova b/tool/run/boot_dir/nova index a7de335df0..4a979fa39c 100644 --- a/tool/run/boot_dir/nova +++ b/tool/run/boot_dir/nova @@ -1,5 +1,5 @@ proc binary_name_ld_lib_so { } { return "ld-nova.lib.so" } -proc binary_name_core_o { } { return "core-nova.o" } +proc binary_name_core_a { } { return "core-nova.a" } proc binary_name_timer { } { return "nova_timer_drv" } proc kernel_files { } { return hypervisor } @@ -36,14 +36,14 @@ proc run_boot_dir {binaries} { set core_arg "" set ld_arg "" if {![file exists [run_dir]/genode/hypervisor]} { set kernel_arg kernel } - if {![file exists [run_dir]/genode/core-nova.o]} { set core_arg core/nova } + if {![file exists [run_dir]/genode/core-nova.a]} { set core_arg core/nova } if {![file exists [run_dir]/genode/ld.lib.so]} { set ld_arg lib/ld/nova } set targets "$kernel_arg $core_arg $ld_arg" if {[llength $targets]} { build $targets } if {$kernel_arg != ""} { file copy -force bin/hypervisor [run_dir]/genode/hypervisor } - if {$core_arg != ""} { file copy -force bin/core-nova.o [run_dir]/genode/core-nova.o } + if {$core_arg != ""} { file copy -force bin/core-nova.a [run_dir]/genode/core-nova.a } if {$ld_arg != ""} { file copy -force bin/ld-nova.lib.so [run_dir]/genode/ld.lib.so } # diff --git a/tool/run/boot_dir/okl4 b/tool/run/boot_dir/okl4 index fa77895bd3..4251d505ac 100644 --- a/tool/run/boot_dir/okl4 +++ b/tool/run/boot_dir/okl4 @@ -1,5 +1,5 @@ proc binary_name_ld_lib_so { } { return "ld-okl4.lib.so" } -proc binary_name_core_o { } { return "core-okl4.o" } +proc binary_name_core_a { } { return "core-okl4.a" } proc binary_name_timer { } { return "pit_timer_drv" } proc kernel_files { } { return okl4 } diff --git a/tool/run/boot_dir/pistachio b/tool/run/boot_dir/pistachio index ae73d62d89..b960cac16f 100644 --- a/tool/run/boot_dir/pistachio +++ b/tool/run/boot_dir/pistachio @@ -1,5 +1,5 @@ proc binary_name_ld_lib_so { } { return "ld-pistachio.lib.so" } -proc binary_name_core_o { } { return "core-pistachio.o" } +proc binary_name_core_a { } { return "core-pistachio.a" } proc binary_name_timer { } { return "pit_timer_drv" } proc kernel_files { } { return { pistachio sigma0-pistachio kickstart-pistachio } } diff --git a/tool/run/boot_dir/sel4 b/tool/run/boot_dir/sel4 index e16f04c1c7..42571f224d 100644 --- a/tool/run/boot_dir/sel4 +++ b/tool/run/boot_dir/sel4 @@ -1,5 +1,5 @@ proc binary_name_ld_lib_so { } { return "ld-sel4.lib.so" } -proc binary_name_core_o { } { return "core-sel4.o" } +proc binary_name_core_a { } { return "core-sel4.a" } proc binary_name_timer { } { if {[have_board imx6q_sabrelite]} { return "imx6_timer_drv" } if {[have_board imx7d_sabre]} { return "imx7_timer_drv" } diff --git a/tool/run/run b/tool/run/run index 9b99b2f5b8..5853bc9827 100755 --- a/tool/run/run +++ b/tool/run/run @@ -969,7 +969,7 @@ proc kernel_files { } { return { } } # proc build_core_image { modules } { - set core_obj [kernel_specific_binary core.o] + set core_obj [kernel_specific_binary core.a] # replace 'core' with actual core-object name in 'modules' list if {[lsearch $modules "core"] != -1} {