From 3c735669af619a54dabf7edbb3815a6118533c18 Mon Sep 17 00:00:00 2001 From: Adrian Catana Date: Wed, 7 Aug 2024 07:08:22 -0700 Subject: [PATCH] Explicit dep resolution for DirectorySoSources when BackupSoSource is enabled Reviewed By: michalgr Differential Revision: D60834153 fbshipit-source-id: 6e66db5da2c73e2d1241aedbde6dc056e5641fb8 --- .../facebook/soloader/DirectorySoSource.java | 6 +++++- .../recovery/ReunpackBackupSoSources.java | 21 ++++++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/java/com/facebook/soloader/DirectorySoSource.java b/java/com/facebook/soloader/DirectorySoSource.java index a44193e..0c5645c 100644 --- a/java/com/facebook/soloader/DirectorySoSource.java +++ b/java/com/facebook/soloader/DirectorySoSource.java @@ -31,7 +31,7 @@ public class DirectorySoSource extends SoSource { public static final int ON_LD_LIBRARY_PATH = 2; protected final File soDirectory; - protected final int flags; + protected int flags; protected final List denyList; /** @@ -47,6 +47,10 @@ public DirectorySoSource(File soDirectory, int flags) { this(soDirectory, flags, new String[0]); } + public void setExplicitDependencyResolution() { + flags |= RESOLVE_DEPENDENCIES; + } + /** * This method is similar to {@link #DirectorySoSource(File, int)}, with the following * differences: diff --git a/java/com/facebook/soloader/recovery/ReunpackBackupSoSources.java b/java/com/facebook/soloader/recovery/ReunpackBackupSoSources.java index 11cee7f..c11dc70 100644 --- a/java/com/facebook/soloader/recovery/ReunpackBackupSoSources.java +++ b/java/com/facebook/soloader/recovery/ReunpackBackupSoSources.java @@ -17,6 +17,7 @@ package com.facebook.soloader.recovery; import com.facebook.soloader.BackupSoSource; +import com.facebook.soloader.DirectorySoSource; import com.facebook.soloader.LogUtil; import com.facebook.soloader.SoLoader; import com.facebook.soloader.SoLoaderDSONotFoundError; @@ -100,6 +101,7 @@ private boolean recoverDSONotFoundError(SoSource[] soSources, String soName, int } private boolean lazyPrepareBackupSoSource(SoSource[] soSources, String soName) { + boolean recovered = false; for (SoSource soSource : soSources) { if (!(soSource instanceof BackupSoSource)) { // NonApk SoSources get reunpacked in ReunpackNonBackupSoSource recovery strategy @@ -111,7 +113,8 @@ private boolean lazyPrepareBackupSoSource(SoSource[] soSources, String soName) { SoLoader.TAG, "Preparing BackupSoSource for the first time " + backupSoSource.getName()); backupSoSource.prepare(0); - return true; + recovered = true; + break; } catch (Exception e) { // Catch a general error and log it, rather than failing during recovery and crashing the // app @@ -128,6 +131,22 @@ private boolean lazyPrepareBackupSoSource(SoSource[] soSources, String soName) { } } + if (recovered) { + for (SoSource soSource : soSources) { + if (!(soSource instanceof DirectorySoSource)) { + continue; + } + if (soSource instanceof BackupSoSource) { + continue; + } + DirectorySoSource directorySoSource = (DirectorySoSource) soSource; + // We need to explicitly resolve dependencies, as dlopen() cannot do + // so for dependencies at non-standard locations. + directorySoSource.setExplicitDependencyResolution(); + } + return true; + } + return false; }