All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/7] build: split and unify linking of final image(s)
@ 2026-08-26 11:57 Jan Beulich
  2026-08-26 12:00 ` [PATCH v2 1/7] x86: split xen-syms/xen.efi linking rules Jan Beulich
                   ` (6 more replies)
  0 siblings, 7 replies; 23+ messages in thread
From: Jan Beulich @ 2026-08-26 11:57 UTC (permalink / raw)
  To: xen-devel@lists.xenproject.org
  Cc: Andrew Cooper, Julien Grall, Stefano Stabellini, Anthony PERARD,
	Michal Orzel, Roger Pau Monné

The monolithic rules, largely but not entirely identical between ports,
were pretty ugly to fiddle with. They also ended up going out of sync
when really they would better have stayed consistent. Break them up,
and use (largely) the same rules for all ports (x86'es xen.efi being
somewhat special, though).

The final three patches are related only in so far as they address
observations made while doing the conversion.

v2 addresses an install issue I had noticed too late, and has one new
patch. See individual patches for details (if any).

1: x86: split xen-syms/xen.efi linking rules
2: Arm: split xen-syms linking rule
3: RISC-V: split xen-syms linking rule
4: PPC: split xen-syms linking rule
5: build: move $(all-symbols-*)
6: build: move $(compare-symbol-tables)
7: RISC-V: place .sdata / .srodata / .riscv.attributes

Jan


^ permalink raw reply	[flat|nested] 23+ messages in thread

* [PATCH v2 1/7] x86: split xen-syms/xen.efi linking rules
  2026-08-26 11:57 [PATCH v2 0/7] build: split and unify linking of final image(s) Jan Beulich
@ 2026-08-26 12:00 ` Jan Beulich
  2026-09-02 14:52   ` Anthony PERARD
  2026-08-26 12:00 ` [PATCH v2 2/7] Arm: split xen-syms linking rule Jan Beulich
                   ` (5 subsequent siblings)
  6 siblings, 1 reply; 23+ messages in thread
From: Jan Beulich @ 2026-08-26 12:00 UTC (permalink / raw)
  To: xen-devel@lists.xenproject.org
  Cc: Andrew Cooper, Julien Grall, Stefano Stabellini, Anthony PERARD,
	Michal Orzel, Roger Pau Monné, Teddy Astie

Doing so, besides (hopefully) adding clarity (not the least by way of
using pattern rules where possible), also avoids explicit recursive
$(MAKE) invocations. For xen-syms move re-usable helper rules to a new
scripts/Makefile.link.

While doing so, re-order .map file creation (which can in principle fail)
and check-endbr.sh invocation ahead of putting in place the final image
(which is now the result of a simple rename).

Also drop --source-name= from the tools/symbols invocation which has
--empty passed, for being meaningless there.

