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 r28 rc1/beta2 header asm issue #2107

Open
1 task done
mcagabe19 opened this issue Nov 23, 2024 · 10 comments
Open
1 task done

[BUG]: NDK r28 rc1/beta2 header asm issue #2107

mcagabe19 opened this issue Nov 23, 2024 · 10 comments
Labels

Comments

@mcagabe19
Copy link

Description

whenever I try build mbedtls for armv7, x86 and x86_64 these happen

armv7:

In file included from C:\Users\Lily\AppData\Local\Android\Sdk\ndk\28.0.12674087/toolchains/llvm/prebuilt/windows-x86_64/sysroot/usr/include/netinet/in.h:37:
In file included from C:\Users\Lily\AppData\Local\Android\Sdk\ndk\28.0.12674087/toolchains/llvm/prebuilt/windows-x86_64/sysroot/usr/include/linux/in.h:233:
In file included from C:\Users\Lily\AppData\Local\Android\Sdk\ndk\28.0.12674087/toolchains/llvm/prebuilt/windows-x86_64/sysroot/usr/include/arm-linux-androideabi/asm/byteorder.h:9:
In file included from C:\Users\Lily\AppData\Local\Android\Sdk\ndk\28.0.12674087/toolchains/llvm/prebuilt/windows-x86_64/sysroot/usr/include/linux/byteorder/little_endian.h:17:
In file included from C:\Users\Lily\AppData\Local\Android\Sdk\ndk\28.0.12674087/toolchains/llvm/prebuilt/windows-x86_64/sysroot/usr/include/linux/swab.h:12:
C:\Users\Lily\AppData\Local\Android\Sdk\ndk\28.0.12674087/toolchains/llvm/prebuilt/windows-x86_64/sysroot/usr/include/arm-linux-androideabi/asm/swab.h:18:36: error: expected ')'
   18 |     asm("eor\t%0, %1, %1, ror #16" : "=r" (t) : "r" (x));
      |                                    ^
C:\Users\Lily\AppData\Local\Android\Sdk\ndk\28.0.12674087/toolchains/llvm/prebuilt/windows-x86_64/sysroot/usr/include/arm-linux-androideabi/asm/swab.h:18:8: note: to match this '('
   18 |     asm("eor\t%0, %1, %1, ror #16" : "=r" (t) : "r" (x));
      |        ^
1 error generated.

x86:

In file included from C:\Users\Lily\AppData\Local\Android\Sdk\ndk\28.0.12674087/toolchains/llvm/prebuilt/windows-x86_64/sysroot/usr/include/netinet/in.h:37:
In file included from C:\Users\Lily\AppData\Local\Android\Sdk\ndk\28.0.12674087/toolchains/llvm/prebuilt/windows-x86_64/sysroot/usr/include/linux/in.h:233:
In file included from C:\Users\Lily\AppData\Local\Android\Sdk\ndk\28.0.12674087/toolchains/llvm/prebuilt/windows-x86_64/sysroot/usr/include/i686-linux-android/asm/byteorder.h:9:
In file included from C:\Users\Lily\AppData\Local\Android\Sdk\ndk\28.0.12674087/toolchains/llvm/prebuilt/windows-x86_64/sysroot/usr/include/linux/byteorder/little_endian.h:17:
In file included from C:\Users\Lily\AppData\Local\Android\Sdk\ndk\28.0.12674087/toolchains/llvm/prebuilt/windows-x86_64/sysroot/usr/include/linux/swab.h:12:
C:\Users\Lily\AppData\Local\Android\Sdk\ndk\28.0.12674087/toolchains/llvm/prebuilt/windows-x86_64/sysroot/usr/include/i686-linux-android/asm/swab.h:12:19: error: expected ')'
   12 |   asm("bswapl %0" : "=r" (val) : "0" (val));
      |                   ^
C:\Users\Lily\AppData\Local\Android\Sdk\ndk\28.0.12674087/toolchains/llvm/prebuilt/windows-x86_64/sysroot/usr/include/i686-linux-android/asm/swab.h:12:6: note: to match this '('
   12 |   asm("bswapl %0" : "=r" (val) : "0" (val));
      |      ^
