make: Add MODULE_STATIC_LIB
If a module sets MODULE_STATIC_LIB to true, that module will generate a .a file instead of a partially linked .o file. When WITH_LINKER_GC is enables, unreferenced code and data in c files are dropped from the final elf file. This does not work for most assembly files, since they put code and data directly into the .text and .data section. If a .a file is used instead however, files that have no external references are dropped regardless of which sections they have. If MODULE_STATIC_LIB is true, this change also disabled LK_INIT_HOOK* as files using this as the only entrypoint would also be dropped. Change-Id: I846ac1bf63018d1d713ca841e03191b1fac35bf4
This commit is contained in:
@@ -193,6 +193,7 @@ endif
|
||||
CCACHE ?=
|
||||
CC := $(CCACHE) $(TOOLCHAIN_PREFIX)gcc
|
||||
LD := $(TOOLCHAIN_PREFIX)ld
|
||||
AR := $(TOOLCHAIN_PREFIX)ar
|
||||
OBJDUMP := $(TOOLCHAIN_PREFIX)objdump
|
||||
OBJCOPY := $(TOOLCHAIN_PREFIX)objcopy
|
||||
CPPFILT := $(TOOLCHAIN_PREFIX)c++filt
|
||||
|
||||
@@ -76,6 +76,9 @@ struct lk_init_struct {
|
||||
const char *name;
|
||||
};
|
||||
|
||||
#if MODULE_STATIC_LIB
|
||||
#define LK_INIT_HOOK_FLAGS(a,b,c,d) _Pragma("GCC error \"init hooks are not fully compatible with static libraries\"")
|
||||
#else
|
||||
#define LK_INIT_HOOK_FLAGS(_name, _hook, _level, _flags) \
|
||||
const struct lk_init_struct _init_struct_##_name __ALIGNED(sizeof(void *)) __SECTION(".lk_init") = { \
|
||||
.level = _level, \
|
||||
@@ -83,6 +86,7 @@ struct lk_init_struct {
|
||||
.hook = _hook, \
|
||||
.name = #_name, \
|
||||
};
|
||||
#endif
|
||||
|
||||
#define LK_INIT_HOOK(_name, _hook, _level) \
|
||||
LK_INIT_HOOK_FLAGS(_name, _hook, _level, LK_INIT_FLAG_PRIMARY_CPU)
|
||||
|
||||
@@ -23,7 +23,7 @@ $(OUTELF): $(ALLMODULE_OBJS) $(EXTRA_OBJS) $(LINKER_SCRIPT) $(EXTRA_LINKER_SCRIP
|
||||
@echo linking $@
|
||||
$(NOECHO)$(SIZE) -t --common $(sort $(ALLMODULE_OBJS)) $(EXTRA_OBJS)
|
||||
$(NOECHO)$(LD) $(GLOBAL_LDFLAGS) -dT $(LINKER_SCRIPT) $(addprefix -T,$(EXTRA_LINKER_SCRIPTS)) \
|
||||
$(ALLMODULE_OBJS) $(EXTRA_OBJS) $(LIBGCC) -Map=$(OUTELF).map -o $@
|
||||
--start-group $(ALLMODULE_OBJS) $(EXTRA_OBJS) --end-group $(LIBGCC) -Map=$(OUTELF).map -o $@
|
||||
|
||||
$(OUTELF).sym: $(OUTELF)
|
||||
@echo generating symbols: $@
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
# args:
|
||||
# MODULE : module name (required)
|
||||
# MODULE_SRCS : list of source files, local path (required)
|
||||
# MODULE_STATIC_LIB : if true generate .a instead of .o
|
||||
# MODULE_DEPS : other modules that this one depends on
|
||||
# MODULE_DEFINES : #defines local to this module
|
||||
# MODULE_OPTFLAGS : OPTFLAGS local to this module
|
||||
@@ -62,6 +63,10 @@ MODULE_DEFINES += MODULE_SRCDEPS=\"$(subst $(SPACE),_,$(MODULE_SRCDEPS))\"
|
||||
MODULE_DEFINES += MODULE_DEPS=\"$(subst $(SPACE),_,$(MODULE_DEPS))\"
|
||||
MODULE_DEFINES += MODULE_SRCS=\"$(subst $(SPACE),_,$(MODULE_SRCS))\"
|
||||
|
||||
ifeq (true,$(call TOBOOL,$(MODULE_STATIC_LIB)))
|
||||
MODULE_DEFINES += MODULE_STATIC_LIB=1
|
||||
endif
|
||||
|
||||
# generate a per-module config.h file
|
||||
MODULE_CONFIG := $(MODULE_BUILDDIR)/module_config.h
|
||||
|
||||
@@ -84,12 +89,25 @@ include make/compile.mk
|
||||
#$(info MODULE_OBJS = $(MODULE_OBJS))
|
||||
|
||||
# build a ld -r style combined object
|
||||
ifeq (true,$(call TOBOOL,$(MODULE_STATIC_LIB)))
|
||||
|
||||
MODULE_OBJECT := $(call TOBUILDDIR,$(MODULE_SRCDIR).mod.a)
|
||||
$(MODULE_OBJECT): $(MODULE_OBJS) $(MODULE_EXTRA_OBJS)
|
||||
@$(MKDIR)
|
||||
@echo creating $@
|
||||
$(NOECHO)rm -f $@
|
||||
$(NOECHO)$(AR) rcs $@ $^
|
||||
|
||||
else
|
||||
|
||||
MODULE_OBJECT := $(call TOBUILDDIR,$(MODULE_SRCDIR).mod.o)
|
||||
$(MODULE_OBJECT): $(MODULE_OBJS) $(MODULE_EXTRA_OBJS)
|
||||
@$(MKDIR)
|
||||
@echo linking $@
|
||||
$(NOECHO)$(LD) $(GLOBAL_MODULE_LDFLAGS) -r $^ -o $@
|
||||
|
||||
endif
|
||||
|
||||
# track all of the source files compiled
|
||||
ALLSRCS += $(MODULE_SRCS)
|
||||
|
||||
@@ -108,6 +126,7 @@ MODULE_SRCDIR :=
|
||||
MODULE_BUILDDIR :=
|
||||
MODULE_DEPS :=
|
||||
MODULE_SRCS :=
|
||||
MODULE_STATIC_LIB :=
|
||||
MODULE_OBJS :=
|
||||
MODULE_DEFINES :=
|
||||
MODULE_OPTFLAGS :=
|
||||
|
||||
Reference in New Issue
Block a user