Note that the original "rm" at the end of the rule needs limiting:
Removing intermediate files (which $(MAKE) doesn't itself remove) would
cause re-linking even when installing as root (when common/version.o is
left unaltered, and hence an incremental build should do nothing as long
as nothing else changed in the source tree).

Signed-off-by: Jan Beulich <jbeulich@suse.com>
---
I'd like to keep the "beautification" part, i.e. transforming to more use
of Kbuild.include machinery, separate.

The check-endbr.sh invocation doesn't fit neatly into this model. I was
considering to move it into $(TARGET)'s rule, but that's not very nice
either (both because it'd be odd [strictly speaking: wrong] for xen.efi,
and because it would reduce parallelism).
---
v2: Mark intermediate files as such. Don't use $(if_changed ...).

--- a/xen/arch/x86/Makefile
+++ b/xen/arch/x86/Makefile
@@ -102,12 +102,6 @@ notes_phdrs = --notes
 endif
 endif
 
-syms-warn-dup-y := --warn-dup
-syms-warn-dup-$(CONFIG_SUPPRESS_DUPLICATE_SYMBOL_WARNINGS) :=
-syms-warn-dup-$(CONFIG_ENFORCE_UNIQUE_SYMBOLS) := --error-dup
-
-orphan-handling-$(call ld-option,--orphan-handling=warn) += --orphan-handling=warn
-
 $(TARGET): TMP = $(dot-target).elf32
 $(TARGET): $(TARGET)-syms $(efi-y) $(obj)/boot/mkelf32
 	$(obj)/boot/mkelf32 $(notes_phdrs) $(TARGET)-syms $(TMP) $(XEN_IMG_OFFSET)
@@ -119,31 +113,11 @@ $(TARGET): $(TARGET)-syms $(efi-y) $(obj
 
 CFLAGS-$(XEN_BUILD_EFI) += -DXEN_BUILD_EFI
 
-$(TARGET)-syms: $(objtree)/prelink.o $(obj)/xen.lds
-	$(objtree)/tools/symbols $(all_symbols) --empty > $(dot-target).0.S
-	$(MAKE) $(build)=$(@D) $(dot-target).0.o
-	$(LD) $(XEN_LDFLAGS) -T $(obj)/xen.lds $< $(build_id_linker) --strip-debug \
-	      $(dot-target).0.o -o $(dot-target).0
-	$(NM) -pa --format=sysv $(dot-target).0 \
-		| $(objtree)/tools/symbols $(all_symbols) --sysv --sort \
-		> $(dot-target).1.S
-	$(MAKE) $(build)=$(@D) $(dot-target).1.o
-	$(LD) $(XEN_LDFLAGS) -T $(obj)/xen.lds $< $(build_id_linker) --strip-debug \
-	    $(dot-target).1.o -o $(dot-target).1
-	$(NM) -pa --format=sysv $(dot-target).1 \
-		| $(objtree)/tools/symbols $(all_symbols) --sysv --sort $(syms-warn-dup-y) \
-		> $(dot-target).2.S
-	$(MAKE) $(build)=$(@D) $(dot-target).2.o
-	$(call compare-symbol-tables, $(dot-target).1.o, $(dot-target).2.o)
-	$(LD) $(XEN_LDFLAGS) -T $(obj)/xen.lds $< $(build_id_linker) \
-	    $(orphan-handling-y) $(dot-target).2.o -o $@
-	$(NM) -pa --format=sysv $@ \
-		| $(objtree)/tools/symbols --all-symbols --xensyms --sysv --sort \
-		> $@.map
-	rm -f $(dot-target).[0-9]* $(@D)/..$(@F).[0-9]*
-ifeq ($(CONFIG_XEN_IBT),y)
-	$(SHELL) $(srctree)/tools/check-endbr.sh $@
-endif
+LAST_LINKING_PASS := 2
+
+final-image-check-$(CONFIG_XEN_IBT) = $(SHELL) $(srctree)/tools/check-endbr.sh $<
+
+include scripts/Makefile.link
 
 $(obj)/note.o: $(TARGET)-syms
 	$(OBJCOPY) -O binary --only-section=.note.gnu.build-id $< $@.bin
@@ -191,51 +165,69 @@ note_file_option ?= $(note_file)
 
 extra-$(XEN_BUILD_PE) += efi.lds
 ifeq ($(XEN_BUILD_PE),y)
-$(TARGET).efi: $(obj)/efi/relocs-dummy.o $(obj)/efi/relocs-empty.o $(obj)/efi/mkreloc
-$(TARGET).efi: $(objtree)/prelink.o $(note_file) $(obj)/efi.lds
+
+.INTERMEDIATE: $(addprefix .$(TARGET).efi., \
+                           $(foreach n, 0 1 2, \
+                                     $(n) alt.$(n) $(n)r.o $(n)s.o $(n)r.S $(n)s.S))
+
+.$(TARGET).efi.%.o: .$(TARGET).efi.%.S FORCE
+	$(call cmd,cc_o_S)
+
+.$(TARGET).efi.1r.S: .$(TARGET).efi.0 $(if $(relocs-dummy),.$(TARGET).efi.alt.0)
+.$(TARGET).efi.2r.S: .$(TARGET).efi.1 $(if $(relocs-dummy),.$(TARGET).efi.alt.1)
+
+.$(TARGET).efi.0r.o: $(obj)/efi/relocs-dummy.o $(obj)/efi/mkreloc
+	ln -sf $< $@
+
+.$(TARGET).efi.%r.S:
+	$(MKRELOC) $^ > $@
+
+.$(TARGET).efi.0s.S:
+	$(objtree)/tools/symbols $(all_symbols) --empty > $@
+
+.$(TARGET).efi.1s.S: .$(TARGET).efi.0
+.$(TARGET).efi.2s.S: .$(TARGET).efi.1
+
+.$(TARGET).efi.%s.S:
+	$(NM) -pa --format=sysv $< \
+	  | $(objtree)/tools/symbols $(all_symbols) --sysv --sort \
+ 	    --source-name=$(TARGET).efi.S \
+	  > $@
+
+# See above for why $(note_file) needs removing here.
+efi-objs = $(filter-out $(note_file),$(filter %.o,$^))
+
+.$(TARGET).efi.%: $(objtree)/prelink.o .$(TARGET).efi.%r.o \
+                  .$(TARGET).efi.%s.o $(note_file) $(obj)/efi.lds
+	$(LD) $(call EFI_LDFLAGS,$(VIRT_BASE)) -T $(obj)/efi.lds $(efi-objs) \
+	      --strip-debug $(note_file_option) -o $@
+
+.$(TARGET).efi.alt.%: $(objtree)/prelink.o .$(TARGET).efi.%r.o \
+                      .$(TARGET).efi.%s.o $(note_file) $(obj)/efi.lds
+	$(LD) $(call EFI_LDFLAGS,$(ALT_BASE)) -T $(obj)/efi.lds $(efi-objs) \
+	      --strip-debug $(note_file_option) -o $@
+
+.$(TARGET).efi.2: $(objtree)/prelink.o $(obj)/efi/relocs-empty.o \
+                  .$(TARGET).efi.2r.o .$(TARGET).efi.2s.o $(note_file) \
+                  $(obj)/efi.lds
+	$(call compare-symbol-tables, .$(TARGET).efi.1r.o, .$(TARGET).efi.2r.o)
+	$(call compare-symbol-tables, .$(TARGET).efi.1s.o, .$(TARGET).efi.2s.o)
+	$(LD) $(call EFI_LDFLAGS,$(VIRT_BASE)) -T $(obj)/efi.lds $(efi-objs) \
+	      $(orphan-handling-y) $(note_file_option) -o $@
+
+$(TARGET).efi: .$(TARGET).efi.2
 ifeq ($(CONFIG_DEBUG_INFO),y)
-	$(if $(filter --strip-debug,$(EFI_LDFLAGS)),echo,:) "Will strip debug info from $(@F)"
+	$(if $(filter --strip-debug,$(EFI_LDFLAGS)),echo,:) "No debug info in $(@F)"
 endif
-	$(objtree)/tools/symbols $(all_symbols) --source-name=$(@F).S --empty \
-		> $(dot-target).0s.S
-	$(MAKE) $(build)=$(@D) .$(@F).0s.o
-	$(foreach base, $(VIRT_BASE) $(ALT_BASE), \
-	          $(LD) $(call EFI_LDFLAGS,$(base)) -T $(obj)/efi.lds $< $(relocs-dummy) \
-	                $(dot-target).0s.o $(note_file_option) --strip-debug \
-	                -o $(dot-target).$(base).0 &&) :
-	$(MKRELOC) $(foreach base,$(VIRT_BASE) $(ALT_BASE),$(dot-target).$(base).0) \
-		> $(dot-target).1r.S
-	$(NM) -pa --format=sysv $(dot-target).$(VIRT_BASE).0 \
-		| $(objtree)/tools/symbols $(all_symbols) --sysv --sort \
-                  --source-name=$(@F).S \
-		> $(dot-target).1s.S
-	$(MAKE) $(build)=$(@D) .$(@F).1r.o .$(@F).1s.o
-	$(foreach base, $(VIRT_BASE) $(ALT_BASE), \
-	          $(LD) $(call EFI_LDFLAGS,$(base)) -T $(obj)/efi.lds $<  --strip-debug \
-	                $(dot-target).1r.o $(dot-target).1s.o $(note_file_option) \
-	                -o $(dot-target).$(base).1 &&) :
-	$(MKRELOC) $(foreach base,$(VIRT_BASE) $(ALT_BASE),$(dot-target).$(base).1) \
-		> $(dot-target).2r.S
-	$(NM) -pa --format=sysv $(dot-target).$(VIRT_BASE).1 \
-		| $(objtree)/tools/symbols $(all_symbols) --sysv --sort \
-                  --source-name=$(@F).S \
-		> $(dot-target).2s.S
-	$(MAKE) $(build)=$(@D) .$(@F).2r.o .$(@F).2s.o
-	$(call compare-symbol-tables, $(dot-target).1r.o, $(dot-target).2r.o)
-	$(call compare-symbol-tables, $(dot-target).1s.o, $(dot-target).2s.o)
-	$(LD) $(call EFI_LDFLAGS,$(VIRT_BASE)) -T $(obj)/efi.lds $< $(obj)/efi/relocs-empty.o \
-	      $(dot-target).2r.o $(dot-target).2s.o $(orphan-handling-y) \
-	      $(note_file_option) -o $@
-	$(NM) -pa --format=sysv $@ \
-		| $(objtree)/tools/symbols --all-symbols --xensyms --sysv --sort \
-		> $@.map
+	$(NM) -pa --format=sysv $< \
+	  | $(objtree)/tools/symbols --all-symbols --xensyms --sysv --sort \
+	  > $@.map
 ifeq ($(CONFIG_DEBUG_INFO),y)
-	$(if $(filter --strip-debug,$(EFI_LDFLAGS)),:$(space))$(OBJCOPY) -O elf64-x86-64 $@ $@.elf
+	$(if $(filter --strip-debug,$(EFI_LDFLAGS)),:$(space))$(OBJCOPY) -O elf64-x86-64 $< $@.elf
 endif
+	$(final-image-check-y)
+	mv $< $@
 	rm -f $(dot-target).[0-9]* $(@D)/..$(@F).[0-9]*
-ifeq ($(CONFIG_XEN_IBT),y)
-	$(SHELL) $(srctree)/tools/check-endbr.sh $@
-endif
 else
 $(TARGET).efi: FORCE
 	rm -f $@
--- /dev/null
+++ b/xen/scripts/Makefile.link
@@ -0,0 +1,51 @@
+# SPDX-License-Identifier: GPL-2.0
+# ==========================================================================
+# Helper rules for linking xen-syms
+# ==========================================================================
+
+syms-warn-dup-y := --warn-dup
+syms-warn-dup-$(CONFIG_SUPPRESS_DUPLICATE_SYMBOL_WARNINGS) :=
+syms-warn-dup-$(CONFIG_ENFORCE_UNIQUE_SYMBOLS) := --error-dup
+
+orphan-handling-$(call ld-option,--orphan-handling=warn) := --orphan-handling=warn
+
+final-image-check-y ?= true
+
+.INTERMEDIATE: $(addprefix .$(TARGET)-syms.,$(foreach n,0 1 2 3,$(n) $(n).o $(n).S))
+
+.$(TARGET)-syms.%.o: .$(TARGET)-syms.%.S
+	$(call cmd,cc_o_S)
+
+.$(TARGET)-syms.0.S:
+	$(objtree)/tools/symbols $(all_symbols) --empty > $@
+
+.$(TARGET)-syms.1.S: .$(TARGET)-syms.0
+.$(TARGET)-syms.2.S: .$(TARGET)-syms.1
+.$(TARGET)-syms.3.S: .$(TARGET)-syms.2
+
+.$(TARGET)-syms.%.S:
+	$(NM) -pa --format=sysv $< \
+	  | $(objtree)/tools/symbols $(all_symbols) --sysv --sort \
+	    $(if $(filter $(LAST_LINKING_PASS),$*), $(syms-warn-dup-y)) \
+	  > $@
+
+.$(TARGET)-syms.%: $(objtree)/prelink.o .$(TARGET)-syms.%.o $(obj)/xen.lds
+	$(LD) $(XEN_LDFLAGS) -T $(obj)/xen.lds $(filter %.o,$^) \
+	      $(build_id_linker) --strip-debug -o $@
+
+.$(TARGET)-syms.$(LAST_LINKING_PASS): $(objtree)/prelink.o \
+                                      .$(TARGET)-syms.$(LAST_LINKING_PASS).o \
+                                      $(obj)/xen.lds
+	$(call compare-symbol-tables, \
+	       .$(TARGET)-syms.$(shell expr $(LAST_LINKING_PASS) - 1).o, \
+	       .$(TARGET)-syms.$(LAST_LINKING_PASS).o)
+	$(LD) $(XEN_LDFLAGS) -T $(obj)/xen.lds $(filter %.o,$^) \
+	      $(build_id_linker) $(orphan-handling-y) -o $@
+
+$(TARGET)-syms: .$(TARGET)-syms.$(LAST_LINKING_PASS)
+	$(NM) -pa --format=sysv $< \
+	  | $(objtree)/tools/symbols --all-symbols --xensyms --sysv --sort \
+	  > $@.map
+	$(final-image-check-y)
+	mv $< $@
+	rm -f $(dot-target).[0-9]* $(@D)/..$(@F).[0-9]*



^ permalink raw reply	[flat|nested] 23+ messages in thread

* [PATCH v2 2/7] Arm: split xen-syms linking rule
  2026-08-26 11:57 [PATCH v2 0/7] build: split and unify linking of final image(s) Jan Beulich
  2026-08-26 12:00 ` [PATCH v2 1/7] x86: split xen-syms/xen.efi linking rules Jan Beulich
@ 2026-08-26 12:00 ` Jan Beulich
  2026-09-02 16:32   ` Anthony PERARD
  2026-08-26 12:01 ` [PATCH v2 3/7] RISC-V: " Jan Beulich
                   ` (4 subsequent siblings)
  6 siblings, 1 reply; 23+ messages in thread
From: Jan Beulich @ 2026-08-26 12:00 UTC (permalink / raw)
  To: xen-devel@lists.xenproject.org
  Cc: Andrew Cooper, Julien Grall, Stefano Stabellini, Anthony PERARD,
	Michal Orzel, Roger Pau Monné, Bertrand Marquis,
	Volodymyr Babchuk

Doing so, besides (hopefully) adding clarity (not the least by way of
[re-]using pattern rules where possible), also avoids explicit recursive
$(MAKE) invocations.

By re-using the generic rules introduced when the respective x86 rule was
split,
- the .map file now isn't created after the final binary anymore,
- --strip-debug is passed to $(LD) during early linking passes (for
  consistency the option is also explicitly added to the optional linking
  pass rule),
- CONFIG_{SUPPRESS_DUPLICATE_SYMBOL_WARNINGS,ENFORCE_UNIQUE_SYMBOLS} are
  now properly respected.
Orphan section checking, otoh, is getting suppressed for now, until the
about a dozen warnings which would result have been taken care of.

While the 4th linking step continues to be avoided when possible, a
redundant invocation of $(NM) and tools/symbols (plus the assembling of
the resulting .S file) is hopefully deemed acceptable.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
---
As for the x86 patch, I'd like to keep the "beautification" part, i.e.
transforming to more use of Kbuild.include machinery, separate.

--- a/xen/arch/arm/Makefile
+++ b/xen/arch/arm/Makefile
@@ -84,40 +84,12 @@ ifeq ($(CONFIG_ARM_64),y)
 	ln -sf $(@F) $@.efi
 endif
 
-$(TARGET)-syms: $(objtree)/prelink.o $(obj)/xen.lds
-	$(objtree)/tools/symbols $(all_symbols) --empty > $(dot-target).0.S
-	$(MAKE) $(build)=$(@D) $(dot-target).0.o
-	$(LD) $(XEN_LDFLAGS) -T $(obj)/xen.lds $< $(build_id_linker) \
-	      $(dot-target).0.o -o $(dot-target).0
-	$(NM) -pa --format=sysv $(dot-target).0 \
-		| $(objtree)/tools/symbols $(all_symbols) --sysv --sort \
-		> $(dot-target).1.S
-	$(MAKE) $(build)=$(@D) $(dot-target).1.o
-	$(LD) $(XEN_LDFLAGS) -T $(obj)/xen.lds $< $(build_id_linker) \
-	    $(dot-target).1.o -o $(dot-target).1
-	$(NM) -pa --format=sysv $(dot-target).1 \
-		| $(objtree)/tools/symbols $(all_symbols) --sysv --sort \
-		> $(dot-target).2.S
-	$(MAKE) $(build)=$(@D) $(dot-target).2.o
-	if ! { $(call compare-symbol-tables, $(dot-target).1.o, $(dot-target).2.o) >/dev/null; }; \
-	then \
-		set -e; \
-		$(LD) $(XEN_LDFLAGS) -T $(obj)/xen.lds $< $(build_id_linker) \
-		    $(dot-target).2.o -o $(dot-target).2; \
-		$(NM) -pa --format=sysv $(dot-target).2 \
-			| $(objtree)/tools/symbols $(all_symbols) --sysv --sort \
-			> $(dot-target).3.S; \
-		$(MAKE) $(build)=$(@D) $(dot-target).3.o; \
-		$(call compare-symbol-tables, $(dot-target).2.o, $(dot-target).3.o); \
-	else \
-		ln -sf $(dot-target).2.o $(dot-target).3.o; \
-	fi
-	$(LD) $(XEN_LDFLAGS) -T $(obj)/xen.lds $< $(build_id_linker) \
-	    $(dot-target).3.o -o $@
-	$(NM) -pa --format=sysv $@ \
-		| $(objtree)/tools/symbols --all-symbols --xensyms --sysv --sort \
-		> $@.map
-	rm -f $(dot-target).[0-9]* $(@D)/..$(@F).[0-9]*
+LAST_LINKING_PASS := 3
+
+include scripts/Makefile.link
+
+# Suppress orphan section checking for the time being.
+orphan-handling-y :=
 
 .PHONY: include
 include:
--- a/xen/scripts/Makefile.link
+++ b/xen/scripts/Makefile.link
@@ -33,6 +33,19 @@ final-image-check-y ?= true
 	$(LD) $(XEN_LDFLAGS) -T $(obj)/xen.lds $(filter %.o,$^) \
 	      $(build_id_linker) --strip-debug -o $@
 
+ifneq ($(LAST_LINKING_PASS),2)
+
+.$(TARGET)-syms.2: $(objtree)/prelink.o .$(TARGET)-syms.2.o $(obj)/xen.lds
+	if ! { $(call compare-symbol-tables, .$(TARGET)-syms.1.o, .$(TARGET)-syms.2.o) >/dev/null; }; \
+	then \
+		$(LD) $(XEN_LDFLAGS) -T $(obj)/xen.lds $(filter %.o,$^) \
+		      $(build_id_linker) --strip-debug -o $@; \
+	else \
+		ln -sf .$(TARGET)-syms.1 $@; \
+	fi
+
+endif
+
 .$(TARGET)-syms.$(LAST_LINKING_PASS): $(objtree)/prelink.o \
                                       .$(TARGET)-syms.$(LAST_LINKING_PASS).o \
                                       $(obj)/xen.lds



^ permalink raw reply	[flat|nested] 23+ messages in thread

* [PATCH v2 3/7] RISC-V: split xen-syms linking rule
  2026-08-26 11:57 [PATCH v2 0/7] build: split and unify linking of final image(s) Jan Beulich
  2026-08-26 12:00 ` [PATCH v2 1/7] x86: split xen-syms/xen.efi linking rules Jan Beulich
  2026-08-26 12:00 ` [PATCH v2 2/7] Arm: split xen-syms linking rule Jan Beulich
@ 2026-08-26 12:01 ` Jan Beulich
  2026-08-27 15:56   ` Oleksii Kurochko
  2026-08-26 12:01 ` [PATCH v2 4/7] PPC: " Jan Beulich
                   ` (3 subsequent siblings)
  6 siblings, 1 reply; 23+ messages in thread
From: Jan Beulich @ 2026-08-26 12:01 UTC (permalink / raw)
  To: xen-devel@lists.xenproject.org
  Cc: Andrew Cooper, Julien Grall, Stefano Stabellini, Anthony PERARD,
	Michal Orzel, Roger Pau Monné, Alistair Francis,
	Connor Davis, Oleksii Kurochko

Doing so, besides (hopefully) adding clarity (not the least by way of
[re-]using pattern rules where possible), also avoids explicit recursive
$(MAKE) invocations.

By re-using the generic rules introduced when the respective x86 rule was
split,
- the .map file now isn't created after the final binary anymore,
- --strip-debug is passed to $(LD) during early linking passes (for
  consistency the option is also explicitly added to the optional linking
  pass rule),
- CONFIG_{SUPPRESS_DUPLICATE_SYMBOL_WARNINGS,ENFORCE_UNIQUE_SYMBOLS} are
  now properly respected.
Orphan section checking, otoh, is getting suppressed for now, until the
about a dozen warnings which would result have been taken care of.

While the 4th linking step continues to be avoided when possible, a
redundant invocation of $(NM) and tools/symbols (plus the assembling of
the resulting .S file) is hopefully deemed acceptable.

Signed-off-by: Jan Beulich <jbeulich@suse.com>

--- a/xen/arch/riscv/Makefile
+++ b/xen/arch/riscv/Makefile
@@ -31,40 +31,12 @@ obj-y += vtimer.o
 $(TARGET): $(TARGET)-syms
 	$(OBJCOPY) -O binary -S $< $@
 
-$(TARGET)-syms: $(objtree)/prelink.o $(obj)/xen.lds
-	$(objtree)/tools/symbols $(all_symbols) --empty > $(dot-target).0.S
-	$(MAKE) $(build)=$(@D) $(dot-target).0.o
-	$(LD) $(XEN_LDFLAGS) -T $(obj)/xen.lds $< $(build_id_linker) \
-	      $(dot-target).0.o -o $(dot-target).0
-	$(NM) -pa --format=sysv $(dot-target).0 \
-		| $(objtree)/tools/symbols $(all_symbols) --sysv --sort \
-		> $(dot-target).1.S
-	$(MAKE) $(build)=$(@D) $(dot-target).1.o
-	$(LD) $(XEN_LDFLAGS) -T $(obj)/xen.lds $< $(build_id_linker) \
-	    $(dot-target).1.o -o $(dot-target).1
-	$(NM) -pa --format=sysv $(dot-target).1 \
-		| $(objtree)/tools/symbols $(all_symbols) --sysv --sort \
-		> $(dot-target).2.S
-	$(MAKE) $(build)=$(@D) $(dot-target).2.o
-	if ! { $(call compare-symbol-tables, $(dot-target).1.o, $(dot-target).2.o) >/dev/null; }; \
-	then \
-		set -e; \
-		$(LD) $(XEN_LDFLAGS) -T $(obj)/xen.lds $< $(build_id_linker) \
-		    $(dot-target).2.o -o $(dot-target).2; \
-		$(NM) -pa --format=sysv $(dot-target).2 \
-			| $(objtree)/tools/symbols $(all_symbols) --sysv --sort \
-			> $(dot-target).3.S; \
-		$(MAKE) $(build)=$(@D) $(dot-target).3.o; \
-		$(call compare-symbol-tables, $(dot-target).2.o, $(dot-target).3.o); \
-	else \
-		ln -sf $(dot-target).2.o $(dot-target).3.o; \
-	fi
-	$(LD) $(XEN_LDFLAGS) -T $(obj)/xen.lds $< $(build_id_linker) \
-	    $(dot-target).3.o -o $@
-	$(NM) -pa --format=sysv $@ \
-		| $(objtree)/tools/symbols --all-symbols --xensyms --sysv --sort \
-		> $@.map
-	rm -f $(dot-target).[0-9]* $(@D)/..$(@F).[0-9]*
+LAST_LINKING_PASS := 3
+
+include scripts/Makefile.link
+
+# Suppress orphan section checking for the time being.
+orphan-handling-y :=
 
 $(obj)/xen.lds: $(src)/xen.lds.S FORCE
 	$(call if_changed_dep,cpp_lds_S)



^ permalink raw reply	[flat|nested] 23+ messages in thread

* [PATCH v2 4/7] PPC: split xen-syms linking rule
  2026-08-26 11:57 [PATCH v2 0/7] build: split and unify linking of final image(s) Jan Beulich
                   ` (2 preceding siblings ...)
  2026-08-26 12:01 ` [PATCH v2 3/7] RISC-V: " Jan Beulich
@ 2026-08-26 12:01 ` Jan Beulich
  2026-09-03 11:50   ` Anthony PERARD
  2026-08-26 12:02 ` [PATCH v2 5/7] build: move $(all-symbols-*) Jan Beulich
                   ` (2 subsequent siblings)
  6 siblings, 1 reply; 23+ messages in thread
From: Jan Beulich @ 2026-08-26 12:01 UTC (permalink / raw)
  To: xen-devel@lists.xenproject.org
  Cc: Andrew Cooper, Julien Grall, Stefano Stabellini, Anthony PERARD,
	Michal Orzel, Roger Pau Monné, Timothy Pearson

Doing so, besides (hopefully) adding clarity (not the least by way of
[re-]using pattern rules where possible), also avoids explicit recursive
$(MAKE) invocations.

By re-using the generic rules introduced when the respective x86 rule was
split,
- the .map file now isn't created after the final binary anymore,
- --strip-debug is passed to $(LD) during early linking passes (for
  consistency the option is also explicitly added to the optional linking
  pass rule),
- CONFIG_{SUPPRESS_DUPLICATE_SYMBOL_WARNINGS,ENFORCE_UNIQUE_SYMBOLS} are
  now properly respected.
Orphan section checking, otoh, is getting suppressed for now, until the
about a dozen warnings which would result have been taken care of.

Signed-off-by: Jan Beulich <jbeulich@suse.com>

--- a/xen/arch/ppc/Makefile
+++ b/xen/arch/ppc/Makefile
@@ -11,28 +11,12 @@ obj-y += tlb-radix.o
 $(TARGET): $(TARGET)-syms
 	cp -f $< $@
 
-$(TARGET)-syms: $(objtree)/prelink.o $(obj)/xen.lds
-	$(objtree)/tools/symbols $(all_symbols) --empty > $(dot-target).0.S
-	$(MAKE) $(build)=$(@D) $(dot-target).0.o
-	$(LD) $(XEN_LDFLAGS) -T $(obj)/xen.lds $< $(build_id_linker) \
-	      $(dot-target).0.o -o $(dot-target).0
-	$(NM) -pa --format=sysv $(dot-target).0 \
-		| $(objtree)/tools/symbols $(all_symbols) --sysv --sort \
-		> $(dot-target).1.S
-	$(MAKE) $(build)=$(@D) $(dot-target).1.o
-	$(LD) $(XEN_LDFLAGS) -T $(obj)/xen.lds $< $(build_id_linker) \
-	    $(dot-target).1.o -o $(dot-target).1
-	$(NM) -pa --format=sysv $(dot-target).1 \
-		| $(objtree)/tools/symbols $(all_symbols) --sysv --sort \
-		> $(dot-target).2.S
-	$(MAKE) $(build)=$(@D) $(dot-target).2.o
-	$(call compare-symbol-tables, $(dot-target).1.o, $(dot-target).2.o)
-	$(LD) $(XEN_LDFLAGS) -T $(obj)/xen.lds $< $(build_id_linker) \
-	    $(dot-target).2.o -o $@
-	$(NM) -pa --format=sysv $@ \
-		| $(objtree)/tools/symbols --all-symbols --xensyms --sysv --sort \
-		> $@.map
-	rm -f $(dot-target).[0-9]* $(@D)/..$(@F).[0-9]*
+LAST_LINKING_PASS := 2
+
+include scripts/Makefile.link
+
+# Suppress orphan section checking for the time being.
+orphan-handling-y :=
 
 $(obj)/xen.lds: $(src)/xen.lds.S FORCE
 	$(call if_changed_dep,cpp_lds_S)



^ permalink raw reply	[flat|nested] 23+ messages in thread

* [PATCH v2 5/7] build: move $(all-symbols-*)
  2026-08-26 11:57 [PATCH v2 0/7] build: split and unify linking of final image(s) Jan Beulich
                   ` (3 preceding siblings ...)
  2026-08-26 12:01 ` [PATCH v2 4/7] PPC: " Jan Beulich
@ 2026-08-26 12:02 ` Jan Beulich
  2026-09-03 11:54   ` Anthony PERARD
  2026-08-26 12:03 ` [PATCH v2 6/7] build: move $(compare-symbol-tables) Jan Beulich
  2026-08-26 12:04 ` [PATCH v2 7/7] RISC-V: place .sdata / .srodata / .riscv.attributes Jan Beulich
  6 siblings, 1 reply; 23+ messages in thread
From: Jan Beulich @ 2026-08-26 12:02 UTC (permalink / raw)
  To: xen-devel@lists.xenproject.org
  Cc: Andrew Cooper, Julien Grall, Stefano Stabellini, Anthony PERARD,
	Michal Orzel, Roger Pau Monné, Teddy Astie

With the final linking logic now consolidated in scripts/Makefile.link,
$(all-symbols-*) also doesn't need setting anymore in (and passing down
from) the top level Makefile.

Signed-off-by: Jan Beulich <jbeulich@suse.com>

--- a/xen/Makefile
+++ b/xen/Makefile
@@ -465,10 +465,6 @@ ALL_OBJS-$(CONFIG_CRYPTO) += crypto/buil
 ARCH_LIBS-y               :=
 ALL_LIBS-y                := lib/lib.a
 
-all-symbols-y :=
-all-symbols-$(CONFIG_LIVEPATCH) += --all-symbols
-all-symbols-$(CONFIG_FAST_SYMBOL_LOOKUP) += --sort-by-name
-
 include $(srctree)/arch/$(SRCARCH)/arch.mk
 
 # define new variables to avoid the ones defined in Config.mk
@@ -622,8 +618,7 @@ $(TARGET): outputmakefile asm-generic FO
 	$(Q)$(MAKE) $(build)=arch/$(SRCARCH) include
 	$(Q)$(MAKE) $(build)=. arch/$(SRCARCH)/include/asm/asm-offsets.h
 	$(Q)$(MAKE) $(build)=. MKRELOC=$(MKRELOC) 'ALL_OBJS=$(ALL_OBJS-y)' \
-	            'ALL_LIBS=$(ARCH_LIBS-y) $(ALL_LIBS-y)' \
-	            'all_symbols=$(all-symbols-y)' $@
+	            'ALL_LIBS=$(ARCH_LIBS-y) $(ALL_LIBS-y)' $@
 
 SUBDIRS = xsm arch common crypto drivers lib test
 define all_sources
--- a/xen/arch/x86/Makefile
+++ b/xen/arch/x86/Makefile
@@ -183,14 +183,14 @@ ifeq ($(XEN_BUILD_PE),y)
 	$(MKRELOC) $^ > $@
 
 .$(TARGET).efi.0s.S:
-	$(objtree)/tools/symbols $(all_symbols) --empty > $@
+	$(objtree)/tools/symbols $(all-symbols-y) --empty > $@
 
 .$(TARGET).efi.1s.S: .$(TARGET).efi.0
 .$(TARGET).efi.2s.S: .$(TARGET).efi.1
 
 .$(TARGET).efi.%s.S:
 	$(NM) -pa --format=sysv $< \
-	  | $(objtree)/tools/symbols $(all_symbols) --sysv --sort \
+	  | $(objtree)/tools/symbols $(all-symbols-y) --sysv --sort \
  	    --source-name=$(TARGET).efi.S \
 	  > $@
 
--- a/xen/scripts/Makefile.link
+++ b/xen/scripts/Makefile.link
@@ -3,6 +3,10 @@
 # Helper rules for linking xen-syms
 # ==========================================================================
 
+all-symbols-y :=
+all-symbols-$(CONFIG_LIVEPATCH) += --all-symbols
+all-symbols-$(CONFIG_FAST_SYMBOL_LOOKUP) += --sort-by-name
+
 syms-warn-dup-y := --warn-dup
 syms-warn-dup-$(CONFIG_SUPPRESS_DUPLICATE_SYMBOL_WARNINGS) :=
 syms-warn-dup-$(CONFIG_ENFORCE_UNIQUE_SYMBOLS) := --error-dup
@@ -17,7 +21,7 @@ final-image-check-y ?= true
 	$(call cmd,cc_o_S)
 
 .$(TARGET)-syms.0.S:
-	$(objtree)/tools/symbols $(all_symbols) --empty > $@
+	$(objtree)/tools/symbols $(all-symbols-y) --empty > $@
 
 .$(TARGET)-syms.1.S: .$(TARGET)-syms.0
 .$(TARGET)-syms.2.S: .$(TARGET)-syms.1
@@ -25,7 +29,7 @@ final-image-check-y ?= true
 
 .$(TARGET)-syms.%.S:
 	$(NM) -pa --format=sysv $< \
-	  | $(objtree)/tools/symbols $(all_symbols) --sysv --sort \
+	  | $(objtree)/tools/symbols $(all-symbols-y) --sysv --sort \
 	    $(if $(filter $(LAST_LINKING_PASS),$*), $(syms-warn-dup-y)) \
 	  > $@
 



^ permalink raw reply	[flat|nested] 23+ messages in thread

* [PATCH v2 6/7] build: move $(compare-symbol-tables)
  2026-08-26 11:57 [PATCH v2 0/7] build: split and unify linking of final image(s) Jan Beulich
                   ` (4 preceding siblings ...)
  2026-08-26 12:02 ` [PATCH v2 5/7] build: move $(all-symbols-*) Jan Beulich
@ 2026-08-26 12:03 ` Jan Beulich
  2026-09-03 11:55   ` Anthony PERARD
  2026-08-26 12:04 ` [PATCH v2 7/7] RISC-V: place .sdata / .srodata / .riscv.attributes Jan Beulich
  6 siblings, 1 reply; 23+ messages in thread
From: Jan Beulich @ 2026-08-26 12:03 UTC (permalink / raw)
  To: xen-devel@lists.xenproject.org
  Cc: Andrew Cooper, Julien Grall, Stefano Stabellini, Anthony PERARD,
	Michal Orzel, Roger Pau Monné

With the final linking logic now consolidated in scripts/Makefile.link,
$(compare-symbol-tables) also doesn't need setting anymore in
Kbuild.include.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
---
v2: New.

--- a/xen/scripts/Kbuild.include
+++ b/xen/scripts/Kbuild.include
@@ -56,19 +56,6 @@ 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 $(2) $(@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) ); }' \
--- a/xen/scripts/Makefile.link
+++ b/xen/scripts/Makefile.link
@@ -33,6 +33,18 @@ final-image-check-y ?= true
 	    $(if $(filter $(LAST_LINKING_PASS),$*), $(syms-warn-dup-y)) \
 	  > $@
 
