Skip to content

Commit

Permalink
Only use explicit --build-id=tree for lld.
Browse files Browse the repository at this point in the history
Using sha1 instead of tree turned out to have a larger build impact
than the benchmarking suggested (10% regression in dolphin build
time).

For ndk-build, scan all the linker flags for -fuse-ld and check
APP_LD to determine if lld is being used, and if it is then fallback
to tree. Otherwise, use the linker default.

For CMake we don't know the user's chosen ldflags, so the best we can
do is work off of ANDROID_LD. If the user doesn't use ANDROID_LD and
instead uses -fuse-ld=lld explicitly, they won't be able to debug.

Test: inspected verbose build output for the following configurations:
    * No flags
    * APP_LD=lld
    * APP_LD=gold
    * APP_LD=lld APP_LDFLAGS=-fuse-ld=gold
    * APP_LD=gold APP_LDFLAGS=-fuse-ld=lld
    * For the first three variants, checked CMake with ANDROID_LD.
Bug: http://b/143411084
Bug: android/ndk#885

Change-Id: I62a7b6a296a61bc543c38d406bfb9f15ddb1c7fa
(cherry picked from commit 8ebd5e0)
  • Loading branch information
DanAlbert authored and android-build-prod (mdb) committed Nov 9, 2019
1 parent e12bb32 commit 52a5637
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 6 deletions.
19 changes: 16 additions & 3 deletions build/cmake/android.toolchain.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -452,9 +452,22 @@ list(APPEND ANDROID_COMPILER_FLAGS
-funwind-tables
-fstack-protector-strong
-no-canonical-prefixes)
list(APPEND ANDROID_LINKER_FLAGS
-Wl,--build-id=sha1
-Wl,--fatal-warnings)

# https://github.com/android/ndk/issues/885
# If we're using LLD we need to use a slower build-id algorithm to work around
# the old version of LLDB in Android Studio, which doesn't understand LLD's
# default hash ("fast").
#
# Note that because we cannot see the user's flags, we can't detect this very
# accurately. Users that explicitly use -fuse-ld=lld instead of ANDROID_LD will
# not be able to debug.
if(ANDROID_LD STREQUAL lld)
list(APPEND ANDROID_LINKER_FLAGS -Wl,--build-id=sha1)
else()
list(APPEND ANDROID_LINKER_FLAGS -Wl,--build-id)
endif()

list(APPEND ANDROID_LINKER_FLAGS -Wl,--fatal-warnings)
list(APPEND ANDROID_LINKER_FLAGS_EXE -Wl,--gc-sections)

# Debug and release flags.
Expand Down
27 changes: 25 additions & 2 deletions build/core/build-binary.mk
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,6 @@ ifeq ($(LOCAL_CPP_EXTENSION),)
endif
LOCAL_RS_EXTENSION := $(default-rs-extensions)

LOCAL_LDFLAGS += -Wl,--build-id=sha1

ifneq ($(NDK_APP_STL),system)
LOCAL_CFLAGS += -nostdinc++
LOCAL_LDFLAGS += -nostdlib++
Expand Down Expand Up @@ -498,8 +496,33 @@ CLEAN_OBJS_DIRS += $(LOCAL_OBJS_DIR)
#

linker_ldflags :=
using_lld := false
ifeq ($(APP_LD),lld)
linker_ldflags := -fuse-ld=lld
using_lld := true
endif

combined_ldflags := $(TARGET_LDFLAGS) $(NDK_APP_LDFLAGS) $(LOCAL_LDFLAGS)
ndk_fuse_ld_flags := $(filter -fuse-ld=%,$(combined_ldflags))
ndk_used_linker := $(lastword $(ndk_fuse_ld_flags))
ifeq ($(ndk_used_linker),-fuse-ld=lld)
using_lld := true
else
# In case the user has set APP_LD=lld but also disabled it for a specific
# module.
ifneq ($(ndk_used_linker),)
using_lld := false
endif
endif

# https://github.com/android/ndk/issues/885
# If we're using LLD we need to use a slower build-id algorithm to work around
# the old version of LLDB in Android Studio, which doesn't understand LLD's
# default hash ("fast").
ifeq ($(using_lld),true)
linker_ldflags += -Wl,--build-id=tree
else
linker_ldflags += -Wl,--build-id
endif

my_ldflags := $(TARGET_LDFLAGS) $(linker_ldflags) $(NDK_APP_LDFLAGS) $(LOCAL_LDFLAGS)
Expand Down
5 changes: 4 additions & 1 deletion docs/changelogs/Changelog-r21.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ For Android Studio issues, follow the docs on the [Android Studio site].
* Updated glibc to 2.17.
* Updated gdb to 8.3.
* [Issue 885]: For LLD+LLDB compatibility, the NDK build systems now pass
`-Wl,--build-id=sha1` instead of `-Wl,--build-id`. Third-party build systems
`-Wl,--build-id=tree` instead of `-Wl,--build-id` when using LLD. Note that
the CMake toolchain does not have access to flags set in CMakeLists.txt, so
using an explicit `-fuse-ld=lld` instead of `ANDROID_LD=lld` will produce
output that cannot be debugged with Android Studio. Third-party build systems
need to apply the workaround manually. For more details, see the [Build
System Maintainers Guide][maintainer_linkers].
* Fixed ndk-build to use Clang's default C++ standard version (currently C++14)
Expand Down

0 comments on commit 52a5637

Please sign in to comment.