@@ -326,6 +326,16 @@ endef
#
###############################################################################
+# For building %.init.o files, can be used in kbuild makefiles
+SPECIAL_DATA_SECTIONS := rodata $(foreach a,1 2 4 8 16, \
+ $(foreach w,1 2 4, \
+ rodata.str$(w).$(a)) \
+ rodata.cst$(a)) \
+ $(foreach r,rel rel.ro,data.$(r).local)
+
+###############################################################################
+
+
# delete partially updated (i.e. corrupted) files on error
.DELETE_ON_ERROR:
@@ -384,6 +384,30 @@ $(obj)/%.o: $(src)/%.S $(objtool_dep) FORCE
targets += $(filter-out $(subdir-obj-y), $(real-obj-y)) $(real-obj-m) $(lib-y)
targets += $(extra-y) $(MAKECMDGOALS) $(always)
+# %.init.o objects
+# ----------------
+
+quiet_cmd_obj_init_o = INIT_OBJ $@
+define cmd_obj_init_o
+ set -e; \
+ $(OBJDUMP) -h $< | sed -n '/[0-9]/{s,00*,0,g;p;}' | while read idx name sz rest; do \
+ case "$$name" in \
+ .*.local) ;; \
+ .text|.text.*|.data|.data.*|.bss) \
+ test $$sz != 0 || continue; \
+ echo "Error: size of $<:$$name is 0x$$sz" >&2; \
+ exit $$(expr $$idx + 1);; \
+ esac; \
+ done; \
+ $(OBJCOPY) $(foreach s,$(SPECIAL_DATA_SECTIONS),--rename-section .$(s)=.init.$(s)) $< $@
+endef
+
+$(obj)/%.init.o: $(obj)/%.o FORCE
+ $(call if_changed,obj_init_o)
+
+# Add intermediates files into tagets
+targets += $(patsubst %.init.o,%.o,$(filter %.init.o,$(targets)))
+
# Linker scripts preprocessor (.lds.S -> .lds)
# ---------------------------------------------------------------------------
quiet_cmd_cpp_lds_S = LDS $@
@@ -16,6 +16,10 @@ KBUILD_CFLAGS += $(subdir-ccflags-y)
# only build the compiled-in version
obj-m := $(filter-out $(obj-y),$(obj-m))
+# For a non-LTO build, bundle obj-bin targets in with the normal objs.
+obj-y += $(obj-bin-y)
+obj-bin-y :=
+
# Libraries are always collected in one lib file.
# Filter out objects already built-in
lib-y := $(filter-out $(obj-y), $(sort $(lib-y) $(lib-m)))
@@ -108,6 +112,9 @@ name-fix = $(squote)$(quote)$(subst $(comma),_,$(subst -,_,$1))$(quote)$(squote)
basename_flags = -DKBUILD_BASENAME=$(call name-fix,$(basetarget))
modname_flags = -DKBUILD_MODNAME=$(call name-fix,$(modname))
+# See comment about INIT_SECTIONS_ONLY in include/xen/compiler.h
+$(filter %.init.o,$(real-obj-y) $(extra-y)): ccflags-y += -DINIT_SECTIONS_ONLY
+
orig_c_flags = $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) \
$(ccflags-y) $(CFLAGS_$(basetarget).o)
_c_flags = $(filter-out $(CFLAGS_REMOVE_$(basetarget).o), $(orig_c_flags))
SPECIAL_DATA_SECTIONS is put in Kbuild.include so it can be use in kbuild makefiles. Signed-off-by: Anthony PERARD <anthony.perard@citrix.com> --- xen/scripts/Kbuild.include | 10 ++++++++++ xen/scripts/Makefile.build | 24 ++++++++++++++++++++++++ xen/scripts/Makefile.lib | 7 +++++++ 3 files changed, 41 insertions(+)