+# 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 $(2) $(@D)/.cst.$$$$; \
+    $(OBJDUMP) -t $(@D)/.cst.$$$$ > $(2).sym; \
+    rm -f $(@D)/.cst.$$$$; \
+    diff -u $(1).sym $(2).sym
+endef
+
 .$(TARGET)-syms.%: $(objtree)/prelink.o .$(TARGET)-syms.%.o $(obj)/xen.lds
 	$(LD) $(XEN_LDFLAGS) -T $(obj)/xen.lds $(filter %.o,$^) \
 	      $(build_id_linker) --strip-debug -o $@



^ permalink raw reply	[flat|nested] 23+ messages in thread

* [PATCH v2 7/7] RISC-V: place .sdata / .srodata / .riscv.attributes
  2026-08-26 11:57 [PATCH v2 0/7] build: split and unify linking of final image(s) Jan Beulich
                   ` (5 preceding siblings ...)
  2026-08-26 12:03 ` [PATCH v2 6/7] build: move $(compare-symbol-tables) Jan Beulich
@ 2026-08-26 12:04 ` Jan Beulich
  2026-08-27 15:40   ` Oleksii Kurochko
  6 siblings, 1 reply; 23+ messages in thread
From: Jan Beulich @ 2026-08-26 12:04 UTC (permalink / raw)
  To: xen-devel@lists.xenproject.org
  Cc: Andrew Cooper, Julien Grall, Stefano Stabellini, Anthony PERARD,
	Michal Orzel, Roger Pau Monné, Alistair Francis,
	Connor Davis, Oleksii Kurochko

Of the short-data sections, only .sbss is presently mentioned in the
linker script. Place them next to, but ahead of their "normal" data
sections.

.riscv.attributes can go towards the tail of the image, next to (ahead of)
debug info.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
---
Seeing where .sbss lives, does positioning really not matter at all? I
would have expected that short-data sections want to live close together,
and specifically close to .text / .init.text (seeing that such data is
accessed using AUIPC). I'm puzzled that the psABI doesn't even mention
them, hence leaving it open how exactly they are to be used.

What remains to eliminate orphan section warnings is the placement of
.note.GNU-stack (which perhaps wants dealing with on all of Arm, PPC, and
RISC-V together, ideally unifying with x86) and (odd at the first glance,
but dealt with on x86 as well, i.e. may again want unifying) that of a
number of .rela.* sections.

--- a/xen/arch/riscv/xen.lds.S
+++ b/xen/arch/riscv/xen.lds.S
@@ -44,6 +44,8 @@ SECTIONS
 
         BUGFRAMES
 
+        *(.srodata)
+        *(.srodata.*)
         *(.rodata)
         *(.rodata.*)
         VPCI_ARRAY
@@ -92,6 +94,7 @@ SECTIONS
         SCHEDULER_ARRAY
         HYPFS_PARAM
 
+        *(.sdata .sdata.*)
         *(.data .data.*)
         CONSTRUCTORS
     } :text
@@ -162,6 +165,8 @@ SECTIONS
     /* Section for the device tree blob (if any). */
     .dtb : { *(.dtb) } :text
 
+    .riscv.attributes : { *(.riscv.attributes) } :text
+
     DWARF2_DEBUG_SECTIONS
 
     DISCARD_SECTIONS



^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH v2 7/7] RISC-V: place .sdata / .srodata / .riscv.attributes
  2026-08-26 12:04 ` [PATCH v2 7/7] RISC-V: place .sdata / .srodata / .riscv.attributes Jan Beulich
@ 2026-08-27 15:40   ` Oleksii Kurochko
  2026-08-27 15:53     ` Andrew Cooper
  2026-08-27 15:56     ` Jan Beulich
  0 siblings, 2 replies; 23+ messages in thread
From: Oleksii Kurochko @ 2026-08-27 15:40 UTC (permalink / raw)
  To: Jan Beulich, xen-devel@lists.xenproject.org
  Cc: Andrew Cooper, Julien Grall, Stefano Stabellini, Anthony PERARD,
	Michal Orzel, Roger Pau Monné, Alistair Francis,
	Connor Davis



