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
63 lines
1.8 KiB
Makefile
63 lines
1.8 KiB
Makefile
# use linker garbage collection, if requested
|
|
ifeq ($(WITH_LINKER_GC),1)
|
|
GLOBAL_COMPILEFLAGS += -ffunction-sections -fdata-sections
|
|
GLOBAL_LDFLAGS += --gc-sections
|
|
endif
|
|
|
|
ifneq (,$(EXTRA_BUILDRULES))
|
|
-include $(EXTRA_BUILDRULES)
|
|
endif
|
|
|
|
$(EXTRA_LINKER_SCRIPTS):
|
|
|
|
$(OUTBIN): $(OUTELF)
|
|
@echo generating image: $@
|
|
$(NOECHO)$(SIZE) $<
|
|
$(NOECHO)$(OBJCOPY) -O binary $< $@
|
|
|
|
$(OUTELF).hex: $(OUTELF)
|
|
@echo generating hex file: $@
|
|
$(NOECHO)$(OBJCOPY) -O ihex $< $@
|
|
|
|
$(OUTELF): $(ALLMODULE_OBJS) $(EXTRA_OBJS) $(LINKER_SCRIPT) $(EXTRA_LINKER_SCRIPTS)
|
|
@echo linking $@
|
|
$(NOECHO)$(SIZE) -t --common $(sort $(ALLMODULE_OBJS)) $(EXTRA_OBJS)
|
|
$(NOECHO)$(LD) $(GLOBAL_LDFLAGS) -dT $(LINKER_SCRIPT) $(addprefix -T,$(EXTRA_LINKER_SCRIPTS)) \
|
|
--start-group $(ALLMODULE_OBJS) $(EXTRA_OBJS) --end-group $(LIBGCC) -Map=$(OUTELF).map -o $@
|
|
|
|
$(OUTELF).sym: $(OUTELF)
|
|
@echo generating symbols: $@
|
|
$(NOECHO)$(OBJDUMP) -t $< | $(CPPFILT) > $@
|
|
|
|
$(OUTELF).sym.sorted: $(OUTELF)
|
|
@echo generating sorted symbols: $@
|
|
$(NOECHO)$(OBJDUMP) -t $< | $(CPPFILT) | sort > $@
|
|
|
|
$(OUTELF).lst: $(OUTELF)
|
|
@echo generating listing: $@
|
|
$(NOECHO)$(OBJDUMP) -Mreg-names-raw -d $< | $(CPPFILT) > $@
|
|
|
|
$(OUTELF).debug.lst: $(OUTELF)
|
|
@echo generating listing: $@
|
|
$(NOECHO)$(OBJDUMP) -Mreg-names-raw -S $< | $(CPPFILT) > $@
|
|
|
|
$(OUTELF).dump: $(OUTELF)
|
|
@echo generating objdump: $@
|
|
$(NOECHO)$(OBJDUMP) -x $< > $@
|
|
|
|
$(OUTELF).size: $(OUTELF)
|
|
@echo generating size map: $@
|
|
$(NOECHO)$(NM) -S --size-sort $< > $@
|
|
|
|
# print some information about the build
|
|
$(BUILDDIR)/srcfiles.txt: $(OUTELF)
|
|
@echo generating $@
|
|
$(NOECHO)echo $(sort $(ALLSRCS)) | tr ' ' '\n' > $@
|
|
|
|
$(BUILDDIR)/include_paths.txt: $(OUTELF)
|
|
@echo generating $@
|
|
$(NOECHO)echo $(subst -I,,$(sort $(GLOBAL_INCLUDES))) | tr ' ' '\n' > $@
|
|
|
|
#include arch/$(ARCH)/compile.mk
|
|
|