* [PATCH 1/7] powerpc: use the new post-link pass to check relocations
2016-10-19 3:15 [PATCH 0/7] build updates Nicholas Piggin
@ 2016-10-19 3:15 ` Nicholas Piggin
2016-10-19 3:15 ` [PATCH 2/7] powerpc: add arch/powerpc/tools directory Nicholas Piggin
` (6 subsequent siblings)
7 siblings, 0 replies; 22+ messages in thread
From: Nicholas Piggin @ 2016-10-19 3:15 UTC (permalink / raw)
To: linuxppc-dev; +Cc: Nicholas Piggin, Stephen Rothwell
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.
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
arch/powerpc/Makefile | 11 -----------
arch/powerpc/Makefile.postlink | 34 ++++++++++++++++++++++++++++++++++
2 files changed, 34 insertions(+), 11 deletions(-)
create mode 100644 arch/powerpc/Makefile.postlink
diff --git a/arch/powerpc/Makefile b/arch/powerpc/Makefile
index 617dece..314dd77 100644
--- a/arch/powerpc/Makefile
+++ b/arch/powerpc/Makefile
@@ -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
diff --git a/arch/powerpc/Makefile.postlink b/arch/powerpc/Makefile.postlink
new file mode 100644
index 0000000..f90bdc0
--- /dev/null
+++ b/arch/powerpc/Makefile.postlink
@@ -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)
--
2.9.3
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [PATCH 2/7] powerpc: add arch/powerpc/tools directory
2016-10-19 3:15 [PATCH 0/7] build updates Nicholas Piggin
2016-10-19 3:15 ` [PATCH 1/7] powerpc: use the new post-link pass to check relocations Nicholas Piggin
@ 2016-10-19 3:15 ` Nicholas Piggin
2016-10-19 3:15 ` [PATCH 3/7] powerpc/64s: tool to flag direct branches from unrelocated interrupt vectors Nicholas Piggin
` (5 subsequent siblings)
7 siblings, 0 replies; 22+ messages in thread
From: Nicholas Piggin @ 2016-10-19 3:15 UTC (permalink / raw)
To: linuxppc-dev; +Cc: Nicholas Piggin, Stephen Rothwell
Move 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.
Signed-off-by: Nick Piggin <npiggin@gmail.com>
---
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%)
diff --git a/arch/powerpc/Makefile b/arch/powerpc/Makefile
index 314dd77..0fcb47c 100644
--- a/arch/powerpc/Makefile
+++ b/arch/powerpc/Makefile
@@ -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
diff --git a/arch/powerpc/Makefile.postlink b/arch/powerpc/Makefile.postlink
index f90bdc0..29c0a3a 100644
--- a/arch/powerpc/Makefile.postlink
+++ b/arch/powerpc/Makefile.postlink
@@ -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
diff --git a/arch/powerpc/scripts/gcc-check-mprofile-kernel.sh b/arch/powerpc/tools/gcc-check-mprofile-kernel.sh
similarity index 100%
rename from arch/powerpc/scripts/gcc-check-mprofile-kernel.sh
rename to arch/powerpc/tools/gcc-check-mprofile-kernel.sh
diff --git a/arch/powerpc/relocs_check.sh b/arch/powerpc/tools/relocs_check.sh
similarity index 100%
rename from arch/powerpc/relocs_check.sh
rename to arch/powerpc/tools/relocs_check.sh
--
2.9.3
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [PATCH 3/7] powerpc/64s: tool to flag direct branches from unrelocated interrupt vectors
2016-10-19 3:15 [PATCH 0/7] build updates Nicholas Piggin
2016-10-19 3:15 ` [PATCH 1/7] powerpc: use the new post-link pass to check relocations Nicholas Piggin
2016-10-19 3:15 ` [PATCH 2/7] powerpc: add arch/powerpc/tools directory Nicholas Piggin
@ 2016-10-19 3:15 ` Nicholas Piggin
2016-10-19 4:28 ` Balbir Singh
2016-10-19 10:57 ` Michael Ellerman
2016-10-19 3:15 ` [PATCH 4/7] powerpc/64: tool to check head sections location sanity Nicholas Piggin
` (4 subsequent siblings)
7 siblings, 2 replies; 22+ messages in thread
From: Nicholas Piggin @ 2016-10-19 3:15 UTC (permalink / raw)
To: linuxppc-dev; +Cc: Nicholas Piggin, Stephen Rothwell
Direct 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>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
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
diff --git a/arch/powerpc/Makefile.postlink b/arch/powerpc/Makefile.postlink
index 29c0a3a..1725e64 100644
--- a/arch/powerpc/Makefile.postlink
+++ b/arch/powerpc/Makefile.postlink
@@ -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
diff --git a/arch/powerpc/tools/unrel_branch_check.sh b/arch/powerpc/tools/unrel_branch_check.sh
new file mode 100755
index 0000000..524a9e2
--- /dev/null
+++ b/arch/powerpc/tools/unrel_branch_check.sh
@@ -0,0 +1,56 @@
+#!/bin/bash
+#
+# 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 relocations of a vmlinux for "suspicious"
+# branches from unrelocated code (head_64.S code).
+
+# Have Kbuild supply the path to objdump so we handle cross compilation.
+objdump="$1"
+vmlinux="$2"
+
+#__end_interrupts should be located within the first 64K
+
+end_intr=0x$(
+"$objdump" -R "$vmlinux" -d --start-address=0xc000000000000000 \
+ --stop-address=0xc000000000010000 |
+grep '\<__end_interrupts>:' |
+awk '{print $1}'
+)
+
+BRANCHES=$(
+"$objdump" -R "$vmlinux" -D --start-address=0xc000000000000000 \
+ --stop-address=${end_intr} |
+grep -e "^c[0-9a-f]*:[[:space:]]*\([0-9a-f][0-9a-f][[:space:]]\)\{4\}[[:space:]]*b" |
+grep -v '\<__start_initialization_multiplatform>' |
+grep -v -e 'b.\?.\?ctr' |
+grep -v -e 'b.\?.\?lr' |
+sed 's/://' |
+awk '{ print $1 ":" $6 ":0x" $7 ":" $8 " "}'
+)
+
+for tuple in $BRANCHES
+do
+ from=`echo $tuple | cut -d':' -f1`
+ branch=`echo $tuple | cut -d':' -f2`
+ to=`echo $tuple | cut -d':' -f3 | sed 's/cr[0-7],//'`
+ sym=`echo $tuple | cut -d':' -f4`
+
+ if (( $to > $end_intr ))
+ then
+ if [ -z "$bad_branches" ]; then
+ echo "WARNING: Unrelocated relative branches"
+ bad_branches="yes"
+ fi
+ echo "$from $branch-> $to $sym"
+ fi
+done
+
+if [ -z "$bad_branches" ]; then
+ exit 0
+fi
--
2.9.3
^ permalink raw reply related [flat|nested] 22+ messages in thread
* Re: [PATCH 3/7] powerpc/64s: tool to flag direct branches from unrelocated interrupt vectors
2016-10-19 3:15 ` [PATCH 3/7] powerpc/64s: tool to flag direct branches from unrelocated interrupt vectors Nicholas Piggin
@ 2016-10-19 4:28 ` Balbir Singh
2016-10-19 6:01 ` Nicholas Piggin
2016-10-19 10:57 ` Michael Ellerman
1 sibling, 1 reply; 22+ messages in thread
From: Balbir Singh @ 2016-10-19 4:28 UTC (permalink / raw)
To: Nicholas Piggin, linuxppc-dev; +Cc: Stephen Rothwell
On 19/10/16 14:15, Nicholas Piggin wrote:
> Direct 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>
>
> Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
> ---
If this is the same script I gave you, you can add my SOB line as well
Balbir
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH 3/7] powerpc/64s: tool to flag direct branches from unrelocated interrupt vectors
2016-10-19 4:28 ` Balbir Singh
@ 2016-10-19 6:01 ` Nicholas Piggin
0 siblings, 0 replies; 22+ messages in thread
From: Nicholas Piggin @ 2016-10-19 6:01 UTC (permalink / raw)
To: Balbir Singh; +Cc: linuxppc-dev, Stephen Rothwell
On Wed, 19 Oct 2016 15:28:40 +1100
Balbir Singh <bsingharora@gmail.com> wrote:
> On 19/10/16 14:15, Nicholas Piggin wrote:
> > Direct 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>
> >
> > Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
> > ---
>
> 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.
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH 3/7] powerpc/64s: tool to flag direct branches from unrelocated interrupt vectors
2016-10-19 3:15 ` [PATCH 3/7] powerpc/64s: tool to flag direct branches from unrelocated interrupt vectors Nicholas Piggin
2016-10-19 4:28 ` Balbir Singh
@ 2016-10-19 10:57 ` Michael Ellerman
1 sibling, 0 replies; 22+ messages in thread
From: Michael Ellerman @ 2016-10-19 10:57 UTC (permalink / raw)
To: Nicholas Piggin, linuxppc-dev; +Cc: Stephen Rothwell, Nicholas Piggin
Nicholas Piggin <npiggin@gmail.com> writes:
> Direct 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>
>
> Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
> ---
> 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
^ permalink raw reply [flat|nested] 22+ messages in thread
* [PATCH 4/7] powerpc/64: tool to check head sections location sanity
2016-10-19 3:15 [PATCH 0/7] build updates Nicholas Piggin
` (2 preceding siblings ...)
2016-10-19 3:15 ` [PATCH 3/7] powerpc/64s: tool to flag direct branches from unrelocated interrupt vectors Nicholas Piggin
@ 2016-10-19 3:15 ` Nicholas Piggin
2016-11-15 0:55 ` Michael Ellerman
2016-10-19 3:15 ` [PATCH 5/7] powerpc/64: handle linker stubs in low .text code Nicholas Piggin
` (3 subsequent siblings)
7 siblings, 1 reply; 22+ messages in thread
From: Nicholas Piggin @ 2016-10-19 3:15 UTC (permalink / raw)
To: linuxppc-dev; +Cc: Nicholas Piggin, Stephen Rothwell
Use 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
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
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
diff --git a/arch/powerpc/Makefile.postlink b/arch/powerpc/Makefile.postlink
index 1725e64..b8fe12b 100644
--- a/arch/powerpc/Makefile.postlink
+++ b/arch/powerpc/Makefile.postlink
@@ -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
diff --git a/arch/powerpc/include/asm/head-64.h b/arch/powerpc/include/asm/head-64.h
index ab90c2f..492ebe7 100644
--- a/arch/powerpc/include/asm/head-64.h
+++ b/arch/powerpc/include/asm/head-64.h
@@ -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.
*/
diff --git a/arch/powerpc/kernel/vmlinux.lds.S b/arch/powerpc/kernel/vmlinux.lds.S
index 8295f51..7de0b05 100644
--- a/arch/powerpc/kernel/vmlinux.lds.S
+++ b/arch/powerpc/kernel/vmlinux.lds.S
@@ -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
diff --git a/arch/powerpc/tools/head_check.sh b/arch/powerpc/tools/head_check.sh
new file mode 100755
index 0000000..9635fe7
--- /dev/null
+++ b/arch/powerpc/tools/head_check.sh
@@ -0,0 +1,69 @@
+#!/bin/sh
+
+# 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 inserting
+# 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.
+
+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.txt
+
+
+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"
+
+ exit 1
+fi
+
+top_vma=$(echo $vma | cut -d'0' -f1)
+
+expected_start_text_addr=$(cat .tmp_symbols.txt | grep " a text_start$" | cut -d' ' -f1 | sed "s/^0/$top_vma/")
+
+start_text_addr=$(cat .tmp_symbols.txt | grep " t start_text$" | cut -d' ' -f1)
+
+if [ "$start_text_addr" != "$expected_start_text_addr" ]; then
+ echo "ERROR: start_text address is $start_text_addr, should be $expected_start_text_addr"
+ echo "ERROR: see comments in arch/powerpc/tools/head_check.sh"
+
+ exit 1
+fi
+
+rm .tmp_symbols.txt
--
2.9.3
^ permalink raw reply related [flat|nested] 22+ messages in thread
* Re: [PATCH 4/7] powerpc/64: tool to check head sections location sanity
2016-10-19 3:15 ` [PATCH 4/7] powerpc/64: tool to check head sections location sanity Nicholas Piggin
@ 2016-11-15 0:55 ` Michael Ellerman
2016-11-22 4:54 ` Nicholas Piggin
0 siblings, 1 reply; 22+ messages in thread
From: Michael Ellerman @ 2016-11-15 0:55 UTC (permalink / raw)
To: Nicholas Piggin, linuxppc-dev; +Cc: Stephen Rothwell, Nicholas Piggin
Nicholas Piggin <npiggin@gmail.com> writes:
> diff --git a/arch/powerpc/Makefile.postlink b/arch/powerpc/Makefile.postl=
ink
> index 1725e64..b8fe12b 100644
> --- a/arch/powerpc/Makefile.postlink
> +++ b/arch/powerpc/Makefile.postlink
> @@ -24,6 +27,9 @@ endif
>=20=20
> vmlinux: FORCE
> @true
> +ifeq ($(CONFIG_PPC64),y)
You can just use:
ifdef CONFIG_PPC64
> + $(call cmd,head_check)
> +endif
> ifeq ($(CONFIG_RELOCATABLE),y)
> $(call if_changed,relocs_check)
> endif
> @@ -32,6 +38,7 @@ endif
> @true
>=20=20
> clean:
> + rm -f .tmp_symbols.txt
> @true
We shouldn't need the true anymore should we?
> diff --git a/arch/powerpc/tools/head_check.sh b/arch/powerpc/tools/head_c=
heck.sh
> new file mode 100755
> index 0000000..9635fe7
> --- /dev/null
> +++ b/arch/powerpc/tools/head_check.sh
> @@ -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.
> +# 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.
> +
> +# 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
> +# 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_br=
anch
> +# 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. Th=
is
> +# could cause the kernel to die in early boot.
Can you add:
# Turn this on if you want more debug output:
# set -x
> +
> +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.
> +
> +
> +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)
> +
> +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
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH 4/7] powerpc/64: tool to check head sections location sanity
2016-11-15 0:55 ` Michael Ellerman
@ 2016-11-22 4:54 ` Nicholas Piggin
2016-11-22 5:56 ` Michael Ellerman
0 siblings, 1 reply; 22+ messages in thread
From: Nicholas Piggin @ 2016-11-22 4:54 UTC (permalink / raw)
To: Michael Ellerman; +Cc: linuxppc-dev, Stephen Rothwell
On Tue, 15 Nov 2016 11:55:26 +1100
Michael Ellerman <mpe@ellerman.id.au> wrote:
> Nicholas Piggin <npiggin@gmail.com> writes:
>
> > diff --git a/arch/powerpc/Makefile.postlink b/arch/powerpc/Makefile.postlink
> > index 1725e64..b8fe12b 100644
> > --- a/arch/powerpc/Makefile.postlink
> > +++ b/arch/powerpc/Makefile.postlink
> > @@ -24,6 +27,9 @@ endif
> >
> > vmlinux: 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.
> > + $(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
>
> We shouldn't need the true anymore should we?
True.
> > diff --git a/arch/powerpc/tools/head_check.sh b/arch/powerpc/tools/head_check.sh
> > new file mode 100755
> > index 0000000..9635fe7
> > --- /dev/null
> > +++ b/arch/powerpc/tools/head_check.sh
> > @@ -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.
Okay. How about relocs_check.sh? I just started by copying that.
>
> > +# 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 inserting
> > +# 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:
>
> # Turn this on if you want more debug output:
> # set -x
Can do, same question applies for relocs_check.sh
>
> > +
> > +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.txt
>
> You don't use $nm there.
Thanks, good catch.
> > +
> > +
> > +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.
>
> It says:
>
> ERROR: start_text address is c000000000001100, should be c000000000000200
I must have forgotten to test e. I'll fix that.
Thanks,
Nick
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH 4/7] powerpc/64: tool to check head sections location sanity
2016-11-22 4:54 ` Nicholas Piggin
@ 2016-11-22 5:56 ` Michael Ellerman
0 siblings, 0 replies; 22+ messages in thread
From: Michael Ellerman @ 2016-11-22 5:56 UTC (permalink / raw)
To: Nicholas Piggin; +Cc: linuxppc-dev, Stephen Rothwell
Nicholas Piggin <npiggin@gmail.com> writes:
> On Tue, 15 Nov 2016 11:55:26 +1100
> Michael Ellerman <mpe@ellerman.id.au> wrote:
>> Nicholas Piggin <npiggin@gmail.com> writes:
>> > diff --git a/arch/powerpc/tools/head_check.sh b/arch/powerpc/tools/head_check.sh
>> > new file mode 100755
>> > index 0000000..9635fe7
>> > --- /dev/null
>> > +++ b/arch/powerpc/tools/head_check.sh
>> > @@ -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.
>
> Okay. How about relocs_check.sh? I just started by copying that.
Yeah may as well fix it too.
>> # Turn this on if you want more debug output:
>> # set -x
>
> Can do, same question applies for relocs_check.sh
Yep, save the next person who's debugging it the time.
cheers
^ permalink raw reply [flat|nested] 22+ messages in thread
* [PATCH 5/7] powerpc/64: handle linker stubs in low .text code
2016-10-19 3:15 [PATCH 0/7] build updates Nicholas Piggin
` (3 preceding siblings ...)
2016-10-19 3:15 ` [PATCH 4/7] powerpc/64: tool to check head sections location sanity Nicholas Piggin
@ 2016-10-19 3:15 ` Nicholas Piggin
2016-10-19 3:15 ` [PATCH 6/7] powerpc: switch to using thin archives if COMPILE_TEST is set Nicholas Piggin
` (2 subsequent siblings)
7 siblings, 0 replies; 22+ messages in thread
From: Nicholas Piggin @ 2016-10-19 3:15 UTC (permalink / raw)
To: linuxppc-dev; +Cc: Nicholas Piggin, Stephen Rothwell
Very 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.
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
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(-)
diff --git a/arch/powerpc/include/asm/head-64.h b/arch/powerpc/include/asm/head-64.h
index 492ebe7..f7131cf 100644
--- a/arch/powerpc/include/asm/head-64.h
+++ b/arch/powerpc/include/asm/head-64.h
@@ -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); \
diff --git a/arch/powerpc/kernel/vmlinux.lds.S b/arch/powerpc/kernel/vmlinux.lds.S
index 7de0b05..a09c666 100644
--- a/arch/powerpc/kernel/vmlinux.lds.S
+++ b/arch/powerpc/kernel/vmlinux.lds.S
@@ -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);
diff --git a/arch/powerpc/tools/head_check.sh b/arch/powerpc/tools/head_check.sh
index 9635fe7..ae9faeb 100755
--- a/arch/powerpc/tools/head_check.sh
+++ b/arch/powerpc/tools/head_check.sh
@@ -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
--
2.9.3
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [PATCH 6/7] powerpc: switch to using thin archives if COMPILE_TEST is set
2016-10-19 3:15 [PATCH 0/7] build updates Nicholas Piggin
` (4 preceding siblings ...)
2016-10-19 3:15 ` [PATCH 5/7] powerpc/64: handle linker stubs in low .text code Nicholas Piggin
@ 2016-10-19 3:15 ` Nicholas Piggin
2016-10-19 5:57 ` Stephen Rothwell
` (2 more replies)
2016-10-19 3:16 ` [PATCH 7/7] powerpc/64: allow CONFIG_RELOCATABLE if COMPILE_TEST Nicholas Piggin
2016-10-19 7:44 ` [PATCH 0/7] build updates Nicholas Piggin
7 siblings, 3 replies; 22+ messages in thread
From: Nicholas Piggin @ 2016-10-19 3:15 UTC (permalink / raw)
To: linuxppc-dev; +Cc: Nicholas Piggin, Stephen Rothwell
Enable 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.
Signed-off-by: Stephen Rothwell <sfr@canb.auug.org.au>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
arch/powerpc/Kconfig | 1 +
arch/powerpc/Makefile | 4 ++--
2 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index 65fba4c..00d9e31 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -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
diff --git a/arch/powerpc/Makefile b/arch/powerpc/Makefile
index 0fcb47c..fe76cfe 100644
--- a/arch/powerpc/Makefile
+++ b/arch/powerpc/Makefile
@@ -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
--
2.9.3
^ permalink raw reply related [flat|nested] 22+ messages in thread
* Re: [PATCH 6/7] powerpc: switch to using thin archives if COMPILE_TEST is set
2016-10-19 3:15 ` [PATCH 6/7] powerpc: switch to using thin archives if COMPILE_TEST is set Nicholas Piggin
@ 2016-10-19 5:57 ` Stephen Rothwell
2016-10-19 9:26 ` Nicholas Piggin
2016-10-19 11:00 ` Michael Ellerman
2016-11-22 0:34 ` [6/7] " Michael Ellerman
2 siblings, 1 reply; 22+ messages in thread
From: Stephen Rothwell @ 2016-10-19 5:57 UTC (permalink / raw)
To: Nicholas Piggin; +Cc: linuxppc-dev
Hi Nick,
On Wed, 19 Oct 2016 14:15:59 +1100 Nicholas Piggin <npiggin@gmail.com> wrote:
>
> Enable thin archives build for powerpc when COMPILE_TEST is 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")
--
Cheers,
Stephen Rothwell
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH 6/7] powerpc: switch to using thin archives if COMPILE_TEST is set
2016-10-19 5:57 ` Stephen Rothwell
@ 2016-10-19 9:26 ` Nicholas Piggin
0 siblings, 0 replies; 22+ messages in thread
From: Nicholas Piggin @ 2016-10-19 9:26 UTC (permalink / raw)
To: Stephen Rothwell; +Cc: linuxppc-dev
On Wed, 19 Oct 2016 16:57:23 +1100
Stephen Rothwell <sfr@canb.auug.org.au> wrote:
> Hi Nick,
>
> On Wed, 19 Oct 2016 14:15:59 +1100 Nicholas Piggin <npiggin@gmail.com> wrote:
> >
> > Enable thin archives build for powerpc when COMPILE_TEST is 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")
>
Hi Stephen,
Good point, I'll change it.
Thanks,
Nick
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH 6/7] powerpc: switch to using thin archives if COMPILE_TEST is set
2016-10-19 3:15 ` [PATCH 6/7] powerpc: switch to using thin archives if COMPILE_TEST is set Nicholas Piggin
2016-10-19 5:57 ` Stephen Rothwell
@ 2016-10-19 11:00 ` Michael Ellerman
2016-10-20 3:48 ` Nicholas Piggin
2016-11-22 0:34 ` [6/7] " Michael Ellerman
2 siblings, 1 reply; 22+ messages in thread
From: Michael Ellerman @ 2016-10-19 11:00 UTC (permalink / raw)
To: Nicholas Piggin, linuxppc-dev; +Cc: Stephen Rothwell, Nicholas Piggin
Nicholas Piggin <npiggin@gmail.com> writes:
> Enable 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.
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
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH 6/7] powerpc: switch to using thin archives if COMPILE_TEST is set
2016-10-19 11:00 ` Michael Ellerman
@ 2016-10-20 3:48 ` Nicholas Piggin
0 siblings, 0 replies; 22+ messages in thread
From: Nicholas Piggin @ 2016-10-20 3:48 UTC (permalink / raw)
To: Michael Ellerman; +Cc: linuxppc-dev, Stephen Rothwell
On Wed, 19 Oct 2016 22:00:06 +1100
Michael Ellerman <mpe@ellerman.id.au> wrote:
> Nicholas Piggin <npiggin@gmail.com> writes:
>
> > Enable 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.
>
> 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.
Okay, that should be easy. I'll respin the series.
Thanks,
Nick
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [6/7] powerpc: switch to using thin archives if COMPILE_TEST is set
2016-10-19 3:15 ` [PATCH 6/7] powerpc: switch to using thin archives if COMPILE_TEST is set Nicholas Piggin
2016-10-19 5:57 ` Stephen Rothwell
2016-10-19 11:00 ` Michael Ellerman
@ 2016-11-22 0:34 ` Michael Ellerman
2 siblings, 0 replies; 22+ messages in thread
From: Michael Ellerman @ 2016-11-22 0:34 UTC (permalink / raw)
To: Nicholas Piggin, linuxppc-dev; +Cc: Stephen Rothwell, Nicholas Piggin
On Wed, 2016-10-19 at 03:15:59 UTC, Nicholas Piggin wrote:
> Enable 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.
>
> Signed-off-by: Stephen Rothwell <sfr@canb.auug.org.au>
> Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
Applied to powerpc next, thanks.
https://git.kernel.org/powerpc/c/43c9127d94d62a232ed33ed2eab8a0
cheers
^ permalink raw reply [flat|nested] 22+ messages in thread
* [PATCH 7/7] powerpc/64: allow CONFIG_RELOCATABLE if COMPILE_TEST
2016-10-19 3:15 [PATCH 0/7] build updates Nicholas Piggin
` (5 preceding siblings ...)
2016-10-19 3:15 ` [PATCH 6/7] powerpc: switch to using thin archives if COMPILE_TEST is set Nicholas Piggin
@ 2016-10-19 3:16 ` Nicholas Piggin
2017-05-03 22:18 ` [7/7] " Michael Ellerman
2016-10-19 7:44 ` [PATCH 0/7] build updates Nicholas Piggin
7 siblings, 1 reply; 22+ messages in thread
From: Nicholas Piggin @ 2016-10-19 3:16 UTC (permalink / raw)
To: linuxppc-dev; +Cc: Nicholas Piggin, Stephen Rothwell
This is cruft to work around allmodconfig build breakage.
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
arch/powerpc/Kconfig | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index 00d9e31..f48d2eb 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -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
--
2.9.3
^ permalink raw reply related [flat|nested] 22+ messages in thread
* Re: [PATCH 0/7] build updates
2016-10-19 3:15 [PATCH 0/7] build updates Nicholas Piggin
` (6 preceding siblings ...)
2016-10-19 3:16 ` [PATCH 7/7] powerpc/64: allow CONFIG_RELOCATABLE if COMPILE_TEST Nicholas Piggin
@ 2016-10-19 7:44 ` Nicholas Piggin
2016-10-21 6:35 ` [PATCH 0/7] build updates (and RFC on one-pass kallsyms generation) Nicholas Piggin
7 siblings, 1 reply; 22+ messages in thread
From: Nicholas Piggin @ 2016-10-19 7:44 UTC (permalink / raw)
To: linuxppc-dev; +Cc: Stephen Rothwell
On Wed, 19 Oct 2016 14:15:53 +1100
Nicholas Piggin <npiggin@gmail.com> 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
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH 0/7] build updates (and RFC on one-pass kallsyms generation)
2016-10-19 7:44 ` [PATCH 0/7] build updates Nicholas Piggin
@ 2016-10-21 6:35 ` Nicholas Piggin
0 siblings, 0 replies; 22+ messages in thread
From: Nicholas Piggin @ 2016-10-21 6:35 UTC (permalink / raw)
To: linuxppc-dev; +Cc: Stephen Rothwell, linux-kbuild
On Wed, 19 Oct 2016 18:44:22 +1100
Nicholas Piggin <npiggin@gmail.com> wrote:
> On Wed, 19 Oct 2016 14:15:53 +1100
> Nicholas Piggin <npiggin@gmail.com> 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.
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.
diff --git a/arch/powerpc/kernel/vmlinux.lds.S b/arch/powerpc/kernel/vmlinux.lds.S
index 115a44e..9ebe1df 100644
--- a/arch/powerpc/kernel/vmlinux.lds.S
+++ b/arch/powerpc/kernel/vmlinux.lds.S
@@ -294,6 +294,10 @@ SECTIONS
BSS_SECTION(0, 0, 0)
+ .kallsyms : AT(ADDR(.kallsyms) - LOAD_OFFSET) {
+ KEEP(*(.kallsyms))
+ }
+
. = ALIGN(PAGE_SIZE);
_end = . ;
PROVIDE32 (end = .);
diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
index fafd1a3..311fe07 100644
--- a/kernel/kallsyms.c
+++ b/kernel/kallsyms.c
@@ -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)
{
diff --git a/scripts/kallsyms.c b/scripts/kallsyms.c
index 1f22a18..4327d80 100644
--- a/scripts/kallsyms.c
+++ b/scripts/kallsyms.c
@@ -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 <npiggin@gmail.com>
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.
diff --git a/arch/powerpc/kernel/vmlinux.lds.S b/arch/powerpc/kernel/vmlinux.lds.S
index 9ebe1df..534c8df 100644
--- a/arch/powerpc/kernel/vmlinux.lds.S
+++ b/arch/powerpc/kernel/vmlinux.lds.S
@@ -190,29 +190,6 @@ SECTIONS
*(.machine.desc)
__machine_desc_end = . ;
}
-#ifdef CONFIG_RELOCATABLE
- . = ALIGN(8);
- .dynsym : AT(ADDR(.dynsym) - LOAD_OFFSET)
- {
-#ifdef CONFIG_PPC32
- __dynamic_symtab = .;
-#endif
- *(.dynsym)
- }
- .dynstr : AT(ADDR(.dynstr) - LOAD_OFFSET) { *(.dynstr) }
- .dynamic : AT(ADDR(.dynamic) - LOAD_OFFSET)
- {
- __dynamic_start = .;
- *(.dynamic)
- }
- .hash : AT(ADDR(.hash) - LOAD_OFFSET) { *(.hash) }
- .interp : AT(ADDR(.interp) - LOAD_OFFSET) { *(.interp) }
- .rela.dyn : AT(ADDR(.rela.dyn) - LOAD_OFFSET)
- {
- __rela_dyn_start = .;
- *(.rela*)
- }
-#endif
/* .exit.data is discarded at runtime, not link time,
* to deal with references from .exit.text
*/
@@ -294,9 +271,35 @@ SECTIONS
BSS_SECTION(0, 0, 0)
+#ifdef CONFIG_RELOCATABLE
+ . = ALIGN(8);
+ .dynsym : AT(ADDR(.dynsym) - LOAD_OFFSET)
+ {
+#ifdef CONFIG_PPC32
+ __dynamic_symtab = .;
+#endif
+ *(.dynsym)
+ }
+ .dynstr : AT(ADDR(.dynstr) - LOAD_OFFSET) { *(.dynstr) }
+ .dynamic : AT(ADDR(.dynamic) - LOAD_OFFSET)
+ {
+ __dynamic_start = .;
+ *(.dynamic)
+ }
+ .hash : AT(ADDR(.hash) - LOAD_OFFSET) { *(.hash) }
+ .interp : AT(ADDR(.interp) - LOAD_OFFSET) { *(.interp) }
+ .rela.dyn : AT(ADDR(.rela.dyn) - LOAD_OFFSET)
+ {
+ __rela_dyn_start = .;
+ *(.rela*)
+ }
+#endif
+
+#ifdef CONFIG_KALLSYMS
.kallsyms : AT(ADDR(.kallsyms) - LOAD_OFFSET) {
KEEP(*(.kallsyms))
}
+#endif
. = ALIGN(PAGE_SIZE);
_end = . ;
@@ -313,5 +316,6 @@ SECTIONS
*(.gnu.version*)
*(.gnu.attributes)
*(.eh_frame)
+ *(.kallsyms)
}
}
diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh
index f742c65..b37a62b 100755
--- a/scripts/link-vmlinux.sh
+++ b/scripts/link-vmlinux.sh
@@ -209,15 +209,6 @@ case "${KCONFIG_CONFIG}" in
. "./${KCONFIG_CONFIG}"
esac
-archive_builtin
-
-#link vmlinux.o
-info LD vmlinux.o
-modpost_link vmlinux.o
-
-# modpost vmlinux.o to check for section mismatches
-${MAKE} -f "${srctree}/scripts/Makefile.modpost" vmlinux.o
-
# Update version
info GEN .version
if [ ! -r .version ]; then
@@ -231,54 +222,26 @@ fi;
# final build of init/
${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init GCC_PLUGINS_CFLAGS="${GCC_PLUGINS_CFLAGS}"
+archive_builtin
+
+# link vmlinux.o
+info LD vmlinux.o
+modpost_link vmlinux.o
+
+# modpost vmlinux.o to check for section mismatches
+${MAKE} -f "${srctree}/scripts/Makefile.modpost" vmlinux.o
+
kallsymso=""
-kallsyms_vmlinux=""
if [ -n "${CONFIG_KALLSYMS}" ]; then
-
- # kallsyms support
- # Generate section listing all symbols and add it into vmlinux
- # It's a three step process:
- # 1) Link .tmp_vmlinux1 so it has all symbols and sections,
- # but __kallsyms is empty.
- # Running kallsyms on that gives us .tmp_kallsyms1.o with
- # the right size
- # 2) Link .tmp_vmlinux2 so it now has a __kallsyms section of
- # the right size, but due to the added section, some
- # addresses have shifted.
- # From here, we generate a correct .tmp_kallsyms2.o
- # 2a) We may use an extra pass as this has been necessary to
- # woraround some alignment related bugs.
- # KALLSYMS_EXTRA_PASS=1 is used to trigger this.
- # 3) The correct ${kallsymso} is linked into the final vmlinux.
- #
- # a) Verify that the System.map from vmlinux matches the map from
- # ${kallsymso}.
-
- kallsymso=.tmp_kallsyms2.o
- kallsyms_vmlinux=.tmp_vmlinux2
-
- # step 1
- vmlinux_link "" .tmp_vmlinux1
- kallsyms .tmp_vmlinux1 .tmp_kallsyms1.o
-
- # step 2
- vmlinux_link .tmp_kallsyms1.o .tmp_vmlinux2
- kallsyms .tmp_vmlinux2 .tmp_kallsyms2.o
-
- # step 2a
- if [ -n "${KALLSYMS_EXTRA_PASS}" ]; then
- kallsymso=.tmp_kallsyms3.o
- kallsyms_vmlinux=.tmp_vmlinux3
-
- vmlinux_link .tmp_kallsyms2.o .tmp_vmlinux3
-
- kallsyms .tmp_vmlinux3 .tmp_kallsyms3.o
- fi
+ vmlinux_link "${kallsymso}" .tmp_vmlinux
+ kallsyms .tmp_vmlinux kallsyms.o
+ kallsymso="kallsyms.o"
fi
info LD vmlinux
vmlinux_link "${kallsymso}" vmlinux
+
if [ -n "${CONFIG_BUILDTIME_EXTABLE_SORT}" ]; then
info SORTEX vmlinux
sortextable vmlinux
@@ -287,16 +250,5 @@ fi
info SYSMAP System.map
mksysmap vmlinux System.map
-# step a (see comment above)
-if [ -n "${CONFIG_KALLSYMS}" ]; then
- mksysmap ${kallsyms_vmlinux} .tmp_System.map
-
- if ! cmp -s System.map .tmp_System.map; then
- echo >&2 Inconsistent kallsyms data
- echo >&2 Try "make KALLSYMS_EXTRA_PASS=1" as a workaround
- exit 1
- fi
-fi
-
# We made a new kernel - delete old version file
rm -f .old_version
^ permalink raw reply related [flat|nested] 22+ messages in thread