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

[BUG] NDK r23 gives confusing error message for -fno-integrated-as #1569

Closed
bog-dan-ro opened this issue Aug 24, 2021 · 22 comments
Closed

[BUG] NDK r23 gives confusing error message for -fno-integrated-as #1569

bog-dan-ro opened this issue Aug 24, 2021 · 22 comments
Assignees
Labels
Projects

Comments

@bog-dan-ro
Copy link

Description

Steps to reproduce:

  • create a simple .c file $ cat test.c :
int main() {return 0;}
  • Try to compile it:
$ /path/to/ndk/23.0.7599858/toolchains/llvm/prebuilt/linux-x86_64/bin/clang test.c --target=armv7a-linux-androideabi28 -fno-integrated-as -pipe -D_FILE_OFFSET_BITS=64 -c
/usr/bin/as: unrecognized option '-EL'
clang-12: error: assembler command failed with exit code 1 (use -v to see invocation)

Without -fno-integrated-as it compiles just fine.

I need to pass -fno-integrated-as to workaround pixman issues: https://gitlab.freedesktop.org/pixman/pixman/-/issues/45

@bog-dan-ro bog-dan-ro added the bug label Aug 24, 2021
@enh-google
Copy link
Collaborator

yeah, -fno-integrated-as isn't supported in r23. (i don't whether we should configure things so that if you do use it [and don't manually specify yasm or whatever] we run a script or something that says "-fno-integrated-as is not supported" rather than just quietly running /usr/bin/as which is just misleading.)

we have some docs here about how to fix assembler: https://android.googlesource.com/platform/ndk/+/master/docs/ClangMigration.md#assembler-issues

the .func error in particular is just dead code for gas too, so that's easy. i didn't see the .if error when we fixed all of Android, so i don't have any specific advice to give there (but in general, and especially since the source file is already .S rather than .s, "just use the C preprocessor instead" was useful to me!).

does it work if you move all the .if stuff below the push? the only somewhat-relevant references to this error i found on the internet implied that there are issues before the first instruction is emitted, though they seemed to be .ifs that involved calculations relative to . that doesn't apply here. (that's also supposed to have been fixed in 2019, so we should have that fix already.)

@enh-google enh-google changed the title [BUG] NDK r23 can't compile a simple file using -fno-integrated-as [BUG] NDK r23 gives confusing error message for -fno-integrated-as Aug 24, 2021
@enh-google
Copy link
Collaborator

wait... it's just occurred to me that you're talking about r23, which still has gas, not r24, which is the first release that doesn't.

so for r23, you've probably just got a misconfigured build that's calling the wrong as. (but for r24 you'll need code that can actually build with LLVM.)

@rprichard
Copy link
Collaborator

r23 still has gas, but not with the filename that Clang expects.

r22 has:

  1. toolchains/${target}/prebuilt/${host}/${triple}/bin/as
  2. toolchains/${target}/prebuilt/${host}/bin/${triple}-as
  3. toolchains/llvm/prebuilt/${host}/${triple}/bin/as
  4. toolchains/llvm/prebuilt/${host}/bin/${triple}-as

r23 only has # 4, but I think we also need # 3 for -fno-integrated-as.

@DanAlbert DanAlbert added this to Triaged in r23b via automation Aug 24, 2021
@bog-dan-ro
Copy link
Author

Instead to force everyone to change their asm file to make them llvm compatible, isn't better to make llvm as compatible with gas?
This way you can nuke gas without no worries.

@bog-dan-ro
Copy link
Author

Just for the record, compiling pixman with r21 & r22 with -fno-integrated-as spawns tones of Rd and Rm should be different in mul but at least it compiles ... :)

@stephenhines
Copy link
Collaborator

Instead to force everyone to change their asm file to make them llvm compatible, isn't better to make llvm as compatible with gas?
This way you can nuke gas without no worries.

There are inconsistencies and syntax relaxations for gas that ARM (among other vendors) have said that they won't support in any new compilers/assemblers. If the syntax being used is UAL (unified assembly language), then we can work with ARM to add the missing support. In that particular case, LLVM is correct in telling you that the instruction you're using isn't valid, and gas is merely transforming it into something equivalent. According to this link, "Rd cannot be the same as Rm."

@bog-dan-ro
Copy link
Author

bog-dan-ro commented Aug 25, 2021

At first look it doesn't seem to be an ASM language problem, but llvm as is missing some features:

