diff --git a/android_webview/BUILD.gn b/android_webview/BUILD.gn index 636bedaca4c36..2d3b3cf036233 100644 --- a/android_webview/BUILD.gn +++ b/android_webview/BUILD.gn @@ -312,8 +312,7 @@ shared_library("libwebviewchromium") { deps = [ ":webview_entry_point", ] - configs -= [ "//build/config/android:hide_all_but_jni_onload" ] - configs += [ "//build/config/android:hide_all_but_jni" ] + configs -= [ "//build/config/android:hide_native_jni_exports" ] } if (android_64bit_target_cpu) { @@ -335,8 +334,7 @@ if (android_64bit_target_cpu) { deps = [ ":webview_entry_point", ] - configs -= [ "//build/config/android:hide_all_but_jni_onload" ] - configs += [ "//build/config/android:hide_all_but_jni" ] + configs -= [ "//build/config/android:hide_native_jni_exports" ] } } diff --git a/android_webview/test/BUILD.gn b/android_webview/test/BUILD.gn index f1cdeb4d7d91d..e341ddf02d1c0 100644 --- a/android_webview/test/BUILD.gn +++ b/android_webview/test/BUILD.gn @@ -93,8 +93,7 @@ shared_library("libstandalonelibwebviewchromium") { deps = [ "//android_webview:common", ] - configs -= [ "//build/config/android:hide_all_but_jni_onload" ] - configs += [ "//build/config/android:hide_all_but_jni" ] + configs -= [ "//build/config/android:hide_native_jni_exports" ] } instrumentation_test_apk("android_webview_test_apk") { @@ -292,5 +291,5 @@ shared_library("libdrawgl") { sources = [ "shell/src/draw_gl/draw_gl.cc", ] - configs -= [ "//build/config/android:hide_all_but_jni_onload" ] + configs -= [ "//build/config/android:hide_native_jni_exports" ] } diff --git a/build/android/android_no_jni_exports.lst b/build/android/android_no_jni_exports.lst new file mode 100644 index 0000000000000..ffc6cf7028cb9 --- /dev/null +++ b/build/android/android_no_jni_exports.lst @@ -0,0 +1,17 @@ +# Copyright 2014 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +# This script makes all JNI exported symbols local, to prevent the JVM from +# being able to find them, enforcing use of manual JNI function registration. +# This is used for all Android binaries by default, unless they explicitly state +# that they want JNI exported symbols to remain visible, as we need to ensure +# the manual registration path is correct to maintain compatibility with the +# crazy linker. +# Check ld version script manual: +# https://sourceware.org/binutils/docs-2.24/ld/VERSION.html#VERSION + +{ + local: + Java_*; +}; diff --git a/build/android/android_only_explicit_jni_exports.lst b/build/android/android_only_explicit_jni_exports.lst deleted file mode 100644 index f989691865b26..0000000000000 --- a/build/android/android_only_explicit_jni_exports.lst +++ /dev/null @@ -1,13 +0,0 @@ -# Copyright 2017 The Chromium Authors. All rights reserved. -# Use of this source code is governed by a BSD-style license that can be -# found in the LICENSE file. - -# Linker script that exports only JNI_OnLoad. -# Should be used for libraries that do explicit JNI registration. - -{ - global: - JNI_OnLoad; - local: - *; -}; diff --git a/build/android/android_only_jni_exports.lst b/build/android/android_only_jni_exports.lst deleted file mode 100644 index 1336fee145619..0000000000000 --- a/build/android/android_only_jni_exports.lst +++ /dev/null @@ -1,13 +0,0 @@ -# Copyright 2017 The Chromium Authors. All rights reserved. -# Use of this source code is governed by a BSD-style license that can be -# found in the LICENSE file. - -# Linker script that exports only symbols required for JNI to work. - -{ - global: - JNI_OnLoad; - Java_*; - local: - *; -}; diff --git a/build/config/BUILDCONFIG.gn b/build/config/BUILDCONFIG.gn index 3117013820436..edefb2c6ced88 100644 --- a/build/config/BUILDCONFIG.gn +++ b/build/config/BUILDCONFIG.gn @@ -568,8 +568,10 @@ default_shared_library_configs = default_compiler_configs + [ if (is_android) { # Strip native JNI exports from shared libraries by default. Binaries that # want this can remove this config. - default_shared_library_configs += - [ "//build/config/android:hide_all_but_jni_onload" ] + default_shared_library_configs += [ + "//build/config/android:hide_native_jni_exports", + "//build/config/android:hide_all_but_jni_onload", + ] } set_defaults("shared_library") { configs = default_shared_library_configs @@ -647,7 +649,10 @@ set_defaults("component") { if (is_component_build) { configs = default_shared_library_configs if (is_android) { - configs -= [ "//build/config/android:hide_all_but_jni_onload" ] + configs -= [ + "//build/config/android:hide_native_jni_exports", + "//build/config/android:hide_all_but_jni_onload", + ] } } else { configs = default_compiler_configs diff --git a/build/config/android/BUILD.gn b/build/config/android/BUILD.gn index 2d789333645ce..73c49f41f783e 100644 --- a/build/config/android/BUILD.gn +++ b/build/config/android/BUILD.gn @@ -195,14 +195,17 @@ config("executable_config") { ldflags = [ "-pie" ] } +config("hide_native_jni_exports") { + ldflags = [ "-Wl,--version-script=" + + rebase_path("//build/android/android_no_jni_exports.lst") ] +} + config("hide_all_but_jni_onload") { - ldflags = [ "-Wl,--version-script=" + rebase_path( - "//build/android/android_only_explicit_jni_exports.lst") ] + # TODO(agrieve): https://codereview.chromium.org/2633593004/ } config("hide_all_but_jni") { - ldflags = [ "-Wl,--version-script=" + - rebase_path("//build/android/android_only_jni_exports.lst") ] + # TODO(agrieve): https://codereview.chromium.org/2633593004/ } # Instrumentation ------------------------------------------------------------- diff --git a/chrome/android/BUILD.gn b/chrome/android/BUILD.gn index 6d845da36d65b..a2537ba191808 100644 --- a/chrome/android/BUILD.gn +++ b/chrome/android/BUILD.gn @@ -648,8 +648,7 @@ if (!android_64bit_target_cpu || "//chrome:chrome_android_core", ] - configs -= [ "//build/config/android:hide_all_but_jni_onload" ] - configs += [ "//build/config/android:hide_all_but_jni" ] + configs -= [ "//build/config/android:hide_native_jni_exports" ] if (is_android && use_order_profiling) { deps += [ "//tools/cygprofile" ] } diff --git a/components/cronet/android/BUILD.gn b/components/cronet/android/BUILD.gn index 2d327ef126675..b399a563ed7f6 100644 --- a/components/cronet/android/BUILD.gn +++ b/components/cronet/android/BUILD.gn @@ -264,6 +264,13 @@ shared_library("cronet") { "//base", "//net:net", ] + ldflags = [ "-Wl,--version-script=" + + rebase_path("//components/cronet/android/only_jni_exports.lst") ] + + # Avoid hide_native_jni_exports as it adds another version script, and the + # ARM64 linker throws an error for multiple version scripts with anonymous + # version tags. + configs -= [ "//build/config/android:hide_native_jni_exports" ] } cronet_api_srcjar_deps = [ ":cronet_api_version_srcjar" ] @@ -545,6 +552,14 @@ shared_library("cronet_tests") { include_dirs = [ _cronet_version_header_include_dir ] + ldflags = [ "-Wl,--version-script=" + + rebase_path("//components/cronet/android/only_jni_exports.lst") ] + + # Avoid hide_native_jni_exports as it adds another version script, and the + # ARM64 linker throws an error for multiple version scripts with anonymous + # version tags. + configs -= [ "//build/config/android:hide_native_jni_exports" ] + if (cronet_enable_data_reduction_proxy_support) { deps += [ "//components/data_reduction_proxy/core/browser:browser_small" ] } diff --git a/components/cronet/android/only_jni_exports.lst b/components/cronet/android/only_jni_exports.lst new file mode 100644 index 0000000000000..322201c3eac99 --- /dev/null +++ b/components/cronet/android/only_jni_exports.lst @@ -0,0 +1,10 @@ +# Copyright 2016 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +{ + /* Make sure we don't export anything unneeded as it could cause conflicts + with symbols from embedders. */ + global: JNI_OnLoad; + local: *; +}; diff --git a/gpu/BUILD.gn b/gpu/BUILD.gn index b8b82804cf83e..db9c0ec462ad3 100644 --- a/gpu/BUILD.gn +++ b/gpu/BUILD.gn @@ -55,9 +55,6 @@ shared_library("command_buffer_gles2") { "COMMAND_BUFFER_GLES_LIB_SUPPORT_ONLY", "EGLAPIENTRY=", ] - if (is_android) { - configs -= [ "//build/config/android:hide_all_but_jni_onload" ] - } if (current_os == "win") { defines += [ "EGLAPI=__declspec(dllexport)" ] } else { diff --git a/testing/test.gni b/testing/test.gni index b344945ce9268..9aa7cc47de7e5 100644 --- a/testing/test.gni +++ b/testing/test.gni @@ -59,7 +59,7 @@ template("test") { # the default shared_library configs rather than executable configs. configs -= [ "//build/config:shared_library_config", - "//build/config/android:hide_all_but_jni_onload", + "//build/config/android:hide_native_jni_exports", ] configs += [ "//build/config:executable_config" ] diff --git a/third_party/netty-tcnative/BUILD.gn b/third_party/netty-tcnative/BUILD.gn index 9fecf9c1f0d95..6cf32a4f8e5c2 100644 --- a/third_party/netty-tcnative/BUILD.gn +++ b/third_party/netty-tcnative/BUILD.gn @@ -46,7 +46,7 @@ shared_library("netty-tcnative-so") { include_dirs = [ "../apache-portable-runtime/src/include" ] defines = [ "HAVE_OPENSSL" ] cflags = [ "-w" ] - configs -= [ "//build/config/android:hide_all_but_jni_onload" ] + configs -= [ "//build/config/android:hide_native_jni_exports" ] deps = [ "../apache-portable-runtime:apr", "../boringssl:boringssl", diff --git a/tools/android/memconsumer/BUILD.gn b/tools/android/memconsumer/BUILD.gn index da69770b03c13..70a4447d21762 100644 --- a/tools/android/memconsumer/BUILD.gn +++ b/tools/android/memconsumer/BUILD.gn @@ -30,7 +30,7 @@ shared_library("libmemconsumer") { "memconsumer_hook.cc", ] libs = [ "log" ] - configs -= [ "//build/config/android:hide_all_but_jni_onload" ] + configs -= [ "//build/config/android:hide_native_jni_exports" ] configs -= [ "//build/config/compiler:chromium_code" ] configs += [ "//build/config/compiler:no_chromium_code" ]