On 8/26/26 2:04 PM, Jan Beulich wrote:
> Of the short-data sections, only .sbss is presently mentioned in the
> linker script. Place them next to, but ahead of their "normal" data
> sections.
> 
> .riscv.attributes can go towards the tail of the image, next to (ahead of)
> debug info.
> 
> Signed-off-by: Jan Beulich <jbeulich@suse.com>
> ---
> Seeing where .sbss lives, does positioning really not matter at all? I
> would have expected that short-data sections want to live close together,
> and specifically close to .text / .init.text (seeing that such data is
> accessed using AUIPC). I'm puzzled that the psABI doesn't even mention
> them, hence leaving it open how exactly they are to be used.

It doesn't, and the reason is that the relevant proximity isn't to .text 
but to __global_pointer$. The small-data sections exist to let a linker 
script cluster small objects around that anchor so that ld's relaxation 
pass can fold an auipc+load pair into a single gp-relative access (-+2 
KiB window).

That pass is keyed purely on the symbol being defined 
riscv_global_pointer_value() returns 0 otherwise and the relaxation is 
skipped. We define no __global_pointer$ and head.S never loads gp (it 
appears only as a cpu_user_regs slot in entry.S), so every access stays 
the medany auipc form regardless of section.

I confirmed this by linking the same object twice (look at the script 
below, with and without the symbol: without it, zero gp-relative 
accesses; with it, the pairs collapse.

Worth noting the relaxation is section-agnostic: in the test mentioned 
below a 400-byte array in plain .bss got gp-relative too, purely because 
it landed in range. So the sections are a clustering hint, not a 
mechanism ld keys off.

The script I used:
```
mkdir -p /tmp/gp-demo && cd /tmp/gp-demo

# 1. Test code: one small variable (-> .sbss) and one large array (-> .bss)
cat > s.c <<'EOF'
int small_var;                                  /* 4 bytes   -> .sbss */
int big_arr[100];                               /* 400 bytes -> .bss  */
int read_small(void) { return small_var; }
int read_big(void)   { return big_arr[0]; }
EOF

# 2. Linker script WITHOUT __global_pointer$
cat > nogp.lds <<'EOF'
ENTRY(read_small)
SECTIONS {
   . = 0xffffffffc0000000;
   .text : { *(.text) *(.text.*) }
   .data : { *(.sdata .sdata.*) *(.data .data.*) }
   .bss  : { *(.sbss .sbss.*) *(.bss .bss.*) *(COMMON) }
   /DISCARD/ : { *(.comment) *(.note*) *(.riscv.attributes) }
}
EOF

# 3. Same script, but WITH __global_pointer$ defined
sed 's|^  \.data : {|  __global_pointer$ = . + 0x800;\n  .data : {|' 
nogp.lds > gp.lds

riscv64-linux-gnu-gcc -O2 -march=rv64ima -mabi=lp64 -mcmodel=medany \
                       -ffreestanding -c s.c -o s.o

# Check the INPUT sections: .sbss vs plain .bss (the link merges them, so
# inspect s.o, not the linked ELF)
echo "### INPUT sections the symbols live in ###"
riscv64-linux-gnu-objdump -t s.o | grep -E 'small_var|big_arr'

# Link both ways and compare the generated code
for L in nogp gp; do
   riscv64-linux-gnu-ld -T $L.lds s.o -o $L.elf 2>/dev/null
   echo "=============== $L.lds ==============="
   riscv64-linux-gnu-objdump -d --no-show-raw-insn $L.elf \
     | sed -n '/<read_small>:/,/ret/p;/<read_big>:/,/ret/p'
done

```


> 
> What remains to eliminate orphan section warnings is the placement of
> .note.GNU-stack (which perhaps wants dealing with on all of Arm, PPC, and
> RISC-V together, ideally unifying with x86) and (odd at the first glance,
> but dealt with on x86 as well, i.e. may again want unifying) that of a
> number of .rela.* sections.
> 
> --- a/xen/arch/riscv/xen.lds.S
> +++ b/xen/arch/riscv/xen.lds.S
> @@ -44,6 +44,8 @@ SECTIONS
>   
>           BUGFRAMES
>   
> +        *(.srodata)
> +        *(.srodata.*)
>           *(.rodata)
>           *(.rodata.*)
>           VPCI_ARRAY
> @@ -92,6 +94,7 @@ SECTIONS
>           SCHEDULER_ARRAY
>           HYPFS_PARAM
>   
> +        *(.sdata .sdata.*)
>           *(.data .data.*)
>           CONSTRUCTORS
>       } :text
> @@ -162,6 +165,8 @@ SECTIONS
>       /* Section for the device tree blob (if any). */
>       .dtb : { *(.dtb) } :text
>   
> +    .riscv.attributes : { *(.riscv.attributes) } :text
> +

Nit: .riscv.attributes is SHT_RISCV_ATTRIBUTES, i.e. non-alloc.
:text on it is misleading, and without an explicit address it gets 
sh_addr from .(location counter) after .dtb. Could we use matching the 
idiom used for every other non-alloc section in xen.lds.h:
   .riscv.attributes 0 : { *(.riscv.attributes) }
No functional difference either way (objcopy -O binary drops it, and I 
verified a non-alloc output section doesn't advance dot, so nothing 
downstream shifts), so purely consistency.

Is dropping orphan-handling-y := from arch/riscv/Makefile the intended 
end of this series? As if I understand correctly with such defintion we 
will miss warning so everything of that will be missed:

cd xen
riscv64-linux-gnu-ld -T arch/riscv/xen.lds prelink.o 
--orphan-handling=warn -o /tmp/t.elf 2>&1 \
   | grep 'orphan section'
/usr/bin/riscv64-linux-gnu-ld: warning: orphan section `.note.GNU-stack' 
from `prelink.o' being placed in section `.note.GNU-stack'
/usr/bin/riscv64-linux-gnu-ld: warning: orphan section `.rela.text' from 
`prelink.o' being placed in section `.rela.dyn'
/usr/bin/riscv64-linux-gnu-ld: warning: orphan section `.rela.init.text' 
from `prelink.o' being placed in section `.rela.dyn'
/usr/bin/riscv64-linux-gnu-ld: warning: orphan section 
`.rela.data.read_mostly' from `prelink.o' being placed in section 
`.rela.dyn'
/usr/bin/riscv64-linux-gnu-ld: warning: orphan section `.rela.init.data' 
from `prelink.o' being placed in section `.rela.dyn'
/usr/bin/riscv64-linux-gnu-ld: warning: orphan section 
`.rela.text.header' from `prelink.o' being placed in section `.rela.dyn'

Thanks.

~ Oleksii


^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH v2 7/7] RISC-V: place .sdata / .srodata / .riscv.attributes
  2026-08-27 15:40   ` Oleksii Kurochko
@ 2026-08-27 15:53     ` Andrew Cooper
  2026-08-27 15:56     ` Jan Beulich
  1 sibling, 0 replies; 23+ messages in thread
From: Andrew Cooper @ 2026-08-27 15:53 UTC (permalink / raw)
  To: Oleksii Kurochko, Jan Beulich, xen-devel@lists.xenproject.org
  Cc: Andrew Cooper, Julien Grall, Stefano Stabellini, Anthony PERARD,
	Michal Orzel, Roger Pau Monné, Alistair Francis,
	Connor Davis

On 27/08/2026 4:40 pm, Oleksii Kurochko wrote:
>
> Is dropping orphan-handling-y := from arch/riscv/Makefile the intended
> end of this series? As if I understand correctly with such defintion
> we will miss warning so everything of that will be missed:
>
> cd xen
> riscv64-linux-gnu-ld -T arch/riscv/xen.lds prelink.o
> --orphan-handling=warn -o /tmp/t.elf 2>&1 \
>   | grep 'orphan section'
> /usr/bin/riscv64-linux-gnu-ld: warning: orphan section
> `.note.GNU-stack' from `prelink.o' being placed in section
> `.note.GNU-stack'
> /usr/bin/riscv64-linux-gnu-ld: warning: orphan section `.rela.text'
> from `prelink.o' being placed in section `.rela.dyn'
> /usr/bin/riscv64-linux-gnu-ld: warning: orphan section
> `.rela.init.text' from `prelink.o' being placed in section `.rela.dyn'
> /usr/bin/riscv64-linux-gnu-ld: warning: orphan section
> `.rela.data.read_mostly' from `prelink.o' being placed in section
> `.rela.dyn'
> /usr/bin/riscv64-linux-gnu-ld: warning: orphan section
> `.rela.init.data' from `prelink.o' being placed in section `.rela.dyn'
> /usr/bin/riscv64-linux-gnu-ld: warning: orphan section
> `.rela.text.header' from `prelink.o' being placed in section `.rela.dyn' 
>

Orphaned sections are a huge source of bugs.  Right now, only x86 has
any kind of orphan warning, so the `orphan-handling-y :=` is maintaining
the existing behaviour.

Longterm we do want to delete that override, but IMO it should be
follow-on work, rather than being part of this series.

~Andrew


^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH v2 3/7] RISC-V: split xen-syms linking rule
  2026-08-26 12:01 ` [PATCH v2 3/7] RISC-V: " Jan Beulich
@ 2026-08-27 15:56   ` Oleksii Kurochko
  2026-08-27 16:01     ` Jan Beulich
  0 siblings, 1 reply; 23+ messages in thread
From: Oleksii Kurochko @ 2026-08-27 15:56 UTC (permalink / raw)
  To: Jan Beulich, xen-devel@lists.xenproject.org
  Cc: Andrew Cooper, Julien Grall, Stefano Stabellini, Anthony PERARD,
	Michal Orzel, Roger Pau Monné, Alistair Francis,
	Connor Davis



On 8/26/26 2:01 PM, Jan Beulich wrote:
> Doing so, besides (hopefully) adding clarity (not the least by way of
> [re-]using pattern rules where possible), also avoids explicit recursive
> $(MAKE) invocations.
> 
> By re-using the generic rules introduced when the respective x86 rule was
> split,
> - the .map file now isn't created after the final binary anymore,
> - --strip-debug is passed to $(LD) during early linking passes (for
>    consistency the option is also explicitly added to the optional linking
>    pass rule),
> - CONFIG_{SUPPRESS_DUPLICATE_SYMBOL_WARNINGS,ENFORCE_UNIQUE_SYMBOLS} are
>    now properly respected.
> Orphan section checking, otoh, is getting suppressed for now, until the
> about a dozen warnings which would result have been taken care of.
> 
> While the 4th linking step continues to be avoided when possible, a
> redundant invocation of $(NM) and tools/symbols (plus the assembling of
> the resulting .S file) is hopefully deemed acceptable.
> 
> Signed-off-by: Jan Beulich <jbeulich@suse.com>
> 
> --- a/xen/arch/riscv/Makefile
> +++ b/xen/arch/riscv/Makefile
> @@ -31,40 +31,12 @@ obj-y += vtimer.o
>   $(TARGET): $(TARGET)-syms
>   	$(OBJCOPY) -O binary -S $< $@
>   
> -$(TARGET)-syms: $(objtree)/prelink.o $(obj)/xen.lds
> -	$(objtree)/tools/symbols $(all_symbols) --empty > $(dot-target).0.S
> -	$(MAKE) $(build)=$(@D) $(dot-target).0.o
> -	$(LD) $(XEN_LDFLAGS) -T $(obj)/xen.lds $< $(build_id_linker) \
> -	      $(dot-target).0.o -o $(dot-target).0
> -	$(NM) -pa --format=sysv $(dot-target).0 \
> -		| $(objtree)/tools/symbols $(all_symbols) --sysv --sort \
> -		> $(dot-target).1.S
> -	$(MAKE) $(build)=$(@D) $(dot-target).1.o
> -	$(LD) $(XEN_LDFLAGS) -T $(obj)/xen.lds $< $(build_id_linker) \
> -	    $(dot-target).1.o -o $(dot-target).1
> -	$(NM) -pa --format=sysv $(dot-target).1 \
> -		| $(objtree)/tools/symbols $(all_symbols) --sysv --sort \
> -		> $(dot-target).2.S
> -	$(MAKE) $(build)=$(@D) $(dot-target).2.o
> -	if ! { $(call compare-symbol-tables, $(dot-target).1.o, $(dot-target).2.o) >/dev/null; }; \
> -	then \
> -		set -e; \
> -		$(LD) $(XEN_LDFLAGS) -T $(obj)/xen.lds $< $(build_id_linker) \
> -		    $(dot-target).2.o -o $(dot-target).2; \
> -		$(NM) -pa --format=sysv $(dot-target).2 \
> -			| $(objtree)/tools/symbols $(all_symbols) --sysv --sort \
> -			> $(dot-target).3.S; \
> -		$(MAKE) $(build)=$(@D) $(dot-target).3.o; \
> -		$(call compare-symbol-tables, $(dot-target).2.o, $(dot-target).3.o); \
> -	else \
> -		ln -sf $(dot-target).2.o $(dot-target).3.o; \
> -	fi
> -	$(LD) $(XEN_LDFLAGS) -T $(obj)/xen.lds $< $(build_id_linker) \
> -	    $(dot-target).3.o -o $@
> -	$(NM) -pa --format=sysv $@ \
> -		| $(objtree)/tools/symbols --all-symbols --xensyms --sysv --sort \
> -		> $@.map
> -	rm -f $(dot-target).[0-9]* $(@D)/..$(@F).[0-9]*
> +LAST_LINKING_PASS := 3
> +
> +include scripts/Makefile.link
> +
> +# Suppress orphan section checking for the time being.
> +orphan-handling-y :=

This works, but I think it's worth reconsidering the shape of it.

It works only by virtue of deferred expansion: $(orphan-handling-y) is
referenced solely inside the recipe of the final-pass rule in 
Makefile.link, so the value that matters is the one in effect when that
recipe is expanded, not when the rule was defined. Nothing states that
requirement, and nothing enforces it.

What makes me uneasy is that the ordering is not merely undocumented,
it's inverted with respect to the obvious reading. Makefile.link has

   orphan-handling-$(call ld-option,--orphan-handling=warn) := 
--orphan-handling=warn

