kbuild changes, thin archives, --gc-sections
Subsystems (10)
Nicholas Piggin
reviewerv2 cover kbuild changes, thin archives, --gc-sections
Hi,
I would like to submit the kbuild changes in patches 1-3 for consideration.
I've taken on the feedback, so thanks everybody for that. The biggest change since last time is a more general way for architectures to do a post-link pass in patch 3.
On the question of whether to enable thin archives unconditionally, I prefer to have architectures enable them as they are tested. But I would like to see everybody moved as soon as possible and the incremental linking removed.
All patches should be basically noops without arch enablement, so I include initial powerpc enablement in patches 4-6 for reference, but I will submit those via powerpc maintainer if the kbuild changes are merged.
Thanks,
Nick
Nicholas Piggin (4):
kbuild: allow archs to select build for link dead code/data
elimination
kbuild: add arch specific post-link pass powerpc/64: use linker dce
powerpc: use the new post-link pass to check relocations
Stephen Rothwell (2):
kbuild: allow architectures to use thin archives instead of ld -r
powerpc: switch to using thin archives
Documentation/kbuild/makefiles.txt | 10 +++++ Makefile | 9 ++++ arch/Kconfig | 26 ++++++++++++ arch/powerpc/Kconfig | 1 + arch/powerpc/Makefile | 17 ++------ arch/powerpc/Makefile.postlink | 31 ++++++++++++++ arch/powerpc/kernel/Makefile | 3 ++ arch/powerpc/kernel/vmlinux.lds.S | 2 +- arch/powerpc/platforms/Kconfig.cputype | 2 + arch/x86/entry/vdso/Makefile | 6 +-- include/asm-generic/vmlinux.lds.h | 52 ++++++++++++----------- include/linux/compiler.h | 23 +++++++++++ include/linux/export.h | 30 +++++++------- include/linux/init.h | 38 ++++++----------- init/Makefile | 2 + kernel/Makefile | 3 -- scripts/Makefile.build | 25 +++++++++--- scripts/Makefile.modpost | 3 ++ scripts/link-vmlinux.sh | 75 +++++++++++++++++++++++++++++----- 19 files changed, 258 insertions(+), 100 deletions(-) create mode 100644 arch/powerpc/Makefile.postlink
Signature · 1 line
2.8.1
Nicholas Piggin
reviewerPATCH v2 1/6 kbuild: allow architectures to use thin archives instead of ld -r
From: Stephen Rothwell <[email protected]>
ld -r is an incremental link used to create built-in.o files in build subdirectories. It produces relocatable object files containing all its input files, and these are are then pulled together and relocated in the final link. Aside from the bloat, this constrains the final link relocations, which has bitten large powerpc builds with unresolvable relocations in the final link.
Alan Modra has recommended the kernel use thin archives for linking. This is an alternative and means that the linker has more information available to it when it links the kernel.
This patch enables a config option architectures can select, which causes all built-in.o files to be built as thin archives. built-in.o files in subdirectories do not get symbol table or index attached, which improves speed and size. The final link pass creates a built-in.o archive in the root output directory which includes the symbol table and index. The linker then uses takes this file to link.
The --whole-archive linker option is required, because the linker now has visibility to every individual object file, and it will otherwise just completely avoid including those without external references (consider a file with EXPORT_SYMBOL or initcall or hardware exceptions as its only entry points). The traditional built works "by luck" as built-in.o files are large enough that they're going to get external references. However this optimisation is unpredictable for the kernel (due to above external references), ineffective at culling unused, and costly because the .o files have to be searched for references. Superior alternatives for link-time culling should be used instead.
Build characteristics for inclink vs thinarc, on a small powerpc64le pseries VM with a modest .config:
inclink thinarc
sizes
vmlinux 15 618 680 15 625 028
sum of all built-in.o 56 091 808 1 054 334
sum excluding root built-in.o 151 430
find -name built-in.o | xargs rm ; time make vmlinux
real 22.772s 21.143s user 13.280s 13.430s
sys 4.310s 2.750s
- Final kernel pulled in only about 6K more, which shows how ineffective the object file culling is.
- Build performance looks improved due to less pagecache activity. On IO constrained systems it could be a bigger win.
- Build size saving is significant.
Side note, the toochain understands archives, so there's some tricks,
$ ar t built-in.o # list all files you linked with $ size built-in.o # and their sizes $ objdump -d built-in.o # disassembly (unrelocated) with filenames
Implementation by sfr, minor tweaks by npiggin.
---
Changes since v1
- Fixed um build breakage
- Fixed linking against lib.a archives (add symbol table)
- Tested x86 builds
- Tested arm64 defconfig thin archives cross compile inclinc - 385s 2.7GB; thinarc - 377s 1.8G
arch/Kconfig | 6 +++++ scripts/Makefile.build | 23 +++++++++++++--- scripts/link-vmlinux.sh | 71 +++++++++++++++++++++++++++++++++++++++++-------- 3 files changed, 85 insertions(+), 15 deletions(-)
arch/Kconfig +6 -0
@@ -461,6 +461,12 @@ config CC_STACKPROTECTOR_STRONG endchoice +config THIN_ARCHIVES + bool + help + Select this if the architecture wants to use thin archives + instead of ld -r to create the built-in.o files. + config HAVE_ARCH_WITHIN_STACK_FRAMES bool help
scripts/Makefile.build +19 -4
@@ -358,12 +358,22 @@ $(sort $(subdir-obj-y)): $(subdir-ym) ; # Rule to compile a set of .o files into one .o file # ifdef builtin-target -quiet_cmd_link_o_target = LD $@ + +ifdef CONFIG_THIN_ARCHIVES + cmd_make_builtin = rm -f $@; $(AR) rcST$(KBUILD_ARFLAGS) + cmd_make_empty_builtin = rm -f $@; $(AR) rcST$(KBUILD_ARFLAGS) + quiet_cmd_link_o_target = AR $@ +else + cmd_make_builtin = $(LD) $(ld_flags) -r -o + cmd_make_empty_builtin = rm -f $@; $(AR) rcs$(KBUILD_ARFLAGS) + quiet_cmd_link_o_target = LD $@ +endif + # If the list of objects to link is empty, just create an empty built-in.o cmd_link_o_target = $(if $(strip $(obj-y)),\ - $(LD) $(ld_flags) -r -o $@ $(filter $(obj-y), $^) \ + $(cmd_make_builtin) $@ $(filter $(obj-y), $^) \ $(cmd_secanalysis),\ - rm -f $@; $(AR) rcs$(KBUILD_ARFLAGS) $@) + $(cmd_make_empty_builtin) $@) $(builtin-target): $(obj-y) FORCE $(call if_changed,link_o_target)
@@ -389,7 +399,12 @@ $(modorder-target): $(subdir-ym) FORCE # ifdef lib-target quiet_cmd_link_l_target = AR $@ -cmd_link_l_target = rm -f $@; $(AR) rcs$(KBUILD_ARFLAGS) $@ $(lib-y) + +ifdef CONFIG_THIN_ARCHIVES + cmd_link_l_target = rm -f $@; $(AR) rcT$(KBUILD_ARFLAGS) $@ $(lib-y) +else + cmd_link_l_target = rm -f $@; $(AR) rcs$(KBUILD_ARFLAGS) $@ $(lib-y) +endif $(lib-target): $(lib-y) FORCE $(call if_changed,link_l_target)
scripts/link-vmlinux.sh +60 -11
102 lines not on this page · raw message
Signature · 1 line
2.8.1
Nicholas Piggin
reviewerPATCH v2 2/6 kbuild: allow archs to select link dead code/data elimination
In reply to Nicholas PigginIntroduce LD_DEAD_CODE_DATA_ELIMINATION option for architectures to select to build with -ffunction-sections, -fdata-sections, and link with --gc-sections. It requires some work (documented) to ensure all unreferenced entrypoints are live, and requires toolchain and build verification, so it is made a per-arch option for now.
On a random powerpc64le build, this yelds a significant size saving, it boots and runs fine, but there is a lot I haven't tested as yet, so these savings may be reduced if there are bugs in the link.
text data bss dec filename
11169741 1180744 1923176 14273661 vmlinux 10445269 1004127 1919707 13369103 vmlinux.dce
~700K text, ~170K data, 6% removed from kernel image size.
---
Since v1
- More descriptive config option name
- Improve some comments
- Tested x86 builds, boot in KVM
Makefile | 9 +++++++ arch/Kconfig | 13 ++++++++++ arch/x86/entry/vdso/Makefile | 6 ++--- include/asm-generic/vmlinux.lds.h | 52 ++++++++++++++++++++++----------------- include/linux/compiler.h | 23 +++++++++++++++++ include/linux/export.h | 30 +++++++++++----------- include/linux/init.h | 38 ++++++++++------------------ init/Makefile | 2 ++ kernel/Makefile | 3 --- scripts/Makefile.build | 2 +- 10 files changed, 107 insertions(+), 71 deletions(-)
Makefile +9 -0
@@ -622,6 +622,11 @@ include arch/$(SRCARCH)/Makefile KBUILD_CFLAGS += $(call cc-option,-fno-delete-null-pointer-checks,) KBUILD_CFLAGS += $(call cc-disable-warning,maybe-uninitialized,) +ifdef CONFIG_LD_DEAD_CODE_DATA_ELIMINATION +KBUILD_CFLAGS += $(call cc-option,-ffunction-sections,) +KBUILD_CFLAGS += $(call cc-option,-fdata-sections,) +endif + ifdef CONFIG_CC_OPTIMIZE_FOR_SIZE KBUILD_CFLAGS += -Os else
@@ -802,6 +807,10 @@ LDFLAGS_BUILD_ID = $(patsubst -Wl$(comma)%,%,\ KBUILD_LDFLAGS_MODULE += $(LDFLAGS_BUILD_ID) LDFLAGS_vmlinux += $(LDFLAGS_BUILD_ID) +ifdef CONFIG_LD_DEAD_CODE_DATA_ELIMINATION +LDFLAGS_vmlinux += $(call ld-option, --gc-sections,) +endif + ifeq ($(CONFIG_STRIP_ASM_SYMS),y) LDFLAGS_vmlinux += $(call ld-option, -X,) endif
arch/Kconfig +13 -0
@@ -467,6 +467,19 @@ config THIN_ARCHIVES Select this if the architecture wants to use thin archives instead of ld -r to create the built-in.o files. +config LD_DEAD_CODE_DATA_ELIMINATION + bool + help + Select this if the architecture wants to do dead code and + data elimination with the linker by compiling with + -ffunction-sections -fdata-sections and linking with + --gc-sections. + + This requires that the arch annotates or otherwise protects + its external entry points from being discarded. Linker scripts + must also merge .text.*, .data.*, and .bss.* correctly into + output sections. + config HAVE_ARCH_WITHIN_STACK_FRAMES bool help
arch/x86/entry/vdso/Makefile +2 -4
@@ -2,7 +2,6 @@ # Building vDSO images for x86. # -KBUILD_CFLAGS += $(DISABLE_LTO) KASAN_SANITIZE := n UBSAN_SANITIZE := n OBJECT_FILES_NON_STANDARD := y
@@ -49,8 +48,7 @@ export CPPFLAGS_vdso.lds += -P -C VDSO_LDFLAGS_vdso.lds = -m64 -Wl,-soname=linux-vdso.so.1 \ -Wl,--no-undefined \ - -Wl,-z,max-page-size=4096 -Wl,-z,common-page-size=4096 \ - $(DISABLE_LTO) + -Wl,-z,max-page-size=4096 -Wl,-z,common-page-size=4096 $(obj)/vdso64.so.dbg: $(src)/vdso.lds $(vobjs) FORCE $(call if_changed,vdso)
@@ -171,7 +169,7 @@ quiet_cmd_vdso = VDSO $@ sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@' VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=both) \ - $(call cc-ldoption, -Wl$(comma)--build-id) -Wl,-Bsymbolic $(LTO_CFLAGS) + $(call cc-ldoption, -Wl$(comma)--build-id) -Wl,-Bsymbolic GCOV_PROFILE := n #
include/asm-generic/vmlinux.lds.h +29 -23
174 lines not on this page · raw message
include/linux/compiler.h +23 -0
@@ -182,6 +182,29 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);# define unreachable () do { } while (1)#endif +/* +* KENTRY - kernel entry point +* This can be used to annotate symbols (functions or data) that are used +* without their linker symbol being referenced explicitly. For example, +* interrupt vector handlers, or functions in the kernel image that are found +* programatically. +* +* Not required for symbols exported with EXPORT_SYMBOL, or initcalls. Those +* are handled in their own way (with KEEP() in linker scripts). +* +* KENTRY can be avoided if the symbols in question are marked as KEEP() in the +* linker script. For example an architecture could KEEP() its entire +* boot/exception vector code rather than annotate each function and data. +*/ +#ifndef KENTRY +# define KENTRY (sym) \ + extern typeof(sym) sym; \ + static const unsigned long __kentry_##sym \ + __used \ + __attribute__((section("___kentry" "+" #sym ), used)) \ + = (unsigned long)&sym; +#endif +#ifndef RELOC_HIDE # define RELOC_HIDE (ptr, off) \ ({ unsigned long __ptr; \
include/linux/export.h +15 -15
@@ -1,5 +1,6 @@#ifndef _LINUX_EXPORT_H#define _LINUX_EXPORT_H +/* * Export symbols from the kernel to modules. Forked from module.h * to reduce the amount of pointless cruft we feed to gcc when only
@@ -42,27 +43,26 @@ extern struct module __this_module;#ifdef CONFIG_MODVERSIONS /* Mark the CRC weak since genksyms apparently decides not to * generate a checksums for some symbols */ -#define __CRC_SYMBOL (sym, sec) \ - extern __visible void *__crc_##sym __attribute__((weak)); \ - static const unsigned long __kcrctab_##sym \ - __used \ - __attribute__((section("___kcrctab" sec "+" #sym), unused)) \ +#define __CRC_SYMBOL (sym, sec) \ + extern __visible void *__crc_##sym __attribute__((weak)); \ + static const unsigned long __kcrctab_##sym \ + __used \ + __attribute__((section("___kcrctab" sec "+" #sym), used)) \ = (unsigned long) &__crc_##sym;#else #define __CRC_SYMBOL (sym, sec)#endif /* For every exported symbol, place a struct in the __ksymtab section */ -#define ___EXPORT_SYMBOL (sym, sec) \ - extern typeof(sym) sym; \ - __CRC_SYMBOL(sym, sec) \ - static const char __kstrtab_##sym[] \ - __attribute__((section("__ksymtab_strings"), aligned(1))) \ - = VMLINUX_SYMBOL_STR(sym); \ - extern const struct kernel_symbol __ksymtab_##sym; \ - __visible const struct kernel_symbol __ksymtab_##sym \ - __used \ - __attribute__((section("___ksymtab" sec "+" #sym), unused)) \ +#define ___EXPORT_SYMBOL (sym, sec) \ + extern typeof(sym) sym; \ + __CRC_SYMBOL(sym, sec) \ + static const char __kstrtab_##sym[] \ + __attribute__((section("__ksymtab_strings"), aligned(1))) \ + = VMLINUX_SYMBOL_STR(sym); \ + static const struct kernel_symbol __ksymtab_##sym \ + __used \ + __attribute__((section("___ksymtab" sec "+" #sym), used)) \ = { (unsigned long)&sym, __kstrtab_##sym }#if defined(__KSYM_DEPS__)
include/linux/init.h +13 -25
@@ -150,24 +150,8 @@ extern bool initcall_debug;#ifndef __ASSEMBLY__ -#ifdef CONFIG_LTO -/* Work around a LTO gcc problem: when there is no reference to a variable -* in a module it will be moved to the end of the program. This causes -* reordering of initcalls which the kernel does not like. -* Add a dummy reference function to avoid this. The function is -* deleted by the linker. -*/ -#define LTO_REFERENCE_INITCALL(x) \ - ; /* yes this is needed */ \ - static __used __exit void *reference_##x(void) \ - { \ - return &x; \ - } -#else -#define LTO_REFERENCE_INITCALL (x) -#endif - -/* initcalls are now grouped by functionality into separate +/* +* initcalls are now grouped by functionality into separate * subsections. Ordering inside the subsections is determined * by link order. * For backwards compatibility, initcall() puts the call in
@@ -175,12 +159,16 @@ extern bool initcall_debug;* * The `id' arg to __define_initcall() is needed so that multiple initcalls * can point at the same handler without causing duplicate-symbol build errors. +* +* Initcalls are run by placing pointers in initcall sections that the +* kernel iterates at runtime. The linker can do dead code / data elimination +* and remove that completely, so the initcall sections have to be marked +* as KEEP() in the linker script. */ #define __define_initcall (fn, id) \ static initcall_t __initcall_##fn##id __used \ - __attribute__((__section__(".initcall" #id ".init"))) = fn; \ - LTO_REFERENCE_INITCALL(__initcall_##fn##id) + __attribute__((__section__(".initcall" #id ".init"))) = fn;/* * Early initcalls run before initializing SMP.
@@ -216,15 +204,15 @@ extern bool initcall_debug;#define __initcall (fn) device_initcall(fn) -#define __exitcall (fn) \ +#define __exitcall (fn) \ static exitcall_t __exitcall_##fn __exit_call = fn -#define console_initcall (fn) \ - static initcall_t __initcall_##fn \ +#define console_initcall (fn) \ + static initcall_t __initcall_##fn \ __used __section(.con_initcall.init) = fn -#define security_initcall (fn) \ - static initcall_t __initcall_##fn \ +#define security_initcall (fn) \ + static initcall_t __initcall_##fn \ __used __section(.security_initcall.init) = fnstruct obs_kernel_param {
init/Makefile +2 -0
@@ -2,6 +2,8 @@ # Makefile for the linux kernel. # +ccflags-y := -fno-function-sections -fno-data-sections + obj-y := main.o version.o mounts.o ifneq ($(CONFIG_BLK_DEV_INITRD),y) obj-y += noinitramfs.o
kernel/Makefile +0 -3
@@ -29,9 +29,6 @@ KCOV_INSTRUMENT_extable.o := n KCOV_INSTRUMENT_kcov.o := n KASAN_SANITIZE_kcov.o := n -# cond_syscall is currently not LTO compatible -CFLAGS_sys_ni.o = $(DISABLE_LTO) - obj-y += sched/ obj-y += locking/ obj-y += power/
scripts/Makefile.build +1 -1
@@ -147,7 +147,7 @@ $(multi-objs-y:.o=.s) : modname = $(modname-multi) $(multi-objs-y:.o=.lst) : modname = $(modname-multi) quiet_cmd_cc_s_c = CC $(quiet_modtag) $@ -cmd_cc_s_c = $(CC) $(c_flags) $(DISABLE_LTO) -fverbose-asm -S -o $@ $< +cmd_cc_s_c = $(CC) $(c_flags) -fverbose-asm -S -o $@ $< $(obj)/%.s: $(src)/%.c FORCE $(call if_changed_dep,cc_s_c)
Signature · 1 line
2.8.1
Nicholas Piggin
reviewerPATCH v2 6/6 powerpc: use the new post-link pass to check relocations
In reply to Nicholas PigginCurrently powerpc has to introduce a dependency on its default build target zImage in order to run a relocation check pass over the linked vmlinux. This is deficient because the check is not run if the plain vmlinux target is built, or if one of the other boot targets is built.
Switch to using the kbuild post-link pass in order to run this check. In future powerpc will use this to do more complicated operations, but initially using it for something simple is a good first step.
--- arch/powerpc/Kconfig | 1 + arch/powerpc/Makefile | 11 ----------- arch/powerpc/Makefile.postlink | 31 +++++++++++++++++++++++++++++++ 3 files changed, 32 insertions(+), 11 deletions(-) create mode 100644 arch/powerpc/Makefile.postlink
arch/powerpc/Kconfig +1 -0
@@ -85,6 +85,7 @@ config ARCH_HAS_DMA_SET_COHERENT_MASK config PPC bool default y + select BUILD_ARCH_POSTLINK select ARCH_MIGHT_HAVE_PC_PARPORT select ARCH_MIGHT_HAVE_PC_SERIO select BINFMT_ELF
arch/powerpc/Makefile +0 -11
@@ -270,17 +270,6 @@ PHONY += $(BOOT_TARGETS1) $(BOOT_TARGETS2) boot := arch/$(ARCH)/boot -ifeq ($(CONFIG_RELOCATABLE),y) -quiet_cmd_relocs_check = CALL $< - cmd_relocs_check = $(CONFIG_SHELL) $< "$(OBJDUMP)" "$(obj)/vmlinux" - -PHONY += relocs_check -relocs_check: arch/powerpc/relocs_check.sh vmlinux - $(call cmd,relocs_check) - -zImage: relocs_check -endif - $(BOOT_TARGETS1): vmlinux $(Q)$(MAKE) ARCH=ppc64 $(build)=$(boot) $(patsubst %,$(boot)/%,$@) $(BOOT_TARGETS2): vmlinux
arch/powerpc/Makefile.postlink new file +31 -0
@@ -0,0 +1,31 @@ +# =========================================================================== +# Post-link powerpc pass +# =========================================================================== +# +# 1. Check that vmlinux relocations look sane + +PHONY := __archpost +__archpost: + +include include/config/auto.conf +include scripts/Kbuild.include + +quiet_cmd_relocs_check = CHKREL $@ + cmd_relocs_check = $(CONFIG_SHELL) arch/powerpc/relocs_check.sh "$(OBJDUMP)" "$@" + +# Prevent complainints about nothing to be done +vmlinux: FORCE + @echo -n +ifeq ($(CONFIG_RELOCATABLE),y) + $(call if_changed,relocs_check) +endif + +%.ko: FORCE + @echo -n + + +PHONY += FORCE + +FORCE: + +.PHONY: $(PHONY)
Signature · 1 line
2.8.1
Nicholas Piggin
reviewerPATCH v2 3/6 kbuild: add arch specific post-link pass
In reply to Nicholas PigginAdd an option for architectures to pass over modules after they are linked. powerpc will use this to check linker relocations for sanity, and possibly to fix up alternate instruction patch relocations.
---
Since v1,
- Switched to a more flexible arch makefile invocation.
- Provide a powerpc patch to use it to help existing build issue (rather than only justification being out-of-tree patch).
Documentation/kbuild/makefiles.txt | 10 ++++++++++ arch/Kconfig | 7 +++++++ scripts/Makefile.modpost | 3 +++ scripts/link-vmlinux.sh | 4 ++++ 4 files changed, 24 insertions(+)
Documentation/kbuild/makefiles.txt +10 -0
@@ -41,6 +41,7 @@ This document describes the Linux kernel Makefiles. --- 6.8 Custom kbuild commands --- 6.9 Preprocessing linker scripts --- 6.10 Generic header files + --- 6.11 Post-link pass === 7 Kbuild syntax for exported headers --- 7.1 header-y
@@ -1237,6 +1238,15 @@ When kbuild executes, the following steps are followed (roughly): to list the file in the Kbuild file. See "7.4 generic-y" for further info on syntax etc. +--- 6.11 Post-link pass + + CONFIG_BUILD_ARCH_POSTLINK can be selected in order to have + arch/?/Makefile.postlink invoked on vmlinux and module.ko + files after final link. + + For example, powerpc uses this to check relocations on the + linked vmlinux file. + === 7 Kbuild syntax for exported headers The kernel includes a set of headers that is exported to userspace.
arch/Kconfig +7 -0
@@ -461,6 +461,13 @@ config CC_STACKPROTECTOR_STRONG endchoice +config BUILD_ARCH_POSTLINK + bool + help + Select this if the architecture wants to have a Makefile invoked + on modules and vmlinux after they are linked. The architecture + must provide arch/?/Makefile.postlink + config THIN_ARCHIVES bool help
scripts/Makefile.modpost +3 -0
@@ -123,6 +123,9 @@ quiet_cmd_ld_ko_o = LD [M] $@ $(modules): %.ko :%.o %.mod.o FORCE $(call if_changed,ld_ko_o) +ifdef CONFIG_BUILD_ARCH_POSTLINK + $(Q)$(MAKE) -f $(srctree)/arch/$(SRCARCH)/Makefile.postlink $@ +endif targets += $(modules)
scripts/link-vmlinux.sh +4 -0
@@ -279,6 +279,10 @@ fi info LD vmlinux vmlinux_link "${kallsymso}" vmlinux +if [ -n "${CONFIG_BUILD_ARCH_POSTLINK}" ]; then + ${MAKE} -f ${srctree}/arch/${SRCARCH}/Makefile.postlink vmlinux +fi + if [ -n "${CONFIG_BUILDTIME_EXTABLE_SORT}" ]; then info SORTEX vmlinux sortextable vmlinux
Signature · 1 line
2.8.1
Nicholas Piggin
reviewerPATCH v2 4/6 powerpc: switch to using thin archives
In reply to Nicholas PigginFrom: Stephen Rothwell <[email protected]>
Some change to the way we invoke ar is required so it can be used by scripts/link-vmlinux.sh
--- arch/powerpc/Makefile | 6 ++++-- arch/powerpc/platforms/Kconfig.cputype | 1 + 2 files changed, 5 insertions(+), 2 deletions(-)
arch/powerpc/Makefile +4 -2
@@ -23,7 +23,8 @@ CROSS32AR := $(CROSS32_COMPILE)ar ifeq ($(HAS_BIARCH),y) ifeq ($(CROSS32_COMPILE),) CROSS32CC := $(CC) -m32 -CROSS32AR := GNUTARGET=elf32-powerpc $(AR) +CROSS32AR := $(AR) +KBUILD_ARFLAGS += --target elf32-powerpc endif endif
@@ -93,7 +94,8 @@ ifeq ($(HAS_BIARCH),y) override AS += -a$(CONFIG_WORD_SIZE) override LD += -m elf$(CONFIG_WORD_SIZE)$(LDEMULATION) override CC += -m$(CONFIG_WORD_SIZE) -override AR := GNUTARGET=elf$(CONFIG_WORD_SIZE)-$(GNUTARGET) $(AR) +override AR := $(AR) +KBUILD_ARFLAGS += --target elf$(CONFIG_WORD_SIZE)-$(GNUTARGET) endif LDFLAGS_vmlinux-y := -Bstatic
arch/powerpc/platforms/Kconfig.cputype +1 -0
@@ -1,6 +1,7 @@ config PPC64 bool "64-bit kernel" default n + select THIN_ARCHIVES select ZLIB_DEFLATE help This option selects whether a 32-bit or a 64-bit kernel
Signature · 1 line
2.8.1
Nicholas Piggin
reviewerPATCH v2 5/6 powerpc/64: use linker dead code elimination
In reply to Nicholas Piggin--- arch/powerpc/kernel/Makefile | 3 +++ arch/powerpc/kernel/vmlinux.lds.S | 2 +- arch/powerpc/platforms/Kconfig.cputype | 1 + 3 files changed, 5 insertions(+), 1 deletion(-)
arch/powerpc/kernel/Makefile +3 -0
@@ -4,7 +4,10 @@ CFLAGS_ptrace.o += -DUTS_MACHINE='"$(UTS_MACHINE)"' +ccflags-y += -fno-function-sections -fno-data-sections + subdir-ccflags-$(CONFIG_PPC_WERROR) := -Werror +subdir-ccflags-y += -fno-function-sections -fno-data-sections ifeq ($(CONFIG_PPC64),y) CFLAGS_prom_init.o += $(NO_MINIMAL_TOC)
arch/powerpc/kernel/vmlinux.lds.S +1 -1
@@ -50,7 +50,7 @@ SECTIONS HEAD_TEXT _text = .; /* careful! __ftr_alt_* sections need to be close to .text */ - *(.text .fixup __ftr_alt_* .ref.text) + *(.text .text.* .fixup __ftr_alt_* .ref.text) SCHED_TEXT LOCK_TEXT KPROBES_TEXT
arch/powerpc/platforms/Kconfig.cputype +1 -0
@@ -2,6 +2,7 @@ config PPC64 bool "64-bit kernel" default n select THIN_ARCHIVES + select LD_DEAD_CODE_DATA_ELIMINATION select ZLIB_DEFLATE help This option selects whether a 32-bit or a 64-bit kernel
Signature · 1 line
2.8.1
Hi Nicholas,
Quoted 3 lines · On Thu, 11 Aug 2016 20:16:14 +1000 Nicholas Piggin <[email protected]> wrote:
I would like to submit the kbuild changes in patches 1-3 for consideration.
I would just like to thank Nick for taking my preliminary patches and running with them. There was a lot more to do than I suspected :-)
Quoted 4 lines
All patches should be basically noops without arch enablement, so I include initial powerpc enablement in patches 4-6 for reference, but I will submit those via powerpc maintainer if the kbuild changes are merged.
In this case, if patches 1-3 are merged via the kbuild tree, can I ask that they be put in a separate non-rebaseing topic branch so that they can also be merged into relevant architecture trees.
Signature · 2 lines
Cheers, Stephen Rothwell
Arnd Bergmann
maintainerPATCH 1/1 Xen: remove -fshort-wchar gcc flag
In reply to Nicholas PigginA previous patch added the --no-wchar-size-warning to the Makefile to avoid this harmless warning:
arm-linux-gnueabi-ld: warning: drivers/xen/efi.o uses 2-byte wchar_t yet the output is to use 4-byte wchar_t; use of wchar_t values across objects may fail
Changing kbuild to use thin archives instead of recursive linking unfortunately brings the same warning back during the final link.
This time, we remove the -fshort-wchar flag that originally caused the warning, hopefully fixing the problem for good. I don't see any reason for having the flag in the first place, as the Xen code does not use wchar_t at all.
---
Quoted 5 lines · CEST Nicholas Piggin
Hi,
I would like to submit the kbuild changes in patches 1-3 for consideration.
Quoted 8 lines
I've taken on the feedback, so thanks everybody for that. The biggest change since last time is a more general way for architectures to do a post-link pass in patch 3.
On the question of whether to enable thin archives unconditionally, I prefer to have architectures enable them as they are tested. But I would like to see everybody moved as soon as possible and the incremental linking removed.
It would be nice to get this patch merged along with the thin archive conversion, either by merging it through the xen Tree, or by making it part of Nick's series with an Ack from the xen maintainers.
drivers/xen/Makefile +0 -3
@@ -7,9 +7,6 @@ obj-y += xenbus/ nostackp := $(call cc-option, -fno-stack-protector) CFLAGS_features.o := $(nostackp) -CFLAGS_efi.o += -fshort-wchar -LDFLAGS += $(call ld-option, --no-wchar-size-warning) - dom0-$(CONFIG_ARM64) += arm-device.o dom0-$(CONFIG_PCI) += pci.o dom0-$(CONFIG_USB_SUPPORT) += dbgp.o
Arnd Bergmann
maintainerPATCH 1/1 Xen: remove -fshort-wchar gcc flag
In reply to Nicholas PigginA previous patch added the --no-wchar-size-warning to the Makefile to avoid this harmless warning:
arm-linux-gnueabi-ld: warning: drivers/xen/efi.o uses 2-byte wchar_t yet the output is to use 4-byte wchar_t; use of wchar_t values across objects may fail
Changing kbuild to use thin archives instead of recursive linking unfortunately brings the same warning back during the final link.
This time, we remove the -fshort-wchar flag that originally caused the warning, hopefully fixing the problem for good. I don't see any reason for having the flag in the first place, as the Xen code does not use wchar_t at all.
---
Quoted 5 lines · CEST Nicholas Piggin
Hi,
I would like to submit the kbuild changes in patches 1-3 for consideration.
Quoted 8 lines
I've taken on the feedback, so thanks everybody for that. The biggest change since last time is a more general way for architectures to do a post-link pass in patch 3.
On the question of whether to enable thin archives unconditionally, I prefer to have architectures enable them as they are tested. But I would like to see everybody moved as soon as possible and the incremental linking removed.
It would be nice to get this patch merged along with the thin archive conversion, either by merging it through the xen Tree, or by making it part of Nick's series with an Ack from the xen maintainers.
drivers/xen/Makefile +0 -3
@@ -7,9 +7,6 @@ obj-y += xenbus/ nostackp := $(call cc-option, -fno-stack-protector) CFLAGS_features.o := $(nostackp) -CFLAGS_efi.o += -fshort-wchar -LDFLAGS += $(call ld-option, --no-wchar-size-warning) - dom0-$(CONFIG_ARM64) += arm-device.o dom0-$(CONFIG_PCI) += pci.o dom0-$(CONFIG_USB_SUPPORT) += dbgp.o
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [Xen-devel] [PATCH] Xen: remove -fshort-wchar gcc flag
In reply to Arnd BergmannQuoted 8 lines
Quoted 1 line
Quoted 1 line · On 11.08.16 at 14:39, <[email protected]> wrote:
A previous patch added the --no-wchar-size-warning to the
Makefileto avoid this harmless warning:arm-linux-gnueabi-ld: warning:
drivers/xen/efi.ouses 2-bytewchar_tyet the output is to use 4-bytewchar_t; use ofwchar_tvalues across objects may fail
Quoted 7 lines
Changing kbuild to use thin archives instead of recursive linking unfortunately brings the same warning back during the final link.
This time, we remove the -fshort-wchar flag that originally caused the warning, hopefully fixing the problem for good. I don't see any reason for having the flag in the first place, as the Xen code does not use
wchar_tat all.
It uses efi_char16_t, and by dropping -fshort-wchar you'd open up a trap for anyone to fall into who were to add wide string literals to that same file. EFI using 16-bit characters requires code interfacing with EFI to do so too.
Jan
Re: [PATCH] Xen: remove -fshort-wchar gcc flag
In reply to Arnd BergmannQuoted 8 lines
Quoted 1 line
Quoted 1 line · On 11.08.16 at 14:39, <[email protected]> wrote:
A previous patch added the --no-wchar-size-warning to the
Makefileto avoid this harmless warning:arm-linux-gnueabi-ld: warning:
drivers/xen/efi.ouses 2-bytewchar_tyet the output is to use 4-bytewchar_t; use ofwchar_tvalues across objects may fail
Quoted 7 lines
Changing kbuild to use thin archives instead of recursive linking unfortunately brings the same warning back during the final link.
This time, we remove the -fshort-wchar flag that originally caused the warning, hopefully fixing the problem for good. I don't see any reason for having the flag in the first place, as the Xen code does not use
wchar_tat all.
It uses efi_char16_t, and by dropping -fshort-wchar you'd open up a trap for anyone to fall into who were to add wide string literals to that same file. EFI using 16-bit characters requires code interfacing with EFI to do so too.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Arnd Bergmann
maintainer[EXPERIMENTAL] enable thin archives and --gc-sections on ARM
In reply to Nicholas PigginThis goes on top of Nick's latest version of "[PATCH 0/6 v2] kbuild changes, thin archives, --gc-sections" and enables both features on ARM.
It's a bit half-baked, these are known problems:
- as big-endian support is still broken, I disable it in Kconfig so an allyesconfig build ends up as little-endian
- I've thrown in a change to include/asm-generic/vmlinux.lds.h but don't know whether this is the right way or not. We have to keep .text.fixup linked together with .text, but I separate out .text.unlikely and .text.hot again. This has not caused any link failures for me (yet).
- I mark a ton of sections as KEEP() in vmlinux.lds.S. Some of them might not actually be needed, and I have not spent much time checking what they actually are. However, I did build a few hundred randconfigs without new issues.
arch/arm/Kconfig +2 -0
@@ -83,6 +83,7 @@ config ARM select HAVE_UID16 select HAVE_VIRT_CPU_ACCOUNTING_GEN select IRQ_FORCED_THREADING + select LD_DEAD_CODE_DATA_ELIMINATION select MODULES_USE_ELF_REL select NO_BOOTMEM select OF_EARLY_FLATTREE if OF
@@ -92,6 +93,7 @@ config ARM select PERF_USE_VMALLOC select RTC_LIB select SYS_SUPPORTS_APM_EMULATION + select THIN_ARCHIVES # Above selects are sorted alphabetically; please add new ones # according to that. Thanks. help
arch/arm/kernel/Makefile +3 -0
@@ -13,6 +13,9 @@ endif CFLAGS_REMOVE_return_address.o = -pg +ccflags-y += -fno-function-sections -fno-data-sections +subdir-ccflags-y += -fno-function-sections -fno-data-sections + # Object file lists. obj-y := elf.o entry-common.o irq.o opcodes.o \
arch/arm/kernel/vmlinux-xip.lds.S +13 -13
@@ -12,17 +12,17 @@ #define PROC_INFO \ . = ALIGN(4); \ VMLINUX_SYMBOL(__proc_info_begin) = .; \ - *(.proc.info.init) \ + KEEP(*(.proc.info.init)) \ VMLINUX_SYMBOL(__proc_info_end) = .; #define IDMAP_TEXT \ ALIGN_FUNCTION(); \ VMLINUX_SYMBOL(__idmap_text_start) = .; \ - *(.idmap.text) \ + KEEP(*(.idmap.text)) \ VMLINUX_SYMBOL(__idmap_text_end) = .; \ . = ALIGN(PAGE_SIZE); \ VMLINUX_SYMBOL(__hyp_idmap_text_start) = .; \ - *(.hyp.idmap.text) \ + KEEP(*(.hyp.idmap.text)) \ VMLINUX_SYMBOL(__hyp_idmap_text_end) = .; #ifdef CONFIG_HOTPLUG_CPU
@@ -93,7 +93,7 @@ SECTIONS _stext = .; /* Text and read-only data */ IDMAP_TEXT __exception_text_start = .; - *(.exception.text) + KEEP(*(.exception.text)) __exception_text_end = .; IRQENTRY_TEXT TEXT_TEXT
@@ -114,7 +114,7 @@ SECTIONS __ex_table : AT(ADDR(__ex_table) - LOAD_OFFSET) { __start___ex_table = .; #ifdef CONFIG_MMU - *(__ex_table) + KEEP(*(__ex_table)) #endif __stop___ex_table = .; }
@@ -126,12 +126,12 @@ SECTIONS . = ALIGN(8); .ARM.unwind_idx : { __start_unwind_idx = .; - *(.ARM.exidx*) + KEEP(*(.ARM.exidx*)) __stop_unwind_idx = .; } .ARM.unwind_tab : { __start_unwind_tab = .; - *(.ARM.extab*) + KEEP(*(.ARM.extab*)) __stop_unwind_tab = .; } #endif
@@ -146,14 +146,14 @@ SECTIONS */ __vectors_start = .; .vectors 0xffff0000 : AT(__vectors_start) { - *(.vectors) + KEEP(*(.vectors)) } . = __vectors_start + SIZEOF(.vectors); __vectors_end = .; __stubs_start = .; .stubs ADDR(.vectors) + 0x1000 : AT(__stubs_start) { - *(.stubs) + KEEP(*(.stubs)) } . = __stubs_start + SIZEOF(.stubs); __stubs_end = .;
@@ -169,24 +169,24 @@ SECTIONS } .init.arch.info : { __arch_info_begin = .; - *(.arch.info.init) + KEEP(*(.arch.info.init)) __arch_info_end = .; } .init.tagtable : { __tagtable_begin = .; - *(.taglist.init) + KEEP(*(.taglist.init)) __tagtable_end = .; } #ifdef CONFIG_SMP_ON_UP .init.smpalt : { __smpalt_begin = .; - *(.alt.smp.init) + KEEP(*(.alt.smp.init)) __smpalt_end = .; } #endif .init.pv_table : { __pv_table_begin = .; - *(.pv_table) + KEEP(*(.pv_table)) __pv_table_end = .; } .init.data : {
arch/arm/kernel/vmlinux.lds.S +8 -8
@@ -17,7 +17,7 @@ #define PROC_INFO \ . = ALIGN(4); \ VMLINUX_SYMBOL(__proc_info_begin) = .; \ - *(.proc.info.init) \ + KEEP(*(.proc.info.init)) \ VMLINUX_SYMBOL(__proc_info_end) = .; #define HYPERVISOR_TEXT \
@@ -104,7 +104,7 @@ SECTIONS _stext = .; /* Text and read-only data */ IDMAP_TEXT __exception_text_start = .; - *(.exception.text) + KEEP(*(.exception.text)) __exception_text_end = .; IRQENTRY_TEXT SOFTIRQENTRY_TEXT
@@ -169,14 +169,14 @@ SECTIONS */ __vectors_start = .; .vectors 0xffff0000 : AT(__vectors_start) { - *(.vectors) + KEEP(*(.vectors)) } . = __vectors_start + SIZEOF(.vectors); __vectors_end = .; __stubs_start = .; .stubs ADDR(.vectors) + 0x1000 : AT(__stubs_start) { - *(.stubs) + KEEP(*(.stubs)) } . = __stubs_start + SIZEOF(.stubs); __stubs_end = .;
@@ -192,24 +192,24 @@ SECTIONS } .init.arch.info : { __arch_info_begin = .; - *(.arch.info.init) + KEEP(*(.arch.info.init)) __arch_info_end = .; } .init.tagtable : { __tagtable_begin = .; - *(.taglist.init) + KEEP(*(.taglist.init)) __tagtable_end = .; } #ifdef CONFIG_SMP_ON_UP .init.smpalt : { __smpalt_begin = .; - *(.alt.smp.init) + KEEP(*(.alt.smp.init)) __smpalt_end = .; } #endif .init.pv_table : { __pv_table_begin = .; - *(.pv_table) + KEEP(*(.pv_table)) __pv_table_end = .; } .init.data : {
arch/arm/mm/Kconfig +1 -0
@@ -717,6 +717,7 @@ config SWP_EMULATE config CPU_BIG_ENDIAN bool "Build big-endian kernel" depends on ARCH_SUPPORTS_BIG_ENDIAN + depends on !THIN_ARCHIVES help Say Y if you plan on running a kernel in big-endian mode. Note that your board must be properly built and your board
include/asm-generic/vmlinux.lds.h +3 -1
@@ -433,7 +433,9 @@* during second ld run in second ld pass when generating System.map */ #define TEXT_TEXT \ ALIGN_FUNCTION(); \ - *(.text.hot .text .text.fixup .text.unlikely .text.*) \ + *(.text.hot .text.hot.*) \ + *(.text.unlikely .text.unlikely.*) \ + *(.text .text.*) \ *(.ref.text) \ MEM_KEEP(init.text) \ MEM_KEEP(exit.text) \
Arnd Bergmann
maintainerRe: [PATCH] Xen: remove -fshort-wchar gcc flag
In reply to Jan BeulichQuoted 16 lines · CEST Jan Beulich
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 11.08.16 at 14:39, <[email protected]> wrote:
A previous patch added the --no-wchar-size-warning to the
Makefileto avoid this harmless warning:arm-linux-gnueabi-ld: warning:
drivers/xen/efi.ouses 2-bytewchar_tyet the output is to use 4-bytewchar_t; use ofwchar_tvalues across objects may failQuoted 7 lines
Changing kbuild to use thin archives instead of recursive linking unfortunately brings the same warning back during the final link.
This time, we remove the -fshort-wchar flag that originally caused the warning, hopefully fixing the problem for good. I don't see any reason for having the flag in the first place, as the Xen code does not use
wchar_tat all.
Quoted 4 lines
It uses
efi_char16_t, and by dropping -fshort-wchar you'd open up a trap for anyone to fall into who were to add wide string literals to that same file. EFI using 16-bit characters requires code interfacing with EFI to do so too.
I don't understand. How is this different from other source files that use efi_char16_t or the wchar_t definition from include/linux/nls.h?
As far as I can tell, they all use 16-bit characters, but none of the others sets the flag. Maybe we should just always build with -fshort-wchar from the top-level Makefile?
Arnd
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Arnd Bergmann
maintainerRe: [Xen-devel] [PATCH] Xen: remove -fshort-wchar gcc flag
In reply to Jan BeulichQuoted 16 lines · CEST Jan Beulich
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 11.08.16 at 14:39, <[email protected]> wrote:
A previous patch added the --no-wchar-size-warning to the
Makefileto avoid this harmless warning:arm-linux-gnueabi-ld: warning:
drivers/xen/efi.ouses 2-bytewchar_tyet the output is to use 4-bytewchar_t; use ofwchar_tvalues across objects may failQuoted 7 lines
Changing kbuild to use thin archives instead of recursive linking unfortunately brings the same warning back during the final link.
This time, we remove the -fshort-wchar flag that originally caused the warning, hopefully fixing the problem for good. I don't see any reason for having the flag in the first place, as the Xen code does not use
wchar_tat all.
Quoted 4 lines
It uses
efi_char16_t, and by dropping -fshort-wchar you'd open up a trap for anyone to fall into who were to add wide string literals to that same file. EFI using 16-bit characters requires code interfacing with EFI to do so too.
I don't understand. How is this different from other source files that use efi_char16_t or the wchar_t definition from include/linux/nls.h?
As far as I can tell, they all use 16-bit characters, but none of the others sets the flag. Maybe we should just always build with -fshort-wchar from the top-level Makefile?
Arnd
Re: [Xen-devel] [PATCH] Xen: remove -fshort-wchar gcc flag
Quoted 18 lines
Quoted 1 line
Quoted 1 line · On 11.08.16 at 16:01, <[email protected]> wrote:
Quoted 16 lines · CEST Jan Beulich
Quoted 15 lines
Quoted 1 line
Quoted 1 line · On 11.08.16 at 14:39, <[email protected]> wrote:
A previous patch added the --no-wchar-size-warning to the
Makefileto avoid this harmless warning:arm-linux-gnueabi-ld: warning:
drivers/xen/efi.ouses 2-bytewchar_tyet the output is to use 4-bytewchar_t; use ofwchar_tvalues across objects may failChanging kbuild to use thin archives instead of recursive linking unfortunately brings the same warning back during the final link.
This time, we remove the -fshort-wchar flag that originally caused the warning, hopefully fixing the problem for good. I don't see any reason for having the flag in the first place, as the Xen code does not use
wchar_tat all.
Quoted 7 lines
Quoted 4 lines
It uses
efi_char16_t, and by dropping -fshort-wchar you'd open up a trap for anyone to fall into who were to add wide string literals to that same file. EFI using 16-bit characters requires code interfacing with EFI to do so too.I don't understand. How is this different from other source files that use
efi_char16_tor thewchar_tdefinition frominclude/linux/nls.h?
Perhaps they didn't run into the issue yet?
Quoted 3 lines
As far as I can tell, they all use 16-bit characters, but none of the others sets the flag. Maybe we should just always build with -fshort-wchar from the top-level
Makefile?
Quite possible, unless elsewhere in the tree 4-byte characters are needed.
Jan
Re: [PATCH] Xen: remove -fshort-wchar gcc flag
In reply to Arnd BergmannQuoted 18 lines
Quoted 1 line
Quoted 1 line · On 11.08.16 at 16:01, <[email protected]> wrote:
Quoted 16 lines · CEST Jan Beulich
Quoted 15 lines
Quoted 1 line
Quoted 1 line · On 11.08.16 at 14:39, <[email protected]> wrote:
A previous patch added the --no-wchar-size-warning to the
Makefileto avoid this harmless warning:arm-linux-gnueabi-ld: warning:
drivers/xen/efi.ouses 2-bytewchar_tyet the output is to use 4-bytewchar_t; use ofwchar_tvalues across objects may failChanging kbuild to use thin archives instead of recursive linking unfortunately brings the same warning back during the final link.
This time, we remove the -fshort-wchar flag that originally caused the warning, hopefully fixing the problem for good. I don't see any reason for having the flag in the first place, as the Xen code does not use
wchar_tat all.
Quoted 7 lines
Quoted 4 lines
It uses
efi_char16_t, and by dropping -fshort-wchar you'd open up a trap for anyone to fall into who were to add wide string literals to that same file. EFI using 16-bit characters requires code interfacing with EFI to do so too.I don't understand. How is this different from other source files that use
efi_char16_tor thewchar_tdefinition frominclude/linux/nls.h?
Perhaps they didn't run into the issue yet?
Quoted 3 lines
As far as I can tell, they all use 16-bit characters, but none of the others sets the flag. Maybe we should just always build with -fshort-wchar from the top-level
Makefile?
Quite possible, unless elsewhere in the tree 4-byte characters are needed.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [EXPERIMENTAL] enable thin archives and --gc-sections on ARM
In reply to Arnd BergmannQuoted 3 lines · Arnd Bergmann
This goes on top of Nick's latest version of "[PATCH 0/6 v2] kbuild changes, thin archives, --gc-sections" and enables both features on ARM.
[...]
Quoted 10 lines
- I mark a ton of sections as
KEEP()invmlinux.lds.S. Some of them might not actually be needed, and I have not spent much time checking what they actually are. However, I did build a few hundred randconfigs without new issues.index
7396a5f00c5f..61b9b8784036100644
arch/arm/kernel/vmlinux.lds.S line 20
Quoted 5 lines
arch/arm/kernel/vmlinux.lds.S +1
-1@@ -17,7 +17,7 @@ #define PROC_INFO \ . = ALIGN(4); \ VMLINUX_SYMBOL(__proc_info_begin) = .; \ - *(.proc.info.init) \ + KEEP(*(.proc.info.init)) \
OK.
arch/arm/kernel/vmlinux.lds.S SECTIONS · line 107
Quoted 9 lines
arch/arm/kernel/vmlinux.lds.S +1
-1VMLINUX_SYMBOL(__proc_info_end) = .; #define HYPERVISOR_TEXT \@@ -104,7 +104,7 @@ SECTIONS _stext = .; /* Text and read-only data */ IDMAP_TEXT __exception_text_start = .; - *(.exception.text) + KEEP(*(.exception.text))
No need here. The code there has to be referenced from somewhere. If not it should not be kept.
arch/arm/kernel/vmlinux.lds.S SECTIONS · line 172
Quoted 9 lines
arch/arm/kernel/vmlinux.lds.S +1
-1__exception_text_end = .; IRQENTRY_TEXT SOFTIRQENTRY_TEXT@@ -169,14 +169,14 @@ SECTIONS */ __vectors_start = .; .vectors 0xffff0000 : AT(__vectors_start) { - *(.vectors) + KEEP(*(.vectors))
OK.
arch/arm/kernel/vmlinux.lds.S SECTIONS · line 179
Quoted 8 lines
arch/arm/kernel/vmlinux.lds.S +1
-1} . = __vectors_start + SIZEOF(.vectors); __vectors_end = .; __stubs_start = .; .stubs ADDR(.vectors) + 0x1000 : AT(__stubs_start) { - *(.stubs) + KEEP(*(.stubs))
This is referenced from .vectors entries and therefore the KEEP() is not needed. There is nothing to be saved either ways though.
arch/arm/kernel/vmlinux.lds.S SECTIONS · line 195
Quoted 9 lines
arch/arm/kernel/vmlinux.lds.S +1
-1} . = __stubs_start + SIZEOF(.stubs); __stubs_end = .;@@ -192,24 +192,24 @@ SECTIONS } .init.arch.info : { __arch_info_begin = .; - *(.arch.info.init) + KEEP(*(.arch.info.init))
OK.
arch/arm/kernel/vmlinux.lds.S SECTIONS · line 200
Quoted 6 lines
arch/arm/kernel/vmlinux.lds.S +1
-1__arch_info_end = .; } .init.tagtable : { __tagtable_begin = .; - *(.taglist.init) + KEEP(*(.taglist.init))
OK.
arch/arm/kernel/vmlinux.lds.S SECTIONS · line 206
Quoted 7 lines
arch/arm/kernel/vmlinux.lds.S +1
-1__tagtable_end = .; } #ifdef CONFIG_SMP_ON_UP .init.smpalt : { __smpalt_begin = .; - *(.alt.smp.init) + KEEP(*(.alt.smp.init))
Yes unfortunately this needs a KEEP() right now as there is no explicit references to those entries. But by doing so you force a reference from those entries to all functions they annotate, preventing those functions from being discarded if there isn't any reference to that code otherwise. That's a case that falls into the "missing forward reference" category in my slides.
arch/arm/kernel/vmlinux.lds.S SECTIONS · line 212
Quoted 7 lines
arch/arm/kernel/vmlinux.lds.S +1
-1__smpalt_end = .; } #endif .init.pv_table : { __pv_table_begin = .; - *(.pv_table) + KEEP(*(.pv_table))
Ditto here.
Nicolas
Arnd Bergmann
maintainerRe: [EXPERIMENTAL] enable thin archives and --gc-sections on ARM
Quoted 6 lines · CEST Nicolas Pitre
Review
Quoted 5 lines
#ifdef CONFIG_SMP_ON_UP .init.smpalt : { __smpalt_begin = .;(quoted diff) +1
-1- *(.alt.smp.init) + KEEP(*(.alt.smp.init))
Quoted 6 lines
Yes unfortunately this needs a
KEEP()right now as there is no explicit references to those entries. But by doing so you force a reference from those entries to all functions they annotate, preventing those functions from being discarded if there isn't any reference to that code otherwise. That's a case that falls into the "missing forward reference" category in my slides.
I see. This actually relates to an existing problem with SMP alternatives in exit sections, which cause a linker error. I've done a patch for this at some point, but didn't feel confident enough to send it out
commit 0c598e53b3a0ad7daf077603618001edcf9bface
Author: Arnd Bergmann <[email protected]> Date: Sun Mar 16 20:14:30 2014 +0100
ARM: don't discard exit sections for spinlock debugging
This avoids lots of warnings like this one:
.exit.text' referenced in section .alt.smp.init' of drivers/built-in.o: defined in discarded section `.exit.text' of drivers/built-in.o
for each spinlock that is used in an __exit function, because the smp alternatives try to patch out the spinlock locations.
arch/arm/kernel/vmlinux.lds.S +1 -2
@@ -43,8 +43,7 @@ #define ARM_CPU_KEEP(x) #endif -#if (defined(CONFIG_SMP_ON_UP) && !defined(CONFIG_DEBUG_SPINLOCK)) || \ - defined(CONFIG_GENERIC_BUG) || defined(CONFIG_JUMP_LABEL) +#if defined(CONFIG_SMP_ON_UP) || defined(CONFIG_GENERIC_BUG) || defined(CONFIG_JUMP_LABEL) #define ARM_EXIT_KEEP(x) x #define ARM_EXIT_DISCARD(x) #else
Re: [EXPERIMENTAL] enable thin archives and --gc-sections on ARM
Quoted 14 lines · Arnd Bergmann
Quoted 6 lines · CEST Nicolas Pitre
Review
Quoted 5 lines
#ifdef CONFIG_SMP_ON_UP .init.smpalt : { __smpalt_begin = .;(quoted diff) +1
-1- *(.alt.smp.init) + KEEP(*(.alt.smp.init))Quoted 6 lines
Yes unfortunately this needs a
KEEP()right now as there is no explicit references to those entries. But by doing so you force a reference from those entries to all functions they annotate, preventing those functions from being discarded if there isn't any reference to that code otherwise. That's a case that falls into the "missing forward reference" category in my slides.
Quoted 3 lines
I see. This actually relates to an existing problem with SMP alternatives in exit sections, which cause a linker error. I've done a patch for this at some point, but didn't feel confident enough to send it out
The only sane way I found to solve this implied a patch to gas, and it was accepted upstream. Please see:
http://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=commit;h=451133cefa
The example given is for .init sections, but that would solve the link-time discarding of .exit sections just as well.
Nicolas
Re: [PATCH 3/6] kbuild: add arch specific post-link pass
In reply to Nicholas PigginDne 11.8.2016 v 12:16 Nicholas Piggin napsal(a):
Quoted 68 lines
Add an option for architectures to pass over modules after they are linked. powerpc will use this to check linker relocations for sanity, and possibly to fix up alternate instruction patch relocations.
Signed-off-by Nicholas Piggin <[email protected]>---
Since v1,
- Switched to a more flexible arch makefile invocation.
- Provide a powerpc patch to use it to help existing build issue (rather than only justification being out-of-tree patch).Documentation/kbuild/makefiles.txt | 10 ++++++++++ arch/Kconfig | 7 +++++++ scripts/Makefile.modpost | 3 +++ scripts/link-vmlinux.sh | 4 ++++ 4 files changed, 24 insertions(+)Documentation/kbuild/makefiles.txt +10
-0@@ -41,6 +41,7 @@ This document describes the Linux kernel Makefiles. --- 6.8 Custom kbuild commands --- 6.9 Preprocessing linker scripts --- 6.10 Generic header files + --- 6.11 Post-link pass === 7 Kbuild syntax for exported headers --- 7.1 header-y@@ -1237,6 +1238,15 @@ When kbuild executes, the following steps are followed (roughly): to list the file in the Kbuild file. See "7.4 generic-y" for further info on syntax etc. +--- 6.11 Post-link pass + + CONFIG_BUILD_ARCH_POSTLINK can be selected in order to have + arch/?/Makefile.postlink invoked on vmlinux and module.ko + files after final link. + + For example, powerpc uses this to check relocations on the + linked vmlinux file. + === 7 Kbuild syntax for exported headers The kernel includes a set of headers that is exported to userspace.arch/Kconfig +7
-0@@ -461,6 +461,13 @@ config CC_STACKPROTECTOR_STRONG endchoice +config BUILD_ARCH_POSTLINK + bool + help + Select this if the architecture wants to have a Makefile invoked + on modules and vmlinux after they are linked. The architecture + must provide arch/?/Makefile.postlink + config THIN_ARCHIVES bool helpscripts/Makefile.modpost +0
-0
scripts/Makefile.modpost quiet_cmd_ld_ko_o = LD [M] $@ · line 128
Quoted 6 lines
scripts/Makefile.modpost +3
-0@@ -123,6 +123,9 @@ quiet_cmd_ld_ko_o = LD [M] $@ $(modules): %.ko :%.o %.mod.o FORCE $(call if_changed,ld_ko_o) +ifdef CONFIG_BUILD_ARCH_POSTLINK + $(Q)$(MAKE) -f $(srctree)/arch/$(SRCARCH)/Makefile.postlink $@ +endif
Why not simply branch off the existence of arch/*/Makefile.postlink and drop the kconfig option?
Thanks,
Michal
Nicholas Piggin
reviewerRe: [PATCH 3/6] kbuild: add arch specific post-link pass
Quoted 9 lines · On Tue, 16 Aug 2016 11:23:45 +0200 Michal Marek <[email protected]> wrote:
Dne 11.8.2016 v 12:16 Nicholas Piggin napsal(a):
Review
Quoted 5 lines
$(modules): %.ko :%.o %.mod.o FORCE
(quoted diff) +3
-0$(call if_changed,ld_ko_o) +ifdef CONFIG_BUILD_ARCH_POSTLINK + $(Q)$(MAKE) -f $(srctree)/arch/$(SRCARCH)/Makefile.postlink $@ +endifWhy not simply branch off the existence of
arch/*/Makefile.postlinkand drop the kconfig option?
I just did not think of it. That does seem nicer, thanks. What do you think of this?
Allow architectures to create arch/xxx/Makefile.postlink with targets for vmlinux, modules.ko, and clean, which will be invoked after final linking of vmlinux and modules.
powerpc will use this to check vmlinux linker relocations for sanity, and may use it to fix up alternate instruction patch branch addresses.
---
Since v1,
- Switched to a more flexible arch makefile invocation.
- Provide a powerpc patch to use it to help existing build issue (rather than only justification being out-of-tree patch).
Since v2
- Depend on existence of Makefile.modpost, rather than config option.
- Move post-vmlinux invocation into Makefile rather than link-vmlinux.sh
- Add a clean target
--- Documentation/kbuild/makefiles.txt | 16 ++++++++++++++++ Makefile | 7 +++++++ scripts/Makefile.modpost | 6 ++++++ 3 files changed, 29 insertions(+)
Documentation/kbuild/makefiles.txt +16 -0
@@ -41,6 +41,7 @@ This document describes the Linux kernel Makefiles. --- 6.8 Custom kbuild commands --- 6.9 Preprocessing linker scripts --- 6.10 Generic header files + --- 6.11 Post-link pass === 7 Kbuild syntax for exported headers --- 7.1 header-y
@@ -1237,6 +1238,21 @@ When kbuild executes, the following steps are followed (roughly): to list the file in the Kbuild file. See "7.4 generic-y" for further info on syntax etc. +--- 6.11 Post-link pass + + If the file arch/xxx/Makefile.postlink exists, this makefile + will be invoked for post-link objects (vmlinux and modules.ko) + for architectures to run post-link passes on. Must also handle + the clean target. + + This pass runs after kallsyms generation. If the architecture + needs to modify symbol locations, rather than manipulate the + kallsyms, it may be easier to add another postlink target for + .tmp_vmlinux? targets to be called from link-vmlinux.sh. + + For example, powerpc uses this to check relocation sanity of + the linked vmlinux file. + === 7 Kbuild syntax for exported headers The kernel includes a set of headers that is exported to userspace.
Makefile +7 -0
@@ -954,8 +954,14 @@ include/generated/autoksyms.h: FORCE cmd_link-vmlinux = $(CONFIG_SHELL) $< $(LD) $(LDFLAGS) $(LDFLAGS_vmlinux) quiet_cmd_link-vmlinux = LINK $@ +# Optional arch pass after final link +ARCH_POSTLINK := $(wildcard $(srctree)/arch/$(SRCARCH)/Makefile.postlink) + cmd_postlink-vmlinux = \ + $(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) $@, true) + vmlinux: scripts/link-vmlinux.sh vmlinux_prereq $(vmlinux-deps) FORCE +$(call if_changed,link-vmlinux) + +$(call if_changed,postlink-vmlinux) # Build samples along the rest of the kernel ifdef CONFIG_SAMPLES
@@ -1279,6 +1285,7 @@ $(clean-dirs): vmlinuxclean: $(Q)$(CONFIG_SHELL) $(srctree)/scripts/link-vmlinux.sh clean + $(Q)$(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) clean) clean: archclean vmlinuxclean
scripts/Makefile.modpost +6 -0
@@ -121,8 +121,14 @@ quiet_cmd_ld_ko_o = LD [M] $@ $(KBUILD_LDFLAGS_MODULE) $(LDFLAGS_MODULE) \ -o $@ $(filter-out FORCE,$^) +# Optional arch pass after final link +ARCH_POSTLINK := $(wildcard $(srctree)/arch/$(SRCARCH)/Makefile.postlink) + cmd_postlink-ko = \ + $(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) $@, true) + $(modules): %.ko :%.o %.mod.o FORCE $(call if_changed,ld_ko_o) + +$(call if_changed,postlink-ko) targets += $(modules)
Signature · 1 line
2.8.1
Re: [PATCH 3/6] kbuild: add arch specific post-link pass
Quoted 13 lines · Nicholas Piggin
Quoted 9 lines · On Tue, 16 Aug 2016 11:23:45 +0200 Michal Marek <[email protected]> wrote:
Dne 11.8.2016 v 12:16 Nicholas Piggin napsal(a):
Review
Quoted 5 lines
$(modules): %.ko :%.o %.mod.o FORCE
(quoted diff) +3
-0$(call if_changed,ld_ko_o) +ifdef CONFIG_BUILD_ARCH_POSTLINK + $(Q)$(MAKE) -f $(srctree)/arch/$(SRCARCH)/Makefile.postlink $@ +endifWhy not simply branch off the existence of
arch/*/Makefile.postlinkand drop the kconfig option?
Quoted 2 lines
I just did not think of it. That does seem nicer, thanks. What do you think of this?
[...]
This looks cleaner, thanks!
Michal
Re: [PATCH 3/6] kbuild: add arch specific post-link pass
In reply to Nicholas PigginQuoted 20 lines
Makefile +6
-0@@ -954,8 +954,14 @@ include/generated/autoksyms.h: FORCE cmd_link-vmlinux = $(CONFIG_SHELL) $< $(LD) $(LDFLAGS) $(LDFLAGS_vmlinux) quiet_cmd_link-vmlinux = LINK $@ +# Optional arch pass after final link +ARCH_POSTLINK := $(wildcard $(srctree)/arch/$(SRCARCH)/Makefile.postlink) + cmd_postlink-vmlinux = \ + $(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) $@, true) + vmlinux: scripts/link-vmlinux.sh vmlinux_prereq $(vmlinux-deps) FORCE +$(call if_changed,link-vmlinux) + +$(call if_changed,postlink-vmlinux) # Build samples along the rest of the kernel ifdef CONFIG_SAMPLES
Makefile $(clean-dirs): · line 1291
Quoted 7 lines
Makefile +1
-0@@ -1279,6 +1285,7 @@ $(clean-dirs): vmlinuxclean: $(Q)$(CONFIG_SHELL) $(srctree)/scripts/link-vmlinux.sh clean + $(Q)$(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) clean) clean: archclean vmlinuxclean
Another option would be to embed the logic in the link-vmlinux shell script. It is much simpler for normal humans to read and understand shell scripts, and it would be simpler too.
Quoted 6 lines
scripts/Makefile.modpost +0
-0@@ -121,8 +121,14 @@ quiet_cmd_ld_ko_o = LD [M] $@ $(KBUILD_LDFLAGS_MODULE) $(LDFLAGS_MODULE) \
scripts/Makefile.modpost quiet_cmd_ld_ko_o = LD [M] $@ · line 131
Quoted 10 lines
scripts/Makefile.modpost +6
-0-o $@ $(filter-out FORCE,$^) +# Optional arch pass after final link +ARCH_POSTLINK := $(wildcard $(srctree)/arch/$(SRCARCH)/Makefile.postlink) + cmd_postlink-ko = \ + $(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) $@, true) + $(modules): %.ko :%.o %.mod.o FORCE $(call if_changed,ld_ko_o) + +$(call if_changed,postlink-ko)
For modules we have no script, so here we need this.
Sam
Nicholas Piggin
reviewerRe: [PATCH 3/6] kbuild: add arch specific post-link pass
Quoted 25 lines · On Wed, 17 Aug 2016 11:56:33 +0200 Sam Ravnborg <[email protected]> wrote:
Quoted 25 lines
Makefile +7
-0@@ -954,8 +954,14 @@ include/generated/autoksyms.h: FORCE cmd_link-vmlinux = $(CONFIG_SHELL) $< $(LD) $(LDFLAGS) $(LDFLAGS_vmlinux) quiet_cmd_link-vmlinux = LINK $@ +# Optional arch pass after final link +ARCH_POSTLINK := $(wildcard $(srctree)/arch/$(SRCARCH)/Makefile.postlink) + cmd_postlink-vmlinux = \ + $(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) $@, true) + vmlinux: scripts/link-vmlinux.sh vmlinux_prereq $(vmlinux-deps) FORCE +$(call if_changed,link-vmlinux) + +$(call if_changed,postlink-vmlinux) # Build samples along the rest of the kernel ifdef CONFIG_SAMPLES@@ -1279,6 +1285,7 @@ $(clean-dirs): vmlinuxclean: $(Q)$(CONFIG_SHELL) $(srctree)/scripts/link-vmlinux.sh clean + $(Q)$(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) clean)
Quoted 5 lines
Makefile $(clean-dirs): · line 1291
Quoted 2 lines
Makefile +0
-0clean: archclean vmlinuxcleanAnother option would be to embed the logic in the link-vmlinux shell script. It is much simpler for normal humans to read and understand shell scripts, and it would be simpler too.
I did that in the previous patch. I struggle with Makefiles too, but considering that we need the same recipe for modules, I thought just doing it the same for both was a bit nicer. But I really can go either way on it so whatever maintainers prefer I can respin.
Thanks,
Nick
Nicholas Piggin
reviewerQuoted 14 lines · On Thu, 11 Aug 2016 20:16:14 +1000 Nicholas Piggin <[email protected]> wrote:
Hi,
I would like to submit the kbuild changes in patches 1-3 for consideration.
I've taken on the feedback, so thanks everybody for that. The biggest change since last time is a more general way for architectures to do a post-link pass in patch 3.
On the question of whether to enable thin archives unconditionally, I prefer to have architectures enable them as they are tested. But I would like to see everybody moved as soon as possible and the incremental linking removed.
Quoted 4 lines
All patches should be basically noops without arch enablement, so I include initial powerpc enablement in patches 4-6 for reference, but I will submit those via powerpc maintainer if the kbuild changes are merged.
Hi Michal,
I'm wondering what your thoughts are with this series?
Sam had some other comment on patch 3, but I think it has come to a matter of preference. I don't mind too much, so I can change it to whatever people prefer (sh or makefile).
And did you want me to re-post the series, or are you happy to take updated patches from replies?
The ARM slowness with allyesconfig builds with thin archives was a linker workaround for a processor bug that they don't need to enable for allyesconfig build anyway. I provided them a patch to avoid that. For usual sized builds, it's not noticeable.
Thanks,
Nick
Re: [PATCH] Xen: remove -fshort-wchar gcc flag
In reply to Arnd BergmannQuoted 8 lines · Arnd Bergmann
A previous patch added the --no-wchar-size-warning to the
Makefileto avoid this harmless warning:arm-linux-gnueabi-ld: warning:
drivers/xen/efi.ouses 2-bytewchar_tyet the output is to use 4-bytewchar_t; use ofwchar_tvalues across objects may failChanging kbuild to use thin archives instead of recursive linking unfortunately brings the same warning back during the final link.
Quoted 7 lines
This time, we remove the -fshort-wchar flag that originally caused the warning, hopefully fixing the problem for good. I don't see any reason for having the flag in the first place, as the Xen code does not use
wchar_tat all.Signed-off-by Arnd Bergmann <[email protected]>Fixes 971a69db7dc0 ("Xen: don't warn about 2-byte wchar_t in efi")
David
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Re: [Xen-devel] [PATCH] Xen: remove -fshort-wchar gcc flag
In reply to Arnd BergmannQuoted 8 lines · Arnd Bergmann
A previous patch added the --no-wchar-size-warning to the
Makefileto avoid this harmless warning:arm-linux-gnueabi-ld: warning:
drivers/xen/efi.ouses 2-bytewchar_tyet the output is to use 4-bytewchar_t; use ofwchar_tvalues across objects may failChanging kbuild to use thin archives instead of recursive linking unfortunately brings the same warning back during the final link.
Quoted 7 lines
This time, we remove the -fshort-wchar flag that originally caused the warning, hopefully fixing the problem for good. I don't see any reason for having the flag in the first place, as the Xen code does not use
wchar_tat all.Signed-off-by Arnd Bergmann <[email protected]>Fixes 971a69db7dc0 ("Xen: don't warn about 2-byte wchar_t in efi")
David