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

Does cctools generate/support iPhone Simulator arm64 arch #102

Open
Dayananda87 opened this issue Feb 4, 2021 · 14 comments
Open

Does cctools generate/support iPhone Simulator arm64 arch #102

Dayananda87 opened this issue Feb 4, 2021 · 14 comments

Comments

@Dayananda87
Copy link

Hi,

We are facing a problem with the library generated by cctools as it's doesn't contain arm64 simulator architecture, which is expected by simulators on the M1 mac machine.
Does cctools generate iPhone simulator arm64 arch slice for a library?

Here is the error:
building for iOS Simulator, but linking in object file (libxyz.a(filename.o)) built for iOS

Thanks,
Dayananda

@tpoechtrager
Copy link
Owner

iPhone Simulator is currently not supported. Do you depend on Simulator support? I might be able to get it working.

@Dayananda87
Copy link
Author

@tpoechtrager Thanks for the response.
I've a M1 based macbook whose simulator also has arm64 so wanted to try it out. That will be cool if it works.

Thanks a lot.

@naithar
Copy link

naithar commented Feb 12, 2021

@tpoechtrager I have the same issue while trying to build arm64 tvOS simulator binary.
Resulting binary is considered to be built for tvOS. arm64 tvOS and x86_64 tvOS simulator binaries are built correctly.

@tpoechtrager
Copy link
Owner

@naithar To be honest, I don't know. I can't do any testing either. Maybe it's just a warning and we have to wait for the next ld64 open source release.

Could you try building with Apple's Compiler instead of Mainline LLVM? https://github.com/apple/llvm-project

@naithar
Copy link

naithar commented Feb 12, 2021

I will try, thanks. But I don't have any experience in this, so it might take a while.

Could the problem be related to the way target platform gets determined in some way? Using arm64 arch for simulator platform seems to force device platform. Is there a way to trace where target platform gets incorrectly defined?

@tpoechtrager
Copy link
Owner

Yes, absolutely possible. You could start with adding -v to the compile command.

@naithar
Copy link

naithar commented Feb 12, 2021

For which command should I use this flag? For https://github.com/tpoechtrager/cctools-port/blob/master/usage_examples/ios_toolchain/build.sh or somewhere else? Thanks :)

Edit:
I think I've found flags that I need -tvos_simulator_version_min? But it didn't help.
Changing PlatformSupport.cpp to return only simulator platforms, since it seems like the only place where platform is used, didn't help also.

@tpoechtrager
Copy link
Owner

The compiler is (probably) doing something wrong not the linker. You must examine the compiler.

Add -v to the compiler args.

For example:

