diff mbox series

[RFC,XEN,07/23] xen, Kbuild: Handle obj-bin-y and %.init.o objects

Message ID 20191023164837.2700240-8-anthony.perard@citrix.com (mailing list archive)
State New, archived
Headers show
Series Kconfig update + WIP of using Kbuild | expand

Commit Message

Anthony PERARD Oct. 23, 2019, 4:48 p.m. UTC
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(+)
diff mbox series

Patch

diff --git a/xen/scripts/Kbuild.include b/xen/scripts/Kbuild.include
index 4b0432e095ae..6f95a2519f3c 100644
--- a/xen/scripts/Kbuild.include
+++ b/xen/scripts/Kbuild.include
@@ -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:
 
diff --git a/xen/scripts/Makefile.build b/xen/scripts/Makefile.build
index dd972d5b5edb..68b504c9bdc5 100644
--- a/xen/scripts/Makefile.build
+++ b/xen/scripts/Makefile.build
@@ -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     $@
diff --git a/xen/scripts/Makefile.lib b/xen/scripts/Makefile.lib
index b746199b7f6b..e022f053494e 100644
--- a/xen/scripts/Makefile.lib
+++ b/xen/scripts/Makefile.lib
@@ -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))