All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ard Biesheuvel <ard.biesheuvel@linaro.org>
To: Guenter Roeck <linux@roeck-us.net>
Cc: Russell King <linux@armlinux.org.uk>,
	Mark Rutland <mark.rutland@arm.com>,
	linux-arm-kernel <linux-arm-kernel@lists.infradead.org>,
	Arnd Bergmann <arnd@arndb.de>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [RFC PATCH] ARM: Use logical or instead of addition for badr address calculation
Date: Tue, 19 Jun 2018 20:17:11 +0200	[thread overview]
Message-ID: <CAKv+Gu9JTsKEwwKN4OjmNHLf_86s753f2yEdo=7esERdUCaWiQ@mail.gmail.com> (raw)
In-Reply-To: <20180619172422.GB16846@roeck-us.net>

On 19 June 2018 at 19:24, Guenter Roeck <linux@roeck-us.net> wrote:
> On Tue, Jun 19, 2018 at 03:35:07PM +0200, Ard Biesheuvel wrote:
>> >>
>> >> +       /* this needs to be a separate macro or \@ does not work correctly
>> >> */
>> >> +       .macro  __badr, c, rd, sym
>> >> +       .eqv    .Lsym\@, \sym
>> >> +       adr\c   \rd, .Lsym\@ + 1
>> >
>> >
>> > Wild shot, but the following works for me.
>> >
>> >         .eqv    .Lsym\@, \sym + 1
>> >         adr\c   \rd, .Lsym\@
>> >
>> > Does it make sense ?
>> >
>>
>> Interesting. Do you mean this works with your 2.30 binutils that
>> triggers the original issue?
>>
>
> Yes, it does. It is also the solution used for some graphics libraries,
> though of course now I don't find the link anymore.
>
> Guess this is going nowhere given Russell's response, so I'll just
> live with it, like obviously everyone else does already. I built
> a toolchain using gcc 7.3.0 and binutils 2.28.1 which "solves"
> the problem for me.
>

If we can live with using a wide encoding unconditionally, we could
consider something like below. That forces the symbol references to be
resolved at link time, which means we completely sidestep the new GAS
code.

-----------8<----------------
From: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Date: Tue, 16 Jan 2018 12:12:45 +0000
Subject: [PATCH] ARM: assembler: prevent ADR from setting the Thumb bit twice

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 global symbol
typed as 'function', and emit a relocation that lets the linker fix
up the reference.

Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>

diff --git a/arch/arm/include/asm/assembler.h b/arch/arm/include/asm/assembler.h
index 6ae42ad29518..1a55ce4b245c 100644
--- a/arch/arm/include/asm/assembler.h
+++ b/arch/arm/include/asm/assembler.h
@@ -195,13 +195,22 @@
        .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

+       /* this needs to be a separate macro or \@ does not work correctly */
+       .macro          __badr, c, rd, sym
+       .globl          .Lsym_\sym\()_\@
+       .type           .Lsym_\sym\()_\@, %function
+       .set            .Lsym_\sym\()_\@, \sym
+       .reloc          ., R_ARM_THM_ALU_PREL_11_0, .Lsym_\sym\()_\@
+       adr\c\().w      \rd, .
+       .endm
+
 /*
  * Get current thread_info.
  */

WARNING: multiple messages have this Message-ID (diff)
From: ard.biesheuvel@linaro.org (Ard Biesheuvel)
To: linux-arm-kernel@lists.infradead.org
Subject: [RFC PATCH] ARM: Use logical or instead of addition for badr address calculation
Date: Tue, 19 Jun 2018 20:17:11 +0200	[thread overview]
Message-ID: <CAKv+Gu9JTsKEwwKN4OjmNHLf_86s753f2yEdo=7esERdUCaWiQ@mail.gmail.com> (raw)
In-Reply-To: <20180619172422.GB16846@roeck-us.net>

