Skip to content
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

arch/arm/lib: Fix the assembly sources for the kernel build by LLVM #5718

Open
wants to merge 1 commit into
base: rpi-6.1.y
Choose a base branch
from

Conversation

altimeter-130ft
Copy link

The LLVM assembler is stricter on the source syntax than GCC.

  • Prepend a backslash () to each macro argument.

  • The condition field is always the last portion of an instruction mnemonic.

  • The terms of the relational operators in a conditional assemble directive are integers, not strings.

The assembly source files complying above assemble by both LLVM and GCC / Binutils.

Issue: 5295
Build tested on: clang 14.0.6 and gcc Raspbian 12.2.0-14+rpi1, both armhf native on qemu-static.
Kernel exec tested on: Raspberry Pi 3B+ and Zero W.

The LLVM assembler is stricter on the source syntax than GCC.

- Prepend a backslash (\) to each macro argument.

- The condition field is always the last portion of an instruction mnemonic.

- The terms of the relational operators in a conditional assemble directive are
  integers, not strings.

The assembly source files complying above assemble by both LLVM and GCC /
Binutils.

Signed-off-by: Seigo Tanimura <seigo.tanimura@gmail.com>
ands DAT2, D, #15
beq 164f
.else
ands DAT2, D, #15
beq 164f
rsb DAT2, DAT2, #16
.endif
memcpy_leading_15bytes backwards, align
memcpy_leading_15bytes \backwards, 1
Copy link
Contributor

@iucoen iucoen Nov 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be \align ?
Align is not an argument to this macro. How did the old code even compile?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to know why, too 😂

The test assembly source for a quick reproduction

    .text
    .arch armv6
    .object_arch armv4
    .arm
    .p2align 2

.macro should_not_assemble_macro arg
    .if \arg == 0
        add       a1, a2, #4
    .else
        sub       a1, a3, #2
    .endif
.endm

should_not_assemble:
    should_not_assemble_macro arg

    .type should_not_assemble, %function

    .end

GCC

(raspbian-bookworm-armhf)a130ft@berget:~/work/should-not-assemble$ gcc -o should-not-assemble.o -c should-not-assemble.S 
(raspbian-bookworm-armhf)a130ft@berget:~/work/should-not-assemble$ objdump --disassemble should-not-assemble.o

should-not-assemble.o:     file format elf32-littlearm


Disassembly of section .text:

00000000 <should_not_assemble>:
   0:	e2420002 	sub	r0, r2, #2
(raspbian-bookworm-armhf)a130ft@berget:~/work/should-not-assemble$ 

LLVM (clang)

(raspbian-bookworm-armhf)a130ft@berget:~/work/should-not-assemble$ clang -o should-not-assemble.o -c should-not-assemble.S 
<instantiation>:1:5: error: expected absolute expression
.if arg == 0
    ^
should-not-assemble.S:16:5: note: while in macro instantiation
    should_not_assemble_macro arg
    ^
(raspbian-bookworm-armhf)a130ft@berget:~/work/should-not-assemble$ 

So gcc insists that arg == 0 expanded out of \arg == 0 has the acceptable syntax and evaluates to false.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants