From 8f27babf16d4a0b66cdf53963338e1631249393b Mon Sep 17 00:00:00 2001 From: Norman Feske Date: Wed, 5 Apr 2017 16:51:47 +0200 Subject: [PATCH] mk: strip binaries at /bin/ The /bin/ directory used to contain symbolic links to the unstripped build results. However, since the upcoming depot tool extracts the content of binary archives from bin/, the resulting archives would contain overly large unstripped binaries, which is undesired. On the other hand, always stripping the build results is not a good option either because we rely of symbol information during debugging. This patch changes the installation of build results such that a new 'debug/' directory is populated besides the existing 'bin/' directory. The debug directory contains symbolic links to the unstripped build results whereas the bin directory contains stripped binaries that are palatable for packaging (depot tool) and for assembling boot images (run tool). --- repos/base-okl4/src/kernel/okl4/target.mk | 9 ++++++- repos/base/mk/dep_lib.mk | 4 ++- repos/base/mk/dep_prg.mk | 3 ++- repos/base/mk/global.mk | 2 -- repos/base/mk/lib.mk | 15 ++++++++--- repos/base/mk/prg.mk | 32 ++++++++++++++++++----- repos/base/src/core/target.inc | 21 ++++++++++++--- tool/builddir/build.mk | 13 ++++++--- 8 files changed, 76 insertions(+), 23 deletions(-) diff --git a/repos/base-okl4/src/kernel/okl4/target.mk b/repos/base-okl4/src/kernel/okl4/target.mk index ec5cc13c5..f971c7c2a 100644 --- a/repos/base-okl4/src/kernel/okl4/target.mk +++ b/repos/base-okl4/src/kernel/okl4/target.mk @@ -2,10 +2,17 @@ TARGET = okl4 LIBS = kernel-okl4 SRC_C = dummy.c +# +# Prevent the kernel binary from being stripped. Otherwise, elfweaver would +# complain with the following error: +# +# Error: Symbol "tcb_size" not found in kernel ELF file. Needed for XIP support. +# +STRIP_TARGET_CMD = cp -f $< $@ + LD_TEXT_ADDR := 0xf0100000 LD_SCRIPT_STATIC = $(REP_DIR)/contrib/generated/x86/linker.ld $(TARGET): dummy.c - dummy.c: @touch $@ diff --git a/repos/base/mk/dep_lib.mk b/repos/base/mk/dep_lib.mk index 12a3aa8ac..b3c980c90 100644 --- a/repos/base/mk/dep_lib.mk +++ b/repos/base/mk/dep_lib.mk @@ -14,6 +14,7 @@ # LIB_PROGRESS_LOG - library build log file # BUILD_LIBS - list of libraries to build (without .lib.a or .lib.so suffix) # INSTALL_DIR - destination directory for installing shared libraries +# DEBUG_DIR - destination directory for installing unstripped shared libraries # ACCUMULATE_MISSING_PORTS = 1 @@ -137,7 +138,8 @@ endif echo " SHARED_LIBS=\"\$$(sort \$$(DEP_SO_$(LIB)))\" \\"; \ echo " BUILD_BASE_DIR=$(BUILD_BASE_DIR) \\"; \ echo " SHELL=$(SHELL) \\"; \ - echo " INSTALL_DIR=\$$(INSTALL_DIR)"; \ + echo " INSTALL_DIR=\$$(INSTALL_DIR) \\"; \ + echo " DEBUG_DIR=\$$(DEBUG_DIR)"; \ echo "") >> $(LIB_DEP_FILE) ifdef SHARED_LIB @(echo "SO_NAME($(LIB)) := $(LIB).lib.so"; \ diff --git a/repos/base/mk/dep_prg.mk b/repos/base/mk/dep_prg.mk index 8a56b8e24..da81f5109 100644 --- a/repos/base/mk/dep_prg.mk +++ b/repos/base/mk/dep_prg.mk @@ -70,7 +70,8 @@ endif echo " ARCHIVES=\"\$$(sort \$$(DEP_A_$(TARGET).prg))\" \\"; \ echo " SHARED_LIBS=\"\$$(sort \$$(DEP_SO_$(TARGET).prg))\" \\"; \ echo " SHELL=$(SHELL) \\"; \ - echo " INSTALL_DIR=\"\$$(INSTALL_DIR)\""; \ + echo " INSTALL_DIR=\"\$$(INSTALL_DIR)\" \\"; \ + echo " DEBUG_DIR=\"\$$(DEBUG_DIR)\""; \ echo "") >> $(LIB_DEP_FILE) # # Make 'all' depend on the target, which triggers the building of the target diff --git a/repos/base/mk/global.mk b/repos/base/mk/global.mk index 690a9c469..3ce8cff20 100644 --- a/repos/base/mk/global.mk +++ b/repos/base/mk/global.mk @@ -187,8 +187,6 @@ ALL_INC_DIR += $(foreach REP,$(REPOSITORIES),$(REP)/include) ALL_INC_DIR += $(LIBGCC_INC_DIR) ALL_INC_DIR += $(HOST_INC_DIR) -INSTALL_DIR ?= - VERBOSE ?= @ VERBOSE_DIR ?= --no-print-directory diff --git a/repos/base/mk/lib.mk b/repos/base/mk/lib.mk index d6528809c..6b2d476b4 100644 --- a/repos/base/mk/lib.mk +++ b/repos/base/mk/lib.mk @@ -10,7 +10,8 @@ ## VERBOSE_MK - verboseness of make calls ## BUILD_BASE_DIR - base of build directory tree ## LIB_CACHE_DIR - library build cache location -## INSTALL_DIR - program target build directory +## INSTALL_DIR - installation directory for stripped shared objects +## DEBUG_DIR - installation directory for unstripped shared objects ## SHARED_LIBS - shared-library dependencies of the library ## ARCHIVES - archive dependencies of the library ## REP_DIR - repository where the library resides @@ -131,6 +132,7 @@ ifdef SHARED_LIB ifneq ($(sort $(OBJECTS) $(LIBS)),) LIB_SO := $(addsuffix .lib.so,$(LIB)) INSTALL_SO := $(INSTALL_DIR)/$(LIB_SO) + DEBUG_SO := $(DEBUG_DIR)/$(LIB_SO) endif else LIB_A := $(addsuffix .lib.a,$(LIB)) @@ -151,7 +153,7 @@ all: $(LIB_TAG) # $(LIB_TAG) $(OBJECTS): $(HOST_TOOLS) -$(LIB_TAG): $(LIB_A) $(LIB_SO) $(ABI_SO) $(INSTALL_SO) +$(LIB_TAG): $(LIB_A) $(LIB_SO) $(ABI_SO) $(INSTALL_SO) $(DEBUG_SO) @touch $@ # @@ -246,6 +248,11 @@ $(ABI_SO): $(LIB).symbols.o $(LIB_SO_DEPS) $< \ --end-group --no-whole-archive -$(INSTALL_SO): - $(VERBOSE)ln -sf $(CURDIR)/$(LIB_SO) $@ +$(LIB_SO).stripped: $(LIB_SO) + $(VERBOSE)$(STRIP) -o $@ $< +$(DEBUG_SO): $(LIB_SO) + $(VERBOSE)ln -sf $(CURDIR)/$< $@ + +$(INSTALL_SO): $(LIB_SO).stripped + $(VERBOSE)ln -sf $(CURDIR)/$< $@ diff --git a/repos/base/mk/prg.mk b/repos/base/mk/prg.mk index 9948b9abd..9293ea2b6 100644 --- a/repos/base/mk/prg.mk +++ b/repos/base/mk/prg.mk @@ -7,7 +7,8 @@ ## REP_DIR - source repository of the program ## PRG_REL_DIR - directory of the program relative to 'src/' ## REPOSITORIES - repositories providing libs and headers -## INSTALL_DIR - final install location +## INSTALL_DIR - installation directory for stripped executables +## DEBUG_DIR - installation directory for unstripped executables ## VERBOSE - build verboseness modifier ## VERBOSE_DIR - verboseness modifier for changing directories ## VERBOSE_MK - verboseness of make calls @@ -67,11 +68,15 @@ LD_SCRIPT_STATIC ?= $(BASE_DIR)/src/ld/genode.ld include $(BASE_DIR)/mk/generic.mk include $(BASE_DIR)/mk/base-libs.mk -ifeq ($(INSTALL_DIR),) all: message $(TARGET) -else -all: message $(INSTALL_DIR)/$(TARGET) + +ifneq ($(INSTALL_DIR),) +ifneq ($(DEBUG_DIR),) +all: message $(INSTALL_DIR)/$(TARGET) $(DEBUG_DIR)/$(TARGET) endif +endif + +all: @true # prevent nothing-to-be-done message .PHONY: message @@ -174,16 +179,29 @@ $(TARGET): $(LINK_ITEMS) $(wildcard $(LD_SCRIPTS)) $(LIB_SO_DEPS) $(MSG_LINK)$(TARGET) $(VERBOSE)libs=$(LIB_CACHE_DIR); $(LD_CMD) -o $@ -$(INSTALL_DIR)/$(TARGET): $(TARGET) - $(VERBOSE)ln -sf $(CURDIR)/$(TARGET) $@ +STRIP_TARGET_CMD ?= $(STRIP) -o $@ $< + +$(TARGET).stripped: $(TARGET) + $(VERBOSE)$(STRIP_TARGET_CMD) + +$(INSTALL_DIR)/$(TARGET): $(TARGET).stripped + $(VERBOSE)ln -sf $(CURDIR)/$< $@ + +ifneq ($(DEBUG_DIR),) +$(DEBUG_DIR)/$(TARGET): $(TARGET) + $(VERBOSE)ln -sf $(CURDIR)/$< $@ +endif + else $(TARGET): $(INSTALL_DIR)/$(TARGET): $(TARGET) +$(DEBUG_DIR)/$(TARGET): $(TARGET) endif + clean_prg_objects: $(MSG_CLEAN)$(PRG_REL_DIR) - $(VERBOSE)$(RM) -f $(OBJECTS) $(OBJECTS:.o=.d) $(TARGET) + $(VERBOSE)$(RM) -f $(OBJECTS) $(OBJECTS:.o=.d) $(TARGET) $(TARGET).stripped $(VERBOSE)$(RM) -f *.d *.i *.ii *.s *.ali *.lib.so clean: clean_prg_objects diff --git a/repos/base/src/core/target.inc b/repos/base/src/core/target.inc index b0ce6b010..167aaa22a 100644 --- a/repos/base/src/core/target.inc +++ b/repos/base/src/core/target.inc @@ -1,12 +1,27 @@ TARGET = core CORE_OBJ ?= core.o -$(TARGET): $(CORE_OBJ) - $(VERBOSE)ln -sf $(CURDIR)/$(CORE_OBJ) $(INSTALL_DIR)/$(CORE_OBJ) +$(TARGET): + @true + +ifneq ($(INSTALL_DIR),) +ifneq ($(DEBUG_DIR),) +$(TARGET): $(INSTALL_DIR)/$(CORE_OBJ) $(DEBUG_DIR)/$(CORE_OBJ) + +$(CORE_OBJ).stripped: $(CORE_OBJ) + $(VERBOSE)$(STRIP) --strip-debug -o $@ $< + +$(INSTALL_DIR)/$(CORE_OBJ) : $(CORE_OBJ).stripped + $(VERBOSE)ln -sf $(CURDIR)/$< $(INSTALL_DIR)/$(CORE_OBJ) + +$(DEBUG_DIR)/$(CORE_OBJ) : $(CORE_OBJ) + $(VERBOSE)ln -sf $(CURDIR)/$< $(DEBUG_DIR)/$(CORE_OBJ) +endif +endif .PHONY: $(CORE_OBJ) $(CORE_OBJ): $(VERBOSE)$(LD) $(LD_MARCH) -u _start --whole-archive -r $(LINK_ITEMS) $(LIBCXX_GCC) -o $@ clean cleanall: - $(VERBOSE)rm -f $(CORE_OBJ) + $(VERBOSE)rm -f $(CORE_OBJ) $(CORE_OBJ).stripped diff --git a/tool/builddir/build.mk b/tool/builddir/build.mk index a3f3854f8..50591b357 100644 --- a/tool/builddir/build.mk +++ b/tool/builddir/build.mk @@ -42,6 +42,7 @@ -include etc/build.conf BUILD_BASE_DIR := $(CURDIR) +DEBUG_DIR := $(CURDIR)/debug INSTALL_DIR := $(CURDIR)/bin export BASE_DIR ?= ../base @@ -169,6 +170,7 @@ init_libdep_file: $(dir $(LIB_DEP_FILE)) echo "VERBOSE_MK ?= $(VERBOSE_MK)"; \ echo "VERBOSE_DIR ?= $(VERBOSE_DIR)"; \ echo "INSTALL_DIR ?= $(INSTALL_DIR)"; \ + echo "DEBUG_DIR ?= $(DEBUG_DIR)"; \ echo "SHELL ?= $(SHELL)"; \ echo "MKDIR ?= mkdir"; \ echo ""; \ @@ -262,11 +264,11 @@ endif ## Second stage: build targets based on the result of the first stage ## -$(INSTALL_DIR): +$(INSTALL_DIR) $(DEBUG_DIR): $(VERBOSE)mkdir -p $@ .PHONY: gen_deps_and_build_targets -gen_deps_and_build_targets: $(INSTALL_DIR) $(LIB_DEP_FILE) +gen_deps_and_build_targets: $(INSTALL_DIR) $(DEBUG_DIR) $(LIB_DEP_FILE) @(echo ""; \ echo "ifneq (\$$(MISSING_PORTS),)"; \ echo "check_ports:"; \ @@ -285,7 +287,7 @@ gen_deps_and_build_targets: $(INSTALL_DIR) $(LIB_DEP_FILE) @$(VERBOSE_MK)$(MAKE) $(VERBOSE_DIR) -f $(LIB_DEP_FILE) all .PHONY: again -again: $(INSTALL_DIR) +again: $(INSTALL_DIR) $(DEBUG_DIR) @$(VERBOSE_MK)$(MAKE) $(VERBOSE_DIR) -f $(LIB_DEP_FILE) all ## @@ -352,7 +354,10 @@ clean_gen_files: clean_install_dir: $(VERBOSE)(test -d $(INSTALL_DIR) && find $(INSTALL_DIR) -type l -not -readable -delete) || true -clean_empty_dirs: clean_targets clean_libcache clean_run clean_gen_files clean_install_dir +clean_debug_dir: + $(VERBOSE)(test -d $(DEBUG_DIR) && find $(DEBUG_DIR) -type l -not -readable -delete) || true + +clean_empty_dirs: clean_targets clean_libcache clean_run clean_gen_files clean_install_dir clean_debug_dir $(VERBOSE)$(GNU_FIND) . -depth -type d -empty -delete clean cleanall: clean_empty_dirs