i.e. an unconditional := to orphan-handling-y whenever the linker
supports the option. So an arch that sets orphan-handling-y *before*
the include has its setting silently discarded and ends up with orphan
checking enabled after all: no warning, no error, just a dozen new
linker diagnostics appearing at some later point. And "before the
include" is exactly where one would naturally put it: right next to
LAST_LINKING_PASS, which is the one knob the arch Makefile does set up
front.

I am not insisting on reworking but probably a small comment (in the 
commit mesage at least?) somewhere about that "+orphan-handling-y :=" 
should go after include will be useful.


Thanks.

~ Oleksii


^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH v2 7/7] RISC-V: place .sdata / .srodata / .riscv.attributes
  2026-08-27 15:40   ` Oleksii Kurochko
  2026-08-27 15:53     ` Andrew Cooper
@ 2026-08-27 15:56     ` Jan Beulich
  2026-08-27 16:07       ` Oleksii Kurochko
  1 sibling, 1 reply; 23+ messages in thread
From: Jan Beulich @ 2026-08-27 15:56 UTC (permalink / raw)
  To: Oleksii Kurochko
  Cc: Andrew Cooper, Julien Grall, Stefano Stabellini, Anthony PERARD,
	Michal Orzel, Roger Pau Monné, Alistair Francis,
	Connor Davis, xen-devel@lists.xenproject.org

On 27.08.2026 17:40, Oleksii Kurochko wrote:
> On 8/26/26 2:04 PM, Jan Beulich wrote:
>> Of the short-data sections, only .sbss is presently mentioned in the
>> linker script. Place them next to, but ahead of their "normal" data
>> sections.
>>
>> .riscv.attributes can go towards the tail of the image, next to (ahead of)
>> debug info.
>>
>> Signed-off-by: Jan Beulich <jbeulich@suse.com>
>> ---
>> Seeing where .sbss lives, does positioning really not matter at all? I
>> would have expected that short-data sections want to live close together,
>> and specifically close to .text / .init.text (seeing that such data is
>> accessed using AUIPC). I'm puzzled that the psABI doesn't even mention
>> them, hence leaving it open how exactly they are to be used.
> 
> It doesn't, and the reason is that the relevant proximity isn't to .text 
> but to __global_pointer$.

Anything like this still should be set forth by the psABI, so I don't
quite understand your reply.

> The small-data sections exist to let a linker 
> script cluster small objects around that anchor so that ld's relaxation 
> pass can fold an auipc+load pair into a single gp-relative access (-+2 
> KiB window).
> 
> That pass is keyed purely on the symbol being defined 
> riscv_global_pointer_value() returns 0 otherwise and the relaxation is 
> skipped. We define no __global_pointer$ and head.S never loads gp (it 
> appears only as a cpu_user_regs slot in entry.S), so every access stays 
> the medany auipc form regardless of section.
> 
> I confirmed this by linking the same object twice (look at the script 
> below, with and without the symbol: without it, zero gp-relative 
> accesses; with it, the pairs collapse.
> 
> Worth noting the relaxation is section-agnostic: in the test mentioned 
> below a 400-byte array in plain .bss got gp-relative too, purely because 
> it landed in range. So the sections are a clustering hint, not a 
> mechanism ld keys off.

Okay, fine, but what does this mean for placing the small data sections?
I.e. what does this mean for the patch here (which really it shouldn't
have been me to write in the first place)?

>> What remains to eliminate orphan section warnings is the placement of
>> .note.GNU-stack (which perhaps wants dealing with on all of Arm, PPC, and
>> RISC-V together, ideally unifying with x86) and (odd at the first glance,
>> but dealt with on x86 as well, i.e. may again want unifying) that of a
>> number of .rela.* sections.
>>
>> --- a/xen/arch/riscv/xen.lds.S
>> +++ b/xen/arch/riscv/xen.lds.S
>> @@ -44,6 +44,8 @@ SECTIONS
>>   
>>           BUGFRAMES
>>   
>> +        *(.srodata)
>> +        *(.srodata.*)
>>           *(.rodata)
>>           *(.rodata.*)
>>           VPCI_ARRAY
>> @@ -92,6 +94,7 @@ SECTIONS
>>           SCHEDULER_ARRAY
>>           HYPFS_PARAM
>>   
>> +        *(.sdata .sdata.*)
>>           *(.data .data.*)
>>           CONSTRUCTORS
>>       } :text
>> @@ -162,6 +165,8 @@ SECTIONS
>>       /* Section for the device tree blob (if any). */
>>       .dtb : { *(.dtb) } :text
>>   
>> +    .riscv.attributes : { *(.riscv.attributes) } :text
>> +
> 
> Nit: .riscv.attributes is SHT_RISCV_ATTRIBUTES, i.e. non-alloc.
> :text on it is misleading, and without an explicit address it gets 
> sh_addr from .(location counter) after .dtb. Could we use matching the 
> idiom used for every other non-alloc section in xen.lds.h:
>    .riscv.attributes 0 : { *(.riscv.attributes) }
> No functional difference either way (objcopy -O binary drops it, and I 
> verified a non-alloc output section doesn't advance dot, so nothing 
> downstream shifts), so purely consistency.

Well, I compare attributes rather with notes, which we make part of a
segment (on x86 at least). I can drop the :text if it's that what's
needed to get this in, but I'm not fully convinced. But my knowledge
on the purpose and use of attributes also is still somewhat limited.

> Is dropping orphan-handling-y := from arch/riscv/Makefile the intended 
> end of this series?

It is the intended goal, but not by the end of this series.

> As if I understand correctly with such defintion we 
> will miss warning so everything of that will be missed:
> 
> cd xen
> riscv64-linux-gnu-ld -T arch/riscv/xen.lds prelink.o 
> --orphan-handling=warn -o /tmp/t.elf 2>&1 \
>    | grep 'orphan section'
> /usr/bin/riscv64-linux-gnu-ld: warning: orphan section `.note.GNU-stack' 
> from `prelink.o' being placed in section `.note.GNU-stack'
> /usr/bin/riscv64-linux-gnu-ld: warning: orphan section `.rela.text' from 
> `prelink.o' being placed in section `.rela.dyn'
> /usr/bin/riscv64-linux-gnu-ld: warning: orphan section `.rela.init.text' 
> from `prelink.o' being placed in section `.rela.dyn'
> /usr/bin/riscv64-linux-gnu-ld: warning: orphan section 
> `.rela.data.read_mostly' from `prelink.o' being placed in section 
> `.rela.dyn'
> /usr/bin/riscv64-linux-gnu-ld: warning: orphan section `.rela.init.data' 
> from `prelink.o' being placed in section `.rela.dyn'
> /usr/bin/riscv64-linux-gnu-ld: warning: orphan section 
> `.rela.text.header' from `prelink.o' being placed in section `.rela.dyn'

Yes, if the override was dropped, these warnings would appear on every
build. I thought that may not be wanted, hence the override I put in
(really everywhere except for x86, where things were already tidied).

Jan


^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH v2 3/7] RISC-V: split xen-syms linking rule
  2026-08-27 15:56   ` Oleksii Kurochko
@ 2026-08-27 16:01     ` Jan Beulich
  2026-08-27 16:12       ` Oleksii Kurochko
  0 siblings, 1 reply; 23+ messages in thread
From: Jan Beulich @ 2026-08-27 16:01 UTC (permalink / raw)
  To: Oleksii Kurochko
  Cc: Andrew Cooper, Julien Grall, Stefano Stabellini, Anthony PERARD,
	Michal Orzel, Roger Pau Monné, Alistair Francis,
	Connor Davis, xen-devel@lists.xenproject.org

On 27.08.2026 17:56, Oleksii Kurochko wrote:
> On 8/26/26 2:01 PM, Jan Beulich wrote:
>> Doing so, besides (hopefully) adding clarity (not the least by way of
>> [re-]using pattern rules where possible), also avoids explicit recursive
>> $(MAKE) invocations.
>>
>> By re-using the generic rules introduced when the respective x86 rule was
>> split,
>> - the .map file now isn't created after the final binary anymore,
>> - --strip-debug is passed to $(LD) during early linking passes (for
>>    consistency the option is also explicitly added to the optional linking
>>    pass rule),
>> - CONFIG_{SUPPRESS_DUPLICATE_SYMBOL_WARNINGS,ENFORCE_UNIQUE_SYMBOLS} are
>>    now properly respected.
>> Orphan section checking, otoh, is getting suppressed for now, until the
>> about a dozen warnings which would result have been taken care of.
>>
>> While the 4th linking step continues to be avoided when possible, a
>> redundant invocation of $(NM) and tools/symbols (plus the assembling of
>> the resulting .S file) is hopefully deemed acceptable.
>>
>> Signed-off-by: Jan Beulich <jbeulich@suse.com>
>>
>> --- a/xen/arch/riscv/Makefile
>> +++ b/xen/arch/riscv/Makefile
>> @@ -31,40 +31,12 @@ obj-y += vtimer.o
>>   $(TARGET): $(TARGET)-syms
>>   	$(OBJCOPY) -O binary -S $< $@
>>   
>> -$(TARGET)-syms: $(objtree)/prelink.o $(obj)/xen.lds
>> -	$(objtree)/tools/symbols $(all_symbols) --empty > $(dot-target).0.S
>> -	$(MAKE) $(build)=$(@D) $(dot-target).0.o
>> -	$(LD) $(XEN_LDFLAGS) -T $(obj)/xen.lds $< $(build_id_linker) \
>> -	      $(dot-target).0.o -o $(dot-target).0
>> -	$(NM) -pa --format=sysv $(dot-target).0 \
>> -		| $(objtree)/tools/symbols $(all_symbols) --sysv --sort \
>> -		> $(dot-target).1.S
>> -	$(MAKE) $(build)=$(@D) $(dot-target).1.o
>> -	$(LD) $(XEN_LDFLAGS) -T $(obj)/xen.lds $< $(build_id_linker) \
>> -	    $(dot-target).1.o -o $(dot-target).1
>> -	$(NM) -pa --format=sysv $(dot-target).1 \
>> -		| $(objtree)/tools/symbols $(all_symbols) --sysv --sort \
>> -		> $(dot-target).2.S
>> -	$(MAKE) $(build)=$(@D) $(dot-target).2.o
>> -	if ! { $(call compare-symbol-tables, $(dot-target).1.o, $(dot-target).2.o) >/dev/null; }; \
>> -	then \
>> -		set -e; \
>> -		$(LD) $(XEN_LDFLAGS) -T $(obj)/xen.lds $< $(build_id_linker) \
>> -		    $(dot-target).2.o -o $(dot-target).2; \
>> -		$(NM) -pa --format=sysv $(dot-target).2 \
>> -			| $(objtree)/tools/symbols $(all_symbols) --sysv --sort \
>> -			> $(dot-target).3.S; \
>> -		$(MAKE) $(build)=$(@D) $(dot-target).3.o; \
>> -		$(call compare-symbol-tables, $(dot-target).2.o, $(dot-target).3.o); \
>> -	else \
>> -		ln -sf $(dot-target).2.o $(dot-target).3.o; \
>> -	fi
>> -	$(LD) $(XEN_LDFLAGS) -T $(obj)/xen.lds $< $(build_id_linker) \
>> -	    $(dot-target).3.o -o $@
>> -	$(NM) -pa --format=sysv $@ \
>> -		| $(objtree)/tools/symbols --all-symbols --xensyms --sysv --sort \
>> -		> $@.map
>> -	rm -f $(dot-target).[0-9]* $(@D)/..$(@F).[0-9]*
>> +LAST_LINKING_PASS := 3
>> +
>> +include scripts/Makefile.link
>> +
>> +# Suppress orphan section checking for the time being.
>> +orphan-handling-y :=
> 
> This works, but I think it's worth reconsidering the shape of it.
> 
> It works only by virtue of deferred expansion: $(orphan-handling-y) is
> referenced solely inside the recipe of the final-pass rule in 
> Makefile.link, so the value that matters is the one in effect when that
> recipe is expanded, not when the rule was defined. Nothing states that
> requirement, and nothing enforces it.
> 
> What makes me uneasy is that the ordering is not merely undocumented,
> it's inverted with respect to the obvious reading. Makefile.link has
> 
>    orphan-handling-$(call ld-option,--orphan-handling=warn) := 
> --orphan-handling=warn
> 
> i.e. an unconditional := to orphan-handling-y whenever the linker
> supports the option. So an arch that sets orphan-handling-y *before*
> the include has its setting silently discarded and ends up with orphan
> checking enabled after all: no warning, no error, just a dozen new
> linker diagnostics appearing at some later point. And "before the
> include" is exactly where one would naturally put it: right next to
> LAST_LINKING_PASS, which is the one knob the arch Makefile does set up
> front.
> 
> I am not insisting on reworking but probably a small comment (in the 
> commit mesage at least?) somewhere about that "+orphan-handling-y :=" 
> should go after include will be useful.

I can add a comment (albeit the ordering looks very obvious to me, and
not counterintuitive at all), but the better thing would be for all
arch-es to quickly deal with getting rid of this override again: No
need for an override, no need for a comment.

Jan


^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH v2 7/7] RISC-V: place .sdata / .srodata / .riscv.attributes
  2026-08-27 15:56     ` Jan Beulich
@ 2026-08-27 16:07       ` Oleksii Kurochko
  2026-09-01  7:52         ` Jan Beulich
  0 siblings, 1 reply; 23+ messages in thread
From: Oleksii Kurochko @ 2026-08-27 16:07 UTC (permalink / raw)
  To: Jan Beulich
  Cc: Andrew Cooper, Julien Grall, Stefano Stabellini, Anthony PERARD,
	Michal Orzel, Roger Pau Monné, Alistair Francis,
	Connor Davis, xen-devel@lists.xenproject.org



