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

[WSL1] ndk_25 clang-14 Exec format error #8681

Closed
1 of 2 tasks
gamefunc opened this issue Aug 4, 2022 · 16 comments
Closed
1 of 2 tasks

[WSL1] ndk_25 clang-14 Exec format error #8681

gamefunc opened this issue Aug 4, 2022 · 16 comments

Comments

@gamefunc
Copy link

gamefunc commented Aug 4, 2022

Version

10.0.19044 N/A Build 19044

WSL Version

  • WSL 2
  • WSL 1

Kernel Version

Linux version 4.4.0-19041-Microsoft (Microsoft@Microsoft.com) (gcc version 5.4.0 (GCC) )

Distro Version

debian 11.4

Other Software

ndk https://developer.android.com/ndk/downloads

android-ndk-r25-linux.zip | 530938532 | 9fce956edb6abd5aca42acf6bbfb21a90a67f75b

Repro Steps

unzip android-ndk-r25-linux.zip
root@gamefunc-2550k:/mnt/c/cpps/ndk/android-ndk-r25/toolchains/llvm/prebuilt/linux-x86_64/bin# ./clang-14 --version
-bash: ./clang-14: cannot execute binary file: Exec format error

-bash: ./clang-14: cannot execute binary file: Exec format error

Expected Behavior

