Skip to content

Commit

Permalink
Send a path string of the directories where all transitive deps of un…
Browse files Browse the repository at this point in the history
…windstack_binary live

Summary: unwindstack_binary doesn't get to automatically benefit from our fancy search path logic. Instead, we need to build the search path ahead of time, while we have access to it, and then set it via LD_LIBRARY_PATH in the binary's environment.

Differential Revision: D18474651

fbshipit-source-id: 4f38f4bdadaf3d91ee2572fd8018df21e9250045
  • Loading branch information
tophyr authored and facebook-github-bot committed Nov 15, 2019
1 parent 944dc36 commit ea51029
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 3 deletions.
6 changes: 6 additions & 0 deletions java/com/facebook/soloader/ApplicationSoSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ public String getLibraryPath(String soName) throws IOException {
return soSource.getLibraryPath(soName);
}

@Nullable
@Override
public String[] getLibraryDependencies(String soName) throws IOException {
return soSource.getLibraryDependencies(soName);
}

@Nullable
@Override
public File unpackLibrary(String soName) throws IOException {
Expand Down
11 changes: 11 additions & 0 deletions java/com/facebook/soloader/DirectorySoSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,17 @@ public String getLibraryPath(String soName) throws IOException {
return null;
}

@Nullable
@Override
public String[] getLibraryDependencies(String soName) throws IOException {
File soFile = new File(soDirectory, soName);
if (soFile.exists()) {
return getDependencies(soFile);
} else {
return null;
}
}

private void loadDependencies(File soFile, int loadFlags, StrictMode.ThreadPolicy threadPolicy)
throws IOException {
String dependencies[] = getDependencies(soFile);
Expand Down
31 changes: 29 additions & 2 deletions java/com/facebook/soloader/SoLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -504,11 +504,12 @@ public static final class WrongAbiError extends UnsatisfiedLinkError {
*
* @param libName the library file name, including the prefix and extension.
* @return the full path of the library, or null if it is not found in none of the SoSources.
* @throws IOException
* @throws IOException if there is an error calculating the canonical path of libName
*/
public static @Nullable String getLibraryPath(String libName) throws IOException {
sSoSourcesLock.readLock().lock();
String libPath = null;

sSoSourcesLock.readLock().lock();
try {
if (sSoSources != null) {
for (int i = 0; libPath == null && i < sSoSources.length; ++i) {
Expand All @@ -519,9 +520,35 @@ public static final class WrongAbiError extends UnsatisfiedLinkError {
} finally {
sSoSourcesLock.readLock().unlock();
}

return libPath;
}

/**
* Gets the dependencies of a library.
*
* @param libName the library file name, including the prefix and extension.
* @return An array naming the dependencies of the library, or null if it is not found in any SoSources
* @throws IOException if there is an error reading libName
*/
public static @Nullable String[] getLibraryDependencies(String libName) throws IOException {
String[] deps = null;

sSoSourcesLock.readLock().lock();
try {
if (sSoSources != null) {
for (int i = 0; deps == null && i < sSoSources.length; ++i) {
SoSource currentSource = sSoSources[i];
deps = currentSource.getLibraryDependencies(libName);
}
}
} finally {
sSoSourcesLock.readLock().unlock();
}

return deps;
}

public static boolean loadLibrary(String shortName) {
return loadLibrary(shortName, 0);
}
Expand Down
14 changes: 13 additions & 1 deletion java/com/facebook/soloader/SoSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,25 @@ public abstract int loadLibrary(
*
* @param soFileName the full file name of the library
* @return the full path of a library if it is found on this SoSource, null otherwise.
* @throws IOException
* @throws IOException if there is an error calculating {@code soFileName}'s canonical path
*/
@Nullable
public String getLibraryPath(String soFileName) throws IOException {
return null;
}

/**
* Gets the dependencies of a library if it is found on this SoSource
*
* @param soName Name of library to inspect
* @return An array of library names upon which {@code soName} needs for linking
* @throws IOException if {@code soName} is found but there is an error reading it
*/
@Nullable
public String[] getLibraryDependencies(String soName) throws IOException {
return null;
}

/**
* Add an element to an LD_LIBRARY_PATH under construction.
*
Expand Down

0 comments on commit ea51029

Please sign in to comment.