Skip to content

Commit 3311e1a

Browse files
simpletonfacebook-github-bot
authored andcommitted
Fix LD_LIBRARY_PATH when app running in 64bits
Summary: We don't correctly set LD_LIBRARY_PATH for 64bits builds. It will break some 64bits build like hwasan that depends on system libraries. Reviewed By: BurntBrunch Differential Revision: D20067065 fbshipit-source-id: f69d7b699c8c31e71bb273cd823a6ba291218eb0
1 parent 3a87694 commit 3311e1a

2 files changed

Lines changed: 33 additions & 2 deletions

File tree

‎java/com/facebook/soloader/SoLoader.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,8 @@ private static void initSoSources(Context context, int flags, @Nullable SoFileLo
226226

227227
String LD_LIBRARY_PATH = System.getenv("LD_LIBRARY_PATH");
228228
if (LD_LIBRARY_PATH == null) {
229-
LD_LIBRARY_PATH = "/vendor/lib:/system/lib";
229+
LD_LIBRARY_PATH =
230+
SysUtil.is64Bit() ? "/vendor/lib64:/system/lib64" : "/vendor/lib:/system/lib";
230231
}
231232

232233
String[] systemLibraryDirectories = LD_LIBRARY_PATH.split(":");

‎java/com/facebook/soloader/SysUtil.java‎

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package com.facebook.soloader;
1818

19+
import android.annotation.SuppressLint;
1920
import android.annotation.TargetApi;
2021
import android.content.Context;
2122
import android.content.pm.PackageInfo;
@@ -134,7 +135,7 @@ public static String[] getSupportedAbis() {
134135
//
135136
// Determine the current process bitness and use that to filter
136137
// out incompatible ABIs from SUPPORTED_ABIS.
137-
if (Os.readlink("/proc/self/exe").contains("64")) {
138+
if (is64Bit()) {
138139
allowedAbis.add(MinElf.ISA.AARCH64.toString());
139140
allowedAbis.add(MinElf.ISA.X86_64.toString());
140141
} else {
@@ -176,6 +177,20 @@ public static void fallocateIfSupported(FileDescriptor fd, long length) throws I
176177
}
177178
}
178179
}
180+
181+
@DoNotOptimize
182+
public static boolean is64Bit() throws ErrnoException {
183+
return Os.readlink("/proc/self/exe").contains("64");
184+
}
185+
}
186+
187+
@TargetApi(Build.VERSION_CODES.M)
188+
@DoNotOptimize
189+
private static final class MarshmallowSysdeps {
190+
@DoNotOptimize
191+
public static boolean is64Bit() {
192+
return android.os.Process.is64Bit();
193+
}
179194
}
180195

181196
/**
@@ -261,4 +276,19 @@ public static int getAppVersionCode(Context context) {
261276
}
262277
return 0;
263278
}
279+
280+
@SuppressLint("CatchGeneralException")
281+
public static boolean is64Bit() {
282+
boolean is64bit = false;
283+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
284+
is64bit = MarshmallowSysdeps.is64Bit();
285+
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
286+
try {
287+
is64bit = LollipopSysdeps.is64Bit();
288+
} catch (Exception e) {
289+
Log.e(TAG, String.format("Could not read /proc/self/exe. Err msg: %s", e.getMessage()));
290+
}
291+
}
292+
return is64bit;
293+
}
264294
}

0 commit comments

Comments
 (0)