xen: beginnings of moving library-like code into an archive
v3 cover xen: beginnings of moving library-like code into an archive
In a few cases we link in library-like functions when they're not actually needed. While we could use Kconfig options for each one of them, I think the better approach for such generic code is to build it always (thus making sure a build issue can't be introduced for these in any however exotic configuration) and then put it into an archive, for the linker to pick up as needed. The series here presents a first few tiny steps towards such a goal.
Note that we can't use thin archives yet, due to our tool chain (binutils) baseline being too low.
Further almost immediate steps I'd like to take if the approach meets no opposition are
- split and move the rest of common/lib.c,
- split and move common/string.c, dropping the need for all the __HAVE_ARCH_* (implying possible per-arch archives then need to be specified ahead of lib/lib.a on the linker command lines),
- move common/libelf/ and common/libfdt/.
v3 has a new 1st patch and some review feedback addressed. See individual patches.
1: xen: fix build when $(obj-y) consists of just blanks 2: lib: collect library files in an archive
3: lib: move list sorting code
4: lib: move parse_size_and_unit()
5: lib: move init_constructors()
6: lib: move rbtree code
7: lib: move bsearch code
8: lib: move sort code
Jan
PATCH v3 1/8 xen: fix build when $(obj-y) consists of just blanks
This case can occur when combining empty lists
obj-y :=
...
obj-y += $(empty)
or
obj-y := $(empty) $(empty)
where (only) blanks would accumulate. This was only a latent issue until now, but would become an active issue for Arm once lib/ gets populated with all respective objects going into the to be introduced lib.a.
Also address a related issue at this occasion: When an empty built_in.o gets created, .built_in.o.d will have its dependencies recorded. If, on a subsequent incremental build, an actual constituent of built_in.o appeared, the $(filter-out ) would leave these recorded dependencies in place. But of course the linker won't know what to do with C header files. (The apparent alternative of avoiding to pass $(c_flags) or $(a_flags) would not be reliable afaict, as among these flags there may be some affecting information conveyed via the object file to the linker. The linker, finding inconsistent flags across object files, may then error out.) Using just $(obj-y) won't work either: It breaks when the same object file is listed more than once.
--- xen/Rules.mk | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
xen/Rules.mk +5 -5
@@ -130,13 +130,13 @@ c_flags += $(CFLAGS-y) a_flags += $(CFLAGS-y) $(AFLAGS-y) built_in.o: $(obj-y) $(extra-y) -ifeq ($(obj-y),) +ifeq ($(strip $(obj-y)),) $(CC) $(c_flags) -c -x c /dev/null -o $@ else ifeq ($(CONFIG_LTO),y) - $(LD_LTO) -r -o $@ $(filter-out $(extra-y),$^) + $(LD_LTO) -r -o $@ $(filter $(obj-y),$^) else - $(LD) $(XEN_LDFLAGS) -r -o $@ $(filter-out $(extra-y),$^) + $(LD) $(XEN_LDFLAGS) -r -o $@ $(filter $(obj-y),$^) endif endif
@@ -145,10 +145,10 @@ targets += $(filter-out $(subdir-obj-y), $(obj-y)) $(extra-y) targets += $(MAKECMDGOALS) built_in_bin.o: $(obj-bin-y) $(extra-y) -ifeq ($(obj-bin-y),) +ifeq ($(strip $(obj-bin-y)),) $(CC) $(a_flags) -c -x assembler /dev/null -o $@ else - $(LD) $(XEN_LDFLAGS) -r -o $@ $(filter-out $(extra-y),$^) + $(LD) $(XEN_LDFLAGS) -r -o $@ $(filter $(obj-bin-y),$^) endif # Force execution of pattern rules (for which PHONY cannot be directly used).
Signature · 1 line
2.22.0
Re: [PATCH v3 1/8] xen: fix build when $(obj-y) consists of just blanks
Hi Jan,
Quoted 28 lines · Jan Beulich
This case can occur when combining empty lists
obj-y :=
...
obj-y += $(empty)or
obj-y := $(empty) $(empty)
where (only) blanks would accumulate. This was only a latent issue until now, but would become an active issue for Arm once
lib/gets populated with all respective objects going into the to be introduced lib.a.Also address a related issue at this occasion: When an empty built_in.o gets created, .built_in.o.d will have its dependencies recorded. If, on a subsequent incremental build, an actual constituent of built_in.o appeared, the $(filter-out ) would leave these recorded dependencies in place. But of course the linker won't know what to do with C header files. (The apparent alternative of avoiding to pass $(c_flags) or $(a_flags) would not be reliable afaict, as among these flags there may be some affecting information conveyed via the object file to the linker. The linker, finding inconsistent flags across object files, may then error out.) Using just $(obj-y) won't work either: It breaks when the same object file is listed more than once.
Quoted 2 lines
Reported-by Julien Grall <[email protected]>Signed-off-by Jan Beulich <[email protected]>
Cheers
Bertrand
Quoted 43 lines
---
xen/Rules.mk| 10 +++++-----1 file changed, 5 insertions(+), 5 deletions(-)xen/Rules.mk +1
-1@@ -130,13 +130,13 @@ c_flags += $(CFLAGS-y) a_flags += $(CFLAGS-y) $(AFLAGS-y) built_in.o: $(obj-y) $(extra-y) -ifeq ($(obj-y),) +ifeq ($(strip $(obj-y)),) $(CC) $(c_flags) -c -x c /dev/null -o $@else
ifeq ($(CONFIG_LTO),y)xen/Rules.mk +1
-1- $(LD_LTO) -r -o $@ $(filter-out $(extra-y),$^) + $(LD_LTO) -r -o $@ $(filter $(obj-y),$^)else
xen/Rules.mk +1
-1- $(LD) $(XEN_LDFLAGS) -r -o $@ $(filter-out $(extra-y),$^) + $(LD) $(XEN_LDFLAGS) -r -o $@ $(filter $(obj-y),$^)endif
endifxen/Rules.mk +1
-1@@ -145,10 +145,10 @@ targets += $(filter-out $(subdir-obj-y), $(obj-y)) $(extra-y) targets += $(MAKECMDGOALS) built_in_bin.o: $(obj-bin-y) $(extra-y) -ifeq ($(obj-bin-y),) +ifeq ($(strip $(obj-bin-y)),) $(CC) $(a_flags) -c -x assembler /dev/null -o $@else
xen/Rules.mk +1
-1- $(LD) $(XEN_LDFLAGS) -r -o $@ $(filter-out $(extra-y),$^) + $(LD) $(XEN_LDFLAGS) -r -o $@ $(filter $(obj-bin-y),$^)endif
# Force execution of pattern rules (for which PHONY cannot be directly used).
Signature · 1 line
2.22.0
Re: [PATCH v3 1/8] xen: fix build when $(obj-y) consists of just blanks
In reply to Jan BeulichQuoted 14 lines · Jan Beulich
This case can occur when combining empty lists
obj-y :=
...
obj-y += $(empty)or
obj-y := $(empty) $(empty)
where (only) blanks would accumulate. This was only a latent issue until now, but would become an active issue for Arm once
lib/gets populated with all respective objects going into the to be introduced lib.a.
Quoted 9 lines
Also address a related issue at this occasion: When an empty built_in.o gets created, .built_in.o.d will have its dependencies recorded. If, on a subsequent incremental build, an actual constituent of built_in.o appeared, the $(filter-out ) would leave these recorded dependencies in place. But of course the linker won't know what to do with C header files. (The apparent alternative of avoiding to pass $(c_flags) or $(a_flags) would not be reliable afaict, as among these flags there may be some affecting information conveyed via the object file to the linker. The linker, finding inconsistent flags across object files, may
How about using $(XEN_CFLAGS) instead of $(c_flags)? That should prevent CC from generating the .*.o.d files while keeping the relevant flags. I was planing to do that to avoid the issue, see:
https://lore.kernel.org/xen-devel/[email protected]
Quoted 2 lines
then error out.) Using just $(obj-y) won't work either: It breaks when the same object file is listed more than once.
Do we need to worry about having a object file been listed twice? Wouldn't that be a mistake?
Signature · 1 line
Anthony PERARD
Re: [PATCH v3 1/8] xen: fix build when $(obj-y) consists of just blanks
Quoted 25 lines · Anthony PERARD
Quoted 14 lines · Jan Beulich
This case can occur when combining empty lists
obj-y :=
...
obj-y += $(empty)or
obj-y := $(empty) $(empty)
where (only) blanks would accumulate. This was only a latent issue until now, but would become an active issue for Arm once
lib/gets populated with all respective objects going into the to be introduced lib.a.Quoted 9 lines
Also address a related issue at this occasion: When an empty built_in.o gets created, .built_in.o.d will have its dependencies recorded. If, on a subsequent incremental build, an actual constituent of built_in.o appeared, the $(filter-out ) would leave these recorded dependencies in place. But of course the linker won't know what to do with C header files. (The apparent alternative of avoiding to pass $(c_flags) or $(a_flags) would not be reliable afaict, as among these flags there may be some affecting information conveyed via the object file to the linker. The linker, finding inconsistent flags across object files, may
Quoted 2 lines
How about using $(XEN_CFLAGS) instead of $(c_flags)? That should prevent CC from generating the .*.o.d files while keeping the relevant flags.
What does "relevant" cover? For an empty .o it may not be important right now, but I could see
c_flags = -MMD -MP -MF $(@D)/.$(@F).d $(XEN_CFLAGS) '-D__OBJECT_FILE__="$@"' a_flags = -MMD -MP -MF $(@D)/.$(@F).d $(XEN_AFLAGS)
include $(BASEDIR)/arch/$(TARGET_ARCH)/Rules.mk
c_flags += $(CFLAGS-y)a_flags += $(CFLAGS-y) $(AFLAGS-y)
leading to CFLAGS-y / AFLAGS-y which need to be consistent across _all_ object files (e.g. some recording of ABI used).
Quoted 9 lines
I
was planing to do that to avoid the issue, see:
https://lore.kernel.org/xen-devel/[email protected]Quoted 2 lines
then error out.) Using just $(obj-y) won't work either: It breaks when the same object file is listed more than once.
Do we need to worry about having a object file been listed twice? Wouldn't that be a mistake?
No. The list approach (obj-$(CONFIG_xyz) += ...) easily allows for this to happen. See xen/arch/x86/mm/Makefile for an existing example.
Jan
Anthony PERARD
Reviewed-byRe: [PATCH v3 1/8] xen: fix build when $(obj-y) consists of just blanks
Quoted 15 lines · Jan Beulich
Quoted 2 lines · Anthony PERARD
How about using $(XEN_CFLAGS) instead of $(c_flags)? That should prevent CC from generating the .*.o.d files while keeping the relevant flags.
What does "relevant" cover? For an empty .o it may not be important right now, but I could see
c_flags= -MMD -MP -MF $(@D)/.$(@F).d $(XEN_CFLAGS) '-D__OBJECT_FILE__="$@"'a_flags= -MMD -MP -MF $(@D)/.$(@F).d $(XEN_AFLAGS)include $(BASEDIR)/arch/$(TARGET_ARCH)/Rules.mk
c_flags+= $(CFLAGS-y)a_flags+= $(CFLAGS-y) $(AFLAGS-y)
Quoted 8 lines
leading to CFLAGS-y / AFLAGS-y which need to be consistent across _all_ object files (e.g. some recording of ABI used).
Quoted 2 lines
Do we need to worry about having a object file been listed twice? Wouldn't that be a mistake?
No. The list approach (obj-$(CONFIG_xyz) += ...) easily allows for this to happen. See xen/arch/x86/mm/Makefile for an existing example.
Sounds good,
Thanks,
Signature · 1 line
Anthony PERARD
PATCH v3 2/8 lib: collect library files in an archive
In reply to Jan BeulichIn order to (subsequently) drop odd things like CONFIG_NEEDS_LIST_SORT just to avoid bloating binaries when only some arch-es and/or configurations need generic library routines, combine objects under lib/ into an archive, which the linker then can pick the necessary objects out of.
Note that we can't use thin archives just yet, until we've raised the minimum required binutils version suitably.
--- xen/Rules.mk | 29 +++++++++++++++++++++++++---- xen/arch/arm/Makefile | 6 +++--- xen/arch/x86/Makefile | 8 ++++---- xen/lib/Makefile | 3 ++- 4 files changed, 34 insertions(+), 12 deletions(-)
xen/Rules.mk +25 -4
@@ -41,12 +41,16 @@ ALL_OBJS-y += $(BASEDIR)/xsm/built_in.o ALL_OBJS-y += $(BASEDIR)/arch/$(TARGET_ARCH)/built_in.o ALL_OBJS-$(CONFIG_CRYPTO) += $(BASEDIR)/crypto/built_in.o +ALL_LIBS-y := $(BASEDIR)/lib/lib.a + # Initialise some variables +lib-y := targets := CFLAGS-y := AFLAGS-y := ALL_OBJS := $(ALL_OBJS-y) +ALL_LIBS := $(ALL_LIBS-y) SPECIAL_DATA_SECTIONS := rodata $(foreach a,1 2 4 8 16, \ $(foreach w,1 2 4, \
@@ -60,7 +64,14 @@ include Makefile # --------------------------------------------------------------------------- quiet_cmd_ld = LD $@ -cmd_ld = $(LD) $(XEN_LDFLAGS) -r -o $@ $(real-prereqs) +cmd_ld = $(LD) $(XEN_LDFLAGS) -r -o $@ $(filter-out %.a,$(real-prereqs)) \ + --start-group $(filter %.a,$(real-prereqs)) --end-group + +# Archive +# --------------------------------------------------------------------------- + +quiet_cmd_ar = AR $@ +cmd_ar = rm -f $@; $(AR) cPrs $@ $(real-prereqs) # Objcopy # ---------------------------------------------------------------------------
@@ -86,6 +97,10 @@ obj-y := $(patsubst %/, %/built_in.o, $(obj-y)) # tell kbuild to descend subdir-obj-y := $(filter %/built_in.o, $(obj-y)) +# Libraries are always collected in one lib file. +# Filter out objects already built-in +lib-y := $(filter-out $(obj-y), $(sort $(lib-y))) + $(filter %.init.o,$(obj-y) $(obj-bin-y) $(extra-y)): CFLAGS-y += -DINIT_SECTIONS_ONLY ifeq ($(CONFIG_COVERAGE),y)
@@ -129,7 +144,7 @@ include $(BASEDIR)/arch/$(TARGET_ARCH)/Rules.mk c_flags += $(CFLAGS-y) a_flags += $(CFLAGS-y) $(AFLAGS-y) -built_in.o: $(obj-y) $(extra-y) +built_in.o: $(obj-y) $(if $(strip $(lib-y)),lib.a) $(extra-y) ifeq ($(strip $(obj-y)),) $(CC) $(c_flags) -c -x c /dev/null -o $@ else
@@ -140,8 +155,14 @@ else endif endif +lib.a: $(lib-y) FORCE + $(call if_changed,ar) + targets += built_in.o -targets += $(filter-out $(subdir-obj-y), $(obj-y)) $(extra-y) +ifneq ($(strip $(lib-y)),) +targets += lib.a +endif +targets += $(filter-out $(subdir-obj-y), $(obj-y) $(lib-y)) $(extra-y) targets += $(MAKECMDGOALS) built_in_bin.o: $(obj-bin-y) $(extra-y)
@@ -155,7 +176,7 @@ endif PHONY += FORCE FORCE: -%/built_in.o: FORCE +%/built_in.o %/lib.a: FORCE $(MAKE) -f $(BASEDIR)/Rules.mk -C $* built_in.o %/built_in_bin.o: FORCE
xen/arch/arm/Makefile +3 -3
@@ -90,14 +90,14 @@ endif ifeq ($(CONFIG_LTO),y) # Gather all LTO objects together -prelink_lto.o: $(ALL_OBJS) - $(LD_LTO) -r -o $@ $^ +prelink_lto.o: $(ALL_OBJS) $(ALL_LIBS) + $(LD_LTO) -r -o $@ $(filter-out %.a,$^) --start-group $(filter %.a,$^) --end-group # Link it with all the binary objects prelink.o: $(patsubst %/built_in.o,%/built_in_bin.o,$(ALL_OBJS)) prelink_lto.o $(call if_changed,ld) else -prelink.o: $(ALL_OBJS) FORCE +prelink.o: $(ALL_OBJS) $(ALL_LIBS) FORCE $(call if_changed,ld) endif
xen/arch/x86/Makefile +4 -4
@@ -132,8 +132,8 @@ EFI_OBJS-$(XEN_BUILD_EFI) := efi/relocs-dummy.o ifeq ($(CONFIG_LTO),y) # Gather all LTO objects together -prelink_lto.o: $(ALL_OBJS) - $(LD_LTO) -r -o $@ $^ +prelink_lto.o: $(ALL_OBJS) $(ALL_LIBS) + $(LD_LTO) -r -o $@ $(filter-out %.a,$^) --start-group $(filter %.a,$^) --end-group # Link it with all the binary objects prelink.o: $(patsubst %/built_in.o,%/built_in_bin.o,$(ALL_OBJS)) prelink_lto.o $(EFI_OBJS-y) FORCE
@@ -142,10 +142,10 @@ prelink.o: $(patsubst %/built_in.o,%/built_in_bin.o,$(ALL_OBJS)) prelink_lto.o $ prelink-efi.o: $(patsubst %/built_in.o,%/built_in_bin.o,$(ALL_OBJS)) prelink_lto.o FORCE $(call if_changed,ld) else -prelink.o: $(ALL_OBJS) $(EFI_OBJS-y) FORCE +prelink.o: $(ALL_OBJS) $(ALL_LIBS) $(EFI_OBJS-y) FORCE $(call if_changed,ld) -prelink-efi.o: $(ALL_OBJS) FORCE +prelink-efi.o: $(ALL_OBJS) $(ALL_LIBS) FORCE $(call if_changed,ld) endif
xen/lib/Makefile +2 -1
@@ -1,2 +1,3 @@ -obj-y += ctype.o obj-$(CONFIG_X86) += x86/ + +lib-y += ctype.o
Re: [PATCH v3 2/8] lib: collect library files in an archive
Hi,
Quoted 8 lines · Jan Beulich
In order to (subsequently) drop odd things like
CONFIG_NEEDS_LIST_SORTjust to avoid bloating binaries when only some arch-es and/or configurations need generic library routines, combine objects underlib/into an archive, which the linker then can pick the necessary objects out of.
Quoted 4 lines
Note that we can't use thin archives just yet, until we've raised the minimum required binutils version suitably.
Signed-off-by Jan Beulich <[email protected]>
with one remark...
Quoted 32 lines
---
xen/Rules.mk | 29 +++++++++++++++++++++++++---- xen/arch/arm/Makefile | 6 +++--- xen/arch/x86/Makefile | 8 ++++---- xen/lib/Makefile | 3 ++- 4 files changed, 34 insertions(+), 12 deletions(-)xen/Rules.mk +0
-0@@ -41,12 +41,16 @@ ALL_OBJS-y += $(BASEDIR)/xsm/built_in.oALL_OBJS-y += $(BASEDIR)/arch/$(TARGET_ARCH)/built_in.o
ALL_OBJS-$(CONFIG_CRYPTO) += $(BASEDIR)/crypto/built_in.oxen/Rules.mk +2
-0+ALL_LIBS-y := $(BASEDIR)/lib/lib.a +# Initialise some variables
+lib-y :=
targets :=
CFLAGS-y :=
AFLAGS-y :=
ALL_OBJS:= $(ALL_OBJS-y)
+ALL_LIBS := $(ALL_LIBS-y)SPECIAL_DATA_SECTIONS := rodata $(foreach a,1 2 4 8 16, \ $(foreach w,1 2 4, \xen/Rules.mk +0
-0@@ -60,7 +64,14 @@ include Makefile # ---------------------------------------------------------------------------
quiet_cmd_ld= LD $@
xen/Rules.mk include Makefile · line 68
Quoted 3 lines
xen/Rules.mk +2
-1-cmd_ld = $(LD) $(XEN_LDFLAGS) -r -o $@ $(real-prereqs) +cmd_ld = $(LD) $(XEN_LDFLAGS) -r -o $@ $(filter-out %.a,$(real-prereqs)) \ + --start-group $(filter %.a,$(real-prereqs)) --end-group
This might be a good idea to add a comment to explain why the start/end-group is needed so that someone does not change this back in the future.
Something like: put libraries between start/end group to have unused symbols removed.
Cheers
Bertrand
Quoted 115 lines
xen/Rules.mk +6
-0+ +# Archive +# --------------------------------------------------------------------------- + +quiet_cmd_ar = AR $@ +cmd_ar = rm -f $@; $(AR) cPrs $@ $(real-prereqs)# Objcopy
# ---------------------------------------------------------------------------xen/Rules.mk +4
-0@@ -86,6 +97,10 @@ obj-y := $(patsubst %/, %/built_in.o, $(obj-y)) # tell kbuild to descend subdir-obj-y := $(filter %/built_in.o, $(obj-y)) +# Libraries are always collected in one lib file. +# Filter out objects already built-in +lib-y := $(filter-out $(obj-y), $(sort $(lib-y))) +$(filter %.init.o,$(obj-y) $(obj-bin-y) $(extra-y)): CFLAGS-y += -DINIT_SECTIONS_ONLY
ifeq ($(CONFIG_COVERAGE),y)
xen/Rules.mk +1
-1@@ -129,7 +144,7 @@ include $(BASEDIR)/arch/$(TARGET_ARCH)/Rules.mk c_flags += $(CFLAGS-y) a_flags += $(CFLAGS-y) $(AFLAGS-y) -built_in.o: $(obj-y) $(extra-y) +built_in.o: $(obj-y) $(if $(strip $(lib-y)),lib.a) $(extra-y) ifeq ($(strip $(obj-y)),) $(CC) $(c_flags) -c -x c /dev/null -o $@else
xen/Rules.mk +0
-0@@ -140,8 +155,14 @@ elseendif
endifxen/Rules.mk +3
-0+lib.a: $(lib-y) FORCE + $(call if_changed,ar) +targets += built_in.o
xen/Rules.mk +4
-1-targets += $(filter-out $(subdir-obj-y), $(obj-y)) $(extra-y) +ifneq ($(strip $(lib-y)),) +targets += lib.a +endif +targets += $(filter-out $(subdir-obj-y), $(obj-y) $(lib-y)) $(extra-y)targets += $(MAKECMDGOALS)
built_in_bin.o: $(obj-bin-y) $(extra-y)
xen/Rules.mk +0
-0@@ -155,7 +176,7 @@ endifPHONY += FORCE
FORCE:-%/built_in.o: FORCE
+%/built_in.o %/lib.a: FORCE$(MAKE) -f $(BASEDIR)/Rules.mk -C $* built_in.o%/built_in_bin.o: FORCE
xen/arch/arm/Makefile +2
-2@@ -90,14 +90,14 @@ endif ifeq ($(CONFIG_LTO),y) # Gather all LTO objects together -prelink_lto.o: $(ALL_OBJS) - $(LD_LTO) -r -o $@ $^ +prelink_lto.o: $(ALL_OBJS) $(ALL_LIBS) + $(LD_LTO) -r -o $@ $(filter-out %.a,$^) --start-group $(filter %.a,$^) --end-group # Link it with all the binary objectsprelink.o: $(patsubst %/built_in.o,%/built_in_bin.o,$(ALL_OBJS)) prelink_lto.o
$(call if_changed,ld)else
xen/arch/arm/Makefile +1
-1-prelink.o: $(ALL_OBJS) FORCE +prelink.o: $(ALL_OBJS) $(ALL_LIBS) FORCE$(call if_changed,ld)endif
xen/arch/x86/Makefile +2
-2@@ -132,8 +132,8 @@ EFI_OBJS-$(XEN_BUILD_EFI) := efi/relocs-dummy.o ifeq ($(CONFIG_LTO),y) # Gather all LTO objects together -prelink_lto.o: $(ALL_OBJS) - $(LD_LTO) -r -o $@ $^ +prelink_lto.o: $(ALL_OBJS) $(ALL_LIBS) + $(LD_LTO) -r -o $@ $(filter-out %.a,$^) --start-group $(filter %.a,$^) --end-group # Link it with all the binary objectsprelink.o: $(patsubst %/built_in.o,%/built_in_bin.o,$(ALL_OBJS)) prelink_lto.o $(EFI_OBJS-y) FORCE
xen/arch/x86/Makefile +0
-0@@ -142,10 +142,10 @@ prelink.o: $(patsubst %/built_in.o,%/built_in_bin.o,$(ALL_OBJS)) prelink_lto.o $prelink-efi.o: $(patsubst %/built_in.o,%/built_in_bin.o,$(ALL_OBJS)) prelink_lto.o FORCE
$(call if_changed,ld)else
xen/arch/x86/Makefile +1
-1-prelink.o: $(ALL_OBJS) $(EFI_OBJS-y) FORCE +prelink.o: $(ALL_OBJS) $(ALL_LIBS) $(EFI_OBJS-y) FORCE$(call if_changed,ld)xen/arch/x86/Makefile +1
-1-prelink-efi.o: $(ALL_OBJS) FORCE +prelink-efi.o: $(ALL_OBJS) $(ALL_LIBS) FORCE$(call if_changed,ld)endif
xen/lib/Makefile +0
-1@@ -1,2 +1,3 @@ -obj-y += ctype.oobj-$(CONFIG_X86) += x86/
xen/lib/Makefile +2
-0+ +lib-y += ctype.o
Re: [PATCH v3 2/8] lib: collect library files in an archive
Quoted 8 lines · Bertrand Marquis
Quoted 8 lines · Jan Beulich
In order to (subsequently) drop odd things like
CONFIG_NEEDS_LIST_SORTjust to avoid bloating binaries when only some arch-es and/or configurations need generic library routines, combine objects underlib/into an archive, which the linker then can pick the necessary objects out of.
Quoted 5 lines
Quoted 4 lines
Note that we can't use thin archives just yet, until we've raised the minimum required binutils version suitably.
Signed-off-by Jan Beulich <[email protected]>Reviewed-by Bertrand Marquis <[email protected]>
Thanks.
Quoted 10 lines
xen/Rules.mk include Makefile · line 68
Quoted 7 lines
xen/Rules.mk +0
-0@@ -60,7 +64,14 @@ include Makefile # ---------------------------------------------------------------------------
quiet_cmd_ld= LD $@xen/Rules.mk +2
-1-cmd_ld = $(LD) $(XEN_LDFLAGS) -r -o $@ $(real-prereqs) +cmd_ld = $(LD) $(XEN_LDFLAGS) -r -o $@ $(filter-out %.a,$(real-prereqs)) \ + --start-group $(filter %.a,$(real-prereqs)) --end-groupThis might be a good idea to add a comment to explain why the start/end-group is needed so that someone does not change this back in the future.
Since we're trying to inherit Linux'es build system, I did look there and iirc there was no comment, so I didn't see a basis for us to have one.
Quoted 1 line
Something like: put libraries between start/end group to have unused symbols removed.
Now that's not the reason - why you describe is the default behavior for archives, and there is something like a "whole archive" option iirc to change to a mode where all objects get pulled out. Instead this is a symbol resolution thing aiui - by default earlier archives can't resolve undefined symbols first referenced by objects pulled out of later archives.
Jan
Re: [PATCH v3 2/8] lib: collect library files in an archive
Hi Jan,
Quoted 36 lines · Jan Beulich
Quoted 8 lines · Bertrand Marquis
Quoted 8 lines · Jan Beulich
In order to (subsequently) drop odd things like
CONFIG_NEEDS_LIST_SORTjust to avoid bloating binaries when only some arch-es and/or configurations need generic library routines, combine objects underlib/into an archive, which the linker then can pick the necessary objects out of.Quoted 5 lines
Quoted 4 lines
Note that we can't use thin archives just yet, until we've raised the minimum required binutils version suitably.
Signed-off-by Jan Beulich <[email protected]>Reviewed-by Bertrand Marquis <[email protected]>Thanks.
Quoted 10 lines
xen/Rules.mk include Makefile · line 68
Quoted 7 lines
xen/Rules.mk +0
-0@@ -60,7 +64,14 @@ include Makefile # ---------------------------------------------------------------------------
quiet_cmd_ld= LD $@xen/Rules.mk +2
-1-cmd_ld = $(LD) $(XEN_LDFLAGS) -r -o $@ $(real-prereqs) +cmd_ld = $(LD) $(XEN_LDFLAGS) -r -o $@ $(filter-out %.a,$(real-prereqs)) \ + --start-group $(filter %.a,$(real-prereqs)) --end-groupThis might be a good idea to add a comment to explain why the start/end-group is needed so that someone does not change this back in the future.
Since we're trying to inherit Linux'es build system, I did look there and iirc there was no comment, so I didn't see a basis for us to have one.
Quoted 1 line
Something like: put libraries between start/end group to have unused symbols removed.
Quoted 7 lines
Now that's not the reason - why you describe is the default behavior for archives, and there is something like a "whole archive" option iirc to change to a mode where all objects get pulled out. Instead this is a symbol resolution thing aiui - by default earlier archives can't resolve undefined symbols first referenced by objects pulled out of later archives.
ah yes i remember seeing that.
Maybe just add your last sentence in the commit message.
Cheers
Bertrand
Quoted 2 lines
Jan
Re: [PATCH v3 2/8] lib: collect library files in an archive
In reply to Jan BeulichQuoted 22 lines · Jan Beulich
In order to (subsequently) drop odd things like
CONFIG_NEEDS_LIST_SORTjust to avoid bloating binaries when only some arch-es and/or configurations need generic library routines, combine objects underlib/into an archive, which the linker then can pick the necessary objects out of.Note that we can't use thin archives just yet, until we've raised the minimum required binutils version suitably.
Signed-off-by Jan Beulich <[email protected]>--- xen/Rules.mk | 29 +++++++++++++++++++++++++---- xen/arch/arm/Makefile | 6 +++--- xen/arch/x86/Makefile | 8 ++++---- xen/lib/Makefile | 3 ++- 4 files changed, 34 insertions(+), 12 deletions(-)xen/Rules.mk +0
-0
xen/Rules.mk include Makefile · line 68
Quoted 6 lines
xen/Rules.mk +2
-1@@ -60,7 +64,14 @@ include Makefile # --------------------------------------------------------------------------- quiet_cmd_ld = LD $@ -cmd_ld = $(LD) $(XEN_LDFLAGS) -r -o $@ $(real-prereqs) +cmd_ld = $(LD) $(XEN_LDFLAGS) -r -o $@ $(filter-out %.a,$(real-prereqs)) \ + --start-group $(filter %.a,$(real-prereqs)) --end-group
It might be a bit weird to modify the generic LD command for the benefit of only prelink.o objects but it's probably fine as long as we only use archives for lib.a. libelf and libfdt will just have --start/end-group added to there ld command line. So I guess the change is fine.
The rest looks good,
Thanks,
Signature · 1 line
Anthony PERARD
Re: [PATCH v3 2/8] lib: collect library files in an archive
Quoted 6 lines · Anthony PERARD
Quoted 5 lines · Jan Beulich
xen/Rules.mk +0
-0@@ -60,7 +64,14 @@ include Makefile # ---------------------------------------------------------------------------
Quoted 9 lines
xen/Rules.mk include Makefile · line 68
Quoted 4 lines
xen/Rules.mk +2
-1quiet_cmd_ld = LD $@ -cmd_ld = $(LD) $(XEN_LDFLAGS) -r -o $@ $(real-prereqs) +cmd_ld = $(LD) $(XEN_LDFLAGS) -r -o $@ $(filter-out %.a,$(real-prereqs)) \ + --start-group $(filter %.a,$(real-prereqs)) --end-groupIt might be a bit weird to modify the generic LD command for the benefit of only prelink.o objects but it's probably fine as long as we only use archives for lib.a. libelf and libfdt will just have --start/end-group added to there ld command line. So I guess the change is fine.
I'm afraid I don't understand what the concern is. Neither libelf nor libfdt use any %.a right now. Or are you referring to them merely because it's just them which have got converted to using $(call if-changed ...), and your remark would eventually apply to e.g. built_in.o as well? And then further is all you're worried about the fact that there may be "--start-group --end-group" on the command line, i.e. with nothing inbetween? If so, besides possibly looking a little odd if someone inspected the command lines closely, what possible issue do you see? (If there is one, making the addition of both options conditional upon there being any/multiple %.a in the first place wouldn't be a big problem, albeit Linux also doesn't care whether ${KBUILD_VMLINUX_LIBS} is empty.)
Quoted 2 lines
The rest looks good,
Reviewed-by Anthony PERARD <[email protected]>
Thanks, but I'd prefer the above clarified.
Jan
Re: [PATCH v3 2/8] lib: collect library files in an archive
Quoted 17 lines · Jan Beulich
Quoted 6 lines · Anthony PERARD
Quoted 5 lines · Jan Beulich
xen/Rules.mk +0
-0@@ -60,7 +64,14 @@ include Makefile # ---------------------------------------------------------------------------Quoted 9 lines
xen/Rules.mk include Makefile · line 68
Quoted 4 lines
xen/Rules.mk +2
-1quiet_cmd_ld = LD $@ -cmd_ld = $(LD) $(XEN_LDFLAGS) -r -o $@ $(real-prereqs) +cmd_ld = $(LD) $(XEN_LDFLAGS) -r -o $@ $(filter-out %.a,$(real-prereqs)) \ + --start-group $(filter %.a,$(real-prereqs)) --end-groupIt might be a bit weird to modify the generic LD command for the benefit of only prelink.o objects but it's probably fine as long as we only use archives for lib.a. libelf and libfdt will just have --start/end-group added to there ld command line. So I guess the change is fine.
Quoted 13 lines
I'm afraid I don't understand what the concern is. Neither libelf nor libfdt use any %.a right now. Or are you referring to them merely because it's just them which have got converted to using $(call if-changed ...), and your remark would eventually apply to e.g. built_in.o as well? And then further is all you're worried about the fact that there may be "--start-group --end-group" on the command line, i.e. with nothing inbetween? If so, besides possibly looking a little odd if someone inspected the command lines closely, what possible issue do you see? (If there is one, making the addition of both options conditional upon there being any/multiple %.a in the first place wouldn't be a big problem, albeit Linux also doesn't care whether ${KBUILD_VMLINUX_LIBS} is empty.)
Well, maybe one day we might want to collect objects in build_in.a archives rather than build_in.o, like Linux does, but Xen is probably too small for that to have any impact on the time it takes to build. And if that happen, we will have to change the linker's command anyway to use --whole-archive. So the change is fine.
As for "--start-group --end-group", yes it would just look odd, but I don't think there would by any issue with option added to the command line.
Quoted 6 lines
Quoted 2 lines
The rest looks good,
Reviewed-by Anthony PERARD <[email protected]>Thanks, but I'd prefer the above clarified.
Jan
Signature · 1 line
Anthony PERARD
Ping: Arm: [PATCH v3 2/8] lib: collect library files in an archive
In reply to Jan BeulichQuoted 6 lines · Jan Beulich
In order to (subsequently) drop odd things like
CONFIG_NEEDS_LIST_SORTjust to avoid bloating binaries when only some arch-es and/or configurations need generic library routines, combine objects underlib/into an archive, which the linker then can pick the necessary objects out of.
Quoted 7 lines
Note that we can't use thin archives just yet, until we've raised the minimum required binutils version suitably.
Signed-off-by Jan Beulich <[email protected]>--- xen/Rules.mk | 29 +++++++++++++++++++++++++---- xen/arch/arm/Makefile | 6 +++---
For this and patch 3 of the series, may I ask for an Arm side ack (or otherwise)?
Thanks, Jan
Quoted 147 lines
xen/arch/x86/Makefile | 8 ++++---- xen/lib/Makefile | 3 ++- 4 files changed, 34 insertions(+), 12 deletions(-)xen/Rules.mk +25
-4@@ -41,12 +41,16 @@ ALL_OBJS-y += $(BASEDIR)/xsm/built_in.o ALL_OBJS-y += $(BASEDIR)/arch/$(TARGET_ARCH)/built_in.o ALL_OBJS-$(CONFIG_CRYPTO) += $(BASEDIR)/crypto/built_in.o +ALL_LIBS-y := $(BASEDIR)/lib/lib.a + # Initialise some variables +lib-y := targets := CFLAGS-y := AFLAGS-y := ALL_OBJS := $(ALL_OBJS-y) +ALL_LIBS := $(ALL_LIBS-y) SPECIAL_DATA_SECTIONS := rodata $(foreach a,1 2 4 8 16, \ $(foreach w,1 2 4, \@@ -60,7 +64,14 @@ include Makefile # --------------------------------------------------------------------------- quiet_cmd_ld = LD $@ -cmd_ld = $(LD) $(XEN_LDFLAGS) -r -o $@ $(real-prereqs) +cmd_ld = $(LD) $(XEN_LDFLAGS) -r -o $@ $(filter-out %.a,$(real-prereqs)) \ + --start-group $(filter %.a,$(real-prereqs)) --end-group + +# Archive +# --------------------------------------------------------------------------- + +quiet_cmd_ar = AR $@ +cmd_ar = rm -f $@; $(AR) cPrs $@ $(real-prereqs) # Objcopy # ---------------------------------------------------------------------------@@ -86,6 +97,10 @@ obj-y := $(patsubst %/, %/built_in.o, $(obj-y)) # tell kbuild to descend subdir-obj-y := $(filter %/built_in.o, $(obj-y)) +# Libraries are always collected in one lib file. +# Filter out objects already built-in +lib-y := $(filter-out $(obj-y), $(sort $(lib-y))) + $(filter %.init.o,$(obj-y) $(obj-bin-y) $(extra-y)): CFLAGS-y += -DINIT_SECTIONS_ONLY ifeq ($(CONFIG_COVERAGE),y)@@ -129,7 +144,7 @@ include $(BASEDIR)/arch/$(TARGET_ARCH)/Rules.mk c_flags += $(CFLAGS-y) a_flags += $(CFLAGS-y) $(AFLAGS-y) -built_in.o: $(obj-y) $(extra-y) +built_in.o: $(obj-y) $(if $(strip $(lib-y)),lib.a) $(extra-y) ifeq ($(strip $(obj-y)),) $(CC) $(c_flags) -c -x c /dev/null -o $@ else@@ -140,8 +155,14 @@ else endif endif +lib.a: $(lib-y) FORCE + $(call if_changed,ar) + targets += built_in.o -targets += $(filter-out $(subdir-obj-y), $(obj-y)) $(extra-y) +ifneq ($(strip $(lib-y)),) +targets += lib.a +endif +targets += $(filter-out $(subdir-obj-y), $(obj-y) $(lib-y)) $(extra-y) targets += $(MAKECMDGOALS) built_in_bin.o: $(obj-bin-y) $(extra-y)@@ -155,7 +176,7 @@ endif PHONY += FORCE FORCE: -%/built_in.o: FORCE +%/built_in.o %/lib.a: FORCE $(MAKE) -f $(BASEDIR)/Rules.mk -C $* built_in.o %/built_in_bin.o: FORCExen/arch/arm/Makefile +3
-3@@ -90,14 +90,14 @@ endif ifeq ($(CONFIG_LTO),y) # Gather all LTO objects together -prelink_lto.o: $(ALL_OBJS) - $(LD_LTO) -r -o $@ $^ +prelink_lto.o: $(ALL_OBJS) $(ALL_LIBS) + $(LD_LTO) -r -o $@ $(filter-out %.a,$^) --start-group $(filter %.a,$^) --end-group # Link it with all the binary objects prelink.o: $(patsubst %/built_in.o,%/built_in_bin.o,$(ALL_OBJS)) prelink_lto.o $(call if_changed,ld) else -prelink.o: $(ALL_OBJS) FORCE +prelink.o: $(ALL_OBJS) $(ALL_LIBS) FORCE $(call if_changed,ld) endifxen/arch/x86/Makefile +4
-4@@ -132,8 +132,8 @@ EFI_OBJS-$(XEN_BUILD_EFI) := efi/relocs-dummy.o ifeq ($(CONFIG_LTO),y) # Gather all LTO objects together -prelink_lto.o: $(ALL_OBJS) - $(LD_LTO) -r -o $@ $^ +prelink_lto.o: $(ALL_OBJS) $(ALL_LIBS) + $(LD_LTO) -r -o $@ $(filter-out %.a,$^) --start-group $(filter %.a,$^) --end-group # Link it with all the binary objects prelink.o: $(patsubst %/built_in.o,%/built_in_bin.o,$(ALL_OBJS)) prelink_lto.o $(EFI_OBJS-y) FORCE@@ -142,10 +142,10 @@ prelink.o: $(patsubst %/built_in.o,%/built_in_bin.o,$(ALL_OBJS)) prelink_lto.o $ prelink-efi.o: $(patsubst %/built_in.o,%/built_in_bin.o,$(ALL_OBJS)) prelink_lto.o FORCE $(call if_changed,ld) else -prelink.o: $(ALL_OBJS) $(EFI_OBJS-y) FORCE +prelink.o: $(ALL_OBJS) $(ALL_LIBS) $(EFI_OBJS-y) FORCE $(call if_changed,ld) -prelink-efi.o: $(ALL_OBJS) FORCE +prelink-efi.o: $(ALL_OBJS) $(ALL_LIBS) FORCE $(call if_changed,ld) endifxen/lib/Makefile +2
-1@@ -1,2 +1,3 @@ -obj-y += ctype.o obj-$(CONFIG_X86) += x86/ + +lib-y += ctype.o
Julien Grall
Acked-byRe: Ping: Arm: [PATCH v3 2/8] lib: collect library files in an archive
Hi Jan,
Quoted 10 lines · Jan Beulich
Quoted 9 lines · Jan Beulich
In order to (subsequently) drop odd things like
CONFIG_NEEDS_LIST_SORTjust to avoid bloating binaries when only some arch-es and/or configurations need generic library routines, combine objects underlib/into an archive, which the linker then can pick the necessary objects out of.Note that we can't use thin archives just yet, until we've raised the minimum required binutils version suitably.
Quoted 7 lines
Quoted 4 lines
Signed-off-by Jan Beulich <[email protected]>--- xen/Rules.mk | 29 +++++++++++++++++++++++++---- xen/arch/arm/Makefile | 6 +++---For this and patch 3 of the series, may I ask for an Arm side ack (or otherwise)?
For the 2 patches:
Cheers,
Signature · 1 line
Julien Grall
PATCH v3 3/8 lib: move list sorting code
In reply to Jan BeulichBuild the source file always, as by putting it into an archive it still won't be linked into final binaries when not needed. This way possible build breakage will be easier to notice, and it's more consistent with us unconditionally building other library kind of code (e.g. sort() or bsearch()).
While moving the source file, take the opportunity and drop the pointless EXPORT_SYMBOL() and an unnecessary #include.
---
xen/arch/arm/Kconfig | 4 +---
xen/common/Kconfig | 3 ---
xen/common/Makefile | 1 -
xen/lib/Makefile | 1 +
xen/{common/list_sort.c => lib/list-sort.c} | 2 --
5 files changed, 2 insertions(+), 9 deletions(-)
rename xen/{common/list_sort.c => lib/list-sort.c} (98%)xen/arch/arm/Kconfig +1 -3
@@ -56,9 +56,7 @@ config HVM def_bool y config NEW_VGIC - bool - prompt "Use new VGIC implementation" - select NEEDS_LIST_SORT + bool "Use new VGIC implementation" ---help--- This is an alternative implementation of the ARM GIC interrupt
xen/common/Kconfig +0 -3
@@ -66,9 +66,6 @@ config MEM_ACCESS config NEEDS_LIBELF bool -config NEEDS_LIST_SORT - bool - menu "Speculative hardening" config SPECULATIVE_HARDEN_ARRAY
xen/common/Makefile +0 -1
@@ -21,7 +21,6 @@ obj-y += keyhandler.o obj-$(CONFIG_KEXEC) += kexec.o obj-$(CONFIG_KEXEC) += kimage.o obj-y += lib.o -obj-$(CONFIG_NEEDS_LIST_SORT) += list_sort.o obj-$(CONFIG_LIVEPATCH) += livepatch.o livepatch_elf.o obj-$(CONFIG_MEM_ACCESS) += mem_access.o obj-y += memory.o
xen/lib/Makefile +1 -0
@@ -1,3 +1,4 @@ obj-$(CONFIG_X86) += x86/ lib-y += ctype.o +lib-y += list-sort.o
xen/lib/list-sort.c renamed from xen/common/list_sort.c +0 -2
@@ -15,7 +15,6 @@* this program; If not, see <http://www.gnu.org/licenses/>. */ -#include <xen/lib.h> #include <xen/list.h> #define MAX_LIST_LENGTH_BITS 20
@@ -154,4 +153,3 @@ void list_sort(void *priv, struct list_head *head,merge_and_restore_back_links (priv, cmp, head, part[max_lev], list); } -EXPORT_SYMBOL (list_sort);
Re: [PATCH v3 3/8] lib: move list sorting code
Quoted 10 lines · Jan Beulich
Build the source file always, as by putting it into an archive it still won't be linked into final binaries when not needed. This way possible build breakage will be easier to notice, and it's more consistent with us unconditionally building other library kind of code (e.g.
sort()orbsearch()).
Quoted 4 lines
While moving the source file, take the opportunity and drop the pointless
EXPORT_SYMBOL()and an unnecessary #include.Signed-off-by Jan Beulich <[email protected]>
Cheers
Bertrand
Quoted 81 lines
---
xen/arch/arm/Kconfig | 4 +--- xen/common/Kconfig | 3 --- xen/common/Makefile | 1 - xen/lib/Makefile | 1 + xen/{common/list_sort.c => lib/list-sort.c} | 2 -- 5 files changed, 2 insertions(+), 9 deletions(-)rename
xen/{common/list_sort.c=>lib/list-sort.c} (98%)xen/arch/arm/Kconfig +0
-0@@ -56,9 +56,7 @@ config HVM def_bool yconfig
NEW_VGICxen/arch/arm/Kconfig +1
-3- bool - prompt "Use new VGIC implementation" - select NEEDS_LIST_SORT + bool "Use new VGIC implementation"---help--- This is an alternative implementation of the ARM GIC interruptxen/common/Kconfig +0
-0@@ -66,9 +66,6 @@ config MEM_ACCESSconfig
NEEDS_LIBELF
boolxen/common/Kconfig +0
-3-config NEEDS_LIST_SORT - bool -menu "Speculative hardening"
config
SPECULATIVE_HARDEN_ARRAYxen/common/Makefile +0
-0@@ -21,7 +21,6 @@ obj-y += keyhandler.oobj-$(CONFIG_KEXEC) += kexec.o obj-$(CONFIG_KEXEC) += kimage.o
obj-y += lib.o
-obj-$(CONFIG_NEEDS_LIST_SORT) += list_sort.o obj-$(CONFIG_LIVEPATCH) += livepatch.o livepatch_elf.o obj-$(CONFIG_MEM_ACCESS) += mem_access.o obj-y += memory.oxen/lib/Makefile +0
-0@@ -1,3 +1,4 @@obj-$(CONFIG_X86) += x86/
lib-y += ctype.o
xen/lib/Makefile +1
-0+lib-y += list-sort.oxen/lib/list-sort.c renamed from xen/common/list_sort.c +0
-2@@ -15,7 +15,6 @@* this program; If not, see <http://www.gnu.org/licenses/>. */ -#include <xen/lib.h> #include <xen/list.h> #define MAX_LIST_LENGTH_BITS 20@@ -154,4 +153,3 @@ void list_sort(void *priv, struct list_head *head,merge_and_restore_back_links (priv, cmp, head, part[max_lev], list); } -EXPORT_SYMBOL (list_sort);
PATCH v3 4/8 lib: move parse_size_and_unit()
In reply to Jan Beulich... into its own CU, to build it into an archive.
--- xen/common/lib.c | 39 ---------------------------------- xen/lib/Makefile | 1 + xen/lib/parse-size.c | 50 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 39 deletions(-) create mode 100644 xen/lib/parse-size.c
xen/common/lib.c +0 -39
@@ -423,45 +423,6 @@ uint64_t muldiv64(uint64_t a, uint32_t b, uint32_t c)#endif } -unsigned long long parse_size_and_unit (const char *s,const char **ps) -{ -unsigned long long ret; -const char *s1; - - ret =simple_strtoull (s, &s1,0 ); - -switch ( *s1 ) - { -case 'T' :case 't' : - ret <<=10 ; -/* fallthrough */ -case 'G' :case 'g' : - ret <<=10 ; -/* fallthrough */ -case 'M' :case 'm' : - ret <<=10 ; -/* fallthrough */ -case 'K' :case 'k' : - ret <<=10 ; -/* fallthrough */ -case 'B' :case 'b' : - s1++; -break ; -case '%' : -if ( ps ) -break ; -/* fallthrough */ -default : - ret <<=10 ;/* default to kB */ -break ; - } - -if ( ps !=NULL ) - *ps = s1; - -return ret; -} -typedef void (*ctor_func_t )(void );extern const ctor_func_t __ctors_start[], __ctors_end[];
xen/lib/Makefile +1 -0
@@ -2,3 +2,4 @@ obj-$(CONFIG_X86) += x86/ lib-y += ctype.o lib-y += list-sort.o +lib-y += parse-size.o
xen/lib/parse-size.c new file +50 -0
50 lines not on this page · raw message
Re: [PATCH v3 4/8] lib: move parse_size_and_unit()
Quoted 8 lines · Jan Beulich
... into its own CU, to build it into an archive.
Signed-off-by Jan Beulich <[email protected]>Acked-by Julien Grall <[email protected]>
Cheers
Bertrand
Quoted 124 lines
---
xen/common/lib.c | 39 ---------------------------------- xen/lib/Makefile | 1 + xen/lib/parse-size.c | 50 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 39 deletions(-)create mode 100644
xen/lib/parse-size.cxen/common/lib.c +0
-39@@ -423,45 +423,6 @@ uint64_t muldiv64(uint64_t a, uint32_t b, uint32_t c)#endif } -unsigned long long parse_size_and_unit (const char *s,const char **ps) -{ -unsigned long long ret; -const char *s1; - - ret =simple_strtoull (s, &s1,0 ); - -switch ( *s1 ) - { -case 'T' :case 't' : - ret <<=10 ; -/* fallthrough */ -case 'G' :case 'g' : - ret <<=10 ; -/* fallthrough */ -case 'M' :case 'm' : - ret <<=10 ; -/* fallthrough */ -case 'K' :case 'k' : - ret <<=10 ; -/* fallthrough */ -case 'B' :case 'b' : - s1++; -break ; -case '%' : -if ( ps ) -break ; -/* fallthrough */ -default : - ret <<=10 ;/* default to kB */ -break ; - } - -if ( ps !=NULL ) - *ps = s1; - -return ret; -} -typedef void (*ctor_func_t )(void );extern const ctor_func_t __ctors_start[], __ctors_end[];xen/lib/Makefile +0
-0@@ -2,3 +2,4 @@ obj-$(CONFIG_X86) += x86/lib-y += ctype.o
lib-y += list-sort.oxen/lib/Makefile +1
-0+lib-y += parse-size.oxen/lib/parse-size.c new file +50
-0@@ -0,0 +1,50 @@ +#include <xen/lib.h> + +unsigned long long parse_size_and_unit (const char *s,const char **ps) +{ +unsigned long long ret; +const char *s1; + + ret =simple_strtoull (s, &s1,0 ); + +switch ( *s1 ) + { +case 'T' :case 't' : + ret <<=10 ; +/* fallthrough */ +case 'G' :case 'g' : + ret <<=10 ; +/* fallthrough */ +case 'M' :case 'm' : + ret <<=10 ; +/* fallthrough */ +case 'K' :case 'k' : + ret <<=10 ; +/* fallthrough */ +case 'B' :case 'b' : + s1++; +break ; +case '%' : +if ( ps ) +break ; +/* fallthrough */ +default : + ret <<=10 ;/* default to kB */ +break ; + } + +if ( ps !=NULL ) + *ps = s1; + +return ret; +} + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* tab-width: 4 +* indent-tabs-mode: nil +* End: +*/
PATCH v3 5/8 lib: move init_constructors()
In reply to Jan Beulich... into its own CU, for being unrelated to other things in common/lib.c.
--- xen/common/lib.c | 14 -------------- xen/lib/Makefile | 1 + xen/lib/ctors.c | 25 +++++++++++++++++++++++++ 3 files changed, 26 insertions(+), 14 deletions(-) create mode 100644 xen/lib/ctors.c
xen/common/lib.c +0 -14
@@ -1,6 +1,5 @@#include <xen/lib.h> #include <xen/types.h> -#include <xen/init.h> #include <asm/byteorder.h> /*
@@ -423,19 +422,6 @@ uint64_t muldiv64(uint64_t a, uint32_t b, uint32_t c)#endif } -typedef void (*ctor_func_t )(void ); -extern const ctor_func_t __ctors_start[], __ctors_end[]; - -void __init init_constructors (void ) -{ -const ctor_func_t *f; -for ( f = __ctors_start; f < __ctors_end; ++f ) - (*f)(); - -/* Putting this here seems as good (or bad) as any other place. */ -BUILD_BUG_ON (sizeof (size_t ) !=sizeof (ssize_t )); -} -/* * Local variables: * mode: C
xen/lib/Makefile +1 -0
@@ -1,5 +1,6 @@ obj-$(CONFIG_X86) += x86/ +lib-y += ctors.o lib-y += ctype.o lib-y += list-sort.o lib-y += parse-size.o
xen/lib/ctors.c new file +25 -0
@@ -0,0 +1,25 @@ +#include <xen/init.h> +#include <xen/lib.h> + +typedef void (*ctor_func_t )(void ); +extern const ctor_func_t __ctors_start[], __ctors_end[]; + +void __init init_constructors (void ) +{ +const ctor_func_t *f; +for ( f = __ctors_start; f < __ctors_end; ++f ) + (*f)(); + +/* Putting this here seems as good (or bad) as any other place. */ +BUILD_BUG_ON (sizeof (size_t ) !=sizeof (ssize_t )); +} + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* tab-width: 4 +* indent-tabs-mode: nil +* End: +*/
Re: [PATCH v3 5/8] lib: move init_constructors()
Hi Jan,
Quoted 6 lines · Jan Beulich
... into its own CU, for being unrelated to other things in
common/lib.c.Signed-off-by Jan Beulich <[email protected]>
Cheers
Bertrand
Quoted 82 lines
---
xen/common/lib.c | 14 -------------- xen/lib/Makefile | 1 + xen/lib/ctors.c | 25 +++++++++++++++++++++++++ 3 files changed, 26 insertions(+), 14 deletions(-)create mode 100644
xen/lib/ctors.cxen/common/lib.c +0
-14@@ -1,6 +1,5 @@#include <xen/lib.h> #include <xen/types.h> -#include <xen/init.h> #include <asm/byteorder.h> /* @@ -423,19 +422,6 @@ uint64_t muldiv64(uint64_t a, uint32_t b, uint32_t c)#endif } -typedef void (*ctor_func_t )(void ); -extern const ctor_func_t __ctors_start[], __ctors_end[]; - -void __init init_constructors (void ) -{ -const ctor_func_t *f; -for ( f = __ctors_start; f < __ctors_end; ++f ) - (*f)(); - -/* Putting this here seems as good (or bad) as any other place. */ -BUILD_BUG_ON (sizeof (size_t ) !=sizeof (ssize_t )); -} -/* * Local variables: * mode: C xen/lib/Makefile +0
-0@@ -1,5 +1,6 @@obj-$(CONFIG_X86) += x86/
+lib-y += ctors.o
lib-y += ctype.o
lib-y += list-sort.o
lib-y += parse-size.oxen/lib/ctors.c new file +25
-0@@ -0,0 +1,25 @@ +#include <xen/init.h> +#include <xen/lib.h> + +typedef void (*ctor_func_t )(void ); +extern const ctor_func_t __ctors_start[], __ctors_end[]; + +void __init init_constructors (void ) +{ +const ctor_func_t *f; +for ( f = __ctors_start; f < __ctors_end; ++f ) + (*f)(); + +/* Putting this here seems as good (or bad) as any other place. */ +BUILD_BUG_ON (sizeof (size_t ) !=sizeof (ssize_t )); +} + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* tab-width: 4 +* indent-tabs-mode: nil +* End: +*/
PATCH v3 6/8 lib: move rbtree code
In reply to Jan BeulichBuild this code into an archive, which results in not linking it into x86 final binaries. This saves about 1.5k of dead code.
While moving the source file, take the opportunity and drop the pointless EXPORT_SYMBOL() and an instance of trailing whitespace.
---
xen/common/Makefile | 1 -
xen/lib/Makefile | 1 +
xen/{common => lib}/rbtree.c | 9 +--------
3 files changed, 2 insertions(+), 9 deletions(-)
rename xen/{common => lib}/rbtree.c (98%)xen/common/Makefile +0 -1
@@ -33,7 +33,6 @@ obj-y += preempt.o obj-y += random.o obj-y += rangeset.o obj-y += radix-tree.o -obj-y += rbtree.o obj-y += rcupdate.o obj-y += rwlock.o obj-y += shutdown.o
xen/lib/Makefile +1 -0
@@ -4,3 +4,4 @@ lib-y += ctors.o lib-y += ctype.o lib-y += list-sort.o lib-y += parse-size.o +lib-y += rbtree.o
xen/lib/rbtree.c renamed from xen/common/rbtree.c +1 -8
@@ -25,7 +25,7 @@#include <xen/rbtree.h> /* -* red-black trees properties: http://en.wikipedia.org/wiki/Rbtree +* red-black trees properties: http://en.wikipedia.org/wiki/Rbtree * * 1) A node is either red or black * 2) The root is black
@@ -223,7 +223,6 @@ void rb_insert_color(struct rb_node *node, struct rb_root *root) } } } -EXPORT_SYMBOL (rb_insert_color);static void __rb_erase_color (struct rb_node *parent,struct rb_root *root) {
@@ -467,7 +466,6 @@ void rb_erase(struct rb_node *node, struct rb_root *root)if (rebalance)__rb_erase_color (rebalance, root); } -EXPORT_SYMBOL (rb_erase);/* * This function returns the first node (in sort order) of the tree.
@@ -483,7 +481,6 @@ struct rb_node *rb_first(const struct rb_root *root) n = n->rb_left;return n; } -EXPORT_SYMBOL (rb_first);struct rb_node *rb_last (const struct rb_root *root) {
@@ -496,7 +493,6 @@ struct rb_node *rb_last(const struct rb_root *root) n = n->rb_right;return n; } -EXPORT_SYMBOL (rb_last);struct rb_node *rb_next (const struct rb_node *node) {
@@ -528,7 +524,6 @@ struct rb_node *rb_next(const struct rb_node *node)return parent; } -EXPORT_SYMBOL (rb_next);struct rb_node *rb_prev (const struct rb_node *node) {
@@ -557,7 +552,6 @@ struct rb_node *rb_prev(const struct rb_node *node)return parent; } -EXPORT_SYMBOL (rb_prev);void rb_replace_node (struct rb_node *victim,struct rb_node *new,struct rb_root *root)
@@ -574,4 +568,3 @@ void rb_replace_node(struct rb_node *victim, struct rb_node *new,/* Copy the pointers/colour from the victim to the replacement */ *new = *victim; } -EXPORT_SYMBOL (rb_replace_node);
Re: [PATCH v3 6/8] lib: move rbtree code
Hi,
Quoted 9 lines · Jan Beulich
Build this code into an archive, which results in not linking it into x86 final binaries. This saves about 1.5k of dead code.
While moving the source file, take the opportunity and drop the pointless
EXPORT_SYMBOL()and an instance of trailing whitespace.Signed-off-by Jan Beulich <[email protected]>
Cheers
Bertrand
Quoted 99 lines
---
xen/common/Makefile | 1 - xen/lib/Makefile | 1 + xen/{common => lib}/rbtree.c | 9 +-------- 3 files changed, 2 insertions(+), 9 deletions(-)rename xen/{common =>
lib}/rbtree.c(98%)xen/common/Makefile +0
-0@@ -33,7 +33,6 @@ obj-y += preempt.oobj-y += random.o
obj-y += rangeset.o
obj-y += radix-tree.o
-obj-y += rbtree.o
obj-y += rcupdate.o
obj-y += rwlock.o
obj-y += shutdown.oxen/lib/Makefile +0
-0@@ -4,3 +4,4 @@ lib-y += ctors.olib-y += ctype.o
lib-y += list-sort.o
lib-y += parse-size.oxen/lib/Makefile +1
-0+lib-y += rbtree.oxen/lib/rbtree.c renamed from xen/common/rbtree.c +1
-8@@ -25,7 +25,7 @@#include <xen/rbtree.h> /* -* red-black trees properties: http://en.wikipedia.org/wiki/Rbtree +* red-black trees properties: http://en.wikipedia.org/wiki/Rbtree * * 1) A node is either red or black * 2) The root is black @@ -223,7 +223,6 @@ void rb_insert_color(struct rb_node *node, struct rb_root *root) } } } -EXPORT_SYMBOL (rb_insert_color);static void __rb_erase_color (struct rb_node *parent,struct rb_root *root) {@@ -467,7 +466,6 @@ void rb_erase(struct rb_node *node, struct rb_root *root)if (rebalance)__rb_erase_color (rebalance, root); } -EXPORT_SYMBOL (rb_erase);/* * This function returns the first node (in sort order) of the tree. @@ -483,7 +481,6 @@ struct rb_node *rb_first(const struct rb_root *root) n = n->rb_left;return n; } -EXPORT_SYMBOL (rb_first);struct rb_node *rb_last (const struct rb_root *root) {@@ -496,7 +493,6 @@ struct rb_node *rb_last(const struct rb_root *root) n = n->rb_right;return n; } -EXPORT_SYMBOL (rb_last);struct rb_node *rb_next (const struct rb_node *node) {@@ -528,7 +524,6 @@ struct rb_node *rb_next(const struct rb_node *node)return parent; } -EXPORT_SYMBOL (rb_next);struct rb_node *rb_prev (const struct rb_node *node) {@@ -557,7 +552,6 @@ struct rb_node *rb_prev(const struct rb_node *node)return parent; } -EXPORT_SYMBOL (rb_prev);void rb_replace_node (struct rb_node *victim,struct rb_node *new,struct rb_root *root)@@ -574,4 +568,3 @@ void rb_replace_node(struct rb_node *victim, struct rb_node *new,/* Copy the pointers/colour from the victim to the replacement */ *new = *victim; } -EXPORT_SYMBOL (rb_replace_node);
PATCH v3 7/8 lib: move bsearch code
In reply to Jan BeulichConvert this code to an inline function (backed by an instance in an archive in case the compiler decides against inlining), which results in not having it in x86 final binaries. This saves a little bit of dead code.
--- xen/common/Makefile | 1 - xen/common/bsearch.c | 51 -------------------------------------- xen/include/xen/compiler.h | 1 + xen/include/xen/lib.h | 42 ++++++++++++++++++++++++++++++- xen/lib/Makefile | 1 + xen/lib/bsearch.c | 13 ++++++++++ 6 files changed, 56 insertions(+), 53 deletions(-) delete mode 100644 xen/common/bsearch.c create mode 100644 xen/lib/bsearch.c
xen/common/Makefile +0 -1
@@ -1,6 +1,5 @@ obj-$(CONFIG_ARGO) += argo.o obj-y += bitmap.o -obj-y += bsearch.o obj-$(CONFIG_HYPFS_CONFIG) += config_data.o obj-$(CONFIG_CORE_PARKING) += core_parking.o obj-y += cpu.o
xen/common/bsearch.c deleted +0 -51
51 lines not on this page · raw message
xen/include/xen/compiler.h +1 -0
@@ -12,6 +12,7 @@#define inline __inline__#define always_inline __inline__ __attribute__ ((__always_inline__)) +#define gnu_inline __inline__ __attribute__ ((__gnu_inline__))#define noinline __attribute__((__noinline__))#define noreturn __attribute__((__noreturn__))
xen/include/xen/lib.h +41 -1
49 lines not on this page · raw message
xen/lib/Makefile +1 -0
@@ -1,5 +1,6 @@ obj-$(CONFIG_X86) += x86/ +lib-y += bsearch.o lib-y += ctors.o lib-y += ctype.o lib-y += list-sort.o
xen/lib/bsearch.c new file +13 -0
@@ -0,0 +1,13 @@ +/* +* A generic implementation of binary search for the Linux kernel +* +* Copyright (C) 2008-2009 Ksplice, Inc. +* Author: Tim Abbott <[email protected]> +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation; version 2. +*/ + +#define BSEARCH_IMPLEMENTATION +#include <xen/lib.h>
PATCH v3 8/8 lib: move sort code
In reply to Jan BeulichBuild this code into an archive, partly paralleling bsearch().
---
xen/common/Makefile | 1 -
xen/lib/Makefile | 1 +
xen/{common => lib}/sort.c | 0
3 files changed, 1 insertion(+), 1 deletion(-)
rename xen/{common => lib}/sort.c (100%)xen/common/Makefile +0 -1
@@ -36,7 +36,6 @@ obj-y += rcupdate.o obj-y += rwlock.o obj-y += shutdown.o obj-y += softirq.o -obj-y += sort.o obj-y += smp.o obj-y += spinlock.o obj-y += stop_machine.o
xen/lib/Makefile +1 -0
@@ -6,3 +6,4 @@ lib-y += ctype.o lib-y += list-sort.o lib-y += parse-size.o lib-y += rbtree.o +lib-y += sort.o
xen/lib/sort.c renamed from xen/common/sort.c +0 -0
Re: [PATCH v3 8/8] lib: move sort code
Hi,
Quoted 6 lines · Jan Beulich
Build this code into an archive, partly paralleling
bsearch().Signed-off-by Jan Beulich <[email protected]>Acked-by Julien Grall <[email protected]>
Cheers
Bertrand
Quoted 34 lines
---
xen/common/Makefile | 1 - xen/lib/Makefile | 1 + xen/{common => lib}/sort.c | 0 3 files changed, 1 insertion(+), 1 deletion(-)rename xen/{common =>
lib}/sort.c(100%)xen/common/Makefile +0
-0@@ -36,7 +36,6 @@ obj-y += rcupdate.oobj-y += rwlock.o
obj-y += shutdown.o
obj-y += softirq.o
-obj-y += sort.o
obj-y += smp.o
obj-y += spinlock.o
obj-y += stop_machine.oxen/lib/Makefile +0
-0@@ -6,3 +6,4 @@ lib-y += ctype.olib-y += list-sort.o
lib-y += parse-size.o
lib-y += rbtree.oxen/lib/Makefile +1
-0+lib-y += sort.oxen/lib/sort.c renamed from xen/common/sort.c +0
-0
On Mon, Nov 23, 2020 at 04:16:02PM +0100, Jan Beulich wrote:
[...]
Quoted 9 lines
1: xen: fix build when $(obj-y) consists of just blanks 2: lib: collect library files in an archive
3: lib: move list sorting code
4: lib: moveparse_size_and_unit()
5: lib: moveinit_constructors()
6: lib: move rbtree code
7: lib: move bsearch code
8: lib: move sort code
Hi Jan,
I will review this today, sorry for the delay.
Regards
Bertrand
Quoted 35 lines · Jan Beulich
In a few cases we link in library-like functions when they're not actually needed. While we could use
Kconfigoptions for each one of them, I think the better approach for such generic code is to build it always (thus making sure a build issue can't be introduced for these in any however exotic configuration) and then put it into an archive, for the linker to pick up as needed. The series here presents a first few tiny steps towards such a goal.Note that we can't use thin archives yet, due to our tool chain (binutils) baseline being too low.
Further almost immediate steps I'd like to take if the approach meets no opposition are
- split and move the rest ofcommon/lib.c,
- split and movecommon/string.c, dropping the need for all the __HAVE_ARCH_* (implying possible per-arch archives then need to be specified ahead oflib/lib.aon the linker command lines),
- move common/libelf/ and common/libfdt/.v3 has a new 1st patch and some review feedback addressed. See individual patches.
1: xen: fix build when $(obj-y) consists of just blanks 2: lib: collect library files in an archive
3: lib: move list sorting code
4: lib: moveparse_size_and_unit()
5: lib: moveinit_constructors()
6: lib: move rbtree code
7: lib: move bsearch code
8: lib: move sort codeJan
Quoted 1 line · Bertrand Marquis
I will review this today, sorry for the delay.
Thanks for the reviews, and no problem at all. Since iirc it was you who asked on the last community call, I wanted to point out that despite your reviews and despite Wei's acks the series still won't be able to go in, because patches 2 and 3 are still lacking Arm maintainer acks.
Jan
Quoted 8 lines · Jan Beulich
Quoted 1 line · Bertrand Marquis
I will review this today, sorry for the delay.
Thanks for the reviews, and no problem at all. Since iirc it was you who asked on the last community call, I wanted to point out that despite your reviews and despite Wei's acks the series still won't be able to go in, because patches 2 and 3 are still lacking Arm maintainer acks.
I am waiting on Anthony's input before giving my ack on patch 2. I am not sure whether he is already on holidays.
Cheers,
Signature · 1 line
Julien Grall
Quoted 11 lines · Julien Grall
Quoted 8 lines · Jan Beulich
Quoted 1 line · Bertrand Marquis
I will review this today, sorry for the delay.
Thanks for the reviews, and no problem at all. Since iirc it was you who asked on the last community call, I wanted to point out that despite your reviews and despite Wei's acks the series still won't be able to go in, because patches 2 and 3 are still lacking Arm maintainer acks.
I am waiting on Anthony's input before giving my ack on patch 2.
Well, okay. I'll continue to wait then. What about patch 3 though?
Jan