Skip to content

Commit

Permalink
build: use thin archives rather than incremental linking
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Stewart Smith <[email protected]>
  • Loading branch information
npiggin authored and stewartsmith committed Mar 1, 2018
1 parent f30286c commit f6159cf
Show file tree
Hide file tree
Showing 30 changed files with 40 additions and 35 deletions.
14 changes: 9 additions & 5 deletions Makefile.main
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 > $@, $@)
Expand All @@ -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/ PAYLOAD,$@)

$(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 $@, $@)
Expand Down
5 changes: 3 additions & 2 deletions Makefile.rules
Original file line number Diff line number Diff line change
Expand Up @@ -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 $@, $@)
Expand Down
2 changes: 1 addition & 1 deletion asm/Makefile.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion ccan/Makefile.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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/%)

2 changes: 1 addition & 1 deletion core/Makefile.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion hdata/Makefile.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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/%)
2 changes: 1 addition & 1 deletion hw/Makefile.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion hw/ast-bmc/Makefile.inc
Original file line number Diff line number Diff line change
@@ -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/%)
2 changes: 1 addition & 1 deletion hw/ec/Makefile.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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/%)
2 changes: 1 addition & 1 deletion hw/fsp/Makefile.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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/%)
2 changes: 1 addition & 1 deletion hw/ipmi/Makefile.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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/%)
2 changes: 1 addition & 1 deletion libc/Makefile.inc
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion libc/ctype/Makefile.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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/%)

2 changes: 1 addition & 1 deletion libc/stdio/Makefile.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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/%)
2 changes: 1 addition & 1 deletion libc/stdlib/Makefile.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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/%)

2 changes: 1 addition & 1 deletion libc/string/Makefile.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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/%)

2 changes: 1 addition & 1 deletion libfdt/Makefile.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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/%)

2 changes: 1 addition & 1 deletion libflash/Makefile.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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/%)
2 changes: 1 addition & 1 deletion libpore/Makefile.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion libstb/Makefile.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion libstb/drivers/Makefile.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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)/%)
2 changes: 1 addition & 1 deletion libstb/mbedtls/Makefile.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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)/%)
2 changes: 1 addition & 1 deletion libstb/tss/Makefile.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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)/%)

2 changes: 1 addition & 1 deletion libxz/Makefile.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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/%)
2 changes: 1 addition & 1 deletion platforms/Makefile.inc
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion platforms/astbmc/Makefile.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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/%)

2 changes: 1 addition & 1 deletion platforms/ibm-fsp/Makefile.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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/%)

2 changes: 1 addition & 1 deletion platforms/mambo/Makefile.inc
Original file line number Diff line number Diff line change
@@ -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/%)

2 changes: 1 addition & 1 deletion platforms/qemu/Makefile.inc
Original file line number Diff line number Diff line change
@@ -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/%)

2 changes: 1 addition & 1 deletion platforms/rhesus/Makefile.inc
Original file line number Diff line number Diff line change
@@ -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/%)

0 comments on commit f6159cf

Please sign in to comment.