Issue executing LLVM pass with Android NDK Clang on macOS

205 views
Skip to first unread message

José Lira Junior

unread,
Apr 14, 2024, 7:37:09 PM4/14/24
to android-llvm
Hello.

I'm encountering an issue while attempting to execute a simple LLVM pass using Android NDK Clang on macOS (Sonoma 14.4). Here's a detailed breakdown of the problem:


On Linux, everything works fine and this is the process:
$ $aosp/clang++ -c -Wall -Werror $($aosp/llvm-config --cxxflags) -fPIC -o Hello.o -c Hello/HelloWorld.cpp $ $aosp/clang++ -shared $($aosp/llvm-config --ldflags) -fPIC -fno-rtti -stdlib=libc++ Hello.o -o libHello.so
$ $aosp/clang -O1 -fpass-plugin=$HOME/ndk-passes/libHello.so test.c -S -emit-llvm -o mod_clang.ll
*** VISITOR PASS WORKING ***
Hello from: main number of arguments: 0
$ $prebuilt/clang -O1 -fpass-plugin=$HOME/ndk-passes/libHello.so test.c -S -emit-llvm -o mod_clang.ll
*** VISITOR PASS WORKING ***
Hello from: main number of arguments: 0


You can see I can compile the pass with AOSP Clang and run it with the Prebuilt NDK Clang normally.

Now, on MacOS (Sonoma 14.4), I can also build the pass with AOSP Clang and run it successfully. But when I run with Prebuild NDK Clang it does not work. (Also, I had to pass a lot of flags, making the process way more complex than on Linux, not sure if that's completely correct or if I'm missing something).

$aosp/bin/clang++ $($aosp/bin/llvm-config --cxxflags) -I/Users/ec2-user/llvm-toolchain/out/stage2-install/lib -I/Users/ec2-user/llvm-toolchain/out/stage2-install/include/c++/v1 -isystem /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include -isystem /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1 -nostdinc++ -arch arm64 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX14.4.sdk -fPIC -o Hello.o -c MacHello/HelloWorld.cpp

$aosp/bin/clang++ $($aosp/bin/llvm-config --ldflags) -isystem /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include -isystem /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1 -nostdinc++ -fno-rtti -arch arm64 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX14.4.sdk -dynamiclib -o libHello.dylib -install_name @rpath/libHello.dylib Hello.o -undefined dynamic_lookup

$aosp/bin/clang $($aosp/bin/llvm-config --cflags) -isystem /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include -O1 -fpass-plugin=/Users/ec2-user/llvm-plugin/libHello.dylib test.c -S -emit-llvm -o mod_clang.ll
*** VISITOR PASS WORKING ***
Hello from: main number of arguments: 0

$prebuilt/bin/clang $($aosp/bin/llvm-config --cflags) -isystem /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include -O1 -fpass-plugin=/Users/ec2-user/llvm-plugin/libHello.dylib test.c -S -emit-llvm -o mod_clang.ll

error: unable to load plugin '/Users/ec2-user/llvm-plugin/libHello.dylib': 'Could not load library '/Users/ec2-user/llvm-plugin/libHello.dylib': dlopen(/Users/ec2-user/llvm-plugin/libHello.dylib, 0x0009): symbol not found in flat namespace '__ZN4llvm17PreservedAnalyses14AllAnalysesKeyE'' 1 error generated.


Additional Notes:

The symbol is present on the plugin and on AOSP Clang, but it's really not present on Prebuilt CLang. $ nm libHello.dylib | grep __ZN4llvm17PreservedAnalyses14AllAnalysesKeyE U __ZN4llvm17PreservedAnalyses14AllAnalysesKeyE $ nm $aosp/bin/clang | grep __ZN4llvm17PreservedAnalyses14AllAnalysesKeyE 0000000105bb2240 S __ZN4llvm17PreservedAnalyses14AllAnalysesKeyE $ nm $prebuilt/bin/clang | grep __ZN4llvm17PreservedAnalyses14AllAnalysesKeyE $ echo $? 1



Last thing, but I'm not sure if this is related or expected. But `llvm-config --libs` and `llvm-config --system-libs` are outputing erros like this (it's a long list, if necessary I can post the rest):

$prebuilt/bin/llvm-config --libs llvm-config: error: component libraries and shared library llvm-config: error: missing: /Users/ec2-user/android_ndk_r26c/AndroidNDK11394342.app/Contents/NDK/toolchains/llvm/prebuilt/darwin-x86_64/lib/libLLVMDemangle.a llvm-config: error: missing: /Users/ec2-user/android_ndk_r26c/AndroidNDK11394342.app/Contents/NDK/toolchains/llvm/prebuilt/darwin-x86_64/lib/libLLVMSupport.a llvm-config: error: missing: /Users/ec2-user/android_ndk_r26c/AndroidNDK11394342.app/Contents/NDK/toolchains/llvm/prebuilt/darwin-x86_64/lib/libLLVMTableGen.a llvm-config: error: missing: /Users/ec2-user/android_ndk_r26c/AndroidNDK11394342.app/Contents/NDK/toolchains/llvm/prebuilt/darwin-x86_64/lib/libLLVMTargetParser.a llvm-config: error: missing: /Users/ec2-user/android_ndk_r26c/AndroidNDK11394342.app/Contents/NDK/toolchains/llvm/prebuilt/darwin-x86_64/lib/libLLVMBinaryFormat.a llvm-config: error: missing: /Users/ec2-user/android_ndk_r26c/AndroidNDK11394342.app/Contents/NDK/toolchains/llvm/prebuilt/darwin-x86_64/lib/libLLVMBitstreamReader.a llvm-config: error: missing: /Users/ec2-user/android_ndk_r26c/AndroidNDK11394342.app/Contents/NDK/toolchains/llvm/prebuilt/darwin-x86_64/lib/libLLVMRemarks.a llvm-config: error: missing: /Users/ec2-user/android_ndk_r26c/AndroidNDK11394342.app/Contents/NDK/toolchains/llvm/prebuilt/darwin-x86_64/lib/libLLVMCore.a



Any insights or suggestions on resolving this issue would be greatly appreciated.

Reply all
Reply to author
Forward
0 new messages