From: ard.biesheuvel@linaro.org (Ard Biesheuvel)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v2 4/4] ARM: use single definition for vectors-to-stubs section offset
Date: Wed, 3 Feb 2016 20:04:57 +0100 [thread overview]
Message-ID: <1454526297-5269-5-git-send-email-ard.biesheuvel@linaro.org> (raw)
In-Reply-To: <1454526297-5269-1-git-send-email-ard.biesheuvel@linaro.org>
This replaces a couple of unannotated uses of the constant 0x1000 with
a single definition in the linker script, and updates the referring
code to use it.
Note that this involves explicitly emitting a relocation against the
literal in .stubs containing the address of vector_swi(), since the
assembler refuses to do so.
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---
arch/arm/kernel/entry-armv.S | 17 +++++++++++++----
arch/arm/kernel/traps.c | 4 +++-
arch/arm/kernel/vmlinux.lds.S | 9 ++++++++-
3 files changed, 24 insertions(+), 6 deletions(-)
diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S
index 8575ff42c0d4..c19d3b82edb8 100644
--- a/arch/arm/kernel/entry-armv.S
+++ b/arch/arm/kernel/entry-armv.S
@@ -1064,8 +1064,7 @@ ENDPROC(vector_\name)
.endm
.section .stubs, "ax", %progbits
-__stubs_start:
- @ This must be the first word
+.Lvector_swi:
.word vector_swi
vector_rst:
@@ -1205,16 +1204,26 @@ vector_addrexcptn:
.globl vector_fiq
.section .vectors, "ax", %progbits
-.L__vectors_start:
W(b) vector_rst
W(b) vector_und
- W(ldr) pc, .L__vectors_start + 0x1000
+0: W(ldr) pc, . @ vector_swi
W(b) vector_pabt
W(b) vector_dabt
W(b) vector_addrexcptn
W(b) vector_irq
W(b) vector_fiq
+ /*
+ * The assembler refuses to emit the correct relocation for the
+ * cross-section reference to .Lvector_swi inside the ldr instruction
+ * above, so we have to emit it manually. Note that the addend cannot
+ * be set by the .reloc directive, and the initial offset recorded in
+ * the instruction should compensate for the PC bias of the execution
+ * mode, hence the use of '.' as the label.
+ */
+ ARM( .reloc 0b, R_ARM_LDR_PC_G0, .Lvector_swi )
+ THUMB( .reloc 0b, R_ARM_THM_PC12, .Lvector_swi )
+
.data
.globl cr_alignment
diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
index bc698383e822..d90a5b2c02a3 100644
--- a/arch/arm/kernel/traps.c
+++ b/arch/arm/kernel/traps.c
@@ -792,6 +792,8 @@ void __init early_trap_init(void *vectors_base)
{
#ifndef CONFIG_CPU_V7M
unsigned long vectors = (unsigned long)vectors_base;
+ extern char __stubs_offset[];
+ unsigned long stubs = vectors + (unsigned long)&__stubs_offset;
extern char __stubs_start[], __stubs_end[];
extern char __vectors_start[], __vectors_end[];
unsigned i;
@@ -813,7 +815,7 @@ void __init early_trap_init(void *vectors_base)
* are visible to the instruction stream.
*/
memcpy((void *)vectors, __vectors_start, __vectors_end - __vectors_start);
- memcpy((void *)vectors + 0x1000, __stubs_start, __stubs_end - __stubs_start);
+ memcpy((void *)stubs, __stubs_start, __stubs_end - __stubs_start);
kuser_init(vectors_base);
diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S
index 9f96a54c7d90..8f270c8e9153 100644
--- a/arch/arm/kernel/vmlinux.lds.S
+++ b/arch/arm/kernel/vmlinux.lds.S
@@ -163,7 +163,14 @@ SECTIONS
/*
* The vectors and stubs are relocatable code, and the
* only thing that matters is their relative offsets
+ * The .stubs section is virtually placed exactly 4 KB after
+ * the .vectors section, so that it is in reach for indirect
+ * jumps from the vector table ('ldr pc, <label>', where the
+ * label itself is inside the .stubs section) but can still
+ * be mapped with different permissions.
*/
+ __stubs_offset = 0x1000;
+
.stubs : {
__stubs_start = .;
*(.stubs)
@@ -171,7 +178,7 @@ SECTIONS
}
__vectors_start = .;
- .vectors ADDR(.stubs) - 0x1000 : AT(__vectors_start) {
+ .vectors ADDR(.stubs) - __stubs_offset : AT(__vectors_start) {
*(.vectors)
}
. = __vectors_start + SIZEOF(.vectors);
--
2.5.0
next prev parent reply other threads:[~2016-02-03 19:04 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-03 19:04 [PATCH v2 0/4] kallsyms: remove special handling for CONFIG_ARM Ard Biesheuvel
2016-02-03 19:04 ` [PATCH v2 1/4] ARM: move .vectors and .stubs sections back into the kernel VMA Ard Biesheuvel
2016-02-03 19:04 ` [PATCH v2 2/4] kallsyms: remove special lower address limit for CONFIG_ARM Ard Biesheuvel
2016-02-03 19:04 ` [PATCH v2 3/4] kallsyms: remove --page-offset command line option Ard Biesheuvel
2016-02-03 19:04 ` Ard Biesheuvel [this message]
2016-02-03 20:00 ` [PATCH v2 0/4] kallsyms: remove special handling for CONFIG_ARM Chris Brandt
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=1454526297-5269-5-git-send-email-ard.biesheuvel@linaro.org \
--to=ard.biesheuvel@linaro.org \
--cc=linux-arm-kernel@lists.infradead.org \
/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).