[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v2 1/7] x86: split xen-syms/xen.efi linking rules


  • To: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Wed, 26 Aug 2026 14:00:22 +0200
  • Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=google header.d=suse.com header.i="@suse.com" header.h="Content-Transfer-Encoding:Content-Type:In-Reply-To:Autocrypt:Content-Language:References:Cc:To:From:Subject:User-Agent:MIME-Version:Date:Message-ID"
  • Autocrypt: addr=jbeulich@xxxxxxxx; keydata= xsDiBFk3nEQRBADAEaSw6zC/EJkiwGPXbWtPxl2xCdSoeepS07jW8UgcHNurfHvUzogEq5xk hu507c3BarVjyWCJOylMNR98Yd8VqD9UfmX0Hb8/BrA+Hl6/DB/eqGptrf4BSRwcZQM32aZK 7Pj2XbGWIUrZrd70x1eAP9QE3P79Y2oLrsCgbZJfEwCgvz9JjGmQqQkRiTVzlZVCJYcyGGsD /0tbFCzD2h20ahe8rC1gbb3K3qk+LpBtvjBu1RY9drYk0NymiGbJWZgab6t1jM7sk2vuf0Py O9Hf9XBmK0uE9IgMaiCpc32XV9oASz6UJebwkX+zF2jG5I1BfnO9g7KlotcA/v5ClMjgo6Gl MDY4HxoSRu3i1cqqSDtVlt+AOVBJBACrZcnHAUSuCXBPy0jOlBhxPqRWv6ND4c9PH1xjQ3NP nxJuMBS8rnNg22uyfAgmBKNLpLgAGVRMZGaGoJObGf72s6TeIqKJo/LtggAS9qAUiuKVnygo 3wjfkS9A3DRO+SpU7JqWdsveeIQyeyEJ/8PTowmSQLakF+3fote9ybzd880fSmFuIEJldWxp Y2ggPGpiZXVsaWNoQHN1c2UuY29tPsJgBBMRAgAgBQJZN5xEAhsDBgsJCAcDAgQVAggDBBYC AwECHgECF4AACgkQoDSui/t3IH4J+wCfQ5jHdEjCRHj23O/5ttg9r9OIruwAn3103WUITZee e7Sbg12UgcQ5lv7SzsFNBFk3nEQQCACCuTjCjFOUdi5Nm244F+78kLghRcin/awv+IrTcIWF hUpSs1Y91iQQ7KItirz5uwCPlwejSJDQJLIS+QtJHaXDXeV6NI0Uef1hP20+y8qydDiVkv6l IreXjTb7DvksRgJNvCkWtYnlS3mYvQ9NzS9PhyALWbXnH6sIJd2O9lKS1Mrfq+y0IXCP10eS FFGg+Av3IQeFatkJAyju0PPthyTqxSI4lZYuJVPknzgaeuJv/2NccrPvmeDg6Coe7ZIeQ8Yj t0ARxu2xytAkkLCel1Lz1WLmwLstV30g80nkgZf/wr+/BXJW/oIvRlonUkxv+IbBM3dX2OV8 AmRv1ySWPTP7AAMFB/9PQK/VtlNUJvg8GXj9ootzrteGfVZVVT4XBJkfwBcpC/XcPzldjv+3 HYudvpdNK3lLujXeA5fLOH+Z/G9WBc5pFVSMocI71I8bT8lIAzreg0WvkWg5V2WZsUMlnDL9 mpwIGFhlbM3gfDMs7MPMu8YQRFVdUvtSpaAs8OFfGQ0ia3LGZcjA6Ik2+xcqscEJzNH+qh8V m5jjp28yZgaqTaRbg3M/+MTbMpicpZuqF4rnB0AQD12/3BNWDR6bmh+EkYSMcEIpQmBM51qM EKYTQGybRCjpnKHGOxG0rfFY1085mBDZCH5Kx0cl0HVJuQKC+dV2ZY5AqjcKwAxpE75MLFkr wkkEGBECAAkFAlk3nEQCGwwACgkQoDSui/t3IH7nnwCfcJWUDUFKdCsBH/E5d+0ZnMQi+G0A nAuWpQkjM1ASeQwSHEeAWPgskBQL
  • Cc: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Anthony PERARD <anthony.perard@xxxxxxxxxx>, Michal Orzel <michal.orzel@xxxxxxx>, Roger Pau Monné <roger@xxxxxxxxxxxxxx>, Teddy Astie <teddy.astie@xxxxxxxxxx>
  • Delivery-date: Wed, 26 Aug 2026 12:00:31 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

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@xxxxxxxx>
---
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]*




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.