$ ./target/bin/x86_64-apple-darwin11-clang ~/tmp/test.c  -v
clang version 13.0.0 (https://github.com/llvm/llvm-project.git c16f776028ddd39a4d5ea39d5c3831b1bcbb8c02)
Target: x86_64-apple-darwin11
Thread model: posix
InstalledDir: /opt/llvm/llvm-git/bin
Found CUDA installation: /opt/cuda, version 11.2
"/opt/llvm/llvm-git/bin/clang-13" -cc1 -triple x86_64-apple-ios14.5.0-simulator -Wundef-prefix=TARGET_OS_ -Werror=undef-prefix -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -Werror=implicit-function-declaration -emit-obj -mrelax-all --mrelax-relocations -disable-free -disable-llvm-verifier -discard-value-names -main-file-name test.c -mrelocation-model pic -pic-level 2 -mframe-pointer=all -fno-rounding-math -munwind-tables -target-sdk-version=14.5 -fcompatibility-qualified-id-block-type-checking -fvisibility-inlines-hidden-static-local-var -target-cpu core2 -tune-cpu generic -debugger-tuning=lldb -target-linker-version 450.3 -v -resource-dir /opt/llvm/llvm-git/lib/clang/13.0.0 -isysroot /home/thomas/dev/cctools-port/usage_examples/ios_toolchain/target/bin/../SDK/iPhoneSimulator.sdk -internal-isystem /home/thomas/dev/cctools-port/usage_examples/ios_toolchain/target/bin/../SDK/iPhoneSimulator.sdk/usr/local/include -internal-isystem /opt/llvm/llvm-git/lib/clang/13.0.0/include -internal-externc-isystem /home/thomas/dev/cctools-port/usage_examples/ios_toolchain/target/bin/../SDK/iPhoneSimulator.sdk/usr/include -fdebug-compilation-dir /home/thomas/dev/cctools-port/usage_examples/ios_toolchain -ferror-limit 19 -stack-protector 1 -fblocks -fencode-extended-block-signature -fregister-global-dtors-with-atexit -fgnuc-version=4.2.1 -fmax-type-align=16 -fcolor-diagnostics -o /tmp/test-2e1e02.o -x c /home/thomas/tmp/test.c
clang -cc1 version 13.0.0 based upon LLVM 13.0.0git default target x86_64-unknown-linux-gnu
ignoring nonexistent directory "/home/thomas/dev/cctools-port/usage_examples/ios_toolchain/target/bin/../SDK/iPhoneSimulator.sdk/usr/local/include"
ignoring nonexistent directory "/home/thomas/dev/cctools-port/usage_examples/ios_toolchain/target/bin/../SDK/iPhoneSimulator.sdk/Library/Frameworks"
#include "..." search starts here:
#include <...> search starts here:
/opt/llvm/llvm-git/lib/clang/13.0.0/include
/home/thomas/dev/cctools-port/usage_examples/ios_toolchain/target/bin/../SDK/iPhoneSimulator.sdk/usr/include
/home/thomas/dev/cctools-port/usage_examples/ios_toolchain/target/bin/../SDK/iPhoneSimulator.sdk/System/Library/Frameworks (framework directory)
End of search list.
"/home/thomas/dev/cctools-port/usage_examples/ios_toolchain/target/bin/x86_64-apple-darwin11-ld" -demangle -lto_library /opt/llvm/llvm-git/lib/libLTO.dylib -no_deduplicate -dynamic -arch x86_64 -ios_simulator_version_min 14.5.0 -syslibroot /home/thomas/dev/cctools-port/usage_examples/ios_toolchain/target/bin/../SDK/iPhoneSimulator.sdk -o a.out /tmp/test-2e1e02.o -lSystem
ld: warning: building for iOS Simulator, but linking in .tbd file (/usr/lib/system/libsystem_kernel.dylib) built for macOS
ld: warning: building for iOS Simulator, but linking in .tbd file (/usr/lib/system/libsystem_platform.dylib) built for macOS
ld: warning: building for iOS Simulator, but linking in .tbd file (/usr/lib/system/libsystem_pthread.dylib) built for macOS

@Benau
Copy link

Benau commented May 17, 2021

Seems that clang toolchain assumes only x86 iphone (and tvos probably) simulator atm, this patch should fix this:

diff --git a/clang/lib/Driver/ToolChains/Darwin.cpp b/clang/lib/Driver/ToolChains/Darwin.cpp
index 4b39faf5687c..f1f6f2d523ad 100644
--- a/clang/lib/Driver/ToolChains/Darwin.cpp
+++ b/clang/lib/Driver/ToolChains/Darwin.cpp
@@ -2012,7 +2012,7 @@ void Darwin::AddDeploymentTarget(DerivedArgList &Args) const {
   DarwinEnvironmentKind Environment = OSTarget->getEnvironment();
   // Recognize iOS targets with an x86 architecture as the iOS simulator.
   if (Environment == NativeEnvironment && Platform != MacOS &&
-      OSTarget->canInferSimulatorFromArch() && getTriple().isX86())
+      OSTarget->canInferSimulatorFromArch() && OSTarget->getAsString(Args, Opts).find("simulator") != std::string::npos)
     Environment = Simulator;
 
   VersionTuple NativeTargetVersion;

This patch may not follow official coding style of llvm, but should be able to workaround the problem for now

I'm using apple-llvm, but I think official clang should be the same too, can you try?

my result: (i use my own bash wrapper)

COMPILER_PATH=/opt/cctools/bin /opt/cctools/bin/clang -target arm-apple-darwin11 -isysroot /opt/cctools/sdk/iPhoneSimulator14.5.sdk -arch arm64 -miphonesimulator-version-min=8.0 -fembed-bitcode -mlinker-version=609 -Wno-unused-command-line-argument $@
clang version 13.0.0 (https://github.com/apple/llvm-project 59d63a3681256768e4ae78211d2a15ce583c9ed7)
Target: arm64-apple-darwin11
Thread model: posix
InstalledDir: /opt/cctools/bin
 "/opt/cctools/bin/clang-13" -cc1 -triple arm64-apple-ios8.0.0-simulator -Wundef-prefix=TARGET_OS_ -Werror=undef-prefix -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -Werror=implicit-function-declaration -emit-llvm-bc -emit-llvm-uselists -disable-free -disable-llvm-verifier -discard-value-names -main-file-name test.c -mrelocation-model pic -pic-level 2 -mframe-pointer=non-leaf -fno-rounding-math -munwind-tables -faligned-alloc-unavailable -target-sdk-version=14.5 -fcompatibility-qualified-id-block-type-checking -fvisibility-inlines-hidden-static-local-var -target-cpu apple-m1 -target-feature +v8.5a -target-feature +fp-armv8 -target-feature +neon -target-feature +crc -target-feature +crypto -target-feature +dotprod -target-feature +fp16fml -target-feature +ras -target-feature +lse -target-feature +rdm -target-feature +rcpc -target-feature +zcm -target-feature +zcz -target-feature +fullfp16 -target-feature +sha2 -target-feature +aes -target-abi darwinpcs -fallow-half-arguments-and-returns -debugger-tuning=lldb -target-linker-version 609 -v -fcoverage-compilation-dir=/opt/cctools/bin -resource-dir /opt/cctools/lib/clang/13.0.0 -isysroot /opt/cctools/sdk/iPhoneSimulator14.5.sdk -internal-isystem /opt/cctools/sdk/iPhoneSimulator14.5.sdk/usr/local/include -internal-isystem /opt/cctools/lib/clang/13.0.0/include -internal-externc-isystem /opt/cctools/sdk/iPhoneSimulator14.5.sdk/usr/include -Wno-unused-command-line-argument -fdebug-compilation-dir=/opt/cctools/bin -ferror-limit 19 -stack-protector 1 -fblocks -fencode-extended-block-signature -fregister-global-dtors-with-atexit -fgnuc-version=4.2.1 -fmax-type-align=16 -fcolor-diagnostics -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/test-4854e2.bc -x c test.c
clang -cc1 version 13.0.0 based upon LLVM 13.0.0git default target x86_64-unknown-linux-gnu
ignoring nonexistent directory "/opt/cctools/sdk/iPhoneSimulator14.5.sdk/usr/local/include"
ignoring nonexistent directory "/opt/cctools/sdk/iPhoneSimulator14.5.sdk/Library/Frameworks"
#include "..." search starts here:
#include <...> search starts here:
 /opt/cctools/lib/clang/13.0.0/include
 /opt/cctools/sdk/iPhoneSimulator14.5.sdk/usr/include
 /opt/cctools/sdk/iPhoneSimulator14.5.sdk/System/Library/Frameworks (framework directory)
End of search list.
 "/opt/cctools/bin/clang-13" -cc1 -triple arm64-apple-ios8.0.0-simulator -Wundef-prefix=TARGET_OS_ -Werror=undef-prefix -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -Werror=implicit-function-declaration -emit-obj -mrelax-all --mrelax-relocations -fembed-bitcode=all -fembed-bitcode=all -disable-llvm-passes -faligned-alloc-unavailable -target-sdk-version=14.5 -fcompatibility-qualified-id-block-type-checking -fvisibility-inlines-hidden-static-local-var -fno-rounding-math -target-abi darwinpcs -o /tmp/test-a8462f.o -x ir /tmp/test-4854e2.bc
 "/opt/cctools/bin/arm-apple-darwin11-ld" -demangle -lto_library /opt/cctools/lib/libLTO.dylib -no_deduplicate -dynamic -arch arm64 -platform_version ios-simulator 14.0.0 14.5 -bitcode_bundle -syslibroot /opt/cctools/sdk/iPhoneSimulator14.5.sdk -o a.out /tmp/test-a8462f.o -lSystem

And by the way x86_64 simulator works for me too without any patches:

COMPILER_PATH=/opt/cctools/bin /opt/cctools/bin/clang -target x86_64-apple-darwin11 -isysroot /opt/cctools/sdk/iPhoneSimulator14.5.sdk -arch x86_64 -miphonesimulator-version-min=8.0 -fembed-bitcode -mlinker-version=609 -Wno-unused-command-line-argument $@)
clang version 13.0.0 (https://github.com/apple/llvm-project 59d63a3681256768e4ae78211d2a15ce583c9ed7)
Target: x86_64-apple-darwin11
Thread model: posix
InstalledDir: /opt/cctools/bin
 "/opt/cctools/bin/clang-13" -cc1 -triple x86_64-apple-ios8.0.0-simulator -Wundef-prefix=TARGET_OS_ -Werror=undef-prefix -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -Werror=implicit-function-declaration -emit-llvm-bc -emit-llvm-uselists -disable-free -disable-llvm-verifier -discard-value-names -main-file-name test.c -mrelocation-model pic -pic-level 2 -mframe-pointer=all -fno-rounding-math -munwind-tables -faligned-alloc-unavailable -target-sdk-version=14.5 -fcompatibility-qualified-id-block-type-checking -fvisibility-inlines-hidden-static-local-var -target-cpu core2 -tune-cpu generic -debugger-tuning=lldb -target-linker-version 609 -v -fcoverage-compilation-dir=/opt/cctools/bin -resource-dir /opt/cctools/lib/clang/13.0.0 -isysroot /opt/cctools/sdk/iPhoneSimulator14.5.sdk -internal-isystem /opt/cctools/sdk/iPhoneSimulator14.5.sdk/usr/local/include -internal-isystem /opt/cctools/lib/clang/13.0.0/include -internal-externc-isystem /opt/cctools/sdk/iPhoneSimulator14.5.sdk/usr/include -Wno-unused-command-line-argument -fdebug-compilation-dir=/opt/cctools/bin -ferror-limit 19 -stack-protector 1 -fblocks -fencode-extended-block-signature -fregister-global-dtors-with-atexit -fgnuc-version=4.2.1 -fmax-type-align=16 -fcolor-diagnostics -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/test-7db49b.bc -x c test.c
clang -cc1 version 13.0.0 based upon LLVM 13.0.0git default target x86_64-unknown-linux-gnu
ignoring nonexistent directory "/opt/cctools/sdk/iPhoneSimulator14.5.sdk/usr/local/include"
ignoring nonexistent directory "/opt/cctools/sdk/iPhoneSimulator14.5.sdk/Library/Frameworks"
#include "..." search starts here:
#include <...> search starts here:
 /opt/cctools/lib/clang/13.0.0/include
 /opt/cctools/sdk/iPhoneSimulator14.5.sdk/usr/include
 /opt/cctools/sdk/iPhoneSimulator14.5.sdk/System/Library/Frameworks (framework directory)
End of search list.
 "/opt/cctools/bin/clang-13" -cc1 -triple x86_64-apple-ios8.0.0-simulator -Wundef-prefix=TARGET_OS_ -Werror=undef-prefix -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -Werror=implicit-function-declaration -emit-obj -mrelax-all --mrelax-relocations -fembed-bitcode=all -fembed-bitcode=all -disable-llvm-passes -faligned-alloc-unavailable -target-sdk-version=14.5 -fcompatibility-qualified-id-block-type-checking -fvisibility-inlines-hidden-static-local-var -fno-rounding-math -o /tmp/test-c14fab.o -x ir /tmp/test-7db49b.bc
 "/opt/cctools/bin/x86_64-apple-darwin11-ld" -demangle -lto_library /opt/cctools/lib/libLTO.dylib -no_deduplicate -dynamic -arch x86_64 -platform_version ios-simulator 8.0.0 14.5 -bitcode_bundle -syslibroot /opt/cctools/sdk/iPhoneSimulator14.5.sdk -o a.out /tmp/test-c14fab.o -lSystem

akien-mga added a commit to godotengine/build-containers that referenced this issue Jul 12, 2021
We have to wait for a resolution to tpoechtrager/cctools-port#102
or try a custom LLVM build with the proposed patch in that issue.
akien-mga added a commit to godotengine/build-containers that referenced this issue Jul 12, 2021
We have to wait for a resolution to tpoechtrager/cctools-port#102
or try a custom LLVM build with the proposed patch in that issue.
@akien-mga
Copy link

akien-mga commented Sep 5, 2023

For the record, as of Apple Clang based on LLVM 15.0.0, I seem to be able to build iPhoneSimulator for arm64 (using SDK 16.4 from Xcode 14.3.1).

I haven't tried with upstream LLVM 15.0.0.

Edit: It builds, but doesn't work it seems. Building an app for iOS simulator with our Godot library built with ioscross, we get:

building for iOS Simulator, but linking in object file built for iOS, file 'libgodot.a'

@tpoechtrager
Copy link
Owner

Are you using the correct SDK and correct target triple? According to ChatGPT it should be something like x86_64-apple-iosXX.Y-simulator

@Un1q32
Copy link
Contributor

Un1q32 commented Sep 9, 2023

I can build for arm64 iOS simulator just fine with upstream clang 16.0.6 on Linux, the ChatGPT target triple is correct except for the arch, which should be arm64 as they are building for arm64.
You can also use darwinXX as the OS instead of iosXX.Y-simulator, but you might have to add -mios-simulator-version-min=XX to clang arguements

@akien-mga
Copy link

akien-mga commented Sep 11, 2023

I'm using the correct SDK, but I'm not sure I'm using the target triple correctly.

I was using the default in usage_examples/ios_toolchain/build.sh, after patching the SDK dir:

git clone --progress https://github.com/tpoechtrager/cctools-port
cd /root/cctools-port
git checkout f28fb5e9c31efd3d0552afcce2d2c03cae25c1ca
sed -i '/WRAPPER_SDKDIR/s/iPhoneOS/iPhoneSimulator/' usage_examples/ios_toolchain/build.sh
usage_examples/ios_toolchain/build.sh /root/files/iPhoneSimulator16.4.sdk.tar.xz arm64

Now reading you I see that I might need to patch usage_examples/ios_toolchain/build.sh further, or do all build steps manually to fully control the parameters.

But I can't seem to pass a target triple as suggested for the cctools-port build:

$ ../../cctools/configure --target="arm64-apple-ios16.4-simulator" --prefix=$TARGETDIR --with-libtapi=$TARGETDIR
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking target system type... Invalid configuration `arm64-apple-ios16.4-simulator': machine `arm64-apple' not recognized
configure: error: /bin/sh ../../cctools/config.sub arm64-apple-ios16.4-simulator failed

It seems my Clang install (from latest osxcross with Apple Clang 15.0.0) doesn't recognize arm64-apple as a valid machine. arm-apple works. But then I can't find a system variant that works for the simulator. The default arm-apple-darwin11 works ok.


For the record, this is my current setup:

@tpoechtrager
Copy link
Owner

It's actually autogen that doesn't recognize the architecture. The best way to work around this would be to use --target=aarch64-... instead of arm64 and then in the wrapper add -arch arm64 to the compiler flags. There might be a chance aarch64- works out of the box without the need of -arch arm64. Depends on what Clang does in the compiler driver.

Or use --target=arm-.... and when compiling stuff add -arch arm64 to the compiler flags.

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

6 participants