/path/to/android-sdk/ndk/21.1.6352462/toolchains/llvm/prebuilt/linux-x86_64/bin/clang -
Ipixman/libpixman-arm-simd.a.p -Ipixman -I../pixman -Xclang -fcolor-diagnostics -pipe -D_FILE_OFFSE
T_BITS=64 -Wall -Winvalid-pch -O2 -g -Wdeclaration-after-statement -fno-strict-aliasing -fvisibilit
y=hidden -Wundef -ftrapping-math -Wno-unused-local-typedefs -DHAVE_CONFIG_H --target=armv7a-linux-a
ndroideabi28 -fPIC -MD -MQ pixman/libpixman-arm-simd.a.p/pixman-arm-simd-asm.S.o -MF pixman/libpixm
an-arm-simd.a.p/pixman-arm-simd-asm.S.o.d -o pixman/libpixman-arm-simd.a.p/pixman-arm-simd-asm.S.o 
-c ../pixman/pixman-arm-simd-asm.S
<instantiation>:1:1: error: unknown directive
.func fname
^
../pixman/pixman-arm-simd-asm.h:599:5: note: while in macro instantiation
    pixman_asm_function fname
    ^
/tmp/pixman-arm-simd-asm-0ff417.s:913:1: note: while in macro instantiation
generate_composite_function pixman_composite_src_8888_8888_asm_armv6, 32, 0, 32, FLAG_DST_WRITEONLY
 | FLAG_COND_EXEC | FLAG_SPILL_LINE_VARS_WIDE | FLAG_PROCESS_PRESERVES_SCRATCH, 4, blit_init, nop_m
acro, nop_macro, blit_process_head, nop_macro, blit_inner_loop
^
../pixman/pixman-arm-simd-asm.h:614:6: error: expected absolute expression
 .if prefetch_distance == 0
     ^
/tmp/pixman-arm-simd-asm-0ff417.s:913:1: note: while in macro instantiation
generate_composite_function pixman_composite_src_8888_8888_asm_armv6, 32, 0, 32, FLAG_DST_WRITEONLY
 | FLAG_COND_EXEC | FLAG_SPILL_LINE_VARS_WIDE | FLAG_PROCESS_PRESERVES_SCRATCH, 4, blit_init, nop_m
acro, nop_macro, blit_process_head, nop_macro, blit_inner_loop
^
../pixman/pixman-arm-simd-asm.h:620:6: error: expected absolute expression
 .if src_bpp == 32
     ^

Attached the entire output in case you need it : out.txt

@bog-dan-ro
Copy link
Author

According to this link, "Rd cannot be the same as Rm."

Just for the record, I'm seeing those messages when I'm compiling .c files with -fno-integrated-as not .s files.

@rprichard
Copy link
Collaborator

I think the problems with .if results from Clang's incomplete .altmacro support. pixman-arm-simd-asm.S uses .altmacro. Here's the non-altmacro behavior:

$ cat >test.S <<EOF
    .macro foo arg_
    .set arg, arg_
    .if arg != 42
    .error "arg must be 42"
    .endif
    .endm
    foo 42
EOF

$ gcc -c test.S
test.S: Assembler messages:
test.S:7: Error: arg must be 42

$ clang -c test.S
<instantiation>:2:9: error: expected absolute expression
    .if arg != 42
        ^
...

It can be fixed using \arg_:

$ cat >test.S <<EOF
    .macro foo arg_
    .set arg, \arg_
    .if arg != 42
    .error "arg must be 42"
    .endif
    .endm
    foo 42
EOF

$ gcc -c test.S
<success>

$ clang -c test.S
<success>

But .altmacro changes a bunch of stuff, and it can also be used instead of escaping the macro argument:

$ cat >test.S <<EOF
    .altmacro
    .macro foo arg_
    .set arg, arg_
    .if arg != 42
    .error "arg must be 42"
    .endif
    .endm
    foo 42
EOF

$ gcc -c test.S
<success>

$ clang -c test.S
<instantiation>:2:9: error: expected absolute expression
    .if arg != 42
        ^

There are a few open .altmacro bugs already, but I don't think this one is open yet:
https://bugs.llvm.org/buglist.cgi?quicksearch=altmacro

@rprichard
Copy link
Collaborator

FWIW: ART uses .altmacro but only with GNU as:
https://android.googlesource.com/platform/art/+/refs/tags/android-11.0.0_r40/runtime/arch/x86_64/asm_support_x86_64.S#30

ART uses .altmacro to work around this GCC-vs-Clang preprocessor difference. My guess, though, is that we could rewrite that code to work without .altmacro (and use the same code for GCC and Clang).

@enh-google
Copy link
Collaborator

