build updates
Nicholas Piggin
reviewercover build updates
Hi,
I was hoping to get these posted earlier, but they had a dependency on the kbuild tree which took a while to merge. Hopefully we can get at least the first 4 patches in, which are just sanity checks on the final binary.
With this series applied, I'm able to build[*] and boot a 64-bit book3s allyesconfig kernel, a 200MB vmlinux (although today's tree breaks in some random driver initcall in late boot). That's largely a culmination of Stephen Rothwell's work (including the kbuild changes that were merged earlier in 4.9), I just picked up some of his patches so attributions may not be 100% reflective of reality.
[*] Building allyesconfig still requires KALLSYMS_EXTRA_PASS=1, which
I'm yet to look into.
Thanks,
Nick
Nicholas Piggin (7):
powerpc: use the new post-link pass to check relocations
powerpc: add arch/powerpc/tools directory
powerpc/64s: tool to flag direct branches from unrelocated interrupt
vectors
powerpc/64: tool to check head sections location sanity powerpc/64: handle linker stubs in low .text code
powerpc: switch to using thin archives if COMPILE_TEST is set powerpc/64: allow CONFIG_RELOCATABLE if COMPILE_TEST
arch/powerpc/Kconfig | 5 +-
arch/powerpc/Makefile | 17 +----
arch/powerpc/Makefile.postlink | 48 ++++++++++++++
arch/powerpc/include/asm/head-64.h | 20 ++++--
arch/powerpc/kernel/vmlinux.lds.S | 28 ++------
.../gcc-check-mprofile-kernel.sh | 0
arch/powerpc/tools/head_check.sh | 74 ++++++++++++++++++++++
arch/powerpc/{ => tools}/relocs_check.sh | 0
arch/powerpc/tools/unrel_branch_check.sh | 56 ++++++++++++++++
9 files changed, 203 insertions(+), 45 deletions(-)
create mode 100644 arch/powerpc/Makefile.postlink
rename arch/powerpc/{scripts => tools}/gcc-check-mprofile-kernel.sh (100%)
create mode 100755 arch/powerpc/tools/head_check.sh
rename arch/powerpc/{ => tools}/relocs_check.sh (100%)
create mode 100755 arch/powerpc/tools/unrel_branch_check.shSignature · 1 line
2.9.3
Nicholas Piggin
reviewerPATCH 1/7 powerpc: use the new post-link pass to check relocations
Currently 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.
--- arch/powerpc/Makefile | 11 ----------- arch/powerpc/Makefile.postlink | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 11 deletions(-) create mode 100644 arch/powerpc/Makefile.postlink
arch/powerpc/Makefile +0 -11
@@ -263,17 +263,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 +34 -0
@@ -0,0 +1,34 @@ +# =========================================================================== +# 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) $(srctree)/arch/powerpc/relocs_check.sh "$(OBJDUMP)" "$@" + +# `@true` prevents complaint when there is nothing to be done + +vmlinux: FORCE + @true +ifeq ($(CONFIG_RELOCATABLE),y) + $(call if_changed,relocs_check) +endif + +%.ko: FORCE + @true + +clean: + @true + +PHONY += FORCE clean + +FORCE: + +.PHONY: $(PHONY)
Signature · 1 line
2.9.3
Nicholas Piggin
reviewerPATCH 2/7 powerpc: add arch/powerpc/tools directory
In reply to Nicholas PigginMove a couple of existing scripts there, and remove scripts directory:
a script is a tool, a tool is not a script. I plan to add some tools that require compilation (though not in this series), so this matches other architectures more closely.
---
arch/powerpc/Makefile | 2 +-
arch/powerpc/Makefile.postlink | 2 +-
arch/powerpc/{scripts => tools}/gcc-check-mprofile-kernel.sh | 0
arch/powerpc/{ => tools}/relocs_check.sh | 0
4 files changed, 2 insertions(+), 2 deletions(-)
rename arch/powerpc/{scripts => tools}/gcc-check-mprofile-kernel.sh (100%)
rename arch/powerpc/{ => tools}/relocs_check.sh (100%)arch/powerpc/Makefile +1 -1
@@ -126,7 +126,7 @@ CFLAGS-$(CONFIG_GENERIC_CPU) += -mcpu=powerpc64 endif ifdef CONFIG_MPROFILE_KERNEL - ifeq ($(shell $(srctree)/arch/powerpc/scripts/gcc-check-mprofile-kernel.sh $(CC) -I$(srctree)/include -D__KERNEL__),OK) + ifeq ($(shell $(srctree)/arch/powerpc/tools/gcc-check-mprofile-kernel.sh $(CC) -I$(srctree)/include -D__KERNEL__),OK) CC_FLAGS_FTRACE := -pg -mprofile-kernel KBUILD_CPPFLAGS += -DCC_USING_MPROFILE_KERNEL else
arch/powerpc/Makefile.postlink +1 -1
@@ -11,7 +11,7 @@ include include/config/auto.conf include scripts/Kbuild.include quiet_cmd_relocs_check = CHKREL $@ - cmd_relocs_check = $(CONFIG_SHELL) $(srctree)/arch/powerpc/relocs_check.sh "$(OBJDUMP)" "$@" + cmd_relocs_check = $(CONFIG_SHELL) $(srctree)/arch/powerpc/tools/relocs_check.sh "$(OBJDUMP)" "$@" # `@true` prevents complaint when there is nothing to be done
arch/powerpc/tools/gcc-check-mprofile-kernel.sh renamed from arch/powerpc/scripts/gcc-check-mprofile-kernel.sh +0 -0
arch/powerpc/tools/relocs_check.sh renamed from arch/powerpc/relocs_check.sh +0 -0
Signature · 1 line
2.9.3
Nicholas Piggin
reviewerPATCH 3/7 powerpc/64s: tool to flag direct branches from unrelocated interrupt vectors
In reply to Nicholas PigginDirect banches from code below __end_interrupts to code above __end_interrupts when built with CONFIG_RELOCATABLE are disallowed because they will break when the kernel is not located at 0.
Sample output:
WARNING: Unrelocated relative branches
c000000000000118 bl-> 0xc000000000038fb8 <pnv_restore_hyp_resource>
c00000000000013c b-> 0xc0000000001068a4 <kvm_start_guest>
c000000000000148 b-> 0xc00000000003919c <pnv_wakeup_loss>
c00000000000014c b-> 0xc00000000003923c <pnv_wakeup_noloss>
c0000000000005a4 b-> 0xc000000000106ffc <kvmppc_interrupt_hv>
c000000000001af0 b-> 0xc000000000106ffc <kvmppc_interrupt_hv>
c000000000001b24 b-> 0xc000000000106ffc <kvmppc_interrupt_hv>
c000000000001b58 b-> 0xc000000000106ffc <kvmppc_interrupt_hv>--- arch/powerpc/Makefile.postlink | 9 ++++- arch/powerpc/tools/unrel_branch_check.sh | 56 ++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 1 deletion(-) create mode 100755 arch/powerpc/tools/unrel_branch_check.sh
arch/powerpc/Makefile.postlink +8 -1
@@ -11,7 +11,14 @@ include include/config/auto.conf include scripts/Kbuild.include quiet_cmd_relocs_check = CHKREL $@ - cmd_relocs_check = $(CONFIG_SHELL) $(srctree)/arch/powerpc/tools/relocs_check.sh "$(OBJDUMP)" "$@" +ifeq ($(CONFIG_PPC_BOOK3S_64),y) + cmd_relocs_check = \ + $(CONFIG_SHELL) $(srctree)/arch/powerpc/tools/relocs_check.sh "$(OBJDUMP)" "$@" ; \ + $(CONFIG_SHELL) $(srctree)/arch/powerpc/tools/unrel_branch_check.sh "$(OBJDUMP)" "$@" +else + cmd_relocs_check = \ + $(CONFIG_SHELL) $(srctree)/arch/powerpc/tools/relocs_check.sh "$(OBJDUMP)" "$@" +endif # `@true` prevents complaint when there is nothing to be done
arch/powerpc/tools/unrel_branch_check.sh new file +56 -0
56 lines not on this page · raw message
Signature · 1 line
2.9.3
Re: [PATCH 3/7] powerpc/64s: tool to flag direct branches from unrelocated interrupt vectors
Quoted 16 lines · Nicholas Piggin
Direct banches from code below
__end_interruptsto code above__end_interruptswhen built withCONFIG_RELOCATABLEare disallowed because they will break when the kernel is not located at 0.Sample output:
WARNING: Unrelocated relative branches c000000000000118 bl-> 0xc000000000038fb8 <pnv_restore_hyp_resource> c00000000000013c b-> 0xc0000000001068a4 <kvm_start_guest> c000000000000148 b-> 0xc00000000003919c <pnv_wakeup_loss> c00000000000014c b-> 0xc00000000003923c <pnv_wakeup_noloss> c0000000000005a4 b-> 0xc000000000106ffc <kvmppc_interrupt_hv> c000000000001af0 b-> 0xc000000000106ffc <kvmppc_interrupt_hv> c000000000001b24 b-> 0xc000000000106ffc <kvmppc_interrupt_hv> c000000000001b58 b-> 0xc000000000106ffc <kvmppc_interrupt_hv>
Quoted 2 lines
Signed-off-by Nicholas Piggin <[email protected]>---
If this is the same script I gave you, you can add my SOB line as well
Balbir
Nicholas Piggin
reviewerRe: [PATCH 3/7] powerpc/64s: tool to flag direct branches from unrelocated interrupt vectors
Quoted 17 lines · On Wed, 19 Oct 2016 15:28:40 +1100 Balbir Singh <[email protected]> wrote:
Quoted 16 lines · Nicholas Piggin
Direct banches from code below
__end_interruptsto code above__end_interruptswhen built withCONFIG_RELOCATABLEare disallowed because they will break when the kernel is not located at 0.Sample output:
WARNING: Unrelocated relative branches c000000000000118 bl-> 0xc000000000038fb8 <pnv_restore_hyp_resource> c00000000000013c b-> 0xc0000000001068a4 <kvm_start_guest> c000000000000148 b-> 0xc00000000003919c <pnv_wakeup_loss> c00000000000014c b-> 0xc00000000003923c <pnv_wakeup_noloss> c0000000000005a4 b-> 0xc000000000106ffc <kvmppc_interrupt_hv> c000000000001af0 b-> 0xc000000000106ffc <kvmppc_interrupt_hv> c000000000001b24 b-> 0xc000000000106ffc <kvmppc_interrupt_hv> c000000000001b58 b-> 0xc000000000106ffc <kvmppc_interrupt_hv>
Quoted 4 lines
Quoted 2 lines
Signed-off-by Nicholas Piggin <[email protected]>---
If this is the same script I gave you, you can add my SOB line as well
I can't remember now, but I know you had something... I'm usually careful to get attributions right. I'll add your SOB.
Michael Ellerman
reviewerRe: [PATCH 3/7] powerpc/64s: tool to flag direct branches from unrelocated interrupt vectors
In reply to Nicholas PigginQuoted 16 lines · Nicholas Piggin
Direct banches from code below
__end_interruptsto code above__end_interruptswhen built withCONFIG_RELOCATABLEare disallowed because they will break when the kernel is not located at 0.Sample output:
WARNING: Unrelocated relative branches c000000000000118 bl-> 0xc000000000038fb8 <pnv_restore_hyp_resource> c00000000000013c b-> 0xc0000000001068a4 <kvm_start_guest> c000000000000148 b-> 0xc00000000003919c <pnv_wakeup_loss> c00000000000014c b-> 0xc00000000003923c <pnv_wakeup_noloss> c0000000000005a4 b-> 0xc000000000106ffc <kvmppc_interrupt_hv> c000000000001af0 b-> 0xc000000000106ffc <kvmppc_interrupt_hv> c000000000001b24 b-> 0xc000000000106ffc <kvmppc_interrupt_hv> c000000000001b58 b-> 0xc000000000106ffc <kvmppc_interrupt_hv>
Quoted 4 lines
Signed-off-by Nicholas Piggin <[email protected]>--- arch/powerpc/Makefile.postlink | 9 ++++- arch/powerpc/tools/unrel_branch_check.sh | 56 ++++++++++++++++++++++++++++++++
arch/powerpc/scripts is meant for these kind of scripts (there's only one there ATM, and yes we should move others in there).
cheers
Nicholas Piggin
reviewerPATCH 4/7 powerpc/64: tool to check head sections location sanity
In reply to Nicholas PigginUse a tool to check the location of "fixed sections" is where we expected them, which catches cases the linker script can't (stubs being added to start of .text section), and which ends up being neater.
Sample output:
ERROR: start_text address is c000000000008100, should be c000000000008000
ERROR: see comments in arch/powerpc/tools/head_check.sh
--- arch/powerpc/Makefile.postlink | 7 ++++ arch/powerpc/include/asm/head-64.h | 4 +-- arch/powerpc/kernel/vmlinux.lds.S | 26 ++------------ arch/powerpc/tools/head_check.sh | 69 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 80 insertions(+), 26 deletions(-) create mode 100755 arch/powerpc/tools/head_check.sh
arch/powerpc/Makefile.postlink +7 -0
@@ -10,6 +10,9 @@ __archpost: include include/config/auto.conf include scripts/Kbuild.include +quiet_cmd_head_check = CHKHEAD $@ + cmd_head_check = $(CONFIG_SHELL) $(srctree)/arch/powerpc/tools/head_check.sh "$(NM)" "$@" + quiet_cmd_relocs_check = CHKREL $@ ifeq ($(CONFIG_PPC_BOOK3S_64),y) cmd_relocs_check = \
@@ -24,6 +27,9 @@ endif vmlinux: FORCE @true +ifeq ($(CONFIG_PPC64),y) + $(call cmd,head_check) +endif ifeq ($(CONFIG_RELOCATABLE),y) $(call if_changed,relocs_check) endif
@@ -32,6 +38,7 @@ endif @true clean: + rm -f .tmp_symbols.txt @true PHONY += FORCE clean
arch/powerpc/include/asm/head-64.h +2 -2
@@ -49,8 +49,8 @@* CLOSE_FIXED_SECTION() or elsewhere, there may be something * unexpected being added there. Remove the '. = x_len' line, rebuild, and * check what is pushing the section down. -* - If the build dies in linking, check arch/powerpc/kernel/vmlinux.lds.S -* for instructions. +* - If the build dies in linking, check arch/powerpc/tools/head_check.sh +* comments. * - If the kernel crashes or hangs in very early boot, it could be linker * stubs at the start of the main text. */
arch/powerpc/kernel/vmlinux.lds.S +2 -24
@@ -58,7 +58,6 @@ SECTIONS #ifdef CONFIG_PPC64 KEEP(*(.head.text.first_256B)); #ifdef CONFIG_PPC_BOOK3E -# define END_FIXED 0x100 #else KEEP(*(.head.text.real_vectors)); *(.head.text.real_trampolines);
@@ -66,38 +65,17 @@ SECTIONS *(.head.text.virt_trampolines); # if defined(CONFIG_PPC_PSERIES) || defined(CONFIG_PPC_POWERNV) KEEP(*(.head.data.fwnmi_page)); -# define END_FIXED 0x8000 -# else -# define END_FIXED 0x7000 # endif #endif - ASSERT((. == END_FIXED), "vmlinux.lds.S: fixed section overflow error"); #else /* !CONFIG_PPC64 */ HEAD_TEXT #endif } :kernel - /* - * If the build dies here, it's likely code in head_64.S is referencing - * labels it can't reach, and the linker inserting stubs without the - * assembler's knowledge. To debug, remove the above assert and - * rebuild. Look for branch stubs in the fixed section region. - * - * Linker stub generation could be allowed in "trampoline" - * sections if absolutely necessary, but this would require - * some rework of the fixed sections. Before resorting to this, - * consider references that have sufficient addressing range, - * (e.g., hand coded trampolines) so the linker does not have - * to add stubs. - * - * Linker stubs at the top of the main text section are currently not - * detected, and will result in a crash at boot due to offsets being - * wrong. - */ .text : AT(ADDR(.text) - LOAD_OFFSET) { - ALIGN_FUNCTION(); /* careful! __ftr_alt_* sections need to be close to .text */ - *(.text .fixup __ftr_alt_* .ref.text) + ALIGN_FUNCTION(); + *(.text .fixup __ftr_alt_* .ref.text); SCHED_TEXT CPUIDLE_TEXT LOCK_TEXT
arch/powerpc/tools/head_check.sh new file +69 -0
69 lines not on this page · raw message
Signature · 1 line
2.9.3
Michael Ellerman
reviewerRe: [PATCH 4/7] powerpc/64: tool to check head sections location sanity
arch/powerpc/Makefile.postl=
Quoted 1 line · Nicholas Piggin
arch/powerpc/Makefile.postl= renamed from arch/powerpc/Makefile.postlink +0
-0
ink
arch/powerpc/Makefile.postlink endif · line 30
Quoted 8 lines
index 1725e64..b8fe12b 100644
arch/powerpc/Makefile.postlink +0
-0@@ -24,6 +27,9 @@ endif=20=20
vmlinux: FORCEarch/powerpc/Makefile.postlink +1
-0@true +ifeq ($(CONFIG_PPC64),y)
You can just use:
ifdef CONFIG_PPC64
arch/powerpc/Makefile.postlink endif · line 42
Quoted 11 lines
arch/powerpc/Makefile.postlink +2
-0+ $(call cmd,head_check) +endif ifeq ($(CONFIG_RELOCATABLE),y) $(call if_changed,relocs_check) endif@@ -32,6 +38,7 @@ endif @true=20=20
clean:arch/powerpc/Makefile.postlink +1
-0+ rm -f .tmp_symbols.txt @true
We shouldn't need the true anymore should we?
arch/powerpc/tools/head_c=
Quoted 1 line
arch/powerpc/tools/head_c= renamed from arch/powerpc/tools/head_check.sh +0
-0
heck.sh
arch/powerpc/tools/head_check.sh line 1
Quoted 6 lines
new file mode 100755
index 0000000..9635fe7arch/powerpc/tools/head_check.sh new file +1
-0@@ -0,0 +1,69 @@ +#!/bin/sh
We run this explicitly via $(CONFIG_SHELL), so having a shebang here is redundant and also a little confusing. I added "-x" here, to turn on tracing, but it doesn't take effect, so I think better to just drop the line. If anyone wants to run it manually they can just pass it to sh.
Quoted 7 lines
arch/powerpc/tools/head_check.sh new file +7
-0+# Copyright =C2=A9 2016 IBM Corporation + +# 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; either version +# 2 of the License, or (at your option) any later version. +
arch/powerpc/tools/head_check.sh
Quoted 10 lines
arch/powerpc/tools/head_check.sh new file +10
-0+# This script checks the head of a vmlinux for linker stubs that +# break our placement of fixed-location code for 64-bit. + +# based on relocs_check.pl +# Copyright =C2=A9 2009 IBM Corporation + +# READ THIS +# +# If the build dies here, it's likely code in head_64.S or nearby is +# referencing labels it can't reach, which results in the linker inserti=
ng
arch/powerpc/tools/head_check.sh line 19
Quoted 1 line
arch/powerpc/tools/head_check.sh new file +1
-0+# stubs without the assembler's knowledge. This can move code around in =
ways
arch/powerpc/tools/head_check.sh line 21
Quoted 2 lines
arch/powerpc/tools/head_check.sh new file +2
-0+# that break the fixed location placement stuff (head-64.h). To debug, +# disassemble the vmlinux and look for branch stubs (long_branch, plt_br=
anch
arch/powerpc/tools/head_check.sh
Quoted 5 lines
arch/powerpc/tools/head_check.sh new file +5
-0+# etc) in the fixed section region (0 - 0x8000ish). Check what places are +# calling those stubs. +# +# Linker stubs use the TOC pointer, so even if fixed section code could +# tolerate them being inserted into head code, they can't be allowed in =
low
arch/powerpc/tools/head_check.sh line 27
Quoted 1 line
arch/powerpc/tools/head_check.sh new file +1
-0+# level entry code (boot, interrupt vectors, etc) until r2 is set up. Th=
is
arch/powerpc/tools/head_check.sh line 29
Quoted 1 line
arch/powerpc/tools/head_check.sh new file +1
-0+# could cause the kernel to die in early boot.
Can you add:
# Turn this on if you want more debug output:
# set -x
arch/powerpc/tools/head_check.sh
Quoted 11 lines
arch/powerpc/tools/head_check.sh new file +11
-0+ +if [ $# -lt 2 ]; then + echo "$0 [path to nm] [path to vmlinux]" 1>&2 + exit 1 +fi + +# Have Kbuild supply the path to nm so we handle cross compilation. +nm=3D"$1" +vmlinux=3D"$2" + +nm "$vmlinux" | grep -e " T _stext$" -e " t start_first_256B$" -e " a te=
xt_start$" -e " t start_text$" -m4 > .tmp_symbols.txt
You don't use $nm there.
arch/powerpc/tools/head_check.sh
Quoted 7 lines
arch/powerpc/tools/head_check.sh new file +7
-0+ + +vma=3D$(cat .tmp_symbols.txt | grep " T _stext$" | cut -d' ' -f1) + +expected_start_head_addr=3D$vma + +start_head_addr=3D$(cat .tmp_symbols.txt | grep " t start_first_256B$" |=
cut -d' ' -f1)
arch/powerpc/tools/head_check.sh line 51
Quoted 4 lines
arch/powerpc/tools/head_check.sh new file +4
-0+ +if [ "$start_head_addr" !=3D "$expected_start_head_addr" ]; then + echo "ERROR: head code starts at $start_head_addr, should be 0" + echo "ERROR: see comments in arch/powerpc/tools/head_check.sh"
This is blowing up for me with ppc64e_defconfig.
It says:
ERROR: start_text address is c000000000001100, should be c000000000000200
cheers
Nicholas Piggin
reviewerRe: [PATCH 4/7] powerpc/64: tool to check head sections location sanity
Quoted 8 lines · On Tue, 15 Nov 2016 11:55:26 +1100 Michael Ellerman <[email protected]> wrote:
Quoted 6 lines · Nicholas Piggin
arch/powerpc/Makefile.postlink +0
-0@@ -24,6 +27,9 @@ endif
Quoted 7 lines
arch/powerpc/Makefile.postlink endif · line 30
Quoted 3 lines
arch/powerpc/Makefile.postlink +1
-0vmlinux: FORCE @true +ifeq ($(CONFIG_PPC64),y)You can just use:
ifdef
CONFIG_PPC64
Okay. The same applies to other parts of this file added earlier. I'll fix.
Quoted 8 lines
Quoted 8 lines
arch/powerpc/Makefile.postlink +2
-0+ $(call cmd,head_check) +endif ifeq ($(CONFIG_RELOCATABLE),y) $(call if_changed,relocs_check) endif@@ -32,6 +38,7 @@ endif @true
Quoted 5 lines
arch/powerpc/Makefile.postlink endif · line 42
Quoted 3 lines
arch/powerpc/Makefile.postlink +1
-0clean: + rm -f .tmp_symbols.txt @trueWe shouldn't need the true anymore should we?
True.
Quoted 4 lines
Quoted 4 lines
arch/powerpc/tools/head_check.sh new file +0
-1--- /dev/null
Quoted 8 lines
arch/powerpc/tools/head_check.sh line 1
Quoted 3 lines
+++
b/arch/powerpc/tools/head_check.sharch/powerpc/tools/head_check.sh new file +1
-0@@ -0,0 +1,69 @@ +#!/bin/shWe run this explicitly via $(CONFIG_SHELL), so having a shebang here is redundant and also a little confusing. I added "-x" here, to turn on tracing, but it doesn't take effect, so I think better to just drop the line. If anyone wants to run it manually they can just pass it to sh.
Okay. How about relocs_check.sh? I just started by copying that.
Quoted 31 lines
Quoted 18 lines
arch/powerpc/tools/head_check.sh new file +17
-0+# Copyright © 2016 IBM Corporation + +# 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; either version +# 2 of the License, or (at your option) any later version. + +# This script checks the head of a vmlinux for linker stubs that +# break our placement of fixed-location code for 64-bit. + +# based on relocs_check.pl +# Copyright © 2009 IBM Corporation + +# READ THIS +# +# If the build dies here, it's likely code in head_64.S or nearby is +# referencing labels it can't reach, which results in the linker insertingarch/powerpc/tools/head_check.sh line 29
Quoted 10 lines
arch/powerpc/tools/head_check.sh new file +10
-0+# stubs without the assembler's knowledge. This can move code around in ways +# that break the fixed location placement stuff (head-64.h). To debug, +# disassemble the vmlinux and look for branch stubs (long_branch, plt_branch +# etc) in the fixed section region (0 - 0x8000ish). Check what places are +# calling those stubs. +# +# Linker stubs use the TOC pointer, so even if fixed section code could +# tolerate them being inserted into head code, they can't be allowed in low +# level entry code (boot, interrupt vectors, etc) until r2 is set up. This +# could cause the kernel to die in early boot.Can you add:
Quoted 2 lines
# Turn this on if you want more debug output:
# set -x
Can do, same question applies for relocs_check.sh
Quoted 14 lines
arch/powerpc/tools/head_check.sh line 40
Quoted 12 lines
arch/powerpc/tools/head_check.sh new file +11
-0+ +if [ $# -lt 2 ]; then + echo "$0 [path to nm] [path to vmlinux]" 1>&2 + exit 1 +fi + +# Have Kbuild supply the path to nm so we handle cross compilation. +nm="$1" +vmlinux="$2" + +nm "$vmlinux" | grep -e " T _stext$" -e " t start_first_256B$" -e " a text_start$" -e " t start_text$" -m4 > .tmp_symbols.txtYou don't use $nm there.
Thanks, good catch.
Quoted 14 lines
arch/powerpc/tools/head_check.sh line 51
Quoted 11 lines
arch/powerpc/tools/head_check.sh new file +11
-0+ + +vma=$(cat .tmp_symbols.txt | grep " T _stext$" | cut -d' ' -f1) + +expected_start_head_addr=$vma + +start_head_addr=$(cat .tmp_symbols.txt | grep " t start_first_256B$" | cut -d' ' -f1) + +if [ "$start_head_addr" != "$expected_start_head_addr" ]; then + echo "ERROR: head code starts at $start_head_addr, should be 0" + echo "ERROR: see comments in arch/powerpc/tools/head_check.sh"This is blowing up for me with
ppc64e_defconfig.
Quoted 3 lines
It says:
ERROR:
start_textaddress isc000000000001100, should bec000000000000200
I must have forgotten to test e. I'll fix that.
Thanks,
Nick
Michael Ellerman
reviewerRe: [PATCH 4/7] powerpc/64: tool to check head sections location sanity
Quoted 16 lines · Nicholas Piggin
Quoted 13 lines · On Tue, 15 Nov 2016 11:55:26 +1100 Michael Ellerman <[email protected]> wrote:
arch/powerpc/tools/head_check.sh line 1
Quoted 7 lines · Nicholas Piggin
arch/powerpc/tools/head_check.sh new file +1
-0@@ -0,0 +1,69 @@ +#!/bin/shWe run this explicitly via $(CONFIG_SHELL), so having a shebang here is redundant and also a little confusing. I added "-x" here, to turn on tracing, but it doesn't take effect, so I think better to just drop the line. If anyone wants to run it manually they can just pass it to sh.
Quoted 1 line
Okay. How about
relocs_check.sh? I just started by copying that.
Yeah may as well fix it too.
Quoted 4 lines
Quoted 2 lines
# Turn this on if you want more debug output:
# set -xCan do, same question applies for
relocs_check.sh
Yep, save the next person who's debugging it the time.
cheers
Nicholas Piggin
reviewerPATCH 5/7 powerpc/64: handle linker stubs in low .text code
In reply to Nicholas PigginVery large kernels require linker stubs, but the linker tends to place them in ways that make it very difficult to detect programatically with the assembler when taking absolute real (physical) addresses. This breaks the early boot code. Create a small section just before the .text section with an empty 256 - 4 bytes, and adjust the start of the .text section to match. The linker will tend to put stubs in that section and not break our start-of-.text section label.
This is a tiny waste of space on common kernels, but allows large kernels to build and boot, which is convenient enough to outweigh the cost.
This is a sad hack, which I will improve on if I can find out how to achieve it a better way. Until then, it seems to work.
--- arch/powerpc/include/asm/head-64.h | 16 +++++++++++++--- arch/powerpc/kernel/vmlinux.lds.S | 2 ++ arch/powerpc/tools/head_check.sh | 5 +++++ 3 files changed, 20 insertions(+), 3 deletions(-)
arch/powerpc/include/asm/head-64.h +13 -3
@@ -63,11 +63,21 @@ . = 0x0; \ start_##sname: +/* +* .linker_stub_catch section is used to catch linker stubs from being +* inserted in our .text section, above the start_text label (which breaks +* the ABS_ADDR calculation). See kernel/vmlinux.lds.S and tools/head_check.sh +* for more details. We would prefer to just keep a cacheline (0x80), but +* 0x100 seems to be how the linker aligns branch stub groups. +*/ #define OPEN_TEXT_SECTION (start) \ - text_start = (start); \ + .section ".linker_stub_catch","ax",@progbits; \ +linker_stub_catch: \ + . = 0x4; \ .section ".text","ax",@progbits; \ - . = 0x0; \ -start_text: + text_start = (start) + 0x100; \ + .balign 0x100; \ +start_text: \#define ZERO_FIXED_SECTION (sname, start, end) \ sname##_start = (start); \
arch/powerpc/kernel/vmlinux.lds.S +2 -0
@@ -73,6 +73,8 @@ SECTIONS } :kernel .text : AT(ADDR(.text) - LOAD_OFFSET) { + *(.linker_stub_catch); + . = . ; /* careful! __ftr_alt_* sections need to be close to .text */ ALIGN_FUNCTION(); *(.text .fixup __ftr_alt_* .ref.text);
arch/powerpc/tools/head_check.sh +5 -0
@@ -23,6 +23,11 @@ # etc) in the fixed section region (0 - 0x8000ish). Check what places are # calling those stubs. # +# A ".linker_stub_catch" section is used to catch some stubs generated by +# early .text code, which tend to get placed at the start of the section. +# If there are too many such stubs, they can overflow this section. Expanding +# it may help (or reducing the number of stub branches). +# # Linker stubs use the TOC pointer, so even if fixed section code could # tolerate them being inserted into head code, they can't be allowed in low # level entry code (boot, interrupt vectors, etc) until r2 is set up. This
Signature · 1 line
2.9.3
Nicholas Piggin
reviewerPATCH 6/7 powerpc: switch to using thin archives if COMPILE_TEST is set
In reply to Nicholas PigginEnable thin archives build for powerpc when COMPILE_TEST is set. Thin archives are explained in this commit:
a5967db9af51a84f5e181600954714a9e4c69f1f
This is a gradual way to introduce the option to testers.
Some change to the way we invoke ar is required so it can be used by scripts/link-vmlinux.sh.
--- arch/powerpc/Kconfig | 1 + arch/powerpc/Makefile | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-)
arch/powerpc/Kconfig +1 -0
@@ -80,6 +80,7 @@ config ARCH_HAS_DMA_SET_COHERENT_MASK config PPC bool default y + select THIN_ARCHIVES if COMPILE_TEST select ARCH_MIGHT_HAVE_PC_PARPORT select ARCH_MIGHT_HAVE_PC_SERIO select BINFMT_ELF
arch/powerpc/Makefile +2 -2
@@ -23,7 +23,7 @@ CROSS32AR := $(CROSS32_COMPILE)ar ifeq ($(HAS_BIARCH),y) ifeq ($(CROSS32_COMPILE),) CROSS32CC := $(CC) -m32 -CROSS32AR := GNUTARGET=elf32-powerpc $(AR) +KBUILD_ARFLAGS += --target=elf32-powerpc endif endif
@@ -85,7 +85,7 @@ ifeq ($(HAS_BIARCH),y) override AS += -a$(BITS) override LD += -m elf$(BITS)$(LDEMULATION) override CC += -m$(BITS) -override AR := GNUTARGET=elf$(BITS)-$(GNUTARGET) $(AR) +KBUILD_ARFLAGS += --target=elf$(BITS)-$(GNUTARGET) endif LDFLAGS_vmlinux-y := -Bstatic
Signature · 1 line
2.9.3
Re: [PATCH 6/7] powerpc: switch to using thin archives if COMPILE_TEST is set
Hi Nick,
Quoted 5 lines · On Wed, 19 Oct 2016 14:15:59 +1100 Nicholas Piggin <[email protected]> wrote:
Enable thin archives build for powerpc when
COMPILE_TESTis set. Thin archives are explained in this commit:
a5967db9af51a84f5e181600954714a9e4c69f1f
This reference should be like this:
a5967db9af51 ("kbuild: allow architectures to use thin archives instead of ld -r")
Signature · 2 lines
Cheers, Stephen Rothwell
Nicholas Piggin
reviewerRe: [PATCH 6/7] powerpc: switch to using thin archives if COMPILE_TEST is set
Quoted 4 lines · On Wed, 19 Oct 2016 16:57:23 +1100 Stephen Rothwell <[email protected]>…
Hi Nick,
Quoted 1 line · On Wed, 19 Oct 2016 14:15:59 +1100 Nicholas Piggin <[email protected]> wrote:
Quoted 9 lines
Quoted 4 lines
Enable thin archives build for powerpc when
COMPILE_TESTis set. Thin archives are explained in this commit:
a5967db9af51a84f5e181600954714a9e4c69f1fThis reference should be like this:
a5967db9af51("kbuild: allow architectures to use thin archives instead of ld -r")
Hi Stephen,
Good point, I'll change it.
Thanks,
Nick
Michael Ellerman
reviewerRe: [PATCH 6/7] powerpc: switch to using thin archives if COMPILE_TEST is set
In reply to Nicholas PigginQuoted 6 lines · Nicholas Piggin
Enable thin archives build for powerpc when
COMPILE_TESTis set. Thin archives are explained in this commit:
a5967db9af51a84f5e181600954714a9e4c69f1fThis is a gradual way to introduce the option to testers.
I think I'd rather this was actually a user-selectable option, eg.
config USE_THIN_ARCHIVES
bool "Build the kernel using thin archives" default n
select THIN_ARCHIVES
help
Build the kernel using thin archives. If you're unsure say N.
cheers
Nicholas Piggin
reviewerRe: [PATCH 6/7] powerpc: switch to using thin archives if COMPILE_TEST is set
Quoted 11 lines · On Wed, 19 Oct 2016 22:00:06 +1100 Michael Ellerman <[email protected]> wrote:
Quoted 6 lines · Nicholas Piggin
Enable thin archives build for powerpc when
COMPILE_TESTis set. Thin archives are explained in this commit:
a5967db9af51a84f5e181600954714a9e4c69f1fThis is a gradual way to introduce the option to testers.
I think I'd rather this was actually a user-selectable option, eg.
Quoted 7 lines
config
USE_THIN_ARCHIVES
bool "Build the kernel using thin archives" default n
selectTHIN_ARCHIVES
help
Build the kernel using thin archives. If you're unsure say N.
Okay, that should be easy. I'll respin the series.
Thanks,
Nick
Michael Ellerman
AppliedRe: [6/7] powerpc: switch to using thin archives if COMPILE_TEST is set
In reply to Nicholas PigginQuoted 5 lines · Nicholas Piggin
Enable thin archives build for powerpc when
COMPILE_TESTis set. Thin archives are explained in this commit:
a5967db9af51a84f5e181600954714a9e4c69f1f
Quoted 7 lines
This is a gradual way to introduce the option to testers.
Some change to the way we invoke ar is required so it can be used by
scripts/link-vmlinux.sh.Signed-off-by Stephen Rothwell <[email protected]>Signed-off-by Nicholas Piggin <[email protected]>
Applied to powerpc next, thanks.
https://git.kernel.org/powerpc/c/43c9127d94d62a232ed33ed2eab8a0
cheers
Nicholas Piggin
reviewerPATCH 7/7 powerpc/64: allow CONFIG_RELOCATABLE if COMPILE_TEST
In reply to Nicholas PigginThis is cruft to work around allmodconfig build breakage.
--- arch/powerpc/Kconfig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/powerpc/Kconfig +2 -2
@@ -458,7 +458,7 @@ config KEXEC config RELOCATABLE bool "Build a relocatable kernel" - depends on (PPC64 && !COMPILE_TEST) || (FLATMEM && (44x || FSL_BOOKE)) + depends on PPC64 || (FLATMEM && (44x || FSL_BOOKE)) select NONSTATIC_KERNEL help This builds a kernel image that is capable of running at the
@@ -482,7 +482,7 @@ config RELOCATABLE config CRASH_DUMP bool "Build a kdump crash kernel" depends on PPC64 || 6xx || FSL_BOOKE || (44x && !SMP) - select RELOCATABLE if (PPC64 && !COMPILE_TEST) || 44x || FSL_BOOKE + select RELOCATABLE if PPC64 || 44x || FSL_BOOKE help Build a kernel suitable for use as a kdump capture kernel. The same kernel binary can be used as production kernel and dump
Signature · 1 line
2.9.3
Michael Ellerman
AppliedRe: [7/7] powerpc/64: allow CONFIG_RELOCATABLE if COMPILE_TEST
Quoted 3 lines · Nicholas Piggin
This is cruft to work around allmodconfig build breakage.
Signed-off-by Nicholas Piggin <[email protected]>
Applied to powerpc next, thanks.
https://git.kernel.org/powerpc/c/084a275e4c9477c432b05e872c3a29
cheers
Nicholas Piggin
reviewerQuoted 2 lines · On Wed, 19 Oct 2016 14:15:53 +1100 Nicholas Piggin <[email protected]> wrote:
[*] Building allyesconfig still requires KALLSYMS_EXTRA_PASS=1, which
I'm yet to look into.
Oh, it's because the kallsyms payload increases kernel image size and that causes more linker stubs to be generated, which have symbols, which go into kallsyms... What a nightmare.
We can use --no-emit-stub-syms, but it's kind of nice to have names for things.
Thanks,
Nick
Nicholas Piggin
reviewerRe: [PATCH 0/7] build updates (and RFC on one-pass kallsyms generation)
Quoted 6 lines · On Wed, 19 Oct 2016 18:44:22 +1100 Nicholas Piggin <[email protected]> wrote:
Quoted 2 lines · On Wed, 19 Oct 2016 14:15:53 +1100 Nicholas Piggin <[email protected]> wrote:
[*] Building allyesconfig still requires KALLSYMS_EXTRA_PASS=1, which
I'm yet to look into.
Quoted 6 lines
Oh, it's because the kallsyms payload increases kernel image size and that causes more linker stubs to be generated, which have symbols, which go into kallsyms... What a nightmare.
We can use --no-emit-stub-syms, but it's kind of nice to have names for things.
This is a real quick hack at a way to improve it.
Even if we don't go with the kbuild change (which causes a slight regression in a handful of symbols), I'll pursue the .kallsyms section and powerpc change to move it toward the end: that should be enough to avoid the build failures, and it moves a huge blob of cold data from the middle of the image.
kbuild: put kallsyms into its own section
With example linker script implementation for powerpc. This allows us to put the kallsyms section at the end of the image rather than in the middle, which doesn't jumble all our offsets when linking it in, or causing liker to add more stubs. Which means we can do kallsyms generation in one pass. A few values (_end, and some kallsyms_ variables) do move, so they don't get correct symbols.
arch/powerpc/kernel/vmlinux.lds.S +4 -0
@@ -294,6 +294,10 @@ SECTIONS BSS_SECTION(0, 0, 0) + .kallsyms : AT(ADDR(.kallsyms) - LOAD_OFFSET) { + KEEP(*(.kallsyms)) + } + . = ALIGN(PAGE_SIZE); _end = . ; PROVIDE32 (end = .);
kernel/kallsyms.c +14 -8
@@ -37,24 +37,30 @@* These will be re-linked against their real values * during the second link stage. */ -extern const unsigned long kallsyms_addresses[]__weak ; -extern const int kallsyms_offsets[]__weak ; -extern const u8 kallsyms_names[]__weak ; +extern const unsigned long kallsyms_addresses[] +__attribute__((weak, section(".kallsyms"))); +extern const int kallsyms_offsets[] +__attribute__((weak, section(".kallsyms"))); +extern const u8 kallsyms_names[] +__attribute__((weak, section(".kallsyms")));/* * Tell the compiler that the count isn't in the small data section if the arch * has one (eg: FRV). */ extern const unsigned long kallsyms_num_syms -__attribute__((weak, section(".rodata"))); +__attribute__((weak, section(".kallsyms")));extern const unsigned long kallsyms_relative_base -__attribute__((weak, section(".rodata"))); +__attribute__((weak, section(".kallsyms"))); -extern const u8 kallsyms_token_table[]__weak ; -extern const u16 kallsyms_token_index[]__weak ; +extern const u8 kallsyms_token_table[] +__attribute__((weak, section(".kallsyms"))); +extern const u16 kallsyms_token_index[] +__attribute__((weak, section(".kallsyms"))); -extern const unsigned long kallsyms_markers[]__weak ; +extern const unsigned long kallsyms_markers[] +__attribute__((weak, section(".kallsyms")));static inline int is_kernel_inittext (unsigned long addr) {
scripts/kallsyms.c +1 -1
@@ -349,7 +349,7 @@ static void write_src(void)printf ("#define ALGN .align 4\n" );printf ("#endif\n" ); -printf ("\t.section .rodata, \"a\"\n" ); +printf ("\t.section .kallsyms, \"a\"\n" );/* Provide proper symbols relocatability by their relativeness * to a fixed anchor point in the runtime image, either '_text'
commit 61502b241e9b597a60d6032a5f5a4c1dfbcafece
Author: Nicholas Piggin <[email protected]> Date: Wed Oct 19 19:56:26 2016 +1100
kbuild: one-pass kallsyms generation
With kallsyms at the end of the image, linking kallsyms doesn't change around all offsets or cause linker stubs to be added. This means kallsyms generation can be done in just one pass, and it won't fail due to linker stubs.
arch/powerpc/kernel/vmlinux.lds.S +27 -23
70 lines not on this page · raw message
scripts/link-vmlinux.sh +13 -61
98 lines not on this page · raw message