我如何找出我正在使用Apple的Clang编译的ARM变体?



我正在用clang(在命令行-出于良好但复杂的原因)从C和c++代码构建iOS软件,并想知道编译器针对的是ARMv8的哪个变体(例如,8,8.3等)。一个相关的问题:clang如何列出支持的目标架构,但许多答案依赖于诸如llc之类的工具,而这些工具在苹果的Xcode中没有提供。

这是相当简单的,一旦你发现如何。一个有用的工具是一个绝对最小的C程序,不包括:

main( int argc, char *argv[]) 
{
    return 0;
}

使用——verbose选项编译此文件,这将使编译器生成大量关于其工作的输出。例如,

clang -arch arm64 -fexceptions -std=c99 --verbose minimal_c_program_with_no_includes.c

实际上是一个针对ARM macOS的编译器,它产生的输出包括:

-triple arm64-apple-macosx11.0.0 -main-file-name minimal_c_program_with_no_includes.c  
-target-sdk-version=11.0 -target-cpu vortex -target-feature +v8.3a 
-target-feature +fp-armv8 -target-feature +neon

而在iOS 14及更高版本的编译中使用:

clang -arch arm64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk
-mios-version-min=14.0 -fexceptions -std=c99 --verbose minimal_c_program_with_no_includes.c

生产:

-triple arm64-apple-ios14.0.0 -main-file-name minimal_c_program_with_no_includes.c 
-target-sdk-version=14.2 -target-cpu apple-a7 -target-feature +fp-armv8 
-target-feature +neon

-target-sdk-version值是因为我使用的是Xcode 12.2,它有iOS 14.2 SDK。

最新更新