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

Clang fails to load on iOS 15.4 #391

Closed
bummoblizard opened this issue Mar 11, 2022 · 18 comments
Closed

Clang fails to load on iOS 15.4 #391

bummoblizard opened this issue Mar 11, 2022 · 18 comments

Comments

@bummoblizard
Copy link
Contributor

bummoblizard commented Mar 11, 2022

Clang doesn't seem to work on iOS 15.4. This issue can be reproduced on a-shell and other apps that uses https://github.com/holzschu/llvm-project.

Looks like this has something to do with libc++.1.dylib being missing in iOS 15.4. I found a message from Xcode 13.3 RC release note that might relate to this (https://developer.apple.com/documentation/Xcode-Release-Notes/xcode-13_3-release-notes):

Xcode no longer passes -stdlib=libstdc++ to Clang, because Clang no longer supports that library on Apple platforms. If your project defines the CLANG_CXX_LIBRARY build setting, remove it because it no longer does anything. (83768231)

Error from Xcode:

Failed loading clang from clang.framework/clang, cause = dlopen(clang.framework/clang, 0x0009): Library not loaded: @rpath/libc++.1.dylib
  Referenced from: /private/var/containers/Bundle/Application/860EA2C4-8F59-456A-A643-DBE4C1E23DB8/Code.app/Frameworks/clang.framework/clang
  Reason: tried: '/usr/lib/system/introspection/libc++.1.dylib' (no such file), 
'/private/var/containers/Bundle/Application/860EA2C4-8F59-456A-A643-DBE4C1E23DB8/Code.app/Frameworks/libc++.1.dylib' (no such file), 
'/private/var/containers/Bundle/Application/860EA2C4-8F59-456A-A643-DBE4C1E23DB8/Code.app/Frameworks/clang.framework/Frameworks/libc++.1.dylib' (no such file), 
'/private/var/containers/Bundle/Application/860EA2C4-8F59-456A-A643-DBE4C1E23DB8/Code.app/Frameworks/libc++.1.dylib' (no such file), 
'/private/var/containers/Bundle/Application/860EA2C4-8F59-456A-A643-DBE4C1E23DB8/Code.app/Frameworks/clang.framework/Frameworks/libc++.1.dylib' (no such file), 
'/private/var/containers/Bundle/Application/860EA2C4-8F59-456A-A643-DBE4C1E23DB8/Code.app/Frameworks/libc++.1.dylib' (no such file), 
'/private/var/containers/Bundle/Application/860EA2C4-8F59-456A-A643-DBE4C1E23DB8/Code.app/Frameworks/ios_system.framework/Frameworks/libc++.1.dylib' (no such file), 
'/private/var/containers/Bundle/Application/860EA2C4-8F59-456A-A643-DBE4C1E23DB8/Code.app/Frameworks/libc++.1.dylib' (no such file),
'/private/var/containers/Bundle/Application/860EA2C4-8F59-456A-A643-DBE4C1E23DB8/Code.app/Frameworks/libc++.1.dylib' (no such file), 
'/private/var/containers/Bundle/Application/860EA2C4-8F59-456A-A643-DBE4C1E23DB8/Code.app/Frameworks/libc++.1.dylib' (no such file)

a-Shell screenshot:
IMG_EFAB83A4E6EC-1

@holzschu
Copy link
Owner

I am not able to reproduce the issue, but I don't have iOS 15.4 yet.

What I can say for sure is that we are not using iOS version of libc++.1.dylib (because it is not available to normal users anyway) but instead creating our own libc++, which is in ~/Library/usr/lib/wasm32-wasi/.

The "Failed loading clang" error means that iOS has an issue with the developer signature on clang.framework. Re-installing and/or rebooting might clear up this permission issue.

@bummoblizard
Copy link
Contributor Author

Thank you for the insight! It's a problem exclusive to iOS 15.4 since many reported the problem on their iOS 15.4 devices.

I'm trying to recompile clang with the latest Xcode and see how it goes.

@holzschu
Copy link
Owner

I'm sorry, I did not read your error message carefully enough. You're absolutely right.
We have a problem here: if I recompile with my settings (Xcode 13.2), Xcode will find libc++.1.dylib, and include it.

I need to download Xcode 13.3RC in order to create the new framework.

@bummoblizard
Copy link
Contributor Author

I'm still wondering where the issue is here. It looks like the dylib was a part of iOS library and linked when building clang.

Not sure why it's removed in 15.4.

@holzschu
Copy link
Owner

Yes, that's surprising that they removed it, and it's going to break a lot of apps. I have no ideas why they would do that.

@bummoblizard
Copy link
Contributor Author

bummoblizard commented Mar 15, 2022

I can confirm this issue can be reproduced on iOS 15.4 GM. I was having issues compiling clang on my desktop but I will try again today.

@holzschu
Copy link
Owner

Yes, I can confirm it too. I'm in the process of upgrading OSX, so I can upgrade Xcode, so I can recompile LLVM.

@bummoblizard
Copy link
Contributor Author

When building for iOS, it failed with the below message. I'm not sure if it's my environment or Xcode's fault.

[961/7323] Linking C shared library lib/libomp.dylib
FAILED: lib/libomp.dylib 
: && /Users/kenchung/Desktop/llvm-project/build_osx/bin/clang -arch arm64 -target arm64-apple-darwin19.6.0 -O2 -D_LIBCPP_STRING_H_HAS_CONST_OVERLOADS  -I/Users/kenchung/Desktop/llvm-project/build_osx/include/ -I/Users/kenchung/Desktop/llvm-project/build_osx/include/c++/v1/ -I/Users/kenchung/Desktop/llvm-project -miphoneos-version-min=14 -fPIC -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wstring-conversion -Wmisleading-indentation -fdiagnostics-color -Wall -Wcast-qual -Wformat-pedantic -Wimplicit-fallthrough -Wsign-compare -Wno-extra -Wno-pedantic -O3 -DNDEBUG -arch arm64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS15.4.sdk -dynamiclib -Wl,-headerpad_max_install_names -nostdlib -F/Users/kenchung/Desktop/llvm-project/ios_system.xcframework/ios-arm64 -O2 -framework ios_system -lobjc -lc -lc++ -miphoneos-version-min=14  -current_version 5.0 -compatibility_version 5.0 -L lib/clang/14.0.0/lib/darwin -lclang_rt.cc_kext_ios -o lib/libomp.dylib -install_name @rpath/libomp.dylib projects/openmp/runtime/src/CMakeFiles/omp.dir/kmp_alloc.cpp.o projects/openmp/runtime/src/CMakeFiles/omp.dir/kmp_atomic.cpp.o projects/openmp/runtime/src/CMakeFiles/omp.dir/kmp_csupport.cpp.o projects/openmp/runtime/src/CMakeFiles/omp.dir/kmp_debug.cpp.o projects/openmp/runtime/src/CMakeFiles/omp.dir/kmp_itt.cpp.o projects/openmp/runtime/src/CMakeFiles/omp.dir/kmp_environment.cpp.o projects/openmp/runtime/src/CMakeFiles/omp.dir/kmp_error.cpp.o projects/openmp/runtime/src/CMakeFiles/omp.dir/kmp_global.cpp.o projects/openmp/runtime/src/CMakeFiles/omp.dir/kmp_i18n.cpp.o projects/openmp/runtime/src/CMakeFiles/omp.dir/kmp_io.cpp.o projects/openmp/runtime/src/CMakeFiles/omp.dir/kmp_runtime.cpp.o projects/openmp/runtime/src/CMakeFiles/omp.dir/kmp_settings.cpp.o projects/openmp/runtime/src/CMakeFiles/omp.dir/kmp_str.cpp.o projects/openmp/runtime/src/CMakeFiles/omp.dir/kmp_tasking.cpp.o projects/openmp/runtime/src/CMakeFiles/omp.dir/kmp_threadprivate.cpp.o projects/openmp/runtime/src/CMakeFiles/omp.dir/kmp_utility.cpp.o projects/openmp/runtime/src/CMakeFiles/omp.dir/kmp_barrier.cpp.o projects/openmp/runtime/src/CMakeFiles/omp.dir/kmp_wait_release.cpp.o projects/openmp/runtime/src/CMakeFiles/omp.dir/kmp_affinity.cpp.o projects/openmp/runtime/src/CMakeFiles/omp.dir/kmp_dispatch.cpp.o projects/openmp/runtime/src/CMakeFiles/omp.dir/kmp_lock.cpp.o projects/openmp/runtime/src/CMakeFiles/omp.dir/kmp_sched.cpp.o projects/openmp/runtime/src/CMakeFiles/omp.dir/z_Linux_util.cpp.o projects/openmp/runtime/src/CMakeFiles/omp.dir/kmp_gsupport.cpp.o projects/openmp/runtime/src/CMakeFiles/omp.dir/thirdparty/ittnotify/ittnotify_static.cpp.o projects/openmp/runtime/src/CMakeFiles/omp.dir/kmp_taskdeps.cpp.o projects/openmp/runtime/src/CMakeFiles/omp.dir/kmp_cancel.cpp.o projects/openmp/runtime/src/CMakeFiles/omp.dir/kmp_ftn_cdecl.cpp.o projects/openmp/runtime/src/CMakeFiles/omp.dir/kmp_ftn_extra.cpp.o projects/openmp/runtime/src/CMakeFiles/omp.dir/kmp_version.cpp.o projects/openmp/runtime/src/CMakeFiles/omp.dir/ompt-general.cpp.o projects/openmp/runtime/src/CMakeFiles/omp.dir/z_Linux_asm.S.o   && cd /Users/kenchung/Desktop/llvm-project/build-iphoneos/lib && /opt/homebrew/Cellar/cmake/3.20.3/bin/cmake -E create_symlink libomp.dylib libgomp.dylib && /opt/homebrew/Cellar/cmake/3.20.3/bin/cmake -E create_symlink libomp.dylib libiomp5.dylib
ld: library not found for -lclang_rt.cc_kext_ios
clang-14: error: linker command failed with exit code 1 (use -v to see invocation)
[964/7323] Building C object projects/..._rt.builtins_x86_64_osx.dir/mulxc3.c.o
ninja: build stopped: subcommand failed.

@holzschu
Copy link
Owner

I'm recompiling now, I'll see what happens.
The error message is still confusing for me, compared to the release note.

The error message says it cannot find libc++, while the release note warns about the disparition of libstdc++. I can now confirm that libc++ is very much present in the iOS 15.4 SDK, at exactly the same place where it was in the previous SDKs.

@holzschu
Copy link
Owner

holzschu commented Mar 16, 2022

After recompiling clang, I can now run clang on a-Shell. I have accidentally updated LLVM and clang to version 14.0, but I don't think that'll be too much of an issue. Linking fails (ld: command not found), but it seems related to changes in LLVM 14.0, I should be able to fix it.

Update: it runs now. clang, clang++.

@bummoblizard
Copy link
Contributor Author

After recompiling clang, I can now run clang on a-Shell. I have accidentally updated LLVM and clang to version 14.0, but I don't think that'll be too much of an issue. Linking fails (ld: command not found), but it seems related to changes in LLVM 14.0, I should be able to fix it.

Great. That means it was a problem of my environment. Looking forward to the update.

@holzschu
Copy link
Owner

Great. That means it was a problem of my environment.

Not necessarily. Maybe it was an incompatibility between the source code of LLVM 13.0 and the SDK included with XCode 13.3.

@bummoblizard
Copy link
Contributor Author

@holzschu Will you publish the changes to https://github.com/holzschu/llvm-project?

@holzschu
Copy link
Owner

According to git, the only change was to bootstrap.sh. I'm not sure what happened, or how the version number got bumped to 14.0. Anyway, it's pushed.

@bummoblizard
Copy link
Contributor Author

According to git, the only change was to bootstrap.sh. I'm not sure what happened, or how the version number got bumped to 14.0. Anyway, it's pushed.

Unfortunately I'm stilling having the ld: library not found for -lclang_rt.cc_kext_ios error. It would be great if you can upload the binaries to the release.

@holzschu
Copy link
Owner

The release has been published: https://github.com/holzschu/llvm-project/releases
Hope it works for you.

@bummoblizard
Copy link
Contributor Author

The release has been published: https://github.com/holzschu/llvm-project/releases
Hope it works for you.

Thank you! I think there was some compatibility issue with M1 Mac with the CMake scripts causing it not to copy clang_rt.cc_kext_ios. I managed to build it after manually copying the files.

@holzschu
Copy link
Owner

Version 1.8.6 (now out on the AppStore) fixes this issue.

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

No branches or pull requests

2 participants