C:\Users\Lily\AppData\Local\Android\Sdk\ndk\28.0.12674087/toolchains/llvm/prebuilt/windows-x86_64/sysroot/usr/include/i686-linux-android/asm/swab.h:26:43: error: expected ')'
   26 |   asm("bswapl %0; bswapl %1; xchgl %0,%1" : "=r" (v.s.a), "=r" (v.s.b) : "0" (v.s.a), "1" (v.s.b));
      |                                           ^
C:\Users\Lily\AppData\Local\Android\Sdk\ndk\28.0.12674087/toolchains/llvm/prebuilt/windows-x86_64/sysroot/usr/include/i686-linux-android/asm/swab.h:26:6: note: to match this '('
   26 |   asm("bswapl %0; bswapl %1; xchgl %0,%1" : "=r" (v.s.a), "=r" (v.s.b) : "0" (v.s.a), "1" (v.s.b));
      |      ^
2 errors generated.

x86_64:

In file included from C:\Users\Lily\AppData\Local\Android\Sdk\ndk\28.0.12674087/toolchains/llvm/prebuilt/windows-x86_64/sysroot/usr/include/netinet/in.h:37:
In file included from C:\Users\Lily\AppData\Local\Android\Sdk\ndk\28.0.12674087/toolchains/llvm/prebuilt/windows-x86_64/sysroot/usr/include/linux/in.h:233:
In file included from C:\Users\Lily\AppData\Local\Android\Sdk\ndk\28.0.12674087/toolchains/llvm/prebuilt/windows-x86_64/sysroot/usr/include/x86_64-linux-android/asm/byteorder.h:9:
In file included from C:\Users\Lily\AppData\Local\Android\Sdk\ndk\28.0.12674087/toolchains/llvm/prebuilt/windows-x86_64/sysroot/usr/include/linux/byteorder/little_endian.h:17:
In file included from C:\Users\Lily\AppData\Local\Android\Sdk\ndk\28.0.12674087/toolchains/llvm/prebuilt/windows-x86_64/sysroot/usr/include/linux/swab.h:12:
C:\Users\Lily\AppData\Local\Android\Sdk\ndk\28.0.12674087/toolchains/llvm/prebuilt/windows-x86_64/sysroot/usr/include/x86_64-linux-android/asm/swab.h:12:19: error: expected ')'
   12 |   asm("bswapl %0" : "=r" (val) : "0" (val));
      |                   ^
C:\Users\Lily\AppData\Local\Android\Sdk\ndk\28.0.12674087/toolchains/llvm/prebuilt/windows-x86_64/sysroot/usr/include/x86_64-linux-android/asm/swab.h:12:6: note: to match this '('
   12 |   asm("bswapl %0" : "=r" (val) : "0" (val));
      |      ^
C:\Users\Lily\AppData\Local\Android\Sdk\ndk\28.0.12674087/toolchains/llvm/prebuilt/windows-x86_64/sysroot/usr/include/x86_64-linux-android/asm/swab.h:29:19: error: expected ')'
   29 |   asm("bswapq %0" : "=r" (val) : "0" (val));
      |                   ^
C:\Users\Lily\AppData\Local\Android\Sdk\ndk\28.0.12674087/toolchains/llvm/prebuilt/windows-x86_64/sysroot/usr/include/x86_64-linux-android/asm/swab.h:29:6: note: to match this '('
   29 |   asm("bswapq %0" : "=r" (val) : "0" (val));
      |      ^
2 errors generated.

also my target is android24 if you're wondering

I am using a supported NDK

  • I have checked and the NDK I'm using is currently supported

Affected versions

r28

@mcagabe19 mcagabe19 added the bug label Nov 23, 2024
@enh-google
Copy link
Collaborator

are you trying to compile as c89 or something?

@mcagabe19
Copy link
Author

mcagabe19 commented Dec 1, 2024

I use -std=c11 so I don't think but tho when I removed that line it compiled fine

@enh-google
Copy link
Collaborator

can you provide the full cc command line? it looks like the compiler's interpreting that asm() as a function call rather than inline assembler (c89 was just my guess for why that might be).

