aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java
diff options
context:
space:
mode:
authorGravatar Adam Michael <ajmichael@google.com>2016-08-10 22:31:57 +0000
committerGravatar Yue Gan <yueg@google.com>2016-08-11 09:17:58 +0000
commitb96f74f18d132245d4a8029164b981c04d49ded2 (patch)
tree5d2eadb58257d0b4ad57fe1817eb4f442f2412b6 /src/main/java
parentfb1d53df557ee10f13ed4299f0688ea81cfe4fb6 (diff)
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
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/android/AndroidCommon.java13
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/android/NativeLibs.java9
2 files changed, 13 insertions, 9 deletions
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.<String>of());
}
public static CcLinkParamsStore getCcLinkParamsStore(
- final Iterable<? extends TransitiveInfoCollection> deps) {
+ final Iterable<? extends TransitiveInfoCollection> deps, final Collection<String> 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<String, Iterable<Artifact>> result = new LinkedHashMap<>();
for (Map.Entry<String, Collection<TransitiveInfoCollection>> 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()),