Android NDK 工具链中的 LLVM 有什么用? [英] What's the use of LLVM in Android NDK Toolchains?

查看:23
本文介绍了Android NDK 工具链中的 LLVM 有什么用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

LLVM 在 Android NDK 工具链中有什么用?

<小时>

简单回顾:

我在 Ubuntu 上使用 Gradlew 构建我的本地项目,目标是 arm 和 x86_64 架构.似乎是利用 LLVM 来调用 arm-linux-androideabi-4.9 以及 x86_64(?)

以下内容摘自 armeabi-v7a/ndkBuild_build_output.log:

<块引用>

/home/mypc/Android/android-ndk-r17c/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++-MMD -MP -MF/home/mypc/git/android-project-1/build/intermediates/ndkBuild/debug/obj/local/armeabi-v7a/objs-debug/module-5/stream_cpp.o.d-gcc-toolchain/home/mypc/Android/android-ndk-r17c/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64-fpic -ffunction-sections -funwind-tables -fstack-protector-strong -Wno-invalid-command-line-argument ...

..以下内容摘自 x86_64/ndkBuild_build_output.log:

<块引用>

/home/mypc/Android/android-ndk-r17c/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++-MMD -MP -MF/home/mypc/git/android-project-1/build/intermediates/ndkBuild/debug/obj/local/x86_64/objs-debug/module-5/stream_cpp.o.d-gcc-toolchain/home/mypc/Android/android-ndk-r17c/toolchains/x86_64-4.9/prebuilt/linux-x86_64-target x86_64-none-linux-android -ffunction-sections -funwind-tables -fstack-protector-strong -fPIC -Wno-invalid-command-line-argument ...

  • ..."表示我已经剪掉了这条单行命令的长尾.
  • 个人文件夹的名称和项目已更改.

让我们看看 Android NDK 的 toolchains 文件夹里面有什么:

myacc:~/.../android-ndk-r17c/toolchains$ tree -L 1.├── aarch64-linux-android-4.9├── arm-linux-androideabi-4.9├── llvm├── mips64el-linux-android-4.9├── mipsel-linux-android-4.9├── 通知-MIPS├── 通知-MIPS64├── 渲染脚本├── x86-4.9└── x86_64-4.9

<小时>

这让我很困惑.我认为 llvm 是一种工具链,因为它被放置在这里,与其他工具链相邻.同样,LLVM 在 Android NDK 工具链中的实际用途是什么?

感谢您的帮助:)

解决方案

LLVM 是编译器(后端).使用的编译器是 Clang,它位于 llvm 目录中.(LLVM 是 Clang 中进行实际代码生成的组件的名称,也就是后端.)

以前,NDK 使用 GCC 作为编译器.使用 GCC,每个目标架构(arm、aarch64、x86 等)都有一个单独的 GCC 副本,该副本是使用配置的单个目标构建的.另一方面,Clang/LLVM 可以使用单个编译器可执行文件针对任何已配置的架构.因此,使用 Clang,您将节省一些磁盘空间,避免使用许多单独的编译器可执行文件.这就是为什么 llvm 目录树只有一个副本的原因.

在 NDK r17 中,您可以使用 GCC 和 Clang 编译器;默认情况下使用 Clang,但 GCC 仍可用于尚未能够迁移到使用 Clang 的项目.在较新的 NDK 版本中,旧的 GCC 已被删除.

在较新的 NDK 版本中,即使删除了 GCC,像 aarch64-linux-android-4.9 这样的架构特定目录仍然保留,因为 GNU binutils(构建使用的次要工具)进程)仍在使用,并且每个架构也有一份副本(即使它们在技术上可能跨架构工作).

至于为什么要为例如arm 还提到了 x86_64;当您运行 Clang 或 GCC 时,您正在为运行 x86_64 的构建计算机运行可执行文件,因此路径的 prebuilt/linux-x86_64 部分.

What's the use of LLVM in Android NDK Toolchains?


A little recap:

I was building my native project with Gradlew on Ubuntu, targeting arm and x86_64 architectures. Seems that LLVM were utilized to call C/C++ compiler of arm-linux-androideabi-4.9 as well as x86_64(?)

The following is extracted from armeabi-v7a/ndkBuild_build_output.log:

/home/mypc/Android/android-ndk-r17c/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ -MMD -MP -MF /home/mypc/git/android-project-1/build/intermediates/ndkBuild/debug/obj/local/armeabi-v7a/objs-debug/module-5/stream_cpp.o.d -gcc-toolchain /home/mypc/Android/android-ndk-r17c/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64 -fpic -ffunction-sections -funwind-tables -fstack-protector-strong -Wno-invalid-command-line-argument ...

..and the following is extracted from x86_64/ndkBuild_build_output.log:

/home/mypc/Android/android-ndk-r17c/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ -MMD -MP -MF /home/mypc/git/android-project-1/build/intermediates/ndkBuild/debug/obj/local/x86_64/objs-debug/module-5/stream_cpp.o.d -gcc-toolchain /home/mypc/Android/android-ndk-r17c/toolchains/x86_64-4.9/prebuilt/linux-x86_64 -target x86_64-none-linux-android -ffunction-sections -funwind-tables -fstack-protector-strong -fPIC -Wno-invalid-command-line-argument ...

  • The "..." indicates that there's a long tail of this single-line command I've trimmed off.
  • Names of personal folders & project were changed.

Let's take a look what's inside Android NDK's toolchains folder:

myacc:~/.../android-ndk-r17c/toolchains$ tree -L 1
.
├── aarch64-linux-android-4.9
├── arm-linux-androideabi-4.9
├── llvm
├── mips64el-linux-android-4.9
├── mipsel-linux-android-4.9
├── NOTICE-MIPS
├── NOTICE-MIPS64
├── renderscript
├── x86-4.9
└── x86_64-4.9


It's quite confusing to me. I thought llvm is a kind of toolchain since it's placed here, next to other toolchains. Again, what's actually the use of LLVM in Android NDK Toolchains?

Thanks for the help :)

解决方案

LLVM is the compiler (backend). The compiler used is Clang, which resides within the llvm directory. (LLVM is the name of the component of Clang that does the actual code generation, aka backend.)

Previously, the NDK used GCC as compiler. With GCC, each target architecture (arm, aarch64, x86 etc) had a separate copy of GCC built with that individual target configured. Clang/LLVM on the other hand can target any configured architecture with one single compiler executable. So with Clang, you'll save a bit of diskspace, avoiding to have many separate compiler executables. That's why there's only one copy of the llvm directory tree.

In NDK r17, you have both GCC and Clang compilers available; Clang is used by default but GCC is still available for projects that haven't been able to migrate to using Clang yet. In newer NDK versions, the old GCC is removed.

In the newer NDK versions, even if GCC is removed, the architecture specific directories like aarch64-linux-android-4.9 are still kept around, as the GNU binutils (minor tools used by the build process) are still used, and those also come in one copy per architecture (even though they technically might work across architectures).

And as for why building for e.g. arm also mentions x86_64; when you are running Clang or GCC, you are running an executable for your build computer which runs x86_64, hence the prebuilt/linux-x86_64 part of the paths.

这篇关于Android NDK 工具链中的 LLVM 有什么用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