[Skiboot] [PATCH] build: use thin archives rather than incremental linking
Nicholas Piggin
npiggin at gmail.com
Sat Feb 10 19:42:49 AEDT 2018
This changes to build system to use thin archives rather than
incremental linking for built-in.o, similar to recent change to Linux.
built-in.o is renamed to built-in.a, and is created as a thin archive
with no index, for speed and size. All built-in.a are aggregated into
a skiboot.tmp.a which is a thin archive built with an index, making it
suitable or linking. This is input into the final link.
The advantags of build size and linker code placement flexibility are
not as great with skiboot as a bigger project like Linux, but it's a
conceptually better way to build, and is more compatible with link
time optimisation in toolchains which might be interesting for skiboot
particularly for size reductions.
Size of build tree before this patch is 34.4MB, afterwards 23.1MB.
Signed-off-by: Nicholas Piggin <npiggin at gmail.com>
---
Makefile.main | 14 +++++++++-----
Makefile.rules | 5 +++--
asm/Makefile.inc | 2 +-
ccan/Makefile.inc | 2 +-
core/Makefile.inc | 2 +-
hdata/Makefile.inc | 2 +-
hw/Makefile.inc | 2 +-
hw/ast-bmc/Makefile.inc | 2 +-
hw/ec/Makefile.inc | 2 +-
hw/fsp/Makefile.inc | 2 +-
hw/ipmi/Makefile.inc | 2 +-
libc/Makefile.inc | 2 +-
libc/ctype/Makefile.inc | 2 +-
libc/stdio/Makefile.inc | 2 +-
libc/stdlib/Makefile.inc | 2 +-
libc/string/Makefile.inc | 2 +-
libfdt/Makefile.inc | 2 +-
libflash/Makefile.inc | 2 +-
libpore/Makefile.inc | 2 +-
libstb/Makefile.inc | 2 +-
libstb/drivers/Makefile.inc | 2 +-
libstb/mbedtls/Makefile.inc | 2 +-
libstb/tss/Makefile.inc | 2 +-
libxz/Makefile.inc | 2 +-
platforms/Makefile.inc | 2 +-
platforms/astbmc/Makefile.inc | 2 +-
platforms/ibm-fsp/Makefile.inc | 2 +-
platforms/mambo/Makefile.inc | 2 +-
platforms/qemu/Makefile.inc | 2 +-
platforms/rhesus/Makefile.inc | 2 +-
30 files changed, 40 insertions(+), 35 deletions(-)
diff --git a/Makefile.main b/Makefile.main
index 516afdd6..aab6b7a2 100644
--- a/Makefile.main
+++ b/Makefile.main
@@ -126,7 +126,7 @@ LDFLAGS += -Wl,-pie
LDFLAGS += -Wl,-Ttext-segment,$(LD_TEXT) -Wl,-N -Wl,--build-id=none
LDFLAGS += -Wl,--no-multi-toc
LDFLAGS += -mcpu=power7 -mbig-endian -Wl,--oformat,elf64-powerpc
-
+LDFLAGS_FINAL = $(LDFLAGS) -Wl,--whole-archive
LDRFLAGS=-melf64ppc
# Debug stuff
#LDFLAGS += -Wl,-v -Wl,-Map,foomap
@@ -213,8 +213,8 @@ OBJS += $(LIBC) $(CCAN) $(DEVSRC_OBJ) $(LIBPORE)
OBJS_NO_VER = $(OBJS)
ALL_OBJS = $(OBJS) version.o
-ALL_OBJS_1 = $(ALL_OBJS) asm/dummy_map.o
-ALL_OBJS_2 = $(ALL_OBJS) asm/real_map.o
+ALL_OBJS_1 = $(TARGET).tmp.a asm/dummy_map.o
+ALL_OBJS_2 = $(TARGET).tmp.a asm/real_map.o
$(TARGET).lid.xz: $(TARGET).lid
$(call Q,XZ, cat $^ | xz -9 -C crc32 > $@, $@)
@@ -228,13 +228,17 @@ $(TARGET).lid.stb: $(TARGET).lid libstb/create-container
$(TARGET).lid.xz.stb: $(TARGET).lid.xz libstb/create-container
$(call Q,STB-DEVELOPMENT-SIGNED-CONTAINER,$(SRC)/libstb/sign-with-local-keys.sh $< $@ $(SRC)/libstb/keys/,$@)
+$(TARGET).tmp.a: $(ALL_OBJS)
+ @rm -f $(TARGET).tmp.a
+ $(call Q,AR, $(AR) rcsTPD $@ $(ALL_OBJS), $@)
+
$(TARGET).tmp.elf: $(ALL_OBJS_1) $(TARGET).lds $(KERNEL)
- $(call Q,LD, $(CC) $(LDFLAGS) -T $(TARGET).lds $(ALL_OBJS_1) -o $@, $@)
+ $(call Q,LD, $(CC) $(LDFLAGS_FINAL) -o $@ -T $(TARGET).lds $(ALL_OBJS_1), $@)
asm/real_map.o : $(TARGET).tmp.map
$(TARGET).elf: $(ALL_OBJS_2) $(TARGET).lds $(KERNEL)
- $(call Q,LD, $(CC) $(LDFLAGS) -T $(TARGET).lds $(ALL_OBJS_2) -o $@, $@)
+ $(call Q,LD, $(CC) $(LDFLAGS_FINAL) -o $@ -T $(TARGET).lds $(ALL_OBJS_2), $@)
$(SUBDIRS):
$(call Q,MKDIR,mkdir -p $@, $@)
diff --git a/Makefile.rules b/Makefile.rules
index 80121c33..e5f6dfcf 100644
--- a/Makefile.rules
+++ b/Makefile.rules
@@ -67,8 +67,9 @@ endif
%.i : %.c
$(call Q,CC, $(CC) $(call cook_cflags,$@) -E -c $< -o $@, $@)
-%built-in.o :
- $(call Q,LD, $(LD) $(LDRFLAGS) -r $^ -o $@, $@)
+%built-in.a :
+ @rm -f $@
+ $(call Q,AR, $(AR) rcSTPD $@ $^, $@)
%.lds : %.lds.S
$(call Q,CC, $(CC) $(CPPFLAGS) -P -E $< -o $@, $@)
diff --git a/asm/Makefile.inc b/asm/Makefile.inc
index 2828caf9..343abc23 100644
--- a/asm/Makefile.inc
+++ b/asm/Makefile.inc
@@ -2,7 +2,7 @@
SUBDIRS += asm
ASM_OBJS = head.o misc.o kernel-wrapper.o cvc_entry.o
-ASM=asm/built-in.o
+ASM=asm/built-in.a
# Add extra dependency to the kernel wrapper
kernel_wrapper.o : $(KERNEL)
diff --git a/ccan/Makefile.inc b/ccan/Makefile.inc
index 1a89b2e8..36e75774 100644
--- a/ccan/Makefile.inc
+++ b/ccan/Makefile.inc
@@ -2,7 +2,7 @@
SUBDIRS += ccan ccan/list ccan/str
CCAN_OBJS = list/list.o str/str.o
-CCAN=ccan/built-in.o
+CCAN=ccan/built-in.a
$(CCAN): $(CCAN_OBJS:%=ccan/%)
diff --git a/core/Makefile.inc b/core/Makefile.inc
index d6a7269f..20bc2ce8 100644
--- a/core/Makefile.inc
+++ b/core/Makefile.inc
@@ -15,7 +15,7 @@ ifeq ($(SKIBOOT_GCOV),1)
CORE_OBJS += gcov-profiling.o
endif
-CORE=core/built-in.o
+CORE=core/built-in.a
CFLAGS_SKIP_core/relocate.o = -pg -fstack-protector-all
CFLAGS_SKIP_core/relocate.o += -fstack-protector -fstack-protector-strong
diff --git a/hdata/Makefile.inc b/hdata/Makefile.inc
index c17b04ff..6f47314d 100644
--- a/hdata/Makefile.inc
+++ b/hdata/Makefile.inc
@@ -3,6 +3,6 @@
SUBDIRS += hdata
HDATA_OBJS = spira.o paca.o pcia.o hdif.o memory.o fsp.o iohub.o vpd.o slca.o
HDATA_OBJS += cpu-common.o vpd-common.o hostservices.o i2c.o tpmrel.o
-DEVSRC_OBJ = hdata/built-in.o
+DEVSRC_OBJ = hdata/built-in.a
$(DEVSRC_OBJ): $(HDATA_OBJS:%=hdata/%)
diff --git a/hw/Makefile.inc b/hw/Makefile.inc
index 04cacd12..2dc3cc07 100644
--- a/hw/Makefile.inc
+++ b/hw/Makefile.inc
@@ -8,7 +8,7 @@ HW_OBJS += phb3.o sfc-ctrl.o fake-rtc.o bt.o p8-i2c.o prd.o
HW_OBJS += dts.o lpc-rtc.o npu.o npu-hw-procedures.o xive.o phb4.o
HW_OBJS += fake-nvram.o lpc-mbox.o npu2.o npu2-hw-procedures.o
HW_OBJS += phys-map.o sbe-p9.o capp.o occ-sensor.o vas.o
-HW=hw/built-in.o
+HW=hw/built-in.a
# FIXME hack this for now
CFLAGS_hw/phb4.o = -Wno-unused-value -Wno-unused-parameter
diff --git a/hw/ast-bmc/Makefile.inc b/hw/ast-bmc/Makefile.inc
index a97c0dbe..29e7a35b 100644
--- a/hw/ast-bmc/Makefile.inc
+++ b/hw/ast-bmc/Makefile.inc
@@ -1,5 +1,5 @@
SUBDIRS += hw/ast-bmc
AST_BMC_OBJS = ast-io.o ast-sf-ctrl.o
-AST_BMC = hw/ast-bmc/built-in.o
+AST_BMC = hw/ast-bmc/built-in.a
$(AST_BMC): $(AST_BMC_OBJS:%=hw/ast-bmc/%)
diff --git a/hw/ec/Makefile.inc b/hw/ec/Makefile.inc
index 09c9c848..f944d4df 100644
--- a/hw/ec/Makefile.inc
+++ b/hw/ec/Makefile.inc
@@ -3,6 +3,6 @@
SUBDIRS += hw/ec
EC_OBJS = gpio.o
-EC=hw/ec/built-in.o
+EC=hw/ec/built-in.a
$(EC): $(EC_OBJS:%=hw/ec/%)
diff --git a/hw/fsp/Makefile.inc b/hw/fsp/Makefile.inc
index 71690954..7a477db7 100644
--- a/hw/fsp/Makefile.inc
+++ b/hw/fsp/Makefile.inc
@@ -6,5 +6,5 @@ FSP_OBJS += fsp-diag.o fsp-leds.o fsp-mem-err.o fsp-op-panel.o
FSP_OBJS += fsp-elog-read.o fsp-elog-write.o fsp-epow.o fsp-dpo.o
FSP_OBJS += fsp-dump.o fsp-mdst-table.o fsp-chiptod.o fsp-ipmi.o
FSP_OBJS += fsp-attn.o
-FSP = hw/fsp/built-in.o
+FSP = hw/fsp/built-in.a
$(FSP): $(FSP_OBJS:%=hw/fsp/%)
diff --git a/hw/ipmi/Makefile.inc b/hw/ipmi/Makefile.inc
index a54602cb..34d6bd31 100644
--- a/hw/ipmi/Makefile.inc
+++ b/hw/ipmi/Makefile.inc
@@ -3,5 +3,5 @@ SUBDIRS += hw/ipmi
IPMI_OBJS = ipmi-rtc.o ipmi-power.o ipmi-fru.o ipmi-sel.o
IPMI_OBJS += ipmi-watchdog.o ipmi-sensor.o ipmi-attn.o
-IPMI = hw/ipmi/built-in.o
+IPMI = hw/ipmi/built-in.a
$(IPMI): $(IPMI_OBJS:%=hw/ipmi/%)
diff --git a/libc/Makefile.inc b/libc/Makefile.inc
index 66ce4ab0..13f8034f 100644
--- a/libc/Makefile.inc
+++ b/libc/Makefile.inc
@@ -1,7 +1,7 @@
LIBCDIR = libc
SUBDIRS += $(LIBCDIR)
-LIBC = $(LIBCDIR)/built-in.o $(LIBCDIR)/time.o
+LIBC = $(LIBCDIR)/built-in.a $(LIBCDIR)/time.o
include $(SRC)/$(LIBCDIR)/string/Makefile.inc
include $(SRC)/$(LIBCDIR)/ctype/Makefile.inc
diff --git a/libc/ctype/Makefile.inc b/libc/ctype/Makefile.inc
index da78c983..c183a54b 100644
--- a/libc/ctype/Makefile.inc
+++ b/libc/ctype/Makefile.inc
@@ -14,6 +14,6 @@ SUBDIRS += $(LIBCDIR)/ctype
CTYPE_OBJS = isdigit.o isprint.o isspace.o isxdigit.o tolower.o toupper.o
-CTYPE = $(LIBCDIR)/ctype/built-in.o
+CTYPE = $(LIBCDIR)/ctype/built-in.a
$(CTYPE): $(CTYPE_OBJS:%=$(LIBCDIR)/ctype/%)
diff --git a/libc/stdio/Makefile.inc b/libc/stdio/Makefile.inc
index d2aee0f5..a5436d73 100644
--- a/libc/stdio/Makefile.inc
+++ b/libc/stdio/Makefile.inc
@@ -17,5 +17,5 @@ STDIO_OBJS = vfprintf.o vsnprintf.o fprintf.o \
setvbuf.o fputc.o puts.o fputs.o putchar.o \
stdchnls.o fileno.o snprintf.o
-STDIO = $(LIBCDIR)/stdio/built-in.o
+STDIO = $(LIBCDIR)/stdio/built-in.a
$(STDIO): $(STDIO_OBJS:%=$(LIBCDIR)/stdio/%)
diff --git a/libc/stdlib/Makefile.inc b/libc/stdlib/Makefile.inc
index 22417dfb..8a78d173 100644
--- a/libc/stdlib/Makefile.inc
+++ b/libc/stdlib/Makefile.inc
@@ -15,6 +15,6 @@ SUBDIRS += $(LIBCDIR)/stdlib
STDLIB_OBJS = error.o atoi.o atol.o strtol.o strtoul.o \
rand.o labs.o
-STDLIB = $(LIBCDIR)/stdlib/built-in.o
+STDLIB = $(LIBCDIR)/stdlib/built-in.a
$(STDLIB): $(STDLIB_OBJS:%=$(LIBCDIR)/stdlib/%)
diff --git a/libc/string/Makefile.inc b/libc/string/Makefile.inc
index fb2f0371..122f5daa 100644
--- a/libc/string/Makefile.inc
+++ b/libc/string/Makefile.inc
@@ -16,6 +16,6 @@ STRING_OBJS = strcat.o strchr.o strcmp.o strcpy.o strlen.o \
strncmp.o strncpy.o strstr.o memset.o memcpy.o memcpy_from_ci.o \
memmove.o memchr.o memcmp.o strcasecmp.o strncasecmp.o \
strtok.o strdup.o
-STRING = $(LIBCDIR)/string/built-in.o
+STRING = $(LIBCDIR)/string/built-in.a
$(STRING): $(STRING_OBJS:%=$(LIBCDIR)/string/%)
diff --git a/libfdt/Makefile.inc b/libfdt/Makefile.inc
index e477d7c4..63c9d38e 100644
--- a/libfdt/Makefile.inc
+++ b/libfdt/Makefile.inc
@@ -12,7 +12,7 @@ LIBFDT_OBJS = $(LIBFDT_SRCS:%.c=%.o)
CFLAGS_SKIP_libfdt/fdt_sw.o = -Wstack-usage=4096
SUBDIRS += libfdt
-LIBFDT = libfdt/built-in.o
+LIBFDT = libfdt/built-in.a
$(LIBFDT): $(LIBFDT_OBJS:%=libfdt/%)
diff --git a/libflash/Makefile.inc b/libflash/Makefile.inc
index ea64eb46..2474abfc 100644
--- a/libflash/Makefile.inc
+++ b/libflash/Makefile.inc
@@ -2,6 +2,6 @@ LIBFLASH_SRCS = libflash.c libffs.c ecc.c blocklevel.c mbox-flash.c
LIBFLASH_OBJS = $(LIBFLASH_SRCS:%.c=%.o)
SUBDIRS += libflash
-LIBFLASH = libflash/built-in.o
+LIBFLASH = libflash/built-in.a
$(LIBFLASH): $(LIBFLASH_OBJS:%=libflash/%)
diff --git a/libpore/Makefile.inc b/libpore/Makefile.inc
index cc891279..1060a049 100644
--- a/libpore/Makefile.inc
+++ b/libpore/Makefile.inc
@@ -3,7 +3,7 @@ LIBPORE_SRCS += p8_pore_table_static_data.c sbe_xip_image.c pore_inline_assemble
LIBPORE_OBJS_1 = $(LIBPORE_SRCS:%.c=%.o)
LIBPORE_OBJS = $(LIBPORE_OBJS_1:%.C=%.o)
SUBDIRS += libpore
-LIBPORE = libpore/built-in.o
+LIBPORE = libpore/built-in.a
CFLAGS_SKIP_libpore/pore_inline_assembler.o=-Wsuggest-attribute=const
diff --git a/libstb/Makefile.inc b/libstb/Makefile.inc
index 3ea530ad..6d54c5cd 100644
--- a/libstb/Makefile.inc
+++ b/libstb/Makefile.inc
@@ -6,7 +6,7 @@ SUBDIRS += $(LIBSTB_DIR)
LIBSTB_SRCS = container.c tpm_chip.c cvc.c secureboot.c trustedboot.c
LIBSTB_OBJS = $(LIBSTB_SRCS:%.c=%.o)
-LIBSTB = $(LIBSTB_DIR)/built-in.o
+LIBSTB = $(LIBSTB_DIR)/built-in.a
include $(SRC)/$(LIBSTB_DIR)/mbedtls/Makefile.inc
include $(SRC)/$(LIBSTB_DIR)/drivers/Makefile.inc
diff --git a/libstb/drivers/Makefile.inc b/libstb/drivers/Makefile.inc
index 3b8ed0f8..80356eb3 100644
--- a/libstb/drivers/Makefile.inc
+++ b/libstb/drivers/Makefile.inc
@@ -6,6 +6,6 @@ SUBDIRS += $(DRIVERS_DIR)
DRIVERS_SRCS = tpm_i2c_interface.c tpm_i2c_nuvoton.c
DRIVERS_OBJS = $(DRIVERS_SRCS:%.c=%.o)
-DRIVERS = $(DRIVERS_DIR)/built-in.o
+DRIVERS = $(DRIVERS_DIR)/built-in.a
$(DRIVERS): $(DRIVERS_OBJS:%=$(DRIVERS_DIR)/%)
diff --git a/libstb/mbedtls/Makefile.inc b/libstb/mbedtls/Makefile.inc
index 07aa26a0..deacd26c 100644
--- a/libstb/mbedtls/Makefile.inc
+++ b/libstb/mbedtls/Makefile.inc
@@ -6,6 +6,6 @@ SUBDIRS += $(MBEDTLS_DIR)
MBEDTLS_SRCS = sha512.c
MBEDTLS_OBJS = $(MBEDTLS_SRCS:%.c=%.o)
-MBEDTLS = $(MBEDTLS_DIR)/built-in.o
+MBEDTLS = $(MBEDTLS_DIR)/built-in.a
$(MBEDTLS): $(MBEDTLS_OBJS:%=$(MBEDTLS_DIR)/%)
diff --git a/libstb/tss/Makefile.inc b/libstb/tss/Makefile.inc
index 2b5c3b9f..ed5154d7 100644
--- a/libstb/tss/Makefile.inc
+++ b/libstb/tss/Makefile.inc
@@ -7,7 +7,7 @@ SUBDIRS += $(TSS_DIR)
TSS_SRCS = trustedbootCmds.C trustedTypes.C trustedbootUtils.C \
tpmLogMgr.C
TSS_OBJS = $(TSS_SRCS:%.C=%.o)
-TSS = $(TSS_DIR)/built-in.o
+TSS = $(TSS_DIR)/built-in.a
$(TSS): $(TSS_OBJS:%=$(TSS_DIR)/%)
diff --git a/libxz/Makefile.inc b/libxz/Makefile.inc
index 29873286..4fe7c3e4 100644
--- a/libxz/Makefile.inc
+++ b/libxz/Makefile.inc
@@ -2,6 +2,6 @@ LIBXZ_SRCS = xz_dec_stream.c xz_dec_lzma2.c xz_crc32.c
LIBXZ_OBJS = $(LIBXZ_SRCS:%.c=%.o)
SUBDIRS += libxz
-LIBXZ = libxz/built-in.o
+LIBXZ = libxz/built-in.a
$(LIBXZ): $(LIBXZ_OBJS:%=libxz/%)
diff --git a/platforms/Makefile.inc b/platforms/Makefile.inc
index 90cd0f1c..3269532a 100644
--- a/platforms/Makefile.inc
+++ b/platforms/Makefile.inc
@@ -1,7 +1,7 @@
PLATDIR = platforms
SUBDIRS += $(PLATDIR)
-PLATFORMS = $(PLATDIR)/built-in.o
+PLATFORMS = $(PLATDIR)/built-in.a
include $(SRC)/$(PLATDIR)/ibm-fsp/Makefile.inc
include $(SRC)/$(PLATDIR)/rhesus/Makefile.inc
diff --git a/platforms/astbmc/Makefile.inc b/platforms/astbmc/Makefile.inc
index 49292c10..d9965365 100644
--- a/platforms/astbmc/Makefile.inc
+++ b/platforms/astbmc/Makefile.inc
@@ -6,6 +6,6 @@ ASTBMC_OBJS = pnor.o common.o slots.o \
garrison.o barreleye.o \
witherspoon.o zaius.o romulus.o p9dsu.o
-ASTBMC = $(PLATDIR)/astbmc/built-in.o
+ASTBMC = $(PLATDIR)/astbmc/built-in.a
$(ASTBMC): $(ASTBMC_OBJS:%=$(PLATDIR)/astbmc/%)
diff --git a/platforms/ibm-fsp/Makefile.inc b/platforms/ibm-fsp/Makefile.inc
index e9daab2b..c4b55a31 100644
--- a/platforms/ibm-fsp/Makefile.inc
+++ b/platforms/ibm-fsp/Makefile.inc
@@ -2,6 +2,6 @@ SUBDIRS += $(PLATDIR)/ibm-fsp
IBM_FSP_OBJS = common.o lxvpd.o apollo.o apollo-pci.o \
firenze.o firenze-pci.o zz.o
-IBM_FSP = $(PLATDIR)/ibm-fsp/built-in.o
+IBM_FSP = $(PLATDIR)/ibm-fsp/built-in.a
$(IBM_FSP): $(IBM_FSP_OBJS:%=$(PLATDIR)/ibm-fsp/%)
diff --git a/platforms/mambo/Makefile.inc b/platforms/mambo/Makefile.inc
index f3023ef0..b0e6b0c4 100644
--- a/platforms/mambo/Makefile.inc
+++ b/platforms/mambo/Makefile.inc
@@ -1,6 +1,6 @@
SUBDIRS += $(PLATDIR)/mambo
MAMBO_OBJS = mambo.o console.o
-MAMBO = $(PLATDIR)/mambo/built-in.o
+MAMBO = $(PLATDIR)/mambo/built-in.a
$(MAMBO): $(MAMBO_OBJS:%=$(PLATDIR)/mambo/%)
diff --git a/platforms/qemu/Makefile.inc b/platforms/qemu/Makefile.inc
index 11a44dbd..d4f988e7 100644
--- a/platforms/qemu/Makefile.inc
+++ b/platforms/qemu/Makefile.inc
@@ -1,6 +1,6 @@
SUBDIRS += $(PLATDIR)/qemu
QEMU_OBJS = qemu.o
-QEMU = $(PLATDIR)/qemu/built-in.o
+QEMU = $(PLATDIR)/qemu/built-in.a
$(QEMU): $(QEMU_OBJS:%=$(PLATDIR)/qemu/%)
diff --git a/platforms/rhesus/Makefile.inc b/platforms/rhesus/Makefile.inc
index 5899ca2f..3a3fd87e 100644
--- a/platforms/rhesus/Makefile.inc
+++ b/platforms/rhesus/Makefile.inc
@@ -1,6 +1,6 @@
SUBDIRS += $(PLATDIR)/rhesus
RHESUS_OBJS = rhesus.o
-RHESUS = $(PLATDIR)/rhesus/built-in.o
+RHESUS = $(PLATDIR)/rhesus/built-in.a
$(RHESUS): $(RHESUS_OBJS:%=$(PLATDIR)/rhesus/%)
--
2.15.1
More information about the Skiboot
mailing list