root@gamefunc:/media/extra1/android-ndk-r25/toolchains/llvm/prebuilt/linux-x86_64/bin# ./clang-14 --version
Android (8490178, based on r450784d) clang version 14.0.6 (https://android.googlesource.com/toolchain/llvm-project 4c603efb0cca074e9238af8b4106c30add4418f6)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /media/extra1/android-ndk-r25/toolchains/llvm/prebuilt/linux-x86_64/bin/.

Actual Behavior

-bash: ./clang-14: cannot execute binary file: Exec format error

Diagnostic Logs

No response

@Biswa96
Copy link

Biswa96 commented Aug 4, 2022

Is it possible to use WSL2?

@gamefunc
Copy link
Author

gamefunc commented Aug 4, 2022

Is it possible to use WSL2?

emmm, sorry, i just build something,
Other cases, i will use vmware or my srv;

@sweord
Copy link

sweord commented Aug 6, 2022

Ran into the same problem in WSL1.

WSL2 is too slow to build project in NTFS.

@NickDeBeenSAE
Copy link

This is exactly one of the reasons to avoid Windows 11 🤣🤣

@gamefunc
Copy link
Author

gamefunc commented Aug 12, 2022

This is exactly one of the reasons to avoid Windows 11 🤣🤣

i5-2550k: win_11 == joke; return -1;

@Biswa96
Copy link

Biswa96 commented Aug 13, 2022

The issue is in the lxcore.sys kernel driver which implements WSL1. Here is the debug message associated with the exec error:

LX: (FFFF860FE48E4340, FFFF860FE2F81080) (-bash) LxpElfInfoParse: LoadHeaderAlignment

There is a somewhat similar issue with gzip in old Ubuntu release. clang-tidy and clangd from that NDK toolchain both work in same WSL1 environment. It may be possible to patch the ELF header of clang-14 binary to run it in WSL1.

@yunfengzh
Copy link

Why Microsoft lowers wsl1 priority? wsl1 can use the whole physical memory and cpues of host, better than wsl2 which is just a virtual machine, if microsoft implements a proxy with docker API, we will got a windows container immediately. Hope to take it into consideration.

@nefuddos
Copy link

has same issue:
renjg@DESKTOP-V2650P9:/android$ android-ndk-r25/toolchains/llvm/prebuilt/linux-x86_64/bin/clang-14 --help
-bash: android-ndk-r25/toolchains/llvm/prebuilt/linux-x86_64/bin/clang-14: cannot execute binary file: Exec format error
renjg@DESKTOP-V2650P9:
/android$
renjg@DESKTOP-V2650P9:/android$ android-ndk-r25/toolchains/llvm/prebuilt/linux-x86_64/bin/clang --help
-bash: android-ndk-r25/toolchains/llvm/prebuilt/linux-x86_64/bin/clang: cannot execute binary file: Exec format error
renjg@DESKTOP-V2650P9:
/android$ android-ndk-r25/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ --help
-bash: android-ndk-r25/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++: cannot execute binary file: Exec format error
renjg@DESKTOP-V2650P9:~/android$ android-ndk-r25/toolchains/llvm/prebuilt/linux-x86_64/bin/clang-check --help
USAGE: clang-check [options] [... ]

OPTIONS:

Generic Options:

--help - Display available options (--help-hidden for more)
--help-list - Display list of available options (--help-list-hidden for more)
--version - Display the version of this program

clang-check options:

@binsys
Copy link

binsys commented Sep 26, 2022

workaround:
patchelf --set-interpreter /lib64/ld-linux-x86-64.so.2 /home/binsys/work/android-ndk-r25b/toolchains/llvm/prebuilt/linux-x86_64/bin/clang-14

@gamefunc
Copy link
Author

gamefunc commented Oct 9, 2022

workaround: patchelf --set-interpreter /lib64/ld-linux-x86-64.so.2 /home/binsys/work/android-ndk-r25b/toolchains/llvm/prebuilt/linux-x86_64/bin/clang-14

cd /mnt/c/cpps/ndk/linux/toolchains/llvm/prebuilt/linux-x86_64/bin/
cp clang-14 clang
cp clang-14 clang++
patchelf --set-interpreter /lib64/ld-linux-x86-64.so.2 /mnt/c/cpps/ndk/linux/toolchains/llvm/prebuilt/linux-x86_64/bin/clang-14

cd /mnt/c/cpps/libs/openssl/openssl-3.0.5
export ANDROID_NDK_ROOT=/mnt/c/cpps/ndk/linux
PATH=$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/linux-x86_64/bin:$PATH

./Configure android-arm64 -D__ANDROID_API__=26 --prefix="/mnt/c/cpps/libs/openssl/openssl-3.0.5/android/arm64-v8a" --openssldir="/mnt/c/cpps/libs/openssl/openssl-3.0.5/android/arm64-v8a"
make -j4
make install

work but make: *** [Makefile:3200: build_sw] Error 2;
google say not support wsl1, so close;

@gamefunc gamefunc closed this as completed Oct 9, 2022
@binsys
Copy link

binsys commented Oct 22, 2022

workaround:
patchelf --set-interpreter /lib64/ld-linux-x86-64.so.2 /home/binsys/work/android-ndk-r25b/toolchains/llvm/prebuilt/linux-x86_64/bin/clang-14

i know google say "not support wsl1".
this workaround only make clang-14 work in wsl1,but if your code has other problems,it can't resovle it.
Please don't cp file
just one command
please replace [/home/binsys/work/] with your path

@gamefunc
Copy link
Author

gamefunc commented Oct 23, 2022

workaround:
patchelf --set-interpreter /lib64/ld-linux-x86-64.so.2 /home/binsys/work/android-ndk-r25b/toolchains/llvm/prebuilt/linux-x86_64/bin/clang-14

i know google say "not support wsl1". this workaround only make clang-14 work in wsl1,but if your code has other problems,it can't resovle it. Please don't cp file just one command please replace [/home/binsys/work/] with your path

if not cp clang-14 to clang++ clang, the openssl boost build can not run the clang; because clang++/clang file just a bash; my wsl1 can not run it;

my reply is my openssl all build command, not have " [/home/binsys/work/]";

my build command without patchelf work good with ndk_23b on wsl1;

and my build command without patchelf also work good with ndk_25 on original linux and vmware;

my build command not work without patchelf with ndk25 on wsl1,see this issuess.

my build command work but build make install error with patchelf with ndk25 on wsl1.

@binsys
Copy link

binsys commented Oct 24, 2022

workaround:
patchelf --set-interpreter /lib64/ld-linux-x86-64.so.2 /home/binsys/work/android-ndk-r25b/toolchains/llvm/prebuilt/linux-x86_64/bin/clang-14

i know google say "not support wsl1". this workaround only make clang-14 work in wsl1,but if your code has other problems,it can't resovle it. Please don't cp file just one command please replace [/home/binsys/work/] with your path

if not cp clang-14 to clang++ clang, the openssl boost build can not run the clang; because clang++/clang file just a bash; my wsl1 can not run it;

my reply is my openssl all build command, not have " [/home/binsys/work/]";

my build command without patchelf work good with ndk_23b on wsl1;

and my build command without patchelf also work good with ndk_25 on original linux and vmware;

my build command not work without patchelf with ndk25 on wsl1,see this issuess.

my build command work but build make install error with patchelf with ndk25 on wsl1.

must patchelf clang and clang++ after you cp,if you need cp.

@gamefunc
Copy link
Author

gamefunc commented Oct 24, 2022

workaround:
patchelf --set-interpreter /lib64/ld-linux-x86-64.so.2 /home/binsys/work/android-ndk-r25b/toolchains/llvm/prebuilt/linux-x86_64/bin/clang-14

i know google say "not support wsl1". this workaround only make clang-14 work in wsl1,but if your code has other problems,it can't resovle it. Please don't cp file just one command please replace [/home/binsys/work/] with your path

if not cp clang-14 to clang++ clang, the openssl boost build can not run the clang; because clang++/clang file just a bash; my wsl1 can not run it;
my reply is my openssl all build command, not have " [/home/binsys/work/]";
my build command without patchelf work good with ndk_23b on wsl1;
and my build command without patchelf also work good with ndk_25 on original linux and vmware;
my build command not work without patchelf with ndk25 on wsl1,see this issuess.
my build command work but build make install error with patchelf with ndk25 on wsl1.

must patchelf clang and clang++ after you cp,if you need cp.

same problem friend; anyway, now, i use my j1900 x86 route to build android cpp lib then cp to win folder from samba for code use, no "zhe teng" le lol;

@Marcinosoft
Copy link

Marcinosoft commented Jan 13, 2023

workaround: patchelf --set-interpreter /lib64/ld-linux-x86-64.so.2 /home/binsys/work/android-ndk-r25b/toolchains/llvm/prebuilt/linux-x86_64/bin/clang-14

@binsys Many thanks tor this workaround. It helped me with Win10 & Ubuntu 22.04 running via WSL v1 while buidling Kivy project using Buildozer with NDK 25b (issue).

sudo apt install patchelf
patchelf --set-interpreter /lib64/ld-linux-x86-64.so.2 ~/.buildozer/android/platform/android-ndk-r25b/toolchains/llvm/prebuilt/linux-x86_64/bin/clang-14

@EmotionalRonan
Copy link

workaround: patchelf --set-interpreter /lib64/ld-linux-x86-64.so.2 /home/binsys/work/android-ndk-r25b/toolchains/llvm/prebuilt/linux-x86_64/bin/clang-14

workaround: patchelf --set-interpreter /lib64/ld-linux-x86-64.so.2 /home/binsys/work/android-ndk-r25b/toolchains/llvm/prebuilt/linux-x86_64/bin/clang-14

@binsys Many thanks tor this workaround. It helped me with Win10 & Ubuntu 22.04 running via WSL v1 while buidling Kivy project using Buildozer with NDK 25b (issue).

sudo apt install patchelf
patchelf --set-interpreter /lib64/ld-linux-x86-64.so.2 ~/.buildozer/android/platform/android-ndk-r25b/toolchains/llvm/prebuilt/linux-x86_64/bin/clang-14

If none of the above methods work, you can try the following operations

I created a clang script in the clang bin directory
vim /xxxxndk/26.1.10909125/toolchains/llvm/prebuilt/linux-x86_64/bin/clang

#!/bin/sh
/lib64/ld-linux-x86-64.so.2 /home/ronan/Android/SDK/ndk/26.1.10909125/toolchains/llvm/prebuilt/linux-x86_64/bin/clang-17 $@

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

No branches or pull requests

9 participants