From b96f74f18d132245d4a8029164b981c04d49ded2 Mon Sep 17 00:00:00 2001 From: Adam Michael Date: Wed, 10 Aug 2016 22:31:57 +0000 Subject: Sets SONAME on shared objects in Android binaries. Adds a linker flag to set the internal DT_SONAME. This fixes #1578 for SDK 24 and removes the warnings for previous SDKs. There is no need to set the linker flag for android_librarys that depend on native code, because the linker flag will be set by the android_binarys that depend on that android_library. Testing is done via `readelf` executable that is shipped with the NDK. -- Change-Id: I16fdfe6522c8694ce51554289122bf035a61d9ec Reviewed-on: https://bazel-review.googlesource.com/#/c/4302/ MOS_MIGRATED_REVID=129920256 --- .../devtools/build/lib/rules/android/AndroidCommon.java | 13 ++++++++----- .../google/devtools/build/lib/rules/android/NativeLibs.java | 9 +++++---- 2 files changed, 13 insertions(+), 9 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidCommon.java b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidCommon.java index 688c5c5dd6..1000216366 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidCommon.java +++ b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidCommon.java @@ -861,22 +861,25 @@ public class AndroidCommon { } public CcLinkParamsStore getCcLinkParamsStore() { - return getCcLinkParamsStore(javaCommon.targetsTreatedAsDeps(ClasspathType.BOTH)); + return getCcLinkParamsStore( + javaCommon.targetsTreatedAsDeps(ClasspathType.BOTH), ImmutableList.of()); } public static CcLinkParamsStore getCcLinkParamsStore( - final Iterable deps) { + final Iterable deps, final Collection linkOpts) { return new CcLinkParamsStore() { @Override - protected void collect(CcLinkParams.Builder builder, boolean linkingStatically, - boolean linkShared) { - builder.addTransitiveTargets(deps, + protected void collect( + CcLinkParams.Builder builder, boolean linkingStatically, boolean linkShared) { + builder.addTransitiveTargets( + deps, // Link in Java-specific C++ code in the transitive closure JavaCcLinkParamsProvider.TO_LINK_PARAMS, // Link in Android-specific C++ code (e.g., android_libraries) in the transitive closure AndroidCcLinkParamsProvider.TO_LINK_PARAMS, // Link in non-language-specific C++ code in the transitive closure CcLinkParamsProvider.TO_LINK_PARAMS); + builder.addLinkOpts(linkOpts); } }; } diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/NativeLibs.java b/src/main/java/com/google/devtools/build/lib/rules/android/NativeLibs.java index 46446d2f31..421e8f2f53 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/android/NativeLibs.java +++ b/src/main/java/com/google/devtools/build/lib/rules/android/NativeLibs.java @@ -34,14 +34,12 @@ import com.google.devtools.build.lib.rules.cpp.CppFileTypes; import com.google.devtools.build.lib.rules.cpp.LinkerInput; import com.google.devtools.build.lib.rules.nativedeps.NativeDepsHelper; import com.google.devtools.build.lib.vfs.PathFragment; - import java.util.Collection; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedHashMap; import java.util.Map; import java.util.Set; - import javax.annotation.Nullable; /** Represents the collection of native libraries (.so) to be installed in the APK. */ @@ -71,8 +69,11 @@ public final class NativeLibs { Map> result = new LinkedHashMap<>(); for (Map.Entry> entry : depsByArchitecture.asMap().entrySet()) { - CcLinkParams linkParams = AndroidCommon.getCcLinkParamsStore(entry.getValue()) - .get(/* linkingStatically */ true, /* linkShared */ true); + CcLinkParams linkParams = + AndroidCommon.getCcLinkParamsStore( + entry.getValue(), + ImmutableList.of("-Wl,-soname=lib" + ruleContext.getLabel().getName())) + .get(/* linkingStatically */ true, /* linkShared */ true); Artifact nativeDepsLibrary = NativeDepsHelper.maybeCreateAndroidNativeDepsAction( ruleContext, linkParams, configurationMap.get(entry.getKey()), -- cgit v1.2.3