diff options
author | Alex Deymo <deymo@chromium.org> | 2014-08-29 01:07:48 -0700 |
---|---|---|
committer | chrome-internal-fetch <chrome-internal-fetch@google.com> | 2014-11-06 01:15:05 +0000 |
commit | 4f84478d6a101606744eb496b379abeec6c1d881 (patch) | |
tree | b630ca1f2c498a0b53ffafad712a9efeb1939567 | |
parent | 43858da3e3711360c43edf91b6b6737bd582bd34 (diff) | |
download | vboot-4f84478d6a101606744eb496b379abeec6c1d881.tar.gz |
Remove futility linker script.
The futility.lds linker script was used to generate a table with
all the symbols in a specific section called .futil_cmds listed
in order under the symbol "futil_cmds". This allows the source files
to define a command and let the linker figure out the list of
compiled commands. Nevertheless, passing this linker script
makes the linker leave a gap of about 2MiB in the output ELF file.
Instead of mess up with linker scripts just to generate a table of
commands, this patch generates such table in the Makefile looking
at the included sources and compiling that table. The result is a
futility binary of about 88 KiB instead of the 2.1 MiB required
originally.
This patch also adds sys-boot/chromeos-u-boot to the list of ebuilds
tested by emerge_test.sh.
BUG=chromium:408926
BRANCH=None
TEST=BOARD=link ./emerge_test.sh
TEST=BOARD=daisy_spring ./emerge_test.sh
TEST=`readelf -S futility` shows no gap.
TEST=/usr/bin/futility shows no difference in the help output.
Change-Id: I9c0febc76140b404d48aa13e7f948e8ea77a41b5
Reviewed-on: https://chromium-review.googlesource.com/215496
Tested-by: Alex Deymo <deymo@chromium.org>
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
Commit-Queue: Alex Deymo <deymo@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/227859
Tested-by: Daisuke Nojiri <dnojiri@chromium.org>
Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
Commit-Queue: Daisuke Nojiri <dnojiri@chromium.org>
-rw-r--r-- | Makefile | 48 | ||||
-rwxr-xr-x | emerge_test.sh | 1 | ||||
-rw-r--r-- | futility/futility.h | 7 | ||||
-rw-r--r-- | futility/futility.lds | 15 |
4 files changed, 41 insertions, 30 deletions
@@ -551,10 +551,13 @@ FUTIL_SRCS += \ futility/cmd_vb2_verify_fw.c endif -FUTIL_LDS = futility/futility.lds +# List of commands built in futility and futility_s. +FUTIL_STATIC_CMD_LIST = ${BUILD}/gen/futility_static_cmds.c +FUTIL_CMD_LIST = ${BUILD}/gen/futility_cmds.c -FUTIL_STATIC_OBJS = ${FUTIL_STATIC_SRCS:%.c=${BUILD}/%.o} -FUTIL_OBJS = ${FUTIL_SRCS:%.c=${BUILD}/%.o} +FUTIL_STATIC_OBJS = ${FUTIL_STATIC_SRCS:%.c=${BUILD}/%.o} \ + ${FUTIL_STATIC_CMD_LIST:%.c=%.o} +FUTIL_OBJS = ${FUTIL_SRCS:%.c=${BUILD}/%.o} ${FUTIL_CMD_LIST:%.c=%.o} ALL_OBJS += ${FUTIL_OBJS} @@ -880,12 +883,12 @@ signing_install: ${SIGNING_SCRIPTS} ${SIGNING_SCRIPTS_DEV} ${SIGNING_COMMON} .PHONY: futil futil: ${FUTIL_STATIC_BIN} ${FUTIL_BIN} -${FUTIL_STATIC_BIN}: ${FUTIL_LDS} ${FUTIL_STATIC_OBJS} ${UTILLIB} +${FUTIL_STATIC_BIN}: ${FUTIL_STATIC_OBJS} ${UTILLIB} @$(PRINTF) " LD $(subst ${BUILD}/,,$@)\n" ${Q}${LD} -o $@ ${CFLAGS} ${LDFLAGS} -static $^ ${LDLIBS} ${FUTIL_BIN}: LDLIBS += ${CRYPTO_LIBS} -${FUTIL_BIN}: ${FUTIL_LDS} ${FUTIL_OBJS} ${UTILLIB} +${FUTIL_BIN}: ${FUTIL_OBJS} ${UTILLIB} @$(PRINTF) " LD $(subst ${BUILD}/,,$@)\n" ${Q}${LD} -o $@ ${CFLAGS} ${LDFLAGS} $^ ${LDLIBS} @@ -942,6 +945,10 @@ ${BUILD}/%.o: %.c @$(PRINTF) " CC $(subst ${BUILD}/,,$@)\n" ${Q}${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $< +${BUILD}/%.o: ${BUILD}/%.c + @$(PRINTF) " CC $(subst ${BUILD}/,,$@)\n" + ${Q}${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $< + # Rules to recompile a single source file for library and test # TODO: is there a tidier way to do this? ${BUILD}/%_for_lib.o: CFLAGS += -DFOR_LIBRARY @@ -962,11 +969,6 @@ ${BUILD}/%.o: %.cc # ---------------------------------------------------------------------------- # Here are the special tweaks to the generic rules. -# Because we play some clever linker script games to add new commands without -# changing any header files, futility must be linked with ld.bfd, not gold. -${FUTIL_BIN}: LDFLAGS += -fuse-ld=bfd -${FUTIL_STATIC_BIN}: LDFLAGS += -fuse-ld=bfd - # Some utilities need external crypto functions CRYPTO_LIBS := $(shell ${PKG_CONFIG} --libs libcrypto) @@ -1029,6 +1031,32 @@ ${TLCL_TEST_BINS}: OBJS += ${BUILD}/tests/tpm_lite/tlcl_tests.o ${TLCL_TEST_BINS}: ${BUILD}/tests/tpm_lite/tlcl_tests.o ALL_OBJS += ${BUILD}/tests/tpm_lite/tlcl_tests.o +# ---------------------------------------------------------------------------- +# Here are the special rules that don't fit in the generic rules. + +# Generates the list of commands defined in futility by running grep in the +# source files looking for the DECLARE_FUTIL_COMMAND() macro usage. +${FUTIL_STATIC_CMD_LIST}: ${FUTIL_STATIC_SRCS} +${FUTIL_CMD_LIST}: ${FUTIL_SRCS} +${FUTIL_CMD_LIST} ${FUTIL_STATIC_CMD_LIST}: + @$(PRINTF) " GEN $(subst ${BUILD}/,,$@)\n" + ${Q}rm -f $@ $@_t $@_commands + ${Q}mkdir -p ${BUILD}/gen + ${Q}grep -hoRE '^DECLARE_FUTIL_COMMAND\([^,]+' $^ -R \ + | sed 's/DECLARE_FUTIL_COMMAND(\(.*\)/_CMD(\1)/' \ + | sort >>$@_commands + ${Q}echo '#define _CMD(NAME) extern const struct' \ + 'futil_cmd_t __cmd_##NAME;' >> $@_t + ${Q}cat $@_commands >> $@_t + ${Q}echo '#undef _CMD' >> $@_t + ${Q}echo '#define _CMD(NAME) &__cmd_##NAME,' >> $@_t + ${Q}echo 'const struct futil_cmd_t *const futil_cmds[] = {' >> $@_t + ${Q}cat $@_commands >> $@_t + ${Q}echo '0}; /* null-terminated */' >> $@_t + ${Q}echo '#undef _CMD' >> $@_t + ${Q}mv $@_t $@ + ${Q}rm -f $@_commands + ############################################################################## # Targets that exist just to run tests diff --git a/emerge_test.sh b/emerge_test.sh index cbe51444..5861aa25 100755 --- a/emerge_test.sh +++ b/emerge_test.sh @@ -11,6 +11,7 @@ # Required ebuilds: TEST_EBUILDS=" sys-boot/chromeos-bootimage + sys-boot/chromeos-u-boot sys-boot/coreboot sys-boot/depthcharge chromeos-base/chromeos-cryptohome diff --git a/futility/futility.h b/futility/futility.h index 32c553db..dfccf6f9 100644 --- a/futility/futility.h +++ b/futility/futility.h @@ -23,14 +23,11 @@ struct futil_cmd_t { * to them without explictly declaring every function in a header somewhere. */ #define DECLARE_FUTIL_COMMAND(NAME, HANDLER, SHORTHELP) \ - static const struct futil_cmd_t __cmd_##NAME = { \ + const struct futil_cmd_t __cmd_##NAME = { \ .name = #NAME, \ .handler = HANDLER, \ .shorthelp = SHORTHELP \ - }; \ - const struct futil_cmd_t * const __cmd_ptr_##NAME \ - __attribute__((section(".futil_cmds." #NAME))) \ - = &__cmd_##NAME + }; /* This is the list of pointers to all commands. */ extern const struct futil_cmd_t *const futil_cmds[]; diff --git a/futility/futility.lds b/futility/futility.lds deleted file mode 100644 index 0650507f..00000000 --- a/futility/futility.lds +++ /dev/null @@ -1,15 +0,0 @@ -/* - * Copyright (c) 2013 The Chromium OS Authors. All rights reserved. - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -SECTIONS -{ - .rodata : { - . = ALIGN(32); - futil_cmds = .; /* Create the list of commands */ - *(SORT(.futil_cmds.*)); - QUAD(0); /* Null-terminated */ - } -} |