From 393761d2e07461366ea456cea7f67fade95e3b4b Mon Sep 17 00:00:00 2001 From: Dan Albert Date: Wed, 18 Mar 2020 11:49:36 -0700 Subject: Switch to LLD as the default linker. Test: treehugger, some manual inspection of linker flags for sanity Bug: None Change-Id: Ib8b371cc932b46fddb623165c17d77757be9de2d --- docs/BuildSystemMaintainers.md | 56 ++++++++++++++++++++++++++-------------- docs/changelogs/Changelog-r22.md | 20 +++++++++----- 2 files changed, 50 insertions(+), 26 deletions(-) (limited to 'docs') diff --git a/docs/BuildSystemMaintainers.md b/docs/BuildSystemMaintainers.md index 922d84405..b2b057ce4 100644 --- a/docs/BuildSystemMaintainers.md +++ b/docs/BuildSystemMaintainers.md @@ -21,14 +21,16 @@ executables and scripts will differ. ## Introduction -The NDK uses [Clang] as its C/C++ compiler and [Binutils] for linking, -archiving, and object file manipulation. Binutils provides both BFD and gold for -linking. LLVM's [LLD] is also included for testing. AOSP uses LLD by default for -most projects and the NDK is expected to move to it in the future. +The NDK predominantly uses [LLVM] tools for building C/C++ code. These include +[Clang] for compilation, [LLD] for linking, and other [LLVM tools] as well as +some parts of [Binutils] for other tasks. Binutils will soon be entirely +replaced by its LLVM equivalents within the NDK, but it remains available during +the transition. [Binutils]: https://www.gnu.org/software/binutils [Clang]: https://clang.llvm.org/ [LLD]: https://lld.llvm.org/ +[LLVM tools]: https://llvm.org/docs/CommandGuide/ ### Architectures [Architectures]: #architectures @@ -198,23 +200,29 @@ Versions] sections. ## Linkers -Gold is used by default for most architectures, but BFD is used for AArch64 as -Gold emits broken debug information for that architecture (see [Issue 70838247] -for more details). +LLD is the default linker. + +Gold is the fallback linker for most architectures, but BFD is used for AArch64 +as Gold emits broken debug information for that architecture (see [Issue +70838247] for more details). + +The linker used by Clang can be selected with the `-fuse-ld=` argument, +passed during linking. For example, to use gold instead of LLD, pass +`-fuse-ld=gold` when linking. No argument is required to use LLD. + +The default linkers are installed to +`/toolchains/llvm/prebuilt//bin/-ld` and +`/toolchains/llvm/prebuilt///bin/ld`. BFD and gold are +installed as `ld.bfd` or `ld.gold` in the same locations. The triple-prefixed +executables in the common bin directory should be preferred to the +triple-specific bin directory because the triple-specific directory will be +removed when binutils is removed from the NDK. Note: It is usually not necessary to invoke the linkers directly since Clang will do so automatically. Clang will also automatically link CRT objects and default libraries and set up other target-specific options, so it is generally better to use Clang for linking. -The default linkers are installed to -`/toolchains/llvm/prebuilt//bin/-ld` and -`/toolchains/llvm/prebuilt///bin/ld`. To use BFD or gold -explicitly, use `ld.bfd` or `ld.gold` from the same locations. `ld.lld` is not -installed to the triple directory and is not triple-prefixed, but rather is only -installed as `/toolchains/llvm/prebuilt//bin/ld.lld` because the -one binary supports all ABIs. - Warning: Using LLD with GNU `strip` or `objcopy` breaks RelRO. LLVM `strip` and `objcopy` must be used with LLD. See [Issue 843] and the [Binutils] section of this document for more information. @@ -236,16 +244,24 @@ but are not limited to: * readelf * strip -For some of these tools, LLVM equivalents are available. They typically have the +For each of these tools, LLVM equivalents are available. They typically have the same name but are prefixed with `llvm-`. For example, `llvm-strip` is used instead of `-strip` or the `strip` binary from the triple-specific directory. +Note that binutils `as` is used by Clang if the `-fno-integrated-as` argument is +used. + Android is moving away from GNU Binutils in favor of LLVM tools. This is a work -in progress, but it is likely that a future release of the NDK will deprecate -and eventually remove GNU Binutils. For now, ensure that your build system works -with `llvm-strip` and `llvm-objcopy` as they are required when using LLD ([Issue -843]). +in progress, but it is likely that binutils will be deprecated in the next +release of the NDK and removed in the late 2020 LTS release. + +At present, the only binutils tool still used by the NDK's build systems is +`ar`. There may be some issues using `llvm-ar` as a drop in replacement for `ar` +on Darwin that are still being investigated. See [Issue 1209] for more +information. + +[Issue 1209]: https://github.com/android/ndk/issues/1209 ## Sysroot diff --git a/docs/changelogs/Changelog-r22.md b/docs/changelogs/Changelog-r22.md index 0b102a579..bdeb8f04f 100644 --- a/docs/changelogs/Changelog-r22.md +++ b/docs/changelogs/Changelog-r22.md @@ -9,16 +9,14 @@ For Android Studio issues, follow the docs on the [Android Studio site]. ## Announcements -* [LLD](https://lld.llvm.org/) is now available for testing. AOSP has switched - to using LLD by default and the NDK will follow (timeline unknown). Test LLD - in your app by passing `-fuse-ld=lld` when linking. Note that [Issue 843] - will affect builds using LLD with binutils strip and objcopy as opposed to - llvm-strip and llvm-objcopy. +* [LLD](https://lld.llvm.org/) is now the default linker. Gold and BFD will + likely be removed in the next LTS release (Q3-Q4 2020). See the Changes + section below for more information. * [Issue 843]: Build system maintainers should begin testing with LLVM's binutils. Android has switched to using these by default (with the exception of llvm-ar, as we're still investigating some issues on macOS), and GNU - binutils will be removed in a future release. + binutils will likely be removed in the next LTS release (Q3-Q4 2020). ## Changes @@ -38,6 +36,16 @@ For Android Studio issues, follow the docs on the [Android Studio site]. r19, file a bug with your build system maintainer. See the [Build System Maintainers Guide] for information on using the NDK in your own build system. +* LLD is now used by default. If your build is not yet compatible with LLD, you + can continue using the deprecated linkers, set `APP_LD=deprecated` for + ndk-build, `ANDROID_LD=deprecated` for CMake, or use an explicit + `-fuse-ld=gold` or `-fuse-ld=bfd` in your custom build system. If you + encounter issues be sure to file a bug, because this will not be an option in + a subsequent release. + + Note that [Issue 843] will affect builds using LLD with binutils strip and + objcopy as opposed to llvm-strip and llvm-objcopy. + [Build System Maintainers Guide]: https://android.googlesource.com/platform/ndk/+/master/docs/BuildSystemMaintainers.md ## Known Issues -- cgit v1.2.3