On 8/27/26 5:56 PM, Jan Beulich wrote:
> On 27.08.2026 17:40, Oleksii Kurochko wrote:
>> On 8/26/26 2:04 PM, Jan Beulich wrote:
>>> Of the short-data sections, only .sbss is presently mentioned in the
>>> linker script. Place them next to, but ahead of their "normal" data
>>> sections.
>>>
>>> .riscv.attributes can go towards the tail of the image, next to (ahead of)
>>> debug info.
>>>
>>> Signed-off-by: Jan Beulich <jbeulich@suse.com>
>>> ---
>>> Seeing where .sbss lives, does positioning really not matter at all? I
>>> would have expected that short-data sections want to live close together,
>>> and specifically close to .text / .init.text (seeing that such data is
>>> accessed using AUIPC). I'm puzzled that the psABI doesn't even mention
>>> them, hence leaving it open how exactly they are to be used.
>>
>> It doesn't, and the reason is that the relevant proximity isn't to .text
>> but to __global_pointer$.
> 
> Anything like this still should be set forth by the psABI, so I don't
> quite understand your reply.
> 
>> The small-data sections exist to let a linker
>> script cluster small objects around that anchor so that ld's relaxation
>> pass can fold an auipc+load pair into a single gp-relative access (-+2
>> KiB window).
>>
>> That pass is keyed purely on the symbol being defined
>> riscv_global_pointer_value() returns 0 otherwise and the relaxation is
>> skipped. We define no __global_pointer$ and head.S never loads gp (it
>> appears only as a cpu_user_regs slot in entry.S), so every access stays
>> the medany auipc form regardless of section.
>>
>> I confirmed this by linking the same object twice (look at the script
>> below, with and without the symbol: without it, zero gp-relative
>> accesses; with it, the pairs collapse.
>>
>> Worth noting the relaxation is section-agnostic: in the test mentioned
>> below a 400-byte array in plain .bss got gp-relative too, purely because
>> it landed in range. So the sections are a clustering hint, not a
>> mechanism ld keys off.
> 
> Okay, fine, but what does this mean for placing the small data sections?
> I.e. what does this mean for the patch here (which really it shouldn't
> have been me to write in the first place)?

I just wnated to show that a position of .sbss doesn't really matter 
based on the example and so true for other .s* and not only .s* 
sections. What means I am okay with your suggested places in the current 
patch.


> 
>>> What remains to eliminate orphan section warnings is the placement of
>>> .note.GNU-stack (which perhaps wants dealing with on all of Arm, PPC, and
>>> RISC-V together, ideally unifying with x86) and (odd at the first glance,
>>> but dealt with on x86 as well, i.e. may again want unifying) that of a
>>> number of .rela.* sections.
>>>
>>> --- a/xen/arch/riscv/xen.lds.S
>>> +++ b/xen/arch/riscv/xen.lds.S
>>> @@ -44,6 +44,8 @@ SECTIONS
>>>    
>>>            BUGFRAMES
>>>    
>>> +        *(.srodata)
>>> +        *(.srodata.*)
>>>            *(.rodata)
>>>            *(.rodata.*)
>>>            VPCI_ARRAY
>>> @@ -92,6 +94,7 @@ SECTIONS
>>>            SCHEDULER_ARRAY
>>>            HYPFS_PARAM
>>>    
>>> +        *(.sdata .sdata.*)
>>>            *(.data .data.*)
>>>            CONSTRUCTORS
>>>        } :text
>>> @@ -162,6 +165,8 @@ SECTIONS
>>>        /* Section for the device tree blob (if any). */
>>>        .dtb : { *(.dtb) } :text
>>>    
>>> +    .riscv.attributes : { *(.riscv.attributes) } :text
>>> +
>>
>> Nit: .riscv.attributes is SHT_RISCV_ATTRIBUTES, i.e. non-alloc.
>> :text on it is misleading, and without an explicit address it gets
>> sh_addr from .(location counter) after .dtb. Could we use matching the
>> idiom used for every other non-alloc section in xen.lds.h:
>>     .riscv.attributes 0 : { *(.riscv.attributes) }
>> No functional difference either way (objcopy -O binary drops it, and I
>> verified a non-alloc output section doesn't advance dot, so nothing
>> downstream shifts), so purely consistency.
> 
> Well, I compare attributes rather with notes, which we make part of a
> segment (on x86 at least). I can drop the :text if it's that what's
> needed to get this in, but I'm not fully convinced. But my knowledge
> on the purpose and use of attributes also is still somewhat limited.

As I mentioned from functional point of view I don't think that it will 
be an issue so generally you could keep :text here.

That why I wrote "Nit:".

Reviewed-by: Oleksii Kurochko <oleksii.kurochko@gmail.com>

> 
>> Is dropping orphan-handling-y := from arch/riscv/Makefile the intended
>> end of this series?
> 
> It is the intended goal, but not by the end of this series.
> 
>> As if I understand correctly with such defintion we
>> will miss warning so everything of that will be missed:
>>
>> cd xen
>> riscv64-linux-gnu-ld -T arch/riscv/xen.lds prelink.o
>> --orphan-handling=warn -o /tmp/t.elf 2>&1 \
>>     | grep 'orphan section'
>> /usr/bin/riscv64-linux-gnu-ld: warning: orphan section `.note.GNU-stack'
>> from `prelink.o' being placed in section `.note.GNU-stack'
>> /usr/bin/riscv64-linux-gnu-ld: warning: orphan section `.rela.text' from
>> `prelink.o' being placed in section `.rela.dyn'
>> /usr/bin/riscv64-linux-gnu-ld: warning: orphan section `.rela.init.text'
>> from `prelink.o' being placed in section `.rela.dyn'
>> /usr/bin/riscv64-linux-gnu-ld: warning: orphan section
>> `.rela.data.read_mostly' from `prelink.o' being placed in section
>> `.rela.dyn'
>> /usr/bin/riscv64-linux-gnu-ld: warning: orphan section `.rela.init.data'
>> from `prelink.o' being placed in section `.rela.dyn'
>> /usr/bin/riscv64-linux-gnu-ld: warning: orphan section
>> `.rela.text.header' from `prelink.o' being placed in section `.rela.dyn'
> 
> Yes, if the override was dropped, these warnings would appear on every
> build. I thought that may not be wanted, hence the override I put in
> (really everywhere except for x86, where things were already tidied).

Thanks. Got you. It makes sense.

~ Oleksii


^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH v2 3/7] RISC-V: split xen-syms linking rule
  2026-08-27 16:01     ` Jan Beulich
@ 2026-08-27 16:12       ` Oleksii Kurochko
  0 siblings, 0 replies; 23+ messages in thread
From: Oleksii Kurochko @ 2026-08-27 16:12 UTC (permalink / raw)
  To: Jan Beulich
  Cc: Andrew Cooper, Julien Grall, Stefano Stabellini, Anthony PERARD,
	Michal Orzel, Roger Pau Monné, Alistair Francis,
	Connor Davis, xen-devel@lists.xenproject.org



On 8/27/26 6:01 PM, Jan Beulich wrote:
> On 27.08.2026 17:56, Oleksii Kurochko wrote:
>> On 8/26/26 2:01 PM, Jan Beulich wrote:
>>> Doing so, besides (hopefully) adding clarity (not the least by way of
>>> [re-]using pattern rules where possible), also avoids explicit recursive
>>> $(MAKE) invocations.
>>>
>>> By re-using the generic rules introduced when the respective x86 rule was
>>> split,
>>> - the .map file now isn't created after the final binary anymore,
>>> - --strip-debug is passed to $(LD) during early linking passes (for
>>>     consistency the option is also explicitly added to the optional linking
>>>     pass rule),
>>> - CONFIG_{SUPPRESS_DUPLICATE_SYMBOL_WARNINGS,ENFORCE_UNIQUE_SYMBOLS} are
>>>     now properly respected.
>>> Orphan section checking, otoh, is getting suppressed for now, until the
>>> about a dozen warnings which would result have been taken care of.
>>>
>>> While the 4th linking step continues to be avoided when possible, a
>>> redundant invocation of $(NM) and tools/symbols (plus the assembling of
>>> the resulting .S file) is hopefully deemed acceptable.
>>>
>>> Signed-off-by: Jan Beulich <jbeulich@suse.com>
>>>
>>> --- a/xen/arch/riscv/Makefile
>>> +++ b/xen/arch/riscv/Makefile
>>> @@ -31,40 +31,12 @@ obj-y += vtimer.o
>>>    $(TARGET): $(TARGET)-syms
>>>    	$(OBJCOPY) -O binary -S $< $@
>>>    
>>> -$(TARGET)-syms: $(objtree)/prelink.o $(obj)/xen.lds
>>> -	$(objtree)/tools/symbols $(all_symbols) --empty > $(dot-target).0.S
>>> -	$(MAKE) $(build)=$(@D) $(dot-target).0.o
>>> -	$(LD) $(XEN_LDFLAGS) -T $(obj)/xen.lds $< $(build_id_linker) \
>>> -	      $(dot-target).0.o -o $(dot-target).0
>>> -	$(NM) -pa --format=sysv $(dot-target).0 \
>>> -		| $(objtree)/tools/symbols $(all_symbols) --sysv --sort \
>>> -		> $(dot-target).1.S
>>> -	$(MAKE) $(build)=$(@D) $(dot-target).1.o
>>> -	$(LD) $(XEN_LDFLAGS) -T $(obj)/xen.lds $< $(build_id_linker) \
>>> -	    $(dot-target).1.o -o $(dot-target).1
>>> -	$(NM) -pa --format=sysv $(dot-target).1 \
>>> -		| $(objtree)/tools/symbols $(all_symbols) --sysv --sort \
>>> -		> $(dot-target).2.S
>>> -	$(MAKE) $(build)=$(@D) $(dot-target).2.o
>>> -	if ! { $(call compare-symbol-tables, $(dot-target).1.o, $(dot-target).2.o) >/dev/null; }; \
>>> -	then \
>>> -		set -e; \
>>> -		$(LD) $(XEN_LDFLAGS) -T $(obj)/xen.lds $< $(build_id_linker) \
>>> -		    $(dot-target).2.o -o $(dot-target).2; \
>>> -		$(NM) -pa --format=sysv $(dot-target).2 \
>>> -			| $(objtree)/tools/symbols $(all_symbols) --sysv --sort \
>>> -			> $(dot-target).3.S; \
>>> -		$(MAKE) $(build)=$(@D) $(dot-target).3.o; \
>>> -		$(call compare-symbol-tables, $(dot-target).2.o, $(dot-target).3.o); \
>>> -	else \
>>> -		ln -sf $(dot-target).2.o $(dot-target).3.o; \
>>> -	fi
>>> -	$(LD) $(XEN_LDFLAGS) -T $(obj)/xen.lds $< $(build_id_linker) \
>>> -	    $(dot-target).3.o -o $@
>>> -	$(NM) -pa --format=sysv $@ \
>>> -		| $(objtree)/tools/symbols --all-symbols --xensyms --sysv --sort \
>>> -		> $@.map
>>> -	rm -f $(dot-target).[0-9]* $(@D)/..$(@F).[0-9]*
>>> +LAST_LINKING_PASS := 3
>>> +
>>> +include scripts/Makefile.link
>>> +
>>> +# Suppress orphan section checking for the time being.
>>> +orphan-handling-y :=
>>
>> This works, but I think it's worth reconsidering the shape of it.
>>
>> It works only by virtue of deferred expansion: $(orphan-handling-y) is
>> referenced solely inside the recipe of the final-pass rule in
>> Makefile.link, so the value that matters is the one in effect when that
>> recipe is expanded, not when the rule was defined. Nothing states that
>> requirement, and nothing enforces it.
>>
>> What makes me uneasy is that the ordering is not merely undocumented,
>> it's inverted with respect to the obvious reading. Makefile.link has
>>
>>     orphan-handling-$(call ld-option,--orphan-handling=warn) :=
>> --orphan-handling=warn
>>
>> i.e. an unconditional := to orphan-handling-y whenever the linker
>> supports the option. So an arch that sets orphan-handling-y *before*
>> the include has its setting silently discarded and ends up with orphan
>> checking enabled after all: no warning, no error, just a dozen new
>> linker diagnostics appearing at some later point. And "before the
>> include" is exactly where one would naturally put it: right next to
>> LAST_LINKING_PASS, which is the one knob the arch Makefile does set up
>> front.
>>
>> I am not insisting on reworking but probably a small comment (in the
>> commit mesage at least?) somewhere about that "+orphan-handling-y :="
>> should go after include will be useful.
> 
> I can add a comment (albeit the ordering looks very obvious to me, and
> not counterintuitive at all), but the better thing would be for all
> arch-es to quickly deal with getting rid of this override again: No
> need for an override, no need for a comment.

Agree, then no need for the comment:

Reviewed-by: Oleksii Kurochko <oleksii.kurochko@gmail.com>

~ Oleksii



> 
> Jan



^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH v2 7/7] RISC-V: place .sdata / .srodata / .riscv.attributes
  2026-08-27 16:07       ` Oleksii Kurochko
@ 2026-09-01  7:52         ` Jan Beulich
  0 siblings, 0 replies; 23+ messages in thread
From: Jan Beulich @ 2026-09-01  7:52 UTC (permalink / raw)
  To: Oleksii Kurochko
  Cc: Andrew Cooper, Julien Grall, Stefano Stabellini, Anthony PERARD,
	Michal Orzel, Roger Pau Monné, Alistair Francis,
	Connor Davis, xen-devel@lists.xenproject.org

On 27.08.2026 18:07, Oleksii Kurochko wrote:
> On 8/27/26 5:56 PM, Jan Beulich wrote:
>> On 27.08.2026 17:40, Oleksii Kurochko wrote:
>>> On 8/26/26 2:04 PM, Jan Beulich wrote:
>>>> --- a/xen/arch/riscv/xen.lds.S
>>>> +++ b/xen/arch/riscv/xen.lds.S
>>>> @@ -44,6 +44,8 @@ SECTIONS
>>>>    
>>>>            BUGFRAMES
>>>>    
>>>> +        *(.srodata)
>>>> +        *(.srodata.*)
>>>>            *(.rodata)
>>>>            *(.rodata.*)
>>>>            VPCI_ARRAY
>>>> @@ -92,6 +94,7 @@ SECTIONS
>>>>            SCHEDULER_ARRAY
>>>>            HYPFS_PARAM
>>>>    
>>>> +        *(.sdata .sdata.*)
>>>>            *(.data .data.*)
>>>>            CONSTRUCTORS
>>>>        } :text
>>>> @@ -162,6 +165,8 @@ SECTIONS
>>>>        /* Section for the device tree blob (if any). */
>>>>        .dtb : { *(.dtb) } :text
>>>>    
>>>> +    .riscv.attributes : { *(.riscv.attributes) } :text
>>>> +
>>>
>>> Nit: .riscv.attributes is SHT_RISCV_ATTRIBUTES, i.e. non-alloc.
>>> :text on it is misleading, and without an explicit address it gets
>>> sh_addr from .(location counter) after .dtb. Could we use matching the
>>> idiom used for every other non-alloc section in xen.lds.h:
>>>     .riscv.attributes 0 : { *(.riscv.attributes) }
>>> No functional difference either way (objcopy -O binary drops it, and I
>>> verified a non-alloc output section doesn't advance dot, so nothing
>>> downstream shifts), so purely consistency.
>>
>> Well, I compare attributes rather with notes, which we make part of a
>> segment (on x86 at least). I can drop the :text if it's that what's
>> needed to get this in, but I'm not fully convinced. But my knowledge
>> on the purpose and use of attributes also is still somewhat limited.
> 
> As I mentioned from functional point of view I don't think that it will 
> be an issue so generally you could keep :text here.
> 
> That why I wrote "Nit:".
> 
> Reviewed-by: Oleksii Kurochko <oleksii.kurochko@gmail.com>