that is: "i don't think the linux uapi headers are compatible with whatever compiler flags you're using". yes, this is a regression (because we used to filter these particular bits out of the headers, but that caused c23 incompatibilities). i'm not sure how easy/possible it will be to fix that though.

i'm guessing if you locally edit those two lines to say __asm__ instead of asm the error goes away?

@mcagabe19
Copy link
Author

mcagabe19 commented Dec 1, 2024

can you provide the full cc command line? it looks like the compiler's interpreting that asm() as a function call rather than inline assembler (c89 was just my guess for why that might be).

clang++ line is clang++ -std=c11 -Ilib/mbedtls/include/ -Ilib/zlib/ --target=x86_64-linux-android24 -DHXCPP_M64 -DHXCPP_VISIT_ALLOCS -DHXCPP_API_LEVEL=0 -IC:/Users/Lily/GitHub/haxelibs/hxcpp/include -Iinclude --sysroot=C:\Users\Lily\AppData\Local\Android\Sdk\ndk\28.0.12674087/toolchains/llvm/prebuilt/windows-x86_64/sysroot -DANDROID=ANDROID -DHXCPP_CLANG -DHX_ANDROID -DHXCPP_ANDROID_PLATFORM=24 -fvisibility=hidden -ffunction-sections -fstack-protector -fexceptions -c -fpic -O2 -Wno-invalid-offsetof -Wno-return-type-c-linkage -Wno-parentheses -x c ./lib/mbedtls/library/net_sockets.c -oC:/Users/Lily/GitHub/haxelibs/lime/project/obj/android64-x86_64/bbadc3d6_net_sockets.obj (hxcpp lines can be ignored)

but idk how do I check on cc sorry

i'm guessing if you locally edit those two lines to say __asm__ instead of asm the error goes away?

it does indeed go away when I change asm's to __asm__ in swab.h

@enh-google
Copy link
Collaborator

ah, try changing -std=c11 to -std=gnu11 (c11 plus gnu extensions like inline assembler) ... that should let you undo the two __asm__ edits. i'll see if we can come up with a good way to rewrite asm to __asm__ in the uapi headers though, so they "just work" regardless what compiler options are being used.

@mcagabe19
Copy link
Author

mcagabe19 commented Dec 1, 2024

yeah I reverted the __asm__ change and added -std=gnu11 did fix the issue

@enh-google
Copy link
Collaborator

more awkward than i'd hoped for (since our "rewrite A as B" machinery doesn't work within function definitions) but https://android-review.googlesource.com/c/platform/bionic/+/3386019 isn't too bad, and makes <linux/swab.h> quite a bit less unreadable too...

@mcagabe19
Copy link
Author

mcagabe19 commented Dec 2, 2024

hopefully that won't do a big change on new release, I'm not really good at C/C++ stuff sorry

@enh-google
Copy link
Collaborator

hopefully that won't do a big change on new release, I'm not really good at C/C++ stuff sorry

if you mean "hopefully that will be in r28", yes, i think it should be.

if you mean "hopefully that cleanup won't cause other problems", well, as you've seen that's always a possibility when you touch anything in libc, but this change seems safer than the previous change (the one you're already having trouble with) since the new change removes dead code (and the new code that's causing you trouble) rather than adding new code.

hubot pushed a commit to aosp-mirror/platform_bionic that referenced this issue Dec 2, 2024
Just use the clang builtins all the time, as we do for the other
architectures. Specifically this fixes compilation errors caused by the
use of the non-standard `asm` when in a pure C mode like c11 rather than
gnu11.

Bug: android/ndk#2107
Change-Id: I0d6fdd52fd6f9c77d4c5e137d82237c97effd438
@DanAlbert
Copy link
Member

if you mean "hopefully that will be in r28", yes, i think it should be.

A sysroot update after beta is not something we normally want to do, since those are the second most likely thing to introduce regressions after the compiler. I'll have a look at what's actually in the update to gauge how disruptive it might be. If it looks scary, we'll probably ship an RC 2 first.

@DanAlbert DanAlbert added this to NDK r28 Dec 4, 2024
@github-project-automation github-project-automation bot moved this to Unconfirmed in NDK r28 Dec 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Unconfirmed
Development

No branches or pull requests

3 participants