aboutsummaryrefslogtreecommitdiff
path: root/build
diff options
context:
space:
mode:
authorDan Albert <danalbert@google.com>2019-11-08 00:07:19 -0800
committerDan Albert <danalbert@google.com>2019-11-08 01:37:29 -0800
commit8ebd5e0a4462e7ac698b17dc10daf5b849147de7 (patch)
tree5ab279297365d5536435cceb4249dc3d4b59492a /build
parente2d6c749486e1a7901255940b0848c0776c45252 (diff)
downloadndk-8ebd5e0a4462e7ac698b17dc10daf5b849147de7.tar.gz
Only use explicit --build-id=tree for lld.
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: https://github.com/android/ndk/issues/885 Change-Id: I62a7b6a296a61bc543c38d406bfb9f15ddb1c7fa
Diffstat (limited to 'build')
-rw-r--r--build/cmake/android.toolchain.cmake19
-rw-r--r--build/core/build-binary.mk27
2 files changed, 41 insertions, 5 deletions
diff --git a/build/cmake/android.toolchain.cmake b/build/cmake/android.toolchain.cmake
index d9e5fb7e7..cf5312f0e 100644
--- a/build/cmake/android.toolchain.cmake
+++ b/build/cmake/android.toolchain.cmake
@@ -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.
diff --git a/build/core/build-binary.mk b/build/core/build-binary.mk
index 2e1c0648c..21c79cdc5 100644
--- a/build/core/build-binary.mk
+++ b/build/core/build-binary.mk
@@ -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++
@@ -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)