build: split and unify linking of final image(s)
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. Break them up, and use (largely) the same rules for all ports (x86'es xen.efi being somewhat special, though).
The final two patches are related only in so far as they address observations made while doing the conversion.
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: RISC-V: place .sdata / .srodata / .riscv.attributes
Jan
PATCH 1/6 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.
---
I'd like to keep the "beautification" part, i.e. transforming to $(if_changed ...) 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).
xen/arch/x86/Makefile +59 -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,65 @@ 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 + +.$(TARGET).efi.%.o: .$(TARGET).efi.%.S FORCE + $(call if_changed,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 +49 -0
49 lines not on this page · raw message
Re: [PATCH 1/6] x86: split xen-syms/xen.efi linking rules
Quoted 42 lines · Jan Beulich
xen/scripts/Makefile.link new file +39
-0@@ -0,0 +1,49 @@ +# 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 + +.$(TARGET)-syms.%.o: .$(TARGET)-syms.%.S FORCE + $(call if_changed,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)
xen/scripts/Makefile.link line 49
Quoted 10 lines
xen/scripts/Makefile.link new file +10
-0+ $(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 \ + > [email protected] + $(final-image-check-y) + mv $< $@ + rm -f $(dot-target).[0-9]* $(@D)/..$(@F).[0-9]*
Noticing only after sending: We will need to limit what is removed here. Removing all intermediate files means the full linking process will always be redone, even during "make install-xen" as root. Alternatively we should consider explicitly avoiding any rebuilding in that case, much like e.g. x86 Linux Makefile logic does. Thoughts?
Jan
Re: [PATCH 1/6] x86: split xen-syms/xen.efi linking rules
Quoted 49 lines · Jan Beulich
Quoted 48 lines · Jan Beulich
xen/scripts/Makefile.link new file +45
-0@@ -0,0 +1,49 @@ +# 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 + +.$(TARGET)-syms.%.o: .$(TARGET)-syms.%.S FORCE + $(call if_changed,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 \
Quoted 8 lines
xen/scripts/Makefile.link line 49
Quoted 4 lines
xen/scripts/Makefile.link new file +4
-0+ > [email protected] + $(final-image-check-y) + mv $< $@ + rm -f $(dot-target).[0-9]* $(@D)/..$(@F).[0-9]*Noticing only after sending: We will need to limit what is removed here. Removing all intermediate files means the full linking process will always be redone, even during "make install-xen" as root.
Actually it can be kept like this, but intermediate files need marking as such, and $(if_changed ...) shouldn't be used (at least for the moment).
Jan
PATCH 2/6 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 $(if_changed ...) 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
@@ -31,6 +31,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
PATCH 3/6 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)
PATCH 4/6 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)
PATCH 5/6 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
@@ -179,14 +179,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
@@ -15,7 +19,7 @@ final-image-check-y ?= true $(call if_changed,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
@@ -23,7 +27,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)) \ > $@
PATCH 6/6 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