From 626be07153ec1f35fc66ebed4fddf4fc5039585c Mon Sep 17 00:00:00 2001 From: Jooyung Han Date: Tue, 12 Jul 2022 14:29:16 +0900 Subject: [PATCH] Update linker configuration when loading apex On ctl.apex_load control message, init invokes linkerconfig to update linker configuration for the updated apex. Bug: 232173613 Test: CtsInitTestCases Test: VendorApexHostTestCases Change-Id: I01d975849c3f4efe74205a7b04ebbd6864ba1121 --- init/init.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/init/init.cpp b/init/init.cpp index e40627f1c..535033d99 100644 --- a/init/init.cpp +++ b/init/init.cpp @@ -54,6 +54,7 @@ #include #include #include +#include #include #include #include @@ -450,9 +451,33 @@ static Result DoUnloadApex(const std::string& apex_name) { return {}; } +static Result UpdateApexLinkerConfig(const std::string& apex_name) { + // Do not invoke linkerconfig when there's no bin/ in the apex. + const std::string bin_path = "/apex/" + apex_name + "/bin"; + if (access(bin_path.c_str(), R_OK) != 0) { + return {}; + } + const char* linkerconfig_binary = "/apex/com.android.runtime/bin/linkerconfig"; + const char* linkerconfig_target = "/linkerconfig"; + const char* arguments[] = {linkerconfig_binary, "--target", linkerconfig_target, "--apex", + apex_name.c_str(), "--strict"}; + + if (logwrap_fork_execvp(arraysize(arguments), arguments, nullptr, false, LOG_KLOG, false, + nullptr) != 0) { + return ErrnoError() << "failed to execute linkerconfig"; + } + LOG(INFO) << "Generated linker configuration for " << apex_name; + return {}; +} + static Result DoLoadApex(const std::string& apex_name) { std::string prop_name = "init.apex." + apex_name; // TODO(b/232799709) read .rc files from the apex + + if (auto result = UpdateApexLinkerConfig(apex_name); !result.ok()) { + return result.error(); + } + SetProperty(prop_name, "loaded"); return {}; }