FWIW: ART uses .altmacro but only with GNU as:
https://android.googlesource.com/platform/art/+/refs/tags/android-11.0.0_r40/runtime/arch/x86_64/asm_support_x86_64.S#30

ART uses .altmacro to work around this GCC-vs-Clang preprocessor difference. My guess, though, is that we could rewrite that code to work without .altmacro (and use the same code for GCC and Clang).

well, given that ART only builds with clang, we could just delete that code :-)

@DanAlbert
Copy link
Member

Just putting back toolchains/llvm/prebuilt/${host}/${triple}/bin/as doesn't seem to be enough. I wonder if we need to add back all the no-op crt objects to get Clang to recognize the "GCC" directory...

@DanAlbert
Copy link
Member

Yeah, I think that is it. The actual path that gets used for as in r22:

"/work/src/android-ndk-r22b/toolchains/llvm/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/as"

🤮

@DanAlbert
Copy link
Member

DanAlbert commented Sep 1, 2021

https://android-review.googlesource.com/c/platform/ndk/+/1817218 fixes the problem. Sorry about that. In our effort to make sure we were -fno-integrated-as clean before asking users to do so we of course removed all our own uses of it, but neglected to add a test to cover that case. I've added an explicit test of -fno-integrated-as to go with the fix :)

I forked the missing altmacro support discussion into a new bug.

@DanAlbert DanAlbert self-assigned this Sep 1, 2021
@DanAlbert
Copy link
Member

The changelog update so we don't forget to cherry-pick it: https://android-review.googlesource.com/c/platform/ndk/+/1817316

@DanAlbert DanAlbert moved this from Triaged to Needs cherry-pick in r23b Sep 2, 2021
chenguoyin-alibaba pushed a commit to riscv-android-src/platform-ndk that referenced this issue Oct 21, 2021
In particular, link to our migration advice.

This commit is based on 3e47e46, with
the Changelog-r24.md part removed so it can be cherry-picked to
aosp/ndk-release-r23.

Bug: http://b/200995199
Bug: android/ndk#1569
Test: N/A
Change-Id: I61c3107bd389c2da1a5641babdef6f56ca487b1f
(cherry picked from commit 3236d6773fe6ed59f4b44c58c0a5a2fd0e28f86a)
chenguoyin-alibaba pushed a commit to riscv-android-src/platform-ndk that referenced this issue Oct 21, 2021
In particular, link to our migration advice.

This commit is based on 3e47e46, with
the Changelog-r24.md part removed so it can be cherry-picked to
aosp/ndk-release-r23.

Bug: http://b/200995199
Bug: android/ndk#1569
Test: N/A
Change-Id: I61c3107bd389c2da1a5641babdef6f56ca487b1f
(cherry picked from commit 3236d6773fe6ed59f4b44c58c0a5a2fd0e28f86a)
chenguoyin-alibaba pushed a commit to riscv-android-src/platform-ndk that referenced this issue Oct 21, 2021
The change can't be done in this branch since GAS is fully gone in
r24, but the changelog is being updated here to reduce merge
conflicts.

Test: None
Bug: android/ndk#1569
Change-Id: I7de8ffe8880ed05f89d46302f253b5d1d89677c6
(cherry picked from commit 175b1c2)
@Grimler91
Copy link

The as symlinks that were added in https://android-review.googlesource.com/c/platform/ndk/+/1817218 seem to be broken in r23b:

$ ls -l toolchains/llvm/prebuilt/linux-x86_64/*android*/bin/
toolchains/llvm/prebuilt/linux-x86_64/aarch64-linux-android/bin/:
total 4
lrwxrwxrwx 1 root root 131 Oct 23 15:10 as -> /buildbot/src/android/ndk-release-r23/out/linux/android-ndk-r23b/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android-as

toolchains/llvm/prebuilt/linux-x86_64/arm-linux-androideabi/bin/:
total 4
lrwxrwxrwx 1 root root 131 Oct 23 15:10 as -> /buildbot/src/android/ndk-release-r23/out/linux/android-ndk-r23b/toolchains/llvm/prebuilt/linux-x86_64/bin/arm-linux-androideabi-as

toolchains/llvm/prebuilt/linux-x86_64/i686-linux-android/bin/:
total 4
lrwxrwxrwx 1 root root 128 Oct 23 15:10 as -> /buildbot/src/android/ndk-release-r23/out/linux/android-ndk-r23b/toolchains/llvm/prebuilt/linux-x86_64/bin/i686-linux-android-as

toolchains/llvm/prebuilt/linux-x86_64/x86_64-linux-android/bin/:
total 4
lrwxrwxrwx 1 root root 130 Oct 23 15:10 as -> /buildbot/src/android/ndk-release-r23/out/linux/android-ndk-r23b/toolchains/llvm/prebuilt/linux-x86_64/bin/x86_64-linux-android-as

