Skip to contentSkip to conversation

symbols: check table sizes don't change between linking passes 2 and 3

RFC PATCH Superseded Jan Beulich 1 participant 1 message Oct 30, 2025

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 symbols: check table sizes don't change between linking passes 2 and 3

While sizes (and possibly positions) of the symbol table related symbols (and as a result other ones) are expected to change from linking pass 1 to pass 2, no such change should happen anymore from pass 2 to pass 3, or else the internally recorded symbol table wouldn't represent the ELF or PE/COFF ones.

For comparing to be actually useful, i.e. most notably also covering the last of the arrays emitted, symbol sizes need establishing. Make use of the xen/linkage.h machinery to achieve that.

---
Likely other ports also want to add such checking. Really it would be nice if we could properly abstract out shared parts of the linking steps.

RFC: Aiui this can't go in as is right now, or we would break building Xen
with lld. Further changes are first needed to help the situation there.

RFC: I'm all ears towards improvement suggestions in the temporary helper
file handling of compare-symbol-tables. Or ideally some approach to avoid the use of a helper file altogether.

xen/arch/x86/Makefile +3 -0
@@ -146,6 +146,7 @@ $(TARGET)-syms: $(objtree)/prelink.o $(o
 		| $(objtree)/tools/symbols $(all_symbols) --sysv --sort $(syms-warn-dup-y) \
 		> $(dot-target).1.S
 	$(MAKE) $(build)=$(@D) $(dot-target).1.o
+	$(call compare-symbol-tables, $(dot-target).0.o, $(dot-target).1.o)
 	$(LD) $(XEN_LDFLAGS) -T $(obj)/xen.lds $< $(build_id_linker) \
 	    $(orphan-handling-y) $(dot-target).1.o -o $@
 	$(NM) -pa --format=sysv $@ \
@@ -226,6 +227,8 @@ endif
 		| $(objtree)/tools/symbols $(all_symbols) --sysv --sort \
 		> $(dot-target).1s.S
 	$(MAKE) $(build)=$(@D) .$(@F).1r.o .$(@F).1s.o
+	$(call compare-symbol-tables, $(dot-target).0r.o, $(dot-target).1r.o)
+	$(call compare-symbol-tables, $(dot-target).0s.o, $(dot-target).1s.o)
 	$(LD) $(call EFI_LDFLAGS,$(VIRT_BASE)) -T $(obj)/efi.lds $< \
 	      $(dot-target).1r.o $(dot-target).1s.o $(orphan-handling-y) \
 	      $(note_file_option) -o $@
xen/scripts/Kbuild.include +13 -0
@@ -56,6 +56,19 @@ define filechk
 	fi
 endef
 
+###
+# Compare the symbol tables of two object files.  As diff's -I option isn't
+# standardized, the name difference of the two object files needs abstracting
+# out.
+define compare-symbol-tables
+    ln -f $(1) $(@D)/.cst.$$$$; \
+    $(OBJDUMP) -t $(@D)/.cst.$$$$ > $(1).sym; \
+    ln -f $(1) $(@D)/.cst.$$$$; \
+    $(OBJDUMP) -t $(@D)/.cst.$$$$ > $(2).sym; \
+    rm -f $(@D)/.cst.$$$$
+    diff -u $(1).sym $(2).sym
+endef
+
 # as-insn: Check whether assembler supports an instruction.
 # Usage: cflags-y += $(call as-insn,CC FLAGS,"insn",option-yes,option-no)
 as-insn = $(if $(shell echo 'void _(void) { asm volatile ( $(2) ); }' \
xen/tools/symbols.c +43 -46

148 lines not on this page · raw message