From: ard.biesheuvel@linaro.org (Ard Biesheuvel)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 2/2] ARM: assembler: prevent ADR from setting the Thumb bit twice
Date: Tue, 19 Jun 2018 21:26:33 +0200 [thread overview]
Message-ID: <20180619192633.21846-3-ard.biesheuvel@linaro.org> (raw)
In-Reply-To: <20180619192633.21846-1-ard.biesheuvel@linaro.org>
To work around recent issues where ADR references to Thumb function
symbols may or may not have the Thumb bit set already when they are
resolved by GAS, reference the symbol indirectly via a local symbol
typed as 'function', and emit the reference in a way that prevents
the assembler from resolving it directly. Instead, it will be fixed
up by the linker, which behaves consistently and according to spec
when it comes to relocations of symbols with function annotation
targetting wide ADR instructions.
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---
arch/arm/include/asm/assembler.h | 22 +++++++++++++++++++-
1 file changed, 21 insertions(+), 1 deletion(-)
diff --git a/arch/arm/include/asm/assembler.h b/arch/arm/include/asm/assembler.h
index 6ae42ad29518..ee2d4eb26318 100644
--- a/arch/arm/include/asm/assembler.h
+++ b/arch/arm/include/asm/assembler.h
@@ -195,13 +195,33 @@
.irp c,,eq,ne,cs,cc,mi,pl,vs,vc,hi,ls,ge,lt,gt,le,hs,lo
.macro badr\c, rd, sym
#ifdef CONFIG_THUMB2_KERNEL
- adr\c \rd, \sym + 1
+ __badr \c, \rd, \sym
#else
adr\c \rd, \sym
#endif
.endm
.endr
+ /*
+ * GAS's behavior with respect to setting the Thumb bit on addresses
+ * of locally defined symbols taken using adr instructions is
+ * inconsistent, and so we are better off letting the linker handle
+ * it instead. So emit the reference as a relocation, and force a
+ * wide encoding so that we can support both forward and backward
+ * references, and avoid the R_ARM_THM_PC8 relocation that operates
+ * on the narrow encoding, which is documented as not taking the
+ * Thumb bit into account. (IHI 0044E ELF for the ARM Architecture)
+ *
+ * Note that this needs to be a separate macro or \@ does not work
+ * correctly.
+ */
+ .macro __badr, c, rd, sym
+ .set .Lsym\@, \sym
+ .type .Lsym\@, %function
+ .reloc ., R_ARM_THM_ALU_PREL_11_0, .Lsym\@
+ adr\c\().w \rd, .
+ .endm
+
/*
* Get current thread_info.
*/
--
2.17.1
next prev parent reply other threads:[~2018-06-19 19:26 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-19 19:26 [PATCH 0/2] Make badr macro compatible with newer GAS versions Ard Biesheuvel
2018-06-19 19:26 ` [PATCH 1/2] ARM: avoid badr macro for switching to Thumb-2 mode Ard Biesheuvel
2018-06-19 19:26 ` Ard Biesheuvel [this message]
2018-06-19 20:32 ` [PATCH 0/2] Make badr macro compatible with newer GAS versions Guenter Roeck
2018-06-19 20:34 ` Ard Biesheuvel
2018-06-19 20:45 ` Guenter Roeck
2018-06-19 22:23 ` Ard Biesheuvel
2018-06-19 22:50 ` Guenter Roeck
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=20180619192633.21846-3-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).