Fixing so they instead point towards ../../bin/{triple}-as makes -fno-integrated-as work as intended.

@rprichard rprichard added this to Triaged in r23c via automation Oct 29, 2021
@rprichard rprichard removed this from Needs cherry-pick in r23b Oct 29, 2021
@rprichard
Copy link
Collaborator

I uploaded a fix making the as symlink target relative: https://android-review.googlesource.com/c/platform/ndk/+/1875878

@DanAlbert
Copy link
Member

And of course the test passes because it's being run on the same machine (-‸ლ)

@rprichard
Copy link
Collaborator

And of course the test passes because it's being run on the same machine (-‸ლ)

I think detecting this issue would have required building the NDK and the tests on different machines.

Alternately, maybe we could have a test that walks the NDK install directory and verifies that all symlinks are relative.

@enh-google
Copy link
Collaborator

gah, i make this mistake all the time when a configure script or whatever creates an absolute symlink. why do they even do that?! looking at you, pcre2... :-)

@DanAlbert DanAlbert moved this from Triaged to Needs cherry-pick in r23c Nov 9, 2021
unicornx pushed a commit to aosp-riscv/platform-ndk that referenced this issue Jan 7, 2022
Bug: android/ndk#1569
Test: checkbuild.py
Test: verify that all symlinks are relative
Change-Id: I65073f8043029e39ee0667cf880375a3869ae1e0
(cherry picked from commit 15fd1e3)
unicornx pushed a commit to aosp-riscv/platform-ndk that referenced this issue Jan 7, 2022
Bug: android/ndk#1569
Test: checkbuild.py
Test: verify that all symlinks are relative
Test: Use -fno-integrated-as manually
Change-Id: I977734b3681b341f86cf72a95a19a798682fb93c
@orifmilod
Copy link

orifmilod commented Mar 29, 2022

For those who are facing the same issue as @Grimler91 - (seeing /buildbot/...). Please run the command below, it should remove the old broken sym-link files and create new ones.

rm ./toolchains/llvm/prebuilt/linux-x86_64/aarch64-linux-android/bin/as && \
ln -sv ./toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android-as ./toolchains/llvm/prebuilt/linux-x86_64/aarch64-linux-android/bin/as && \
rm ./toolchains/llvm/prebuilt/linux-x86_64/arm-linux-androideabi/bin/as && \
ln -sv ./toolchains/llvm/prebuilt/linux-x86_64/bin/arm-linux-androideabi-as ./toolchains/llvm/prebuilt/linux-x86_64/arm-linux-androideabi/bin/as && \
rm ./toolchains/llvm/prebuilt/linux-x86_64/i686-linux-android/bin/as && \
ln -sv ./toolchains/llvm/prebuilt/linux-x86_64/bin/i686-linux-android-as ./toolchains/llvm/prebuilt/linux-x86_64/i686-linux-android/bin/as && \
rm ./toolchains/llvm/prebuilt/linux-x86_64/x86_64-linux-android/bin/as && \
ln -sv ./toolchains/llvm/prebuilt/linux-x86_64/bin/x86_64-linux-android-as ./toolchains/llvm/prebuilt/linux-x86_64/x86_64-linux-android/bin/as

@DanAlbert
Copy link
Member

Should be fixed in r23 build 8486889.

r23c automation moved this from Needs cherry-pick to Merged Apr 22, 2022
MaoHan001 pushed a commit to riscv-android-src/platform-ndk that referenced this issue Jun 22, 2022
Bug: android/ndk#1569
Test: n/a
Change-Id: I633f07d281707997749ebbd99885dbc5026c293a
(cherry picked from commit 3aa8b12e5ec47d5958b62ae05522057d8ed3e680)
Merged-In: I633f07d281707997749ebbd99885dbc5026c293a
MaoHan001 pushed a commit to riscv-android-src/platform-ndk that referenced this issue Jun 22, 2022
The validation happens immediately after the NDK is built. When the
Windows NDK is cross-compiled from Linux, the scan verifies that there
are no symlinks.

Bug: android/ndk#1569
Test: checkbuild.py
Change-Id: Idea7ef7b1652e4bef16482f4886332335f8fb758
(cherry picked from commit 8076ea3e61531961ced9a43298be446f779c7340)
Merged-In: Idea7ef7b1652e4bef16482f4886332335f8fb758
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
No open projects
r23c
  
Merged
Development

No branches or pull requests

7 participants