On 19 June 2018 at 19:24, Guenter Roeck <linux@roeck-us.net> wrote:
> On Tue, Jun 19, 2018 at 03:35:07PM +0200, Ard Biesheuvel wrote:
>> >>
>> >> +       /* this needs to be a separate macro or \@ does not work correctly
>> >> */
>> >> +       .macro  __badr, c, rd, sym
>> >> +       .eqv    .Lsym\@, \sym
>> >> +       adr\c   \rd, .Lsym\@ + 1
>> >
>> >
>> > Wild shot, but the following works for me.
>> >
>> >         .eqv    .Lsym\@, \sym + 1
>> >         adr\c   \rd, .Lsym\@
>> >
>> > Does it make sense ?
>> >
>>
>> Interesting. Do you mean this works with your 2.30 binutils that
>> triggers the original issue?
>>
>
> Yes, it does. It is also the solution used for some graphics libraries,
> though of course now I don't find the link anymore.
>
> Guess this is going nowhere given Russell's response, so I'll just
> live with it, like obviously everyone else does already. I built
> a toolchain using gcc 7.3.0 and binutils 2.28.1 which "solves"
> the problem for me.
>

If we can live with using a wide encoding unconditionally, we could
consider something like below. That forces the symbol references to be
resolved at link time, which means we completely sidestep the new GAS
code.

-----------8<----------------
From: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Date: Tue, 16 Jan 2018 12:12:45 +0000
Subject: [PATCH] ARM: assembler: prevent ADR from setting the Thumb bit twice

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 global symbol
typed as 'function', and emit a relocation that lets the linker fix
up the reference.

Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>

diff --git a/arch/arm/include/asm/assembler.h b/arch/arm/include/asm/assembler.h
index 6ae42ad29518..1a55ce4b245c 100644
--- a/arch/arm/include/asm/assembler.h
+++ b/arch/arm/include/asm/assembler.h
@@ -195,13 +195,22 @@
        .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

+       /* this needs to be a separate macro or \@ does not work correctly */
+       .macro          __badr, c, rd, sym
+       .globl          .Lsym_\sym\()_\@
+       .type           .Lsym_\sym\()_\@, %function
+       .set            .Lsym_\sym\()_\@, \sym
+       .reloc          ., R_ARM_THM_ALU_PREL_11_0, .Lsym_\sym\()_\@
+       adr\c\().w      \rd, .
+       .endm
+
 /*
  * Get current thread_info.
  */

  reply	other threads:[~2018-06-19 18:17 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-19  5:07 [RFC PATCH] ARM: Use logical or instead of addition for badr address calculation Guenter Roeck
2018-06-19  5:07 ` Guenter Roeck
2018-06-19  7:48 ` Ard Biesheuvel
2018-06-19  7:48   ` Ard Biesheuvel
2018-06-19  7:51   ` Ard Biesheuvel
2018-06-19  7:51     ` Ard Biesheuvel
2018-06-19 13:29   ` Guenter Roeck
2018-06-19 13:29     ` Guenter Roeck
2018-06-19 13:35     ` Ard Biesheuvel
2018-06-19 13:35       ` Ard Biesheuvel
2018-06-19 15:12       ` Russell King - ARM Linux
2018-06-19 15:12         ` Russell King - ARM Linux
2018-06-19 17:14         ` Guenter Roeck
2018-06-19 17:14           ` Guenter Roeck
2018-06-19 18:08           ` Russell King - ARM Linux
2018-06-19 18:08             ` Russell King - ARM Linux
2018-06-19 17:24       ` Guenter Roeck
2018-06-19 17:24         ` Guenter Roeck
2018-06-19 18:17         ` Ard Biesheuvel [this message]
2018-06-19 18:17           ` Ard Biesheuvel
2018-06-19 18:20           ` Ard Biesheuvel
2018-06-19 18:20             ` Ard Biesheuvel
2018-06-19 18:28             ` Ard Biesheuvel
2018-06-19 18:28               ` Ard Biesheuvel

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='CAKv+Gu9JTsKEwwKN4OjmNHLf_86s753f2yEdo=7esERdUCaWiQ@mail.gmail.com' \
    --to=ard.biesheuvel@linaro.org \
    --cc=arnd@arndb.de \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=linux@roeck-us.net \
    --cc=mark.rutland@arm.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.