Thanks. I decided to drop :text, after all. The linker actively ignores
it, producing a PT_RISCV_ATTRIBUTES segment which the linker script
doesn't even ask for. That likely is a linker quirk, yet at the same
time the linker script likely means to actually spell out an attributes
segment (to which this section then should be assigned).

Jan


^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH v2 1/7] x86: split xen-syms/xen.efi linking rules
  2026-08-26 12:00 ` [PATCH v2 1/7] x86: split xen-syms/xen.efi linking rules Jan Beulich
@ 2026-09-02 14:52   ` Anthony PERARD
  2026-09-03  7:26     ` Jan Beulich
  0 siblings, 1 reply; 23+ messages in thread
From: Anthony PERARD @ 2026-09-02 14:52 UTC (permalink / raw)
  To: Jan Beulich
  Cc: xen-devel@lists.xenproject.org, Andrew Cooper, Julien Grall,
	Stefano Stabellini, Michal Orzel, Roger Pau Monné,
	Teddy Astie

[-- Attachment #1: Type: text/plain, Size: 6291 bytes --]

On Wed, Aug 26, 2026 at 02:00:22PM +0200, Jan Beulich wrote:
> Doing so, besides (hopefully) adding clarity (not the least by way of
> using pattern rules where possible), also avoids explicit recursive
> $(MAKE) invocations. For xen-syms move re-usable helper rules to a new
> scripts/Makefile.link.
> 
> While doing so, re-order .map file creation (which can in principle fail)
> and check-endbr.sh invocation ahead of putting in place the final image
> (which is now the result of a simple rename).
> 
> Also drop --source-name= from the tools/symbols invocation which has
> --empty passed, for being meaningless there.
> 
> Note that the original "rm" at the end of the rule needs limiting:
> Removing intermediate files (which $(MAKE) doesn't itself remove) would
> cause re-linking even when installing as root (when common/version.o is
> left unaltered, and hence an incremental build should do nothing as long
> as nothing else changed in the source tree).

But as far as I can tell, both `rm` command are still the same,
unaltered. And both command do removes file mark as intermediate via
.INTERMEDIATE, before make would do so. Without the `rm` commands, make
would leave alone ".xen*.*.o.sym" and "..xen*.*.o.d".

> Signed-off-by: Jan Beulich <jbeulich@suse.com>
> ---
> I'd like to keep the "beautification" part, i.e. transforming to more use
> of Kbuild.include machinery, separate.

Sounds good to me. One step at a time.

> The check-endbr.sh invocation doesn't fit neatly into this model. I was
> considering to move it into $(TARGET)'s rule, but that's not very nice
> either (both because it'd be odd [strictly speaking: wrong] for xen.efi,
> and because it would reduce parallelism).
> ---
> v2: Mark intermediate files as such. Don't use $(if_changed ...).
> 
> --- a/xen/arch/x86/Makefile
> +++ b/xen/arch/x86/Makefile
> @@ -102,12 +102,6 @@ notes_phdrs = --notes
> +LAST_LINKING_PASS := 2
> +
> +final-image-check-$(CONFIG_XEN_IBT) = $(SHELL) $(srctree)/tools/check-endbr.sh $<

How about removing $< from this macro, and letting the users of
$(final-image-check-y) decide which argument to use?

> +
> +include scripts/Makefile.link
>  
>  $(obj)/note.o: $(TARGET)-syms
>  	$(OBJCOPY) -O binary --only-section=.note.gnu.build-id $< $@.bin
> @@ -191,51 +165,69 @@ note_file_option ?= $(note_file)
>  
>  extra-$(XEN_BUILD_PE) += efi.lds
>  ifeq ($(XEN_BUILD_PE),y)
> -$(TARGET).efi: $(obj)/efi/relocs-dummy.o $(obj)/efi/relocs-empty.o $(obj)/efi/mkreloc
> -$(TARGET).efi: $(objtree)/prelink.o $(note_file) $(obj)/efi.lds
> +
> +.INTERMEDIATE: $(addprefix .$(TARGET).efi., \
> +                           $(foreach n, 0 1 2, \
> +                                     $(n) alt.$(n) $(n)r.o $(n)s.o $(n)r.S $(n)s.S))
> +
> +.$(TARGET).efi.%.o: .$(TARGET).efi.%.S FORCE

Left over "FORCE" from v1. Without if_changed we should let make decide
to execute the recipe or not.

> +	$(call cmd,cc_o_S)
> +
> +.$(TARGET).efi.1r.S: .$(TARGET).efi.0 $(if $(relocs-dummy),.$(TARGET).efi.alt.0)
> +.$(TARGET).efi.2r.S: .$(TARGET).efi.1 $(if $(relocs-dummy),.$(TARGET).efi.alt.1)
> +
> +.$(TARGET).efi.0r.o: $(obj)/efi/relocs-dummy.o $(obj)/efi/mkreloc
> +	ln -sf $< $@

Why mkreloc is a prerequisite of this rule? It's not use here.

It could be move to the next rule, where it is actually used, and we
could use order-only prerequisite, so $^ won't be altered. I've check,
order-only prereq where introduced in make 3.80 according to the
changelog of 3.81. And they are not part of the $^ variable.

But the target won't get rebuilt if mkreloc is changed. So order-only
might not be the right type of prerequisite.

> +
> +.$(TARGET).efi.%r.S:
> +	$(MKRELOC) $^ > $@
> +
> +.$(TARGET).efi.0s.S:
> +	$(objtree)/tools/symbols $(all_symbols) --empty > $@
> +
> +.$(TARGET).efi.1s.S: .$(TARGET).efi.0
> +.$(TARGET).efi.2s.S: .$(TARGET).efi.1
> +
> +.$(TARGET).efi.%s.S:
> +	$(NM) -pa --format=sysv $< \
> +	  | $(objtree)/tools/symbols $(all_symbols) --sysv --sort \
> + 	    --source-name=$(TARGET).efi.S \
> +	  > $@
> +
> +# See above for why $(note_file) needs removing here.
> +efi-objs = $(filter-out $(note_file),$(filter %.o,$^))
> +
> +.$(TARGET).efi.%: $(objtree)/prelink.o .$(TARGET).efi.%r.o \
> +                  .$(TARGET).efi.%s.o $(note_file) $(obj)/efi.lds
> +	$(LD) $(call EFI_LDFLAGS,$(VIRT_BASE)) -T $(obj)/efi.lds $(efi-objs) \
> +	      --strip-debug $(note_file_option) -o $@

This command have changed compared to what we have currently, for the
step ".xen.efi.0". In the case where $(relocs-dummy) is empty, this
command doesn't have relocs-dummy.o on the command line. With this patch,
the object is added, via .xen.efi.1r.o. Is this fine?

> +
> +.$(TARGET).efi.alt.%: $(objtree)/prelink.o .$(TARGET).efi.%r.o \
> +                      .$(TARGET).efi.%s.o $(note_file) $(obj)/efi.lds
> +	$(LD) $(call EFI_LDFLAGS,$(ALT_BASE)) -T $(obj)/efi.lds $(efi-objs) \
> +	      --strip-debug $(note_file_option) -o $@
> +
> --- /dev/null
> +++ b/xen/scripts/Makefile.link
> @@ -0,0 +1,51 @@
> +# SPDX-License-Identifier: GPL-2.0
> +# ==========================================================================
> +# Helper rules for linking xen-syms
> +# ==========================================================================
> +
> +syms-warn-dup-y := --warn-dup
> +syms-warn-dup-$(CONFIG_SUPPRESS_DUPLICATE_SYMBOL_WARNINGS) :=
> +syms-warn-dup-$(CONFIG_ENFORCE_UNIQUE_SYMBOLS) := --error-dup
> +
> +orphan-handling-$(call ld-option,--orphan-handling=warn) := --orphan-handling=warn
> +
> +final-image-check-y ?= true
> +
> +.INTERMEDIATE: $(addprefix .$(TARGET)-syms.,$(foreach n,0 1 2 3,$(n) $(n).o $(n).S))
> +
> +.$(TARGET)-syms.%.o: .$(TARGET)-syms.%.S
> +	$(call cmd,cc_o_S)

That recipe change slight we what's currently in tree, there's now
"-DXEN_BUILD_EFI -DBUILD_ID_EFI", but that's probably fine, CFLAGS-y
from xen/arch/x86/Makefile are now taken into account. (That's
likely the case also for .xen.efi.%.o but I haven't checked.)


Overall, the changes looks good to me.

Thanks,


--
Anthony Perard | Vates XCP-ng Developer

XCP-ng & Xen Orchestra - Vates solutions

web: https://vates.tech

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH v2 2/7] Arm: split xen-syms linking rule
  2026-08-26 12:00 ` [PATCH v2 2/7] Arm: split xen-syms linking rule Jan Beulich
@ 2026-09-02 16:32   ` Anthony PERARD
  2026-09-03  7:35     ` Jan Beulich
  0 siblings, 1 reply; 23+ messages in thread
From: Anthony PERARD @ 2026-09-02 16:32 UTC (permalink / raw)
  To: Jan Beulich
  Cc: xen-devel@lists.xenproject.org, Andrew Cooper, Julien Grall,
	Stefano Stabellini, Michal Orzel, Roger Pau Monné,
	Bertrand Marquis, Volodymyr Babchuk

[-- Attachment #1: Type: text/plain, Size: 1628 bytes --]

On Wed, Aug 26, 2026 at 02:00:55PM +0200, Jan Beulich wrote:
> Doing so, besides (hopefully) adding clarity (not the least by way of
> [re-]using pattern rules where possible), also avoids explicit recursive
> $(MAKE) invocations.
> 
> By re-using the generic rules introduced when the respective x86 rule was
> split,
> - the .map file now isn't created after the final binary anymore,
> - --strip-debug is passed to $(LD) during early linking passes (for
>   consistency the option is also explicitly added to the optional linking
>   pass rule),
> - CONFIG_{SUPPRESS_DUPLICATE_SYMBOL_WARNINGS,ENFORCE_UNIQUE_SYMBOLS} are
>   now properly respected.
> Orphan section checking, otoh, is getting suppressed for now, until the
> about a dozen warnings which would result have been taken care of.
> 
> While the 4th linking step continues to be avoided when possible, a
> redundant invocation of $(NM) and tools/symbols (plus the assembling of
> the resulting .S file) is hopefully deemed acceptable.

So with this patch, if .xen-syms.1.o and .xen-syms.2.o are the same
(compare-symbols-tables), we through away .xen-syms.2.o, and build
.xen-syms.3.o from .xen-syms.1 (nm|symbols + as). I guess the resulting
.xen-syms.3.o would be the same as .xen-syms.2.o, so it's probably fine.


I think this patch is fine, I didn't find other difference in command
executed beside the one described in the patch description:

Reviewed-by: Anthony PERARD <anthony.perard@vates.tech>

Thanks,


--
Anthony Perard | Vates XCP-ng Developer

XCP-ng & Xen Orchestra - Vates solutions

web: https://vates.tech

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH v2 1/7] x86: split xen-syms/xen.efi linking rules
  2026-09-02 14:52   ` Anthony PERARD
@ 2026-09-03  7:26     ` Jan Beulich
  0 siblings, 0 replies; 23+ messages in thread
From: Jan Beulich @ 2026-09-03  7:26 UTC (permalink / raw)
  To: Anthony PERARD
  Cc: xen-devel@lists.xenproject.org, Andrew Cooper, Julien Grall,
	Stefano Stabellini, Michal Orzel, Roger Pau Monné,
	Teddy Astie

