build: place app objects in libapplication.a

To prepare for upcoming memory protection features, we need to
distinguish between objects that are owned by the kernel itself
(and will be protected with supervisor permissions) and those
objects which are properly part of the application.

The current policy will be to place in libapplication.a anything
under lib/ (such as the C library), the application itself, and
additional libaries specified by KBUILD_ZEPHYR_APP.

These entities will no longer end up in libzephyr.a, which will
let us do output section routing in the linker script on a
per-file basis.

Some of the internal variables have been combined and simplified.

Issue: ZEP-2184
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
This commit is contained in:
Andrew Boie 2017-06-14 13:06:53 -07:00 committed by Anas Nashif
commit 2a4c2ee23a

View file

@ -606,9 +606,8 @@ include/config/auto.conf: ;
endif # $(dot-config) endif # $(dot-config)
# kernel objects are built as a static library # kernel objects are built as a static library
libs-y := kernel/ libs-y := lib/
core-y := lib/ misc/ boards/ ext/ subsys/ tests/ arch/ core-y := kernel/ drivers/ misc/ boards/ ext/ subsys/ tests/ arch/
drivers-y := drivers/
ARCH = $(subst $(DQUOTE),,$(CONFIG_ARCH)) ARCH = $(subst $(DQUOTE),,$(CONFIG_ARCH))
export ARCH export ARCH
@ -800,8 +799,7 @@ all: $(KERNEL_BIN_NAME) $(KERNEL_STAT_NAME)
# this default value # this default value
export KBUILD_IMAGE ?= zephyr export KBUILD_IMAGE ?= zephyr
zephyr-dirs := $(patsubst %/,%,$(filter %/, $(core-y) $(drivers-y) \ zephyr-dirs := $(patsubst %/,%,$(filter %/,$(libs-y) $(core-y)))
$(libs-y)))
# Workaround for some make notdir implementations that require # Workaround for some make notdir implementations that require
# the paramenter not to end in "/". # the paramenter not to end in "/".
@ -812,20 +810,16 @@ zephyr-app-dir-root := $(abspath $(patsubst %, %/.., $(SOURCE_DIR)))
zephyr-alldirs := $(sort $(zephyr-dirs) $(SOURCE_DIR) $(patsubst %/,%,$(filter %/, \ zephyr-alldirs := $(sort $(zephyr-dirs) $(SOURCE_DIR) $(patsubst %/,%,$(filter %/, \
$(core-) $(drivers-) $(libs-) $(app-)))) $(core-) $(drivers-) $(libs-) $(app-))))
core-y := $(patsubst %/, %/built-in.o, $(core-y)) core-y := $(patsubst %/, %/built-in.o, $(core-y)) kernel/lib.a
app-y := $(patsubst %, %/built-in.o, $(notdir $(zephyr-app-dir-root-name))) app-y := $(patsubst %, %/built-in.o, $(notdir $(zephyr-app-dir-root-name)))
drivers-y := $(patsubst %/, %/built-in.o, $(drivers-y)) libs-y := $(patsubst %/, %/built-in.o, $(libs-y))
libs-y1 := $(patsubst %/, %/lib.a, $(libs-y))
libs-y2 := $(patsubst %/, %/built-in.o, $(libs-y))
libs-y := $(libs-y1) $(libs-y2)
# core-y must be last here. several arches use .gnu.linkonce magic # core-y must be last here. several arches use .gnu.linkonce magic
# to register interrupt or exception handlers, and defaults under # to register interrupt or exception handlers, and defaults under
# arch/ (part of core-y) must be linked after drivers or libs. # arch/ (part of core-y) must be linked after drivers or libs.
export KBUILD_ZEPHYR_MAIN := $(drivers-y) $(libs-y) $(core-y)
export LDFLAGS_zephyr export LDFLAGS_zephyr
zephyr-deps := $(KBUILD_LDS) $(KBUILD_ZEPHYR_MAIN) $(app-y) zephyr-deps := $(KBUILD_LDS) $(core-y) $(libs-y) $(app-y)
ALL_LIBS += $(TOOLCHAIN_LIBS) ALL_LIBS += $(TOOLCHAIN_LIBS)
export ALL_LIBS export ALL_LIBS
@ -833,11 +827,18 @@ export ALL_LIBS
LINK_LIBS := $(foreach l,$(ALL_LIBS), -l$(l)) LINK_LIBS := $(foreach l,$(ALL_LIBS), -l$(l))
quiet_cmd_ar_target = AR $@ quiet_cmd_ar_target = AR $@
# Do not put lib.a into libzephyr.a. lib.a files are to be linked separately to cmd_ar_target = rm -f $@; $(AR) rcT$(KBUILD_ARFLAGS) $@ $^
# the final image
cmd_ar_target = rm -f $@; $(AR) rcT$(KBUILD_ARFLAGS) $@ \ # Contains all the kernel-space objects except the kernel/lib.a which is
$(filter-out %/lib.a, $(KBUILD_ZEPHYR_MAIN)) # linked outside of the --whole-archive directive with different AR
libzephyr.a: $(zephyr-deps) # parameters to save footprint space for unused kernel subsystems
libzephyr.a: $(filter-out %/lib.a, $(core-y))
$(call cmd,ar_target)
# All application objects and third party libraries which would be considered
# to not directly be part of the kernel (and hence whose symbols would not
# be globally marked as supervisor-only in memory protection scenarios)
libapplication.a: $(app-y) $(libs-y) $(KBUILD_ZEPHYR_APP)
$(call cmd,ar_target) $(call cmd,ar_target)
quiet_cmd_create-lnk = LINK $@ quiet_cmd_create-lnk = LINK $@
@ -850,11 +851,10 @@ quiet_cmd_create-lnk = LINK $@
echo "-e __start"; \ echo "-e __start"; \
echo "$(LINKFLAGPREFIX)--start-group"; \ echo "$(LINKFLAGPREFIX)--start-group"; \
echo "$(LINKFLAGPREFIX)--whole-archive"; \ echo "$(LINKFLAGPREFIX)--whole-archive"; \
echo "$(KBUILD_ZEPHYR_APP)"; \ echo "libapplication.a"; \
echo "$(app-y)"; \
echo "libzephyr.a"; \ echo "libzephyr.a"; \
echo "$(LINKFLAGPREFIX)--no-whole-archive"; \ echo "$(LINKFLAGPREFIX)--no-whole-archive"; \
echo "$(filter %/lib.a, $(KBUILD_ZEPHYR_MAIN))"; \ echo "$(filter %/lib.a, $(core-y))"; \
echo "$(objtree)/arch/$(ARCH)/core/offsets/offsets.o"; \ echo "$(objtree)/arch/$(ARCH)/core/offsets/offsets.o"; \
echo "$(LINKFLAGPREFIX)--end-group"; \ echo "$(LINKFLAGPREFIX)--end-group"; \
echo "$(LIB_INCLUDE_DIR) $(LINK_LIBS)"; \ echo "$(LIB_INCLUDE_DIR) $(LINK_LIBS)"; \
@ -871,7 +871,7 @@ linker.cmd: $(zephyr-deps)
$(EXTRA_LINKER_CMD_OPT) $(KBUILD_LDS) -o $@ $(EXTRA_LINKER_CMD_OPT) $(KBUILD_LDS) -o $@
$(PREBUILT_KERNEL): $(zephyr-deps) libzephyr.a $(KBUILD_ZEPHYR_APP) $(app-y) \ $(PREBUILT_KERNEL): $(zephyr-deps) libzephyr.a libapplication.a \
linker.cmd $(KERNEL_NAME).lnk linker.cmd $(KERNEL_NAME).lnk
$(Q)$(CC) -T linker.cmd @$(KERNEL_NAME).lnk -o $@ $(Q)$(CC) -T linker.cmd @$(KERNEL_NAME).lnk -o $@