build: split and unify linking of final image(s)
v2 cover build: split and unify linking of final image(s)
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
PATCH v2 1/7 x86: split xen-syms/xen.efi linking rules
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).
---
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 ...).
xen/arch/x86/Makefile +63 -71
@@ -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 \ - > [email protected] - 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 $< [email protected]
@@ -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 \ - > [email protected] + $(NM) -pa --format=sysv $< \ + | $(objtree)/tools/symbols --all-symbols --xensyms --sysv --sort \ + > [email protected] ifeq ($(CONFIG_DEBUG_INFO),y) - $(if $(filter --strip-debug,$(EFI_LDFLAGS)),:$(space))$(OBJCOPY) -O elf64-x86-64 $@ [email protected] + $(if $(filter --strip-debug,$(EFI_LDFLAGS)),:$(space))$(OBJCOPY) -O elf64-x86-64 $< [email protected] 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 $@
xen/scripts/Makefile.link new file +51 -0
51 lines not on this page · raw message
Re: [PATCH v2 1/7] x86: split xen-syms/xen.efi linking rules
Quoted 9 lines · Jan Beulich
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.shinvocation ahead of putting in place the final image (which is now the result of a simple rename).
Quoted 8 lines
Also drop --source-name= from the
tools/symbolsinvocation 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 (whencommon/version.ois 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".
Quoted 4 lines
Signed-off-by Jan Beulich <[email protected]>---
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.
xen/arch/x86/Makefile notes_phdrs = --notes · line 104
Quoted 13 lines
The
check-endbr.shinvocation 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 ...).xen/arch/x86/Makefile +3
-0@@ -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?
Quoted 7 lines
xen/arch/x86/Makefile +2
-0+ +include scripts/Makefile.link $(obj)/note.o: $(TARGET)-syms $(OBJCOPY) -O binary --only-section=.note.gnu.build-id $< [email protected]@@ -191,51 +165,69 @@ note_file_option ?= $(note_file)
xen/arch/x86/Makefile note_file_option ?= $(note_file) · line 173
Quoted 10 lines
xen/arch/x86/Makefile +6
-2extra-$(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.
xen/arch/x86/Makefile note_file_option ?= $(note_file) · line 180
Quoted 7 lines
xen/arch/x86/Makefile +7
-0+ $(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.
Quoted 13 lines
xen/arch/x86/Makefile +13
-0+ +.$(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 \
xen/arch/x86/Makefile note_file_option ?= $(note_file) · line 203
Quoted 10 lines
xen/arch/x86/Makefile +10
-0+ --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?
Quoted 16 lines
xen/arch/x86/Makefile +6
-0+ +.$(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 $@ +xen/scripts/Makefile.link new file +7
-0@@ -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) :=
xen/scripts/Makefile.link line 17
Quoted 10 lines
xen/scripts/Makefile.link new file +10
-0+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
Re: [PATCH v2 1/7] x86: split xen-syms/xen.efi linking rules
Quoted 19 lines · Anthony PERARD
Quoted 9 lines · Jan Beulich
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.shinvocation ahead of putting in place the final image (which is now the result of a simple rename).Quoted 8 lines
Also drop --source-name= from the
tools/symbolsinvocation 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 (whencommon/version.ois left unaltered, and hence an incremental build should do nothing as long as nothing else changed in the source tree).
Quoted 4 lines
But as far as I can tell, both
rmcommand are still the same, unaltered. And both command do removes file mark as intermediate via .INTERMEDIATE, before make would do so. Without thermcommands, 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.
Quoted 9 lines
xen/arch/x86/Makefile notes_phdrs = --notes · line 104
Quoted 6 lines
xen/arch/x86/Makefile +3
-0@@ -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.
Quoted 15 lines
xen/arch/x86/Makefile note_file_option ?= $(note_file) · line 173
Quoted 12 lines
xen/arch/x86/Makefile +6
-2@@ -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 FORCELeft over "FORCE" from v1. Without
if_changedwe 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).
Quoted 10 lines
xen/arch/x86/Makefile note_file_option ?= $(note_file) · line 180
Quoted 7 lines
xen/arch/x86/Makefile +7
-0+ $(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.
Quoted 7 lines
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 ...
Quoted 2 lines
xen/arch/x86/Makefile note_file_option ?= $(note_file) · line 183
Quoted 2 lines
xen/arch/x86/Makefile +2
-0+.$(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).
Quoted 16 lines
Quoted 16 lines
xen/arch/x86/Makefile +16
-0+.$(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 \
Quoted 8 lines
xen/arch/x86/Makefile note_file_option ?= $(note_file) · line 203
Quoted 3 lines
xen/arch/x86/Makefile +3
-0+ .$(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.
Quoted 17 lines
Quoted 17 lines
xen/scripts/Makefile.link new file +14
-0@@ -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))
Quoted 8 lines
xen/scripts/Makefile.link line 17
Quoted 3 lines
xen/scripts/Makefile.link new file +3
-0+ +.$(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
PATCH v2 2/7 Arm: split xen-syms linking rule
In reply to Jan BeulichDoing 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.
---
As for the x86 patch, I'd like to keep the "beautification" part, i.e. transforming to more use of Kbuild.include machinery, separate.
xen/arch/arm/Makefile +6 -34
@@ -84,40 +84,12 @@ ifeq ($(CONFIG_ARM_64),y) ln -sf $(@F) [email protected] 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 \ - > [email protected] - 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:
xen/scripts/Makefile.link +13 -0
@@ -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
Re: [PATCH v2 2/7] Arm: split xen-syms linking rule
Quoted 15 lines · Jan Beulich
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.
Quoted 3 lines
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:
Thanks,
--
Anthony Perard | Vates XCP-ng Developer
XCP-ng & Xen Orchestra - Vates solutions
web: https://vates.tech
Re: [PATCH v2 2/7] Arm: split xen-syms linking rule
Quoted 16 lines · Anthony PERARD
Quoted 15 lines · Jan Beulich
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.
Quoted 8 lines
Quoted 3 lines
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.
Quoted 7 lines
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 <[email protected]>
Thanks.
Jan
PATCH v2 3/7 RISC-V: split xen-syms linking rule
In reply to Jan BeulichDoing 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.
xen/arch/riscv/Makefile +6 -34
@@ -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 \ - > [email protected] - 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)
Re: [PATCH v2 3/7] RISC-V: split xen-syms linking rule
Quoted 57 lines · Jan Beulich
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 <[email protected]>xen/arch/riscv/Makefile +0
-30@@ -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 $@
xen/arch/riscv/Makefile obj-y += vtimer.o · line 39
Quoted 10 lines
xen/arch/riscv/Makefile +6
-4- $(NM) -pa --format=sysv $@ \ - | $(objtree)/tools/symbols --all-symbols --xensyms --sysv --sort \ - > [email protected] - 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
Re: [PATCH v2 3/7] RISC-V: split xen-syms linking rule
Quoted 92 lines · Oleksii Kurochko
Quoted 57 lines · Jan Beulich
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 <[email protected]>xen/arch/riscv/Makefile +0
-30@@ -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 $@xen/arch/riscv/Makefile obj-y += vtimer.o · line 39
Quoted 10 lines
xen/arch/riscv/Makefile +6
-4- $(NM) -pa --format=sysv $@ \ - | $(objtree)/tools/symbols --all-symbols --xensyms --sysv --sort \ - > [email protected] - 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 archMakefiledoes set up front.
Quoted 3 lines
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
Oleksii Kurochko
Reviewed-byRe: [PATCH v2 3/7] RISC-V: split xen-syms linking rule
Quoted 93 lines · Jan Beulich
Quoted 92 lines · Oleksii Kurochko
Quoted 57 lines · Jan Beulich
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 <[email protected]>xen/arch/riscv/Makefile +0
-30@@ -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 $@xen/arch/riscv/Makefile obj-y += vtimer.o · line 39
Quoted 10 lines
xen/arch/riscv/Makefile +6
-4- $(NM) -pa --format=sysv $@ \ - | $(objtree)/tools/symbols --all-symbols --xensyms --sysv --sort \ - > [email protected] - 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 archMakefiledoes set up front.
Quoted 8 lines
Quoted 3 lines
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:
~ Oleksii
Quoted 2 lines
Jan
PATCH v2 4/7 PPC: split xen-syms linking rule
In reply to Jan BeulichDoing 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.
xen/arch/ppc/Makefile +6 -22
@@ -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 \ - > [email protected] - 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)
Re: [PATCH v2 4/7] PPC: split xen-syms linking rule
Quoted 15 lines · Jan Beulich
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.
Quoted 1 line
Signed-off-by Jan Beulich <[email protected]>
Thanks,
--
Anthony Perard | Vates XCP-ng Developer
XCP-ng & Xen Orchestra - Vates solutions
web: https://vates.tech
PATCH v2 5/7 build: move $(all-symbols-*)
In reply to Jan BeulichWith 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.
xen/Makefile +1 -6
@@ -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
xen/arch/x86/Makefile +2 -2
@@ -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 \ > $@
xen/scripts/Makefile.link +6 -2
@@ -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)) \ > $@
Re: [PATCH v2 5/7] build: move $(all-symbols-*)
Quoted 5 lines · Jan Beulich
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 levelMakefile.Signed-off-by Jan Beulich <[email protected]>
Thanks,
--
Anthony Perard | Vates XCP-ng Developer
XCP-ng & Xen Orchestra - Vates solutions
web: https://vates.tech
PATCH v2 6/7 build: move $(compare-symbol-tables)
In reply to Jan BeulichWith the final linking logic now consolidated in scripts/Makefile.link, $(compare-symbol-tables) also doesn't need setting anymore in Kbuild.include.
---
v2: New.
xen/scripts/Kbuild.include +0 -13
@@ -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) ); }' \
xen/scripts/Makefile.link +12 -0
@@ -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 $@
Re: [PATCH v2 6/7] build: move $(compare-symbol-tables)
Quoted 5 lines · Jan Beulich
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 <[email protected]>
Thanks,
--
Anthony Perard | Vates XCP-ng Developer
XCP-ng & Xen Orchestra - Vates solutions
web: https://vates.tech
PATCH v2 7/7 RISC-V: place .sdata / .srodata / .riscv.attributes
In reply to Jan BeulichOf 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.
---
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.
xen/arch/riscv/xen.lds.S +5 -0
@@ -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
Re: [PATCH v2 7/7] RISC-V: place .sdata / .srodata / .riscv.attributes
Quoted 7 lines · Jan Beulich
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.
Quoted 7 lines
Signed-off-by Jan Beulich <[email protected]>---
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
```Quoted 27 lines
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.
xen/arch/riscv/xen.lds.S +3
-0@@ -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
xen/arch/riscv/xen.lds.S SECTIONS · line 169
Quoted 5 lines
xen/arch/riscv/xen.lds.S +2
-0@@ -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
Re: [PATCH v2 7/7] RISC-V: place .sdata / .srodata / .riscv.attributes
Quoted 15 lines · Oleksii Kurochko
Is dropping orphan-handling-y := from
arch/riscv/Makefilethe 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 -Tarch/riscv/xen.ldsprelink.o --orphan-handling=warn -o/tmp/t.elf2>&1 \
| grep 'orphan section'/usr/bin/riscv64-linux-gnu-ld: warning: orphan section.note.GNU-stack' fromprelink.o' being placed in section `.note.GNU-stack'/usr/bin/riscv64-linux-gnu-ld: warning: orphan section.rela.text' fromprelink.o' being placed in section `.rela.dyn'/usr/bin/riscv64-linux-gnu-ld: warning: orphan section
Quoted 9 lines
.rela.init.text' fromprelink.o' being placed in section.rela.dyn' /usr/bin/riscv64-linux-gnu-ld: warning: orphan section.rela.data.read_mostly' fromprelink.o' being placed in section.rela.dyn'/usr/bin/riscv64-linux-gnu-ld: warning: orphan section.rela.init.data' fromprelink.o' being placed in section.rela.dyn' /usr/bin/riscv64-linux-gnu-ld: warning: orphan section.rela.text.header' fromprelink.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
Re: [PATCH v2 7/7] RISC-V: place .sdata / .srodata / .riscv.attributes
In reply to Oleksii KurochkoQuoted 16 lines · Oleksii Kurochko
Quoted 7 lines · Jan Beulich
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.
Quoted 7 lines
Signed-off-by Jan Beulich <[email protected]>---
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.
Quoted 2 lines
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.
Quoted 11 lines
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$ andhead.Snever loads gp (it appears only as acpu_user_regsslot inentry.S), so every access stays the medany auipc form regardless of section.
Quoted 8 lines
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)?
Quoted 36 lines
Quoted 26 lines
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.
xen/arch/riscv/xen.lds.S +3
-0@@ -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 } :textxen/arch/riscv/xen.lds.S SECTIONS · line 169
Quoted 5 lines
xen/arch/riscv/xen.lds.S +2
-0@@ -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 getssh_addrfrom .(location counter) after .dtb. Could we use matching the idiom used for every other non-alloc section inxen.lds.h:
Quoted 4 lines
.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.
Quoted 2 lines
Is dropping orphan-handling-y := from
arch/riscv/Makefilethe intended end of this series?
It is the intended goal, but not by the end of this series.
Quoted 12 lines
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 -Tarch/riscv/xen.ldsprelink.o --orphan-handling=warn -o/tmp/t.elf2>&1 \
| grep 'orphan section'/usr/bin/riscv64-linux-gnu-ld: warning: orphan section.note.GNU-stack' fromprelink.o' being placed in section.note.GNU-stack' /usr/bin/riscv64-linux-gnu-ld: warning: orphan section.rela.text' fromprelink.o' being placed in section.rela.dyn'/usr/bin/riscv64-linux-gnu-ld: warning: orphan section `.rela.init.text'
Quoted 8 lines
from
prelink.o' being placed in section.rela.dyn'/usr/bin/riscv64-linux-gnu-ld: warning: orphan section.rela.data.read_mostly' fromprelink.o' being placed in section `.rela.dyn'/usr/bin/riscv64-linux-gnu-ld: warning: orphan section.rela.init.data' fromprelink.o' being placed in section.rela.dyn' /usr/bin/riscv64-linux-gnu-ld: warning: orphan section.rela.text.header' fromprelink.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
Oleksii Kurochko
Reviewed-byRe: [PATCH v2 7/7] RISC-V: place .sdata / .srodata / .riscv.attributes
Quoted 38 lines · Jan Beulich
Quoted 16 lines · Oleksii Kurochko
Quoted 7 lines · Jan Beulich
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.
Quoted 7 lines
Signed-off-by Jan Beulich <[email protected]>---
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.Quoted 2 lines
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.
Quoted 15 lines
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$ andhead.Snever loads gp (it appears only as acpu_user_regsslot inentry.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.
Quoted 8 lines
Quoted 4 lines
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.
Quoted 42 lines
Quoted 37 lines
Quoted 27 lines
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.
xen/arch/riscv/xen.lds.S +3
-0@@ -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 } :textxen/arch/riscv/xen.lds.S SECTIONS · line 169
Quoted 5 lines
xen/arch/riscv/xen.lds.S +2
-0@@ -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 getssh_addrfrom .(location counter) after .dtb. Could we use matching the idiom used for every other non-alloc section inxen.lds.h:Quoted 4 lines
.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.
Quoted 4 lines
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:".
Quoted 27 lines
Quoted 3 lines
Is dropping orphan-handling-y := from
arch/riscv/Makefilethe intended end of this series?It is the intended goal, but not by the end of this series.
Quoted 12 lines
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 -Tarch/riscv/xen.ldsprelink.o --orphan-handling=warn -o/tmp/t.elf2>&1 \
| grep 'orphan section'/usr/bin/riscv64-linux-gnu-ld: warning: orphan section.note.GNU-stack' fromprelink.o' being placed in section.note.GNU-stack' /usr/bin/riscv64-linux-gnu-ld: warning: orphan section.rela.text' fromprelink.o' being placed in section.rela.dyn'/usr/bin/riscv64-linux-gnu-ld: warning: orphan section `.rela.init.text'Quoted 8 lines
from
prelink.o' being placed in section.rela.dyn'/usr/bin/riscv64-linux-gnu-ld: warning: orphan section.rela.data.read_mostly' fromprelink.o' being placed in section `.rela.dyn'/usr/bin/riscv64-linux-gnu-ld: warning: orphan section.rela.init.data' fromprelink.o' being placed in section.rela.dyn' /usr/bin/riscv64-linux-gnu-ld: warning: orphan section.rela.text.header' fromprelink.o' being placed in section.rela.dyn'
Quoted 3 lines
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
Re: [PATCH v2 7/7] RISC-V: place .sdata / .srodata / .riscv.attributes
Quoted 43 lines · Oleksii Kurochko
Quoted 37 lines · Jan Beulich
Quoted 31 lines · Oleksii Kurochko
Quoted 20 lines · Jan Beulich
xen/arch/riscv/xen.lds.S +3
-0@@ -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 } :textxen/arch/riscv/xen.lds.S SECTIONS · line 169
Quoted 5 lines
xen/arch/riscv/xen.lds.S +2
-0@@ -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 getssh_addrfrom .(location counter) after .dtb. Could we use matching the idiom used for every other non-alloc section inxen.lds.h:Quoted 4 lines
.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.
Quoted 4 lines
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.
Quoted 6 lines
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 <[email protected]>
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