On 02.09.2026 16:52, Anthony PERARD wrote:
> On Wed, Aug 26, 2026 at 02:00:22PM +0200, Jan Beulich wrote:
>> Doing so, besides (hopefully) adding clarity (not the least by way of
>> using pattern rules where possible), also avoids explicit recursive
>> $(MAKE) invocations. For xen-syms move re-usable helper rules to a new
>> scripts/Makefile.link.
>>
>> While doing so, re-order .map file creation (which can in principle fail)
>> and check-endbr.sh invocation ahead of putting in place the final image
>> (which is now the result of a simple rename).
>>
>> Also drop --source-name= from the tools/symbols invocation which has
>> --empty passed, for being meaningless there.
>>
>> Note that the original "rm" at the end of the rule needs limiting:
>> Removing intermediate files (which $(MAKE) doesn't itself remove) would
>> cause re-linking even when installing as root (when common/version.o is
>> left unaltered, and hence an incremental build should do nothing as long
>> as nothing else changed in the source tree).
> 
> But as far as I can tell, both `rm` command are still the same,
> unaltered. And both command do removes file mark as intermediate via
> .INTERMEDIATE, before make would do so. Without the `rm` commands, make
> would leave alone ".xen*.*.o.sym" and "..xen*.*.o.d".

Oh, I'm sorry - this paragraph is stale from v1. I've now dropped it.

>> --- a/xen/arch/x86/Makefile
>> +++ b/xen/arch/x86/Makefile
>> @@ -102,12 +102,6 @@ notes_phdrs = --notes
>> +LAST_LINKING_PASS := 2
>> +
>> +final-image-check-$(CONFIG_XEN_IBT) = $(SHELL) $(srctree)/tools/check-endbr.sh $<
> 
> How about removing $< from this macro, and letting the users of
> $(final-image-check-y) decide which argument to use?

I did consider doing so, but decided against: The placement of the argument
within the command may (in principle) matter. Now that you also mention this,
I think I'll switch to

final-image-check-$(CONFIG_XEN_IBT) = $(SHELL) $(srctree)/tools/check-endbr.sh $(1)

using

	$(call final-image-check-y, $<)

at the use sites.

>> @@ -191,51 +165,69 @@ note_file_option ?= $(note_file)
>>  
>>  extra-$(XEN_BUILD_PE) += efi.lds
>>  ifeq ($(XEN_BUILD_PE),y)
>> -$(TARGET).efi: $(obj)/efi/relocs-dummy.o $(obj)/efi/relocs-empty.o $(obj)/efi/mkreloc
>> -$(TARGET).efi: $(objtree)/prelink.o $(note_file) $(obj)/efi.lds
>> +
>> +.INTERMEDIATE: $(addprefix .$(TARGET).efi., \
>> +                           $(foreach n, 0 1 2, \
>> +                                     $(n) alt.$(n) $(n)r.o $(n)s.o $(n)r.S $(n)s.S))
>> +
>> +.$(TARGET).efi.%.o: .$(TARGET).efi.%.S FORCE
> 
> Left over "FORCE" from v1. Without if_changed we should let make decide
> to execute the recipe or not.

Oh, indeed. The adjustments to the xen.efi machinery were done merely
to mirror the xen-syms ones; they weren't strictly necessary to do
(and hence this went unnoticed).

>> +	$(call cmd,cc_o_S)
>> +
>> +.$(TARGET).efi.1r.S: .$(TARGET).efi.0 $(if $(relocs-dummy),.$(TARGET).efi.alt.0)
>> +.$(TARGET).efi.2r.S: .$(TARGET).efi.1 $(if $(relocs-dummy),.$(TARGET).efi.alt.1)
>> +
>> +.$(TARGET).efi.0r.o: $(obj)/efi/relocs-dummy.o $(obj)/efi/mkreloc
>> +	ln -sf $< $@
> 
> Why mkreloc is a prerequisite of this rule? It's not use here.
> 
> It could be move to the next rule, where it is actually used, and we
> could use order-only prerequisite, so $^ won't be altered. I've check,
> order-only prereq where introduced in make 3.80 according to the
> changelog of 3.81. And they are not part of the $^ variable.
> 
> But the target won't get rebuilt if mkreloc is changed. So order-only
> might not be the right type of prerequisite.

Indeed, it wants to be a real prereq. And rather than ...

>> +.$(TARGET).efi.%r.S:
>> +	$(MKRELOC) $^ > $@

... filtering it out of $^ I think it's easier the way it is. I can add a
comment, unless you think I need to move it here and do the filtering.

But wait - it really needs to move here, as the tool having been rebuilt
needs to cause rebuilding of these .S files (while .$(TARGET).efi.0r.o
wouldn't change at all).

>> +.$(TARGET).efi.0s.S:
>> +	$(objtree)/tools/symbols $(all_symbols) --empty > $@
>> +
>> +.$(TARGET).efi.1s.S: .$(TARGET).efi.0
>> +.$(TARGET).efi.2s.S: .$(TARGET).efi.1
>> +
>> +.$(TARGET).efi.%s.S:
>> +	$(NM) -pa --format=sysv $< \
>> +	  | $(objtree)/tools/symbols $(all_symbols) --sysv --sort \
>> + 	    --source-name=$(TARGET).efi.S \
>> +	  > $@
>> +
>> +# See above for why $(note_file) needs removing here.
>> +efi-objs = $(filter-out $(note_file),$(filter %.o,$^))
>> +
>> +.$(TARGET).efi.%: $(objtree)/prelink.o .$(TARGET).efi.%r.o \
>> +                  .$(TARGET).efi.%s.o $(note_file) $(obj)/efi.lds
>> +	$(LD) $(call EFI_LDFLAGS,$(VIRT_BASE)) -T $(obj)/efi.lds $(efi-objs) \
>> +	      --strip-debug $(note_file_option) -o $@
> 
> This command have changed compared to what we have currently, for the
> step ".xen.efi.0". In the case where $(relocs-dummy) is empty, this
> command doesn't have relocs-dummy.o on the command line. With this patch,
> the object is added, via .xen.efi.1r.o. Is this fine?

For .xen.efi.0 it's .xen.efi.0r.o, and the rule for the latter is making
a symlink to relocs-dummy.o.

>> --- /dev/null
>> +++ b/xen/scripts/Makefile.link
>> @@ -0,0 +1,51 @@
>> +# SPDX-License-Identifier: GPL-2.0
>> +# ==========================================================================
>> +# Helper rules for linking xen-syms
>> +# ==========================================================================
>> +
>> +syms-warn-dup-y := --warn-dup
>> +syms-warn-dup-$(CONFIG_SUPPRESS_DUPLICATE_SYMBOL_WARNINGS) :=
>> +syms-warn-dup-$(CONFIG_ENFORCE_UNIQUE_SYMBOLS) := --error-dup
>> +
>> +orphan-handling-$(call ld-option,--orphan-handling=warn) := --orphan-handling=warn
>> +
>> +final-image-check-y ?= true
>> +
>> +.INTERMEDIATE: $(addprefix .$(TARGET)-syms.,$(foreach n,0 1 2 3,$(n) $(n).o $(n).S))
>> +
>> +.$(TARGET)-syms.%.o: .$(TARGET)-syms.%.S
>> +	$(call cmd,cc_o_S)
> 
> That recipe change slight we what's currently in tree, there's now
> "-DXEN_BUILD_EFI -DBUILD_ID_EFI", but that's probably fine, CFLAGS-y
> from xen/arch/x86/Makefile are now taken into account. (That's
> likely the case also for .xen.efi.%.o but I haven't checked.)

Yes, the same applies there, and yes, the two extra -D are entirely
benign (and strictly speaking more correct, if either would matter for
these .S files; right now xen.lds.S is their only consumer).

Jan


^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH v2 2/7] Arm: split xen-syms linking rule
  2026-09-02 16:32   ` Anthony PERARD
@ 2026-09-03  7:35     ` Jan Beulich
  0 siblings, 0 replies; 23+ messages in thread
From: Jan Beulich @ 2026-09-03  7:35 UTC (permalink / raw)
  To: Anthony PERARD
  Cc: xen-devel@lists.xenproject.org, Andrew Cooper, Julien Grall,
	Stefano Stabellini, Michal Orzel, Roger Pau Monné,
	Bertrand Marquis, Volodymyr Babchuk

On 02.09.2026 18:32, Anthony PERARD wrote:
> On Wed, Aug 26, 2026 at 02:00:55PM +0200, Jan Beulich wrote:
>> Doing so, besides (hopefully) adding clarity (not the least by way of
>> [re-]using pattern rules where possible), also avoids explicit recursive
>> $(MAKE) invocations.
>>
>> By re-using the generic rules introduced when the respective x86 rule was
>> split,
>> - the .map file now isn't created after the final binary anymore,
>> - --strip-debug is passed to $(LD) during early linking passes (for
>>   consistency the option is also explicitly added to the optional linking
>>   pass rule),
>> - CONFIG_{SUPPRESS_DUPLICATE_SYMBOL_WARNINGS,ENFORCE_UNIQUE_SYMBOLS} are
>>   now properly respected.
>> Orphan section checking, otoh, is getting suppressed for now, until the
>> about a dozen warnings which would result have been taken care of.
>>
>> While the 4th linking step continues to be avoided when possible, a
>> redundant invocation of $(NM) and tools/symbols (plus the assembling of
>> the resulting .S file) is hopefully deemed acceptable.
> 
> So with this patch, if .xen-syms.1.o and .xen-syms.2.o are the same
> (compare-symbols-tables), we through away .xen-syms.2.o, and build
> .xen-syms.3.o from .xen-syms.1 (nm|symbols + as). I guess the resulting
> .xen-syms.3.o would be the same as .xen-syms.2.o,

Anything else would be a significant problem: nm, tools/symbols, and gas
would better produce the same output from the same input.

> so it's probably fine.
> 
> 
> I think this patch is fine, I didn't find other difference in command
> executed beside the one described in the patch description:
> 
> Reviewed-by: Anthony PERARD <anthony.perard@vates.tech>

Thanks.

Jan


^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH v2 4/7] PPC: split xen-syms linking rule
  2026-08-26 12:01 ` [PATCH v2 4/7] PPC: " Jan Beulich
@ 2026-09-03 11:50   ` Anthony PERARD
  0 siblings, 0 replies; 23+ messages in thread
From: Anthony PERARD @ 2026-09-03 11:50 UTC (permalink / raw)
  To: Jan Beulich
  Cc: xen-devel@lists.xenproject.org, Andrew Cooper, Julien Grall,
	Stefano Stabellini, Michal Orzel, Roger Pau Monné,
	Timothy Pearson

[-- Attachment #1: Type: text/plain, Size: 1052 bytes --]

On Wed, Aug 26, 2026 at 02:01:57PM +0200, Jan Beulich wrote:
> Doing so, besides (hopefully) adding clarity (not the least by way of
> [re-]using pattern rules where possible), also avoids explicit recursive
> $(MAKE) invocations.
> 
> By re-using the generic rules introduced when the respective x86 rule was
> split,
> - the .map file now isn't created after the final binary anymore,
> - --strip-debug is passed to $(LD) during early linking passes (for
>   consistency the option is also explicitly added to the optional linking
>   pass rule),
> - CONFIG_{SUPPRESS_DUPLICATE_SYMBOL_WARNINGS,ENFORCE_UNIQUE_SYMBOLS} are
>   now properly respected.
> Orphan section checking, otoh, is getting suppressed for now, until the
> about a dozen warnings which would result have been taken care of.
> 
> Signed-off-by: Jan Beulich <jbeulich@suse.com>

Reviewed-by: Anthony PERARD <anthony.perard@vates.tech>

Thanks,


--
Anthony Perard | Vates XCP-ng Developer

XCP-ng & Xen Orchestra - Vates solutions

web: https://vates.tech

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH v2 5/7] build: move $(all-symbols-*)
  2026-08-26 12:02 ` [PATCH v2 5/7] build: move $(all-symbols-*) Jan Beulich
@ 2026-09-03 11:54   ` Anthony PERARD
  0 siblings, 0 replies; 23+ messages in thread
From: Anthony PERARD @ 2026-09-03 11:54 UTC (permalink / raw)
  To: Jan Beulich
  Cc: xen-devel@lists.xenproject.org, Andrew Cooper, Julien Grall,
	Stefano Stabellini, Michal Orzel, Roger Pau Monné,
	Teddy Astie

[-- Attachment #1: Type: text/plain, Size: 487 bytes --]

On Wed, Aug 26, 2026 at 02:02:57PM +0200, Jan Beulich wrote:
> With the final linking logic now consolidated in scripts/Makefile.link,
> $(all-symbols-*) also doesn't need setting anymore in (and passing down
> from) the top level Makefile.
> 
> Signed-off-by: Jan Beulich <jbeulich@suse.com>

Reviewed-by: Anthony PERARD <anthony.perard@vates.tech>

Thanks,


--
Anthony Perard | Vates XCP-ng Developer

XCP-ng & Xen Orchestra - Vates solutions

web: https://vates.tech

^ permalink raw reply	[flat|nested] 23+ messages in thread

* Re: [PATCH v2 6/7] build: move $(compare-symbol-tables)
  2026-08-26 12:03 ` [PATCH v2 6/7] build: move $(compare-symbol-tables) Jan Beulich
@ 2026-09-03 11:55   ` Anthony PERARD
  0 siblings, 0 replies; 23+ messages in thread
From: Anthony PERARD @ 2026-09-03 11:55 UTC (permalink / raw)
  To: Jan Beulich
  Cc: xen-devel@lists.xenproject.org, Andrew Cooper, Julien Grall,
	Stefano Stabellini, Michal Orzel, Roger Pau Monné

[-- Attachment #1: Type: text/plain, Size: 463 bytes --]

On Wed, Aug 26, 2026 at 02:03:26PM +0200, Jan Beulich wrote:
> With the final linking logic now consolidated in scripts/Makefile.link,
> $(compare-symbol-tables) also doesn't need setting anymore in
> Kbuild.include.
> 
> Signed-off-by: Jan Beulich <jbeulich@suse.com>

Reviewed-by: Anthony PERARD <anthony.perard@vates.tech>

Thanks,


--
Anthony Perard | Vates XCP-ng Developer

XCP-ng & Xen Orchestra - Vates solutions

web: https://vates.tech

^ permalink raw reply	[flat|nested] 23+ messages in thread

end of thread, other threads:[~2026-09-03 11:55 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-26 11:57 [PATCH v2 0/7] build: split and unify linking of final image(s) Jan Beulich
2026-08-26 12:00 ` [PATCH v2 1/7] x86: split xen-syms/xen.efi linking rules Jan Beulich
2026-09-02 14:52   ` Anthony PERARD
2026-09-03  7:26     ` Jan Beulich
2026-08-26 12:00 ` [PATCH v2 2/7] Arm: split xen-syms linking rule Jan Beulich
2026-09-02 16:32   ` Anthony PERARD
2026-09-03  7:35     ` Jan Beulich
2026-08-26 12:01 ` [PATCH v2 3/7] RISC-V: " Jan Beulich
2026-08-27 15:56   ` Oleksii Kurochko
2026-08-27 16:01     ` Jan Beulich
2026-08-27 16:12       ` Oleksii Kurochko
2026-08-26 12:01 ` [PATCH v2 4/7] PPC: " Jan Beulich
2026-09-03 11:50   ` Anthony PERARD
2026-08-26 12:02 ` [PATCH v2 5/7] build: move $(all-symbols-*) Jan Beulich
2026-09-03 11:54   ` Anthony PERARD
2026-08-26 12:03 ` [PATCH v2 6/7] build: move $(compare-symbol-tables) Jan Beulich
2026-09-03 11:55   ` Anthony PERARD
2026-08-26 12:04 ` [PATCH v2 7/7] RISC-V: place .sdata / .srodata / .riscv.attributes Jan Beulich
2026-08-27 15:40   ` Oleksii Kurochko
2026-08-27 15:53     ` Andrew Cooper
2026-08-27 15:56     ` Jan Beulich
2026-08-27 16:07       ` Oleksii Kurochko
2026-09-01  7:52         ` Jan Beulich

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.