探究ndk中llvm与默认llvm的差别

使用ndk中的clang工具链(clang+ld):

03:00:36 ztn@ztn-laptop2 ~ → /home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/clang -target aarch64-linux-android21 main.c -###
Android (7019983 based on r365631c3) clang version 9.0.9 (https://android.googlesource.com/toolchain/llvm-project a2a1e703c0edb03ba29944e529ccbf457742737b) (based on LLVM 9.0.9svn)
Target: aarch64-unknown-linux-android21
Thread model: posix
InstalledDir: /home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin
 "/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/clang" "-cc1" "-triple" "aarch64-unknown-linux-android21" "-emit-obj" "-mrelax-all" "-mnoexecstack" "-disable-free" "-disable-llvm-verifier" "-discard-value-names" "-main-file-name" "main.c" "-mrelocation-model" "pic" "-pic-level" "2" "-pic-is-pie" "-mthread-model" "posix" "-mdisable-fp-elim" "-masm-verbose" "-mconstructor-aliases" "-fuse-init-array" "-target-cpu" "generic" "-target-feature" "+neon" "-target-abi" "aapcs" "-mllvm" "-aarch64-fix-cortex-a53-835769=1" "-fallow-half-arguments-and-returns" "-dwarf-column-info" "-debugger-tuning=gdb" "-resource-dir" "/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/9.0.9" "-internal-isystem" "/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/local/include" "-internal-isystem" "/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/9.0.9/include" "-internal-externc-isystem" "/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/include/aarch64-linux-android" "-internal-externc-isystem" "/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/include" "-internal-externc-isystem" "/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/include" "-fdebug-compilation-dir" "/home/ztn" "-ferror-limit" "19" "-fmessage-length" "0" "-fno-signed-char" "-fobjc-runtime=gcc" "-fdiagnostics-show-option" "-fcolor-diagnostics" "-o" "/tmp/main-f62791.o" "-x" "c" "main.c"
 "/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/../lib/gcc/aarch64-linux-android/4.9.x/../../../../aarch64-linux-android/bin/ld" "-pie" "-z" "noexecstack" "-EL" "--fix-cortex-a53-843419" "--warn-shared-textrel" "-z" "now" "-z" "relro" "-z" "max-page-size=4096" "--hash-style=both" "--enable-new-dtags" "--eh-frame-hdr" "-m" "aarch64linux" "-dynamic-linker" "/system/bin/linker64" "-o" "a.out" "/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/lib/aarch64-linux-android/21/crtbegin_dynamic.o" "-L/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/9.0.9/lib/linux/aarch64" "-L/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/../lib/gcc/aarch64-linux-android/4.9.x" "-L/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/../lib/gcc/aarch64-linux-android/4.9.x/../../../../aarch64-linux-android/lib/../lib64" "-L/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/lib/aarch64-linux-android/21" "-L/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/lib/aarch64-linux-android" "-L/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/../lib/gcc/aarch64-linux-android/4.9.x/../../../../aarch64-linux-android/lib" "-L/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/lib" "/tmp/main-f62791.o" "-lgcc" "-ldl" "-lc" "-lgcc" "-ldl" "/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/lib/aarch64-linux-android/21/crtend_android.o"

利用llvm14.0 clang-default编译+链接指令:

04:05:47 ztn@ztn-laptop2 ~ → clang -target aarch64-linux-android21 main.c --sysroot=/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot -###
Ubuntu clang version 14.0.0-1ubuntu1
Target: aarch64-unknown-linux-android21
Thread model: posix
InstalledDir: /usr/bin
 "/usr/lib/llvm-14/bin/clang" "-cc1" "-triple" "aarch64-unknown-linux-android21" "-emit-obj" "-mrelax-all" "--mrelax-relocations" "-disable-free" "-clear-ast-before-backend" "-disable-llvm-verifier" "-discard-value-names" "-main-file-name" "main.c" "-mrelocation-model" "pic" "-pic-level" "2" "-pic-is-pie" "-mframe-pointer=non-leaf" "-ffp-contract=on" "-fno-rounding-math" "-mconstructor-aliases" "-funwind-tables=2" "-target-cpu" "generic" "-target-feature" "+neon" "-target-feature" "+v8a" "-target-feature" "+fix-cortex-a53-835769" "-target-abi" "aapcs" "-fallow-half-arguments-and-returns" "-mllvm" "-treat-scalable-fixed-error-as-warning" "-debugger-tuning=gdb" "-fcoverage-compilation-dir=/home/ztn" "-resource-dir" "/usr/lib/llvm-14/lib/clang/14.0.0" "-isysroot" "/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot" "-internal-isystem" "/usr/lib/llvm-14/lib/clang/14.0.0/include" "-internal-isystem" "/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/local/include" "-internal-externc-isystem" "/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/aarch64-linux-android" "-internal-externc-isystem" "/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot/include" "-internal-externc-isystem" "/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include" "-fdebug-compilation-dir=/home/ztn" "-ferror-limit" "19" "-fno-signed-char" "-fgnuc-version=4.2.1" "-fcolor-diagnostics" "-D__GCC_HAVE_DWARF2_CFI_ASM=1" "-o" "/tmp/main-f0839f.o" "-x" "c" "main.c"
 "/usr/bin/ld" "--sysroot=/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot" "-pie" "-EL" "--fix-cortex-a53-843419" "--warn-shared-textrel" "-z" "now" "-z" "relro" "-z" "max-page-size=4096" "--hash-style=gnu" "--hash-style=both" "--build-id" "--enable-new-dtags" "--eh-frame-hdr" "-m" "aarch64linux" "-dynamic-linker" "/system/bin/linker64" "-o" "a.out" "/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/aarch64-linux-android/21/crtbegin_dynamic.o" "-L/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/aarch64-linux-android/21" "-L/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/aarch64-linux-android" "-L/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib" "/tmp/main-f0839f.o" "-lgcc" "-ldl" "-lc" "-lgcc" "-ldl" "/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/aarch64-linux-android/21/crtend_android.o"

利用llvm-default中的clang编译(命令也来自default)+ndk中的ld链接(命令来自ndk中的ld):

04:13:36 ztn@ztn-laptop2 ~ → "/usr/lib/llvm-14/bin/clang" "-cc1" "-triple" "aarch64-unknown-linux-android21" "-emit-obj" "-mrelax-all" "--mrelax-relocations" "-disable-free" "-clear-ast-before-backend" "-disable-llvm-verifier" "-discard-value-names" "-main-file-name" "main.c" "-mrelocation-model" "pic" "-pic-level" "2" "-pic-is-pie" "-mframe-pointer=non-leaf" "-ffp-contract=on" "-fno-rounding-math" "-mconstructor-aliases" "-funwind-tables=2" "-target-cpu" "generic" "-target-feature" "+neon" "-target-feature" "+v8a" "-target-feature" "+fix-cortex-a53-835769" "-target-abi" "aapcs" "-fallow-half-arguments-and-returns" "-mllvm" "-treat-scalable-fixed-error-as-warning" "-debugger-tuning=gdb" "-fcoverage-compilation-dir=/home/ztn" "-resource-dir" "/usr/lib/llvm-14/lib/clang/14.0.0" "-isysroot" "/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot" "-internal-isystem" "/usr/lib/llvm-14/lib/clang/14.0.0/include" "-internal-isystem" "/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/local/include" "-internal-externc-isystem" "/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/aarch64-linux-android" "-internal-externc-isystem" "/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot/include" "-internal-externc-isystem" "/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include" "-fdebug-compilation-dir=/home/ztn" "-ferror-limit" "19" "-fno-signed-char" "-fgnuc-version=4.2.1" "-fcolor-diagnostics" "-D__GCC_HAVE_DWARF2_CFI_ASM=1" "-o" "/tmp/main.o" "-x" "c" "main.c"
04:13:38 ztn@ztn-laptop2 ~ → nm /tmp/ma
main-dc2fc4.o  main-f62791.o  main.o         
04:13:38 ztn@ztn-laptop2 ~ → nm /tmp/main.o 
0000000000000000 r $d.1
0000000000000000 n $d.2
0000000000000000 r $d.3
0000000000000000 t $x.0
0000000000000000 T main
                 U printf
04:13:48 ztn@ztn-laptop2 ~ → "/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/../lib/gcc/aarch64-linux-android/4.9.x/../../../../aarch64-linux-android/bin/ld" "-pie" "-z" "noexecstack" "-EL" "--fix-cortex-a53-843419" "--warn-shared-textrel" "-z" "now" "-z" "relro" "-z" "max-page-size=4096" "--hash-style=both" "--enable-new-dtags" "--eh-frame-hdr" "-m" "aarch64linux" "-dynamic-linker" "/system/bin/linker64" "-o" "b.out" "/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/lib/aarch64-linux-android/21/crtbegin_dynamic.o" "-L/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/9.0.9/lib/linux/aarch64" "-L/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/../lib/gcc/aarch64-linux-android/4.9.x" "-L/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/../lib/gcc/aarch64-linux-android/4.9.x/../../../../aarch64-linux-android/lib/../lib64" "-L/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/lib/aarch64-linux-android/21" "-L/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/lib/aarch64-linux-android" "-L/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/../lib/gcc/aarch64-linux-android/4.9.x/../../../../aarch64-linux-android/lib" "-L/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/lib" "/tmp/main.o" "-lgcc" "-ldl" "-lc" "-lgcc" "-ldl" "/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/lib/aarch64-linux-android/21/crtend_android.o"

在android上运行b.out()成功(termux)

采用ld.lld链接(复制最前面的链接参数)

04:30:06 ztn@ztn-laptop2 ~ → ld.lld "-pie" "-z" "noexecstack" "-EL" "--fix-cortex-a53-843419" "--warn-shared-textrel" "-z" "now" "-z" "relro" "-z" "max-page-size=4096" "--hash-style=both" "--enable-new-dtags" "--eh-frame-hdr" "-m" "aarch64linux" "-dynamic-linker" "/system/bin/linker64" "-o" "c.out" "/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/lib/aarch64-linux-android/21/crtbegin_dynamic.o" "-L/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/9.0.9/lib/linux/aarch64" "-L/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/../lib/gcc/aarch64-linux-android/4.9.x" "-L/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/../lib/gcc/aarch64-linux-android/4.9.x/../../../../aarch64-linux-android/lib/../lib64" "-L/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/lib/aarch64-linux-android/21" "-L/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/lib/aarch64-linux-android" "-L/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/../lib/gcc/aarch64-linux-android/4.9.x/../../../../aarch64-linux-android/lib" "-L/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/lib" "/tmp/main.o" "-lgcc" "-ldl" "-lc" "-lgcc" "-ldl" "/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/lib/aarch64-linux-android/21/crtend_android.o"
04:30:34 ztn@ztn-laptop2 ~ → nm c.out 

成功执行

直接调用clang driver

直接用default llvm-clang 加上sysroot 和 -L,调用驱动器来编译(绕过NDK),貌似clang是根据target来判断怎么找文件的,具体路径好像是硬编码进了llvm项目。
在这个里面有写what-makes-clang-look-in-subdirectories-of-the-include-path:
Compiler drivers know where to tell the compiler (or actually the preprocessor) where to look for header files, usually by offsetting from the directory containing the driver executable, and this is hard-coded in the driver. It's generally undesirable to tell the driver to look in other subdirectories automatically, as this will very often result in very hard to track down bugs. In other words you want to specify the directories explicitly with -I.

clang --target=aarch64-linux-android21 -fno-addrsig -fuse-ld="E:\\AndroidSDK\\android-ndk-r20b\\toolchains\\llvm\\prebuilt\\windows\\aarch64-linux-android\\bin\\ld" --sysroot=E:\AndroidSDK\android-ndk-r20b\toolchains\llvm\prebuilt\windows\sysroot "-LE:\\AndroidSDK\\android-ndk-r20b\\toolchains\\llvm\\prebuilt\\windows\\lib\\clang\\8.0.7\\lib\\linux\\aarch64" "-LE:\\AndroidSDK\\android-ndk-r20b\\toolchains\\llvm\\prebuilt\\windows\\bin/../lib/gcc/aarch64-linux-android/4.9.x" "-LE:\\AndroidSDK\\android-ndk-r20b\\toolchains\\llvm\\prebuilt\\windows\\bin/../lib/gcc/aarch64-linux-android/4.9.x/../../../../aarch64-linux-android/lib/../lib64" "-LE:\\AndroidSDK\\android-ndk-r20b\\toolchains\\llvm\\prebuilt\\windows\\bin/../sysroot/usr/lib/aarch64-linux-android/21" "-LE:\\AndroidSDK\\android-ndk-r20b\\toolchains\\llvm\\prebuilt\\windows\\bin/../sysroot/usr/lib/aarch64-linux-android" "-LE:\\AndroidSDK\\android-ndk-r20b\\toolchains\\llvm\\prebuilt\\windows\\bin/../lib/gcc/aarch64-linux-android/4.9.x/../../../../aarch64-linux-android/lib" "-LE:\\AndroidSDK\\android-ndk-r20b\\toolchains\\llvm\\prebuilt\\windows\\bin/../sysroot/usr/lib" main.c

NDK的clang不同于llvm

用cmake构建AndroidManifest同级目录下的项目后(使用Ninja构建)

CMakeFiles/main.dir/build.make 下找到编译命令:

09:37:06 ztn@ztn-laptop2 app ±|master ✗|→ tree CMakeFiles
CMakeFiles
├── 3.22.1
│   ├── CMakeCCompiler.cmake
│   ├── CMakeCXXCompiler.cmake
│   ├── CMakeDetermineCompilerABI_C.bin
│   ├── CMakeDetermineCompilerABI_CXX.bin
│   └── CMakeSystem.cmake
├── cmake.check_cache
├── CMakeDirectoryInformation.cmake
├── CMakeOutput.log
├── CMakeTmp
├── main.dir
│   ├── build.make
│   ├── cmake_clean.cmake
│   ├── compiler_depend.make
│   ├── compiler_depend.ts
│   ├── DependInfo.cmake
│   ├── depend.make
│   ├── flags.make
│   ├── link.txt
│   ├── progress.make
│   └── src
│       └── main
│           └── cpp
│               ├── main.cpp.o
│               └── main.cpp.o.d
├── Makefile2
├── Makefile.cmake
├── progress.marks
└── TargetDirectories.txt

6 directories, 23 files
09:37:17 ztn@ztn-laptop2 app ±|master ✗|→ 

CMakeFiles/main.dir/src/main/cpp/main.cpp.o: CMakeFiles/main.dir/flags.make
CMakeFiles/main.dir/src/main/cpp/main.cpp.o: src/main/cpp/main.cpp
CMakeFiles/main.dir/src/main/cpp/main.cpp.o: CMakeFiles/main.dir/compiler_depend.ts
        @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --green --progress-dir=/home/ztn/androidffmpeg5.0-demo/app/CMakeFiles --progress-num=$(CMAKE_PROGRESS_1) "Building CXX object CMakeFiles/main.dir/src/main/cpp/main.cpp.o"
        /home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ --target=aarch64-none-linux-android21 --gcc-toolchain=/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64 --sysroot=/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot $(CXX_DEFINES) $(CXX_INCLUDES) $(CXX_FLAGS) -MD -MT CMakeFiles/main.dir/src/main/cpp/main.cpp.o -MF CMakeFiles/main.dir/src/main/cpp/main.cpp.o.d -o CMakeFiles/main.dir/src/main/cpp/main.cpp.o -c /home/ztn/androidffmpeg5.0-demo/app/src/main/cpp/main.cpp

CMakeFiles/main.dir/src/main/cpp/main.cpp.i: cmake_force
        @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --green "Preprocessing CXX source to CMakeFiles/main.dir/src/main/cpp/main.cpp.i"
        /home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ --target=aarch64-none-linux-android21 --gcc-toolchain=/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64 --sysroot=/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot $(CXX_DEFINES) $(CXX_INCLUDES) $(CXX_FLAGS) -E /home/ztn/androidffmpeg5.0-demo/app/src/main/cpp/main.cpp > CMakeFiles/main.dir/src/main/cpp/main.cpp.i

CMakeFiles/main.dir/src/main/cpp/main.cpp.s: cmake_force
        @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --green "Compiling CXX source to assembly CMakeFiles/main.dir/src/main/cpp/main.cpp.s"
        /home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ --target=aarch64-none-linux-android21 --gcc-toolchain=/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64 --sysroot=/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot $(CXX_DEFINES) $(CXX_INCLUDES) $(CXX_FLAGS) -S /home/ztn/androidffmpeg5.0-demo/app/src/main/cpp/main.cpp -o CMakeFiles/main.dir/src/main/cpp/main.cpp.s

提取后并采用 -###参数查看clang具体命令

09:24:38 ztn@ztn-laptop2 app ±|master ✗|→ /home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ --target=aarch64-none-linux-android21 --gcc-toolchain=/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64 --sysroot=/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot $CXX_DEFINES $CXX_INCLUDES $CXX_FLAGS -MD -MT CMakeFiles/main.dir/src/main/cpp/main.cpp.o -MF CMakeFiles/main.dir/src/main/cpp/main.cpp.o.d -o CMakeFiles/main.dir/src/main/cpp/main.cpp.o -c /home/ztn/androidffmpeg5.0-demo/app/src/main/cpp/main.cpp -###
Android (7019983 based on r365631c3) clang version 9.0.9 (https://android.googlesource.com/toolchain/llvm-project a2a1e703c0edb03ba29944e529ccbf457742737b) (based on LLVM 9.0.9svn)
Target: aarch64-none-linux-android21
Thread model: posix
InstalledDir: /home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin
 "/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++" "-cc1" "-triple" "aarch64-none-linux-android21" "-emit-obj" "-mrelax-all" "-mnoexecstack" "-disable-free" "-disable-llvm-verifier" "-discard-value-names" "-main-file-name" "main.cpp" "-mrelocation-model" "pic" "-pic-level" "2" "-mthread-model" "posix" "-mdisable-fp-elim" "-masm-verbose" "-mconstructor-aliases" "-munwind-tables" "-fuse-init-array" "-target-cpu" "generic" "-target-feature" "+neon" "-target-abi" "aapcs" "-mllvm" "-aarch64-fix-cortex-a53-835769=1" "-fallow-half-arguments-and-returns" "-dwarf-column-info" "-debug-info-kind=limited" "-dwarf-version=4" "-debugger-tuning=gdb" "-ffunction-sections" "-fdata-sections" "-coverage-notes-file" "/home/ztn/androidffmpeg5.0-demo/app/CMakeFiles/main.dir/src/main/cpp/main.cpp.gcno" "-resource-dir" "/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/9.0.9" "-dependency-file" "CMakeFiles/main.dir/src/main/cpp/main.cpp.o.d" "-sys-header-deps" "-MT" "CMakeFiles/main.dir/src/main/cpp/main.cpp.o" "-D" "main_EXPORTS" "-I" "/home/ztn/androidffmpeg5.0-demo/app/soLib/arm64-v8a/include" "-D" "ANDROID" "-D" "_FORTIFY_SOURCE=2" "-isysroot" "/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot" "-internal-isystem" "/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/c++/v1" "-internal-isystem" "/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/local/include" "-internal-isystem" "/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/9.0.9/include" "-internal-externc-isystem" "/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/aarch64-linux-android" "-internal-externc-isystem" "/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot/include" "-internal-externc-isystem" "/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include" "-Wformat" "-Werror=format-security" "-fdeprecated-macro" "-fdebug-compilation-dir" "/home/ztn/androidffmpeg5.0-demo/app" "-ferror-limit" "19" "-fmessage-length" "0" "-stack-protector" "2" "-fno-signed-char" "-fobjc-runtime=gcc" "-fcxx-exceptions" "-fexceptions" "-fdiagnostics-show-option" "-fcolor-diagnostics" "-o" "CMakeFiles/main.dir/src/main/cpp/main.cpp.o" "-x" "c++" "/home/ztn/androidffmpeg5.0-demo/app/src/main/cpp/main.cpp"
09:24:49 ztn@ztn-laptop2 app ±|master ✗|→ "/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++" "-cc1" "-triple" "aarch64-none-linux-android21" "-emit-obj" "-mrelax-all" "-mnoexecstack" "-disable-free" "-disable-llvm-verifier" "-discard-value-names" "-main-file-name" "main.cpp" "-mrelocation-model" "pic" "-pic-level" "2" "-mthread-model" "posix" "-mdisable-fp-elim" "-masm-verbose" "-mconstructor-aliases" "-munwind-tables" "-fuse-init-array" "-target-cpu" "generic" "-target-feature" "+neon" "-target-abi" "aapcs" "-mllvm" "-aarch64-fix-cortex-a53-835769=1" "-fallow-half-arguments-and-returns" "-dwarf-column-info" "-debug-info-kind=limited" "-dwarf-version=4" "-debugger-tuning=gdb" "-ffunction-sections" "-fdata-sections" "-coverage-notes-file" "/home/ztn/androidffmpeg5.0-demo/app/CMakeFiles/main.dir/src/main/cpp/main.cpp.gcno" "-resource-dir" "/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/9.0.9" "-dependency-file" "CMakeFiles/main.dir/src/main/cpp/main.cpp.o.d" "-sys-header-deps" "-MT" "CMakeFiles/main.dir/src/main/cpp/main.cpp.o" "-D" "main_EXPORTS" "-I" "/home/ztn/androidffmpeg5.0-demo/app/soLib/arm64-v8a/include" "-D" "ANDROID" "-D" "_FORTIFY_SOURCE=2" "-isysroot" "/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot" "-internal-isystem" "/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/c++/v1" "-internal-isystem" "/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/local/include" "-internal-isystem" "/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/9.0.9/include" "-internal-externc-isystem" "/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/aarch64-linux-android" "-internal-externc-isystem" "/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot/include" "-internal-externc-isystem" "/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include" "-Wformat" "-Werror=format-security" "-fdeprecated-macro" "-fdebug-compilation-dir" "/home/ztn/androidffmpeg5.0-demo/app" "-ferror-limit" "19" "-fmessage-length" "0" "-stack-protector" "2" "-fno-signed-char" "-fobjc-runtime=gcc" "-fcxx-exceptions" "-fexceptions" "-fdiagnostics-show-option" "-fcolor-diagnostics" "-o" "CMakeFiles/main.dir/src/main/cpp/main.cpp.o" "-x" "c++" "/home/ztn/androidffmpeg5.0-demo/app/src/main/cpp/main.cpp"
09:24:56 ztn@ztn-laptop2 app ±|master ✗|→ clang++ "-cc1" "-triple" "aarch64-none-linux-android21" "-emit-obj" "-mrelax-all" "-mnoexecstack" "-disable-free" "-disable-llvm-verifier" "-discard-value-names" "-main-file-name" "main.cpp" "-mrelocation-model" "pic" "-pic-level" "2" "-mthread-model" "posix" "-mdisable-fp-elim" "-masm-verbose" "-mconstructor-aliases" "-munwind-tables" "-fuse-init-array" "-target-cpu" "generic" "-target-feature" "+neon" "-target-abi" "aapcs" "-mllvm" "-aarch64-fix-cortex-a53-835769=1" "-fallow-half-arguments-and-returns" "-dwarf-column-info" "-debug-info-kind=limited" "-dwarf-version=4" "-debugger-tuning=gdb" "-ffunction-sections" "-fdata-sections" "-coverage-notes-file" "/home/ztn/androidffmpeg5.0-demo/app/CMakeFiles/main.dir/src/main/cpp/main.cpp.gcno" "-resource-dir" "/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/9.0.9" "-dependency-file" "CMakeFiles/main.dir/src/main/cpp/main.cpp.o.d" "-sys-header-deps" "-MT" "CMakeFiles/main.dir/src/main/cpp/main.cpp.o" "-D" "main_EXPORTS" "-I" "/home/ztn/androidffmpeg5.0-demo/app/soLib/arm64-v8a/include" "-D" "ANDROID" "-D" "_FORTIFY_SOURCE=2" "-isysroot" "/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot" "-internal-isystem" "/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/c++/v1" "-internal-isystem" "/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/local/include" "-internal-isystem" "/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/lib64/clang/9.0.9/include" "-internal-externc-isystem" "/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include/aarch64-linux-android" "-internal-externc-isystem" "/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot/include" "-internal-externc-isystem" "/home/ztn/Android/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include" "-Wformat" "-Werror=format-security" "-fdeprecated-macro" "-fdebug-compilation-dir" "/home/ztn/androidffmpeg5.0-demo/app" "-ferror-limit" "19" "-fmessage-length" "0" "-stack-protector" "2" "-fno-signed-char" "-fobjc-runtime=gcc" "-fcxx-exceptions" "-fexceptions" "-fdiagnostics-show-option" "-fcolor-diagnostics" "-o" "CMakeFiles/main.dir/src/main/cpp/main.cpp.o" "-x" "c++" "/home/ztn/androidffmpeg5.0-demo/app/src/main/cpp/main.cpp"
error: unknown argument: '-mdisable-fp-elim'
error: unknown argument: '-masm-verbose'
error: unknown argument: '-munwind-tables'
error: unknown argument: '-fuse-init-array'
error: unknown argument: '-dwarf-column-info'
error: unknown argument: '-fmessage-length'
error: unknown argument: '-fdiagnostics-show-option'
09:25:11 ztn@ztn-laptop2 app ±|master ✗|→ 

可以看到,从官网下载的LLVM-CLANG工具链没有一些由NDK中clang工具链支持的编译器选项,故谷歌NDK是修改过的一条工具链,不过LLVM main stream 貌似直接支持 arm-cortex-m
这里是具体规格和信息
Supported Devices
LLVM Toolchain Technical-Specifications