From: Nicholas Piggin <npiggin@gmail.com>
To: linuxppc-dev@lists.ozlabs.org
Cc: Nicholas Piggin <npiggin@gmail.com>,
Stephen Rothwell <sfr@canb.auug.org.au>
Subject: [PATCH 5/7] powerpc/64: handle linker stubs in low .text code
Date: Wed, 19 Oct 2016 14:15:58 +1100 [thread overview]
Message-ID: <20161019031600.17933-6-npiggin@gmail.com> (raw)
In-Reply-To: <20161019031600.17933-1-npiggin@gmail.com>
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
next prev parent reply other threads:[~2016-10-19 3:16 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
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 ` [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
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
2016-11-22 5:56 ` Michael Ellerman
2016-10-19 3:15 ` Nicholas Piggin [this message]
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-10-20 3:48 ` Nicholas Piggin
2016-11-22 0:34 ` [6/7] " Michael Ellerman
2016-10-19 3:16 ` [PATCH 7/7] powerpc/64: allow CONFIG_RELOCATABLE if COMPILE_TEST Nicholas Piggin
2017-05-03 22:18 ` [7/7] " Michael Ellerman
2016-10-19 7:44 ` [PATCH 0/7] build updates Nicholas Piggin
2016-10-21 6:35 ` [PATCH 0/7] build updates (and RFC on one-pass kallsyms generation) Nicholas Piggin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20161019031600.17933-6-npiggin@gmail.com \
--to=npiggin@gmail.com \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=sfr@canb.auug.org.au \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).