-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
invalid instruction adrl in arch/arm/{mach-omap2/sleep34xx|crypto/{sha512-core|sha256-core}|boot/compressed/head}.S #430
Comments
The file
(FWIW, I also came across the same issue in the ChaCha20 implementation proposed by @zx2c4, see https://lore.kernel.org/r/[email protected]/) However, the @smithp35 do you have thoughts to this case here? |
ADRL is a difficult pseudo-instruction to implement in LLVM in its full generality due to the way the assembler is implemented. Details of why can be found at https://llvm.org/pr24350 ironically this was my first task in LLVM. I did find a couple of macros that could be used in many of the places that ADRL can be used. The 2 deficiencies being:
.macro MYADRL reg:req, label:req
add \reg, pc, #((\label - .) & 0xff00)
add \reg, \reg, #((\label - .) - ((\label - .) & 0xff00)) - 4
.endm
.macro MYADRLSUB reg:req, label:req
sub \reg, pc, #((. - \label) & 0xff00)
sub \reg, \reg, #((. - \label) - ((. - \label) & 0xff00)) + 4
.endm |
It seems that particular instance does not really need a |
The adrl instruction has been introduced with commit dd31394 ("ARM: omap3: Thumb-2 compatibility for sleep34xx.S"), back when this assembly file was considerably longer. Today adr seems to have enough reach, even when inserting about 60 instructions between the use site and the label. Replace adrl with conventional adr instruction. This allows to build this file using Clang's integrated assembler (which does not support the adrl pseudo instruction). Link: ClangBuiltLinux#430 Signed-off-by: Stefan Agner <[email protected]>
Note that this is not technically a bug in Linux, but we can work around in Linux using |
Following up on the lore thread from March. It looks like linker support for group relocations landed in lld. @ardbiesheuvel had a question about them, but I don't understand how he was envisioning using them? It looks like @agners patch landed in d85d524, v5.8-rc1, but there are a couple more instances of adrl being used; at least for an ARCH=arm defconfig (v7), I see:
@ardbiesheuvel what did you have in mind? Was this it or something else, like @smithp35 's suggestion? |
Only the most basic of the group relocations landed in LLD unfortunately. I didn't add support for the larger group values. There is no way of generating them in llvm-mc either. In summary adrl r0, symbol is something like (I can never remember which way round g0 and g1 go) : It would probably be less disruptive to add support :pc_g0:, :pc_g1: to MC and LLD and using a macro for adrl when clang is used than it would be to try and add support ADRL. From memory ADRL has several complications:
|
Yes, providing something like the following when using Clang and building in ARM mode should do the trick afaict.
although I suppose this may trigger another limitation of the assembler, due to the use of a subsection? |
The Then
Seems to work: .macro adrl, reg:req, lbl:req
.subsection 1
.L1_\@: .long \lbl - (.L2_\@ + 8)
.previous
ldr \reg, .L1_\@
.L2_\@: add \reg, \reg, pc
.endm
foo:
adrl r3, l2dis_3630_offset
bx lr
l2dis_3630_offset:
bx lr same output from the disassembler between clang, gcc, and GNU as. One thing I'm surprised from my example though; it seems it's not an error to define the macro that conflicts with a pseudo. No tools complain about that, so I guess everything is "working as expected," but I would have expected to have to surround the macro definition in a preprocessor guard to define it only for clang. Or maybe that's a feature request to warn when a macro definition would shadow an existing instruction? Oh, if I remove the macro definition then reassemble with GNU as or GCC, the output is no longer the same. No macro:
(not sure what's up with that vs macro:
Ah, I guess those are the same, it't just that the psuedo can smartly be expanded into macro case only when the offset is too large to encode? In that case, we'd still probably want to wrap the macro definition in preprocessor guards, so that users of GNU as don't pay the penalty Clang users would (1 additional non-nop-instruction per adrl, which is not terrible...). |
The adrl pseudo resolves to either add+nop or add+add (depending on the distance), so it is always two instructions. The adrl macro resolves to a literal load + add, so it takes up two instructions, plus 4 bytes for the literal (plus alignment overhead). So the macro should really only be used when it is needed. |
(in response to @smithp35) The following code works in GAS
and produces the following output after linking
so would it be feasible for the Clang assembler to do the same? You will still need to implement the group relocation handling in the linker, of course, but the assembler will not have to deal with the group relocation arithmetic at all. |
Yes that code sequence will assemble in the integrated assembler with a relatively recent version of clang. Support for .reloc in Arm and AArch64 went in about 6 Months ago. Possibly for clang 10 but definitely for clang 11. Would definitely need support in LLD. If it would help resolve this issue then I think it would be worth a go at implementing them. I don't have any spare work time available at the moment, but I could probably take a look in my spare time although progress could be slow. |
@ardbiesheuvel sent a series related to this: https://lore.kernel.org/linux-arm-kernel/[email protected]/T/#t. Looks like a solid cleanup on quick scan (interesting that |
@ardbiesheuvel also sent https://lore.kernel.org/linux-crypto/[email protected]/T/#u for crypto/sha256-core.S. edit: v2: https://lore.kernel.org/linux-crypto/[email protected]/T/#t |
5478193 landed in v5.10-rc1. |
commit d85d524 upstream. The adrl instruction has been introduced with commit dd31394 ("ARM: omap3: Thumb-2 compatibility for sleep34xx.S"), back when this assembly file was considerably longer. Today adr seems to have enough reach, even when inserting about 60 instructions between the use site and the label. Replace adrl with conventional adr instruction. This allows to build this file using Clang's integrated assembler (which does not support the adrl pseudo instruction). Link: ClangBuiltLinux#430 Signed-off-by: Stefan Agner <[email protected]> Signed-off-by: Tony Lindgren <[email protected]> Signed-off-by: Nick Desaulniers <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
commit d85d524 upstream. The adrl instruction has been introduced with commit dd31394 ("ARM: omap3: Thumb-2 compatibility for sleep34xx.S"), back when this assembly file was considerably longer. Today adr seems to have enough reach, even when inserting about 60 instructions between the use site and the label. Replace adrl with conventional adr instruction. This allows to build this file using Clang's integrated assembler (which does not support the adrl pseudo instruction). Link: ClangBuiltLinux/linux#430 Signed-off-by: Stefan Agner <[email protected]> Signed-off-by: Tony Lindgren <[email protected]> Signed-off-by: Nick Desaulniers <[email protected]> Bug: 141693040 Change-Id: I645604524b52b963c8223b82c29a0afd73e104d5
commit d85d524 upstream The adrl instruction has been introduced with commit dd31394 ("ARM: omap3: Thumb-2 compatibility for sleep34xx.S"), back when this assembly file was considerably longer. Today adr seems to have enough reach, even when inserting about 60 instructions between the use site and the label. Replace adrl with conventional adr instruction. This allows to build this file using Clang's integrated assembler (which does not support the adrl pseudo instruction). Link: ClangBuiltLinux#430 Signed-off-by: Stefan Agner <[email protected]> Signed-off-by: Tony Lindgren <[email protected]> Signed-off-by: Florian Fainelli <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
commit d85d524 upstream The adrl instruction has been introduced with commit dd31394 ("ARM: omap3: Thumb-2 compatibility for sleep34xx.S"), back when this assembly file was considerably longer. Today adr seems to have enough reach, even when inserting about 60 instructions between the use site and the label. Replace adrl with conventional adr instruction. This allows to build this file using Clang's integrated assembler (which does not support the adrl pseudo instruction). Link: ClangBuiltLinux#430 Signed-off-by: Stefan Agner <[email protected]> Signed-off-by: Tony Lindgren <[email protected]> Signed-off-by: Florian Fainelli <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
commit d85d524 upstream The adrl instruction has been introduced with commit dd31394 ("ARM: omap3: Thumb-2 compatibility for sleep34xx.S"), back when this assembly file was considerably longer. Today adr seems to have enough reach, even when inserting about 60 instructions between the use site and the label. Replace adrl with conventional adr instruction. This allows to build this file using Clang's integrated assembler (which does not support the adrl pseudo instruction). Link: ClangBuiltLinux/linux#430 Signed-off-by: Stefan Agner <[email protected]> Signed-off-by: Tony Lindgren <[email protected]> Signed-off-by: Florian Fainelli <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
commit d85d524 upstream The adrl instruction has been introduced with commit dd31394 ("ARM: omap3: Thumb-2 compatibility for sleep34xx.S"), back when this assembly file was considerably longer. Today adr seems to have enough reach, even when inserting about 60 instructions between the use site and the label. Replace adrl with conventional adr instruction. This allows to build this file using Clang's integrated assembler (which does not support the adrl pseudo instruction). Link: ClangBuiltLinux/linux#430 Signed-off-by: Stefan Agner <[email protected]> Signed-off-by: Tony Lindgren <[email protected]> Signed-off-by: Florian Fainelli <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
commit d85d524 upstream The adrl instruction has been introduced with commit dd31394 ("ARM: omap3: Thumb-2 compatibility for sleep34xx.S"), back when this assembly file was considerably longer. Today adr seems to have enough reach, even when inserting about 60 instructions between the use site and the label. Replace adrl with conventional adr instruction. This allows to build this file using Clang's integrated assembler (which does not support the adrl pseudo instruction). Link: ClangBuiltLinux/linux#430 Signed-off-by: Stefan Agner <[email protected]> Signed-off-by: Tony Lindgren <[email protected]> Signed-off-by: Florian Fainelli <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
commit d85d524 upstream The adrl instruction has been introduced with commit dd31394 ("ARM: omap3: Thumb-2 compatibility for sleep34xx.S"), back when this assembly file was considerably longer. Today adr seems to have enough reach, even when inserting about 60 instructions between the use site and the label. Replace adrl with conventional adr instruction. This allows to build this file using Clang's integrated assembler (which does not support the adrl pseudo instruction). Link: ClangBuiltLinux/linux#430 Signed-off-by: Stefan Agner <[email protected]> Signed-off-by: Tony Lindgren <[email protected]> Signed-off-by: Florian Fainelli <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
commit d85d524 upstream The adrl instruction has been introduced with commit dd31394 ("ARM: omap3: Thumb-2 compatibility for sleep34xx.S"), back when this assembly file was considerably longer. Today adr seems to have enough reach, even when inserting about 60 instructions between the use site and the label. Replace adrl with conventional adr instruction. This allows to build this file using Clang's integrated assembler (which does not support the adrl pseudo instruction). Link: ClangBuiltLinux/linux#430 Signed-off-by: Stefan Agner <[email protected]> Signed-off-by: Tony Lindgren <[email protected]> Signed-off-by: Florian Fainelli <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
Source: Kernel.org MR: 120397 Type: Integration Disposition: Backport from git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable linux-5.4.y ChangeID: 9e00e5d195ed38bf577101100fa67bf02139623d Description: commit d85d524 upstream The adrl instruction has been introduced with commit dd31394 ("ARM: omap3: Thumb-2 compatibility for sleep34xx.S"), back when this assembly file was considerably longer. Today adr seems to have enough reach, even when inserting about 60 instructions between the use site and the label. Replace adrl with conventional adr instruction. This allows to build this file using Clang's integrated assembler (which does not support the adrl pseudo instruction). Link: ClangBuiltLinux/linux#430 Signed-off-by: Stefan Agner <[email protected]> Signed-off-by: Tony Lindgren <[email protected]> Signed-off-by: Florian Fainelli <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]> Signed-off-by: Armin Kuster <[email protected]>
commit d85d524 upstream The adrl instruction has been introduced with commit dd31394 ("ARM: omap3: Thumb-2 compatibility for sleep34xx.S"), back when this assembly file was considerably longer. Today adr seems to have enough reach, even when inserting about 60 instructions between the use site and the label. Replace adrl with conventional adr instruction. This allows to build this file using Clang's integrated assembler (which does not support the adrl pseudo instruction). Link: ClangBuiltLinux/linux#430 Signed-off-by: Stefan Agner <[email protected]> Signed-off-by: Tony Lindgren <[email protected]> Signed-off-by: Florian Fainelli <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]> (cherry picked from commit 9e00e5d195ed38bf577101100fa67bf02139623d) Signed-off-by: Sherry Yang <[email protected]>
commit d85d5247885ef2e8192287b895c2e381fa931b0b upstream The adrl instruction has been introduced with commit dd31394779aa ("ARM: omap3: Thumb-2 compatibility for sleep34xx.S"), back when this assembly file was considerably longer. Today adr seems to have enough reach, even when inserting about 60 instructions between the use site and the label. Replace adrl with conventional adr instruction. This allows to build this file using Clang's integrated assembler (which does not support the adrl pseudo instruction). Link: ClangBuiltLinux/linux#430 Signed-off-by: Stefan Agner <[email protected]> Signed-off-by: Tony Lindgren <[email protected]> Signed-off-by: Florian Fainelli <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
Assembling the kernel with the integrated assembler leads to the following error:
There are probably other cases e.g. in
arch/arm/crypto/sha512-core.S
.The text was updated successfully, but these errors were encountered: