Kiyoung Kim | e9a77fe | 2019-05-23 11:04:20 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2019 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
Kiyoung Kim | e655807 | 2019-09-30 16:58:39 +0900 | [diff] [blame] | 16 | |
Jooyung Han | 471aeb9 | 2020-02-20 18:21:03 +0900 | [diff] [blame] | 17 | #include <climits> |
| 18 | #include <cstdlib> |
Kiyoung Kim | e9a77fe | 2019-05-23 11:04:20 +0900 | [diff] [blame] | 19 | #include <cstring> |
| 20 | #include <fstream> |
| 21 | #include <iostream> |
| 22 | #include <string> |
| 23 | |
Jooyung Han | a59fbd5 | 2020-01-30 12:57:34 +0900 | [diff] [blame] | 24 | #include <errno.h> |
Kiyoung Kim | 5c8366d | 2019-12-30 18:43:00 +0900 | [diff] [blame] | 25 | #include <fcntl.h> |
Jooyung Han | 471aeb9 | 2020-02-20 18:21:03 +0900 | [diff] [blame] | 26 | #include <getopt.h> |
Kiyoung Kim | 5c8366d | 2019-12-30 18:43:00 +0900 | [diff] [blame] | 27 | #include <sys/stat.h> |
Jooyung Han | a59fbd5 | 2020-01-30 12:57:34 +0900 | [diff] [blame] | 28 | #include <sys/types.h> |
Kiyoung Kim | 5c8366d | 2019-12-30 18:43:00 +0900 | [diff] [blame] | 29 | |
Jooyung Han | 471aeb9 | 2020-02-20 18:21:03 +0900 | [diff] [blame] | 30 | #include <android-base/result.h> |
Jooyung Han | 8e5cc8d | 2020-03-03 00:34:32 +0900 | [diff] [blame] | 31 | #include <android-base/strings.h> |
Jooyung Han | 471aeb9 | 2020-02-20 18:21:03 +0900 | [diff] [blame] | 32 | |
Kiyoung Kim | 284bc72 | 2020-01-20 13:33:00 +0900 | [diff] [blame] | 33 | #include "linkerconfig/apex.h" |
| 34 | #include "linkerconfig/apexconfig.h" |
Kiyoung Kim | e9a77fe | 2019-05-23 11:04:20 +0900 | [diff] [blame] | 35 | #include "linkerconfig/baseconfig.h" |
Kiyoung Kim | 284bc72 | 2020-01-20 13:33:00 +0900 | [diff] [blame] | 36 | #include "linkerconfig/context.h" |
Kiyoung Kim | e655807 | 2019-09-30 16:58:39 +0900 | [diff] [blame] | 37 | #include "linkerconfig/environment.h" |
| 38 | #include "linkerconfig/legacy.h" |
Kiyoung Kim | 853438d | 2019-07-16 09:51:14 +0900 | [diff] [blame] | 39 | #include "linkerconfig/log.h" |
Jooyung Han | 9960aca | 2020-02-06 20:17:53 +0900 | [diff] [blame] | 40 | #include "linkerconfig/namespacebuilder.h" |
Kiyoung Kim | 09cbb08 | 2019-12-05 16:44:34 +0900 | [diff] [blame] | 41 | #include "linkerconfig/recovery.h" |
Kiyoung Kim | e9a77fe | 2019-05-23 11:04:20 +0900 | [diff] [blame] | 42 | #include "linkerconfig/variableloader.h" |
Jooyung Han | a3d5d09 | 2019-09-26 23:23:50 +0900 | [diff] [blame] | 43 | #include "linkerconfig/variables.h" |
Kiyoung Kim | e9a77fe | 2019-05-23 11:04:20 +0900 | [diff] [blame] | 44 | |
Kiyoung Kim | 5c8366d | 2019-12-30 18:43:00 +0900 | [diff] [blame] | 45 | using android::base::ErrnoError; |
| 46 | using android::base::Error; |
Jooyung Han | 8e5cc8d | 2020-03-03 00:34:32 +0900 | [diff] [blame] | 47 | using android::base::Join; |
Kiyoung Kim | 5c8366d | 2019-12-30 18:43:00 +0900 | [diff] [blame] | 48 | using android::base::Result; |
Jooyung Han | 87e7df8 | 2020-02-03 14:23:06 +0900 | [diff] [blame] | 49 | using android::linkerconfig::contents::Context; |
Kiyoung Kim | 284bc72 | 2020-01-20 13:33:00 +0900 | [diff] [blame] | 50 | using android::linkerconfig::modules::ApexInfo; |
Kiyoung Kim | 5c8366d | 2019-12-30 18:43:00 +0900 | [diff] [blame] | 51 | using android::linkerconfig::modules::Configuration; |
| 52 | |
Kiyoung Kim | e9a77fe | 2019-05-23 11:04:20 +0900 | [diff] [blame] | 53 | namespace { |
| 54 | const static struct option program_options[] = { |
| 55 | {"target", required_argument, 0, 't'}, |
Jooyung Han | b4af747 | 2020-02-03 18:07:12 +0900 | [diff] [blame] | 56 | {"strict", no_argument, 0, 's'}, |
Josh Gao | 76614bb | 2019-12-11 15:28:30 -0800 | [diff] [blame] | 57 | #ifndef __ANDROID__ |
Jooyung Han | a3d5d09 | 2019-09-26 23:23:50 +0900 | [diff] [blame] | 58 | {"root", required_argument, 0, 'r'}, |
| 59 | {"vndk", required_argument, 0, 'v'}, |
Jooyung Han | 0441fd3 | 2020-03-31 16:14:56 +0900 | [diff] [blame] | 60 | {"vndk_lite", no_argument, 0, 'e'}, |
| 61 | {"product_vndk", required_argument, 0, 'p'}, |
Kiyoung Kim | 722dad6 | 2019-12-19 15:59:55 +0900 | [diff] [blame] | 62 | {"recovery", no_argument, 0, 'y'}, |
Jooyung Han | a3d5d09 | 2019-09-26 23:23:50 +0900 | [diff] [blame] | 63 | #endif |
Kiyoung Kim | e9a77fe | 2019-05-23 11:04:20 +0900 | [diff] [blame] | 64 | {"help", no_argument, 0, 'h'}, |
| 65 | {0, 0, 0, 0}}; |
| 66 | |
| 67 | struct ProgramArgs { |
Kiyoung Kim | 5c8366d | 2019-12-30 18:43:00 +0900 | [diff] [blame] | 68 | std::string target_directory; |
Jooyung Han | b4af747 | 2020-02-03 18:07:12 +0900 | [diff] [blame] | 69 | bool strict; |
Jooyung Han | a3d5d09 | 2019-09-26 23:23:50 +0900 | [diff] [blame] | 70 | std::string root; |
| 71 | std::string vndk_version; |
Jooyung Han | 0441fd3 | 2020-03-31 16:14:56 +0900 | [diff] [blame] | 72 | bool vndk_lite; |
| 73 | std::string product_vndk_version; |
Kiyoung Kim | 722dad6 | 2019-12-19 15:59:55 +0900 | [diff] [blame] | 74 | bool is_recovery; |
Kiyoung Kim | e9a77fe | 2019-05-23 11:04:20 +0900 | [diff] [blame] | 75 | }; |
| 76 | |
| 77 | [[noreturn]] void PrintUsage(int status = EXIT_SUCCESS) { |
Kiyoung Kim | 5c8366d | 2019-12-30 18:43:00 +0900 | [diff] [blame] | 78 | std::cerr << "Usage : linkerconfig [--target <target_directory>]" |
Jooyung Han | b4af747 | 2020-02-03 18:07:12 +0900 | [diff] [blame] | 79 | " [--strict]" |
Jooyung Han | a3d5d09 | 2019-09-26 23:23:50 +0900 | [diff] [blame] | 80 | #ifndef __ANDROID__ |
| 81 | " --root <root dir>" |
| 82 | " --vndk <vndk version>" |
Jooyung Han | 0441fd3 | 2020-03-31 16:14:56 +0900 | [diff] [blame] | 83 | " --vndk_lite" |
| 84 | " --product_vndk <product vndk version>" |
Kiyoung Kim | 722dad6 | 2019-12-19 15:59:55 +0900 | [diff] [blame] | 85 | " --recovery" |
Jooyung Han | a3d5d09 | 2019-09-26 23:23:50 +0900 | [diff] [blame] | 86 | #endif |
| 87 | " [--help]" |
Kiyoung Kim | e9a77fe | 2019-05-23 11:04:20 +0900 | [diff] [blame] | 88 | << std::endl; |
| 89 | exit(status); |
| 90 | } |
| 91 | |
Jooyung Han | 471aeb9 | 2020-02-20 18:21:03 +0900 | [diff] [blame] | 92 | std::string RealPath(std::string_view path) { |
| 93 | char resolved_path[PATH_MAX]; |
| 94 | if (realpath(path.data(), resolved_path) != nullptr) { |
| 95 | return resolved_path; |
| 96 | } |
| 97 | PrintUsage(-1); |
| 98 | } |
| 99 | |
Kiyoung Kim | e9a77fe | 2019-05-23 11:04:20 +0900 | [diff] [blame] | 100 | bool ParseArgs(int argc, char* argv[], ProgramArgs* args) { |
| 101 | int parse_result; |
Jooyung Han | a3d5d09 | 2019-09-26 23:23:50 +0900 | [diff] [blame] | 102 | while ((parse_result = getopt_long( |
Jooyung Han | 0441fd3 | 2020-03-31 16:14:56 +0900 | [diff] [blame] | 103 | argc, argv, "t:sr:v:ep:hyl", program_options, NULL)) != -1) { |
Kiyoung Kim | e9a77fe | 2019-05-23 11:04:20 +0900 | [diff] [blame] | 104 | switch (parse_result) { |
| 105 | case 't': |
Kiyoung Kim | 5c8366d | 2019-12-30 18:43:00 +0900 | [diff] [blame] | 106 | args->target_directory = optarg; |
Kiyoung Kim | e9a77fe | 2019-05-23 11:04:20 +0900 | [diff] [blame] | 107 | break; |
Jooyung Han | b4af747 | 2020-02-03 18:07:12 +0900 | [diff] [blame] | 108 | case 's': |
| 109 | args->strict = true; |
| 110 | break; |
Jooyung Han | a3d5d09 | 2019-09-26 23:23:50 +0900 | [diff] [blame] | 111 | case 'r': |
Jooyung Han | 471aeb9 | 2020-02-20 18:21:03 +0900 | [diff] [blame] | 112 | args->root = RealPath(optarg); |
Jooyung Han | a3d5d09 | 2019-09-26 23:23:50 +0900 | [diff] [blame] | 113 | break; |
| 114 | case 'v': |
| 115 | args->vndk_version = optarg; |
| 116 | break; |
Jooyung Han | 0441fd3 | 2020-03-31 16:14:56 +0900 | [diff] [blame] | 117 | case 'e': |
| 118 | args->vndk_lite = true; |
| 119 | break; |
| 120 | case 'p': |
| 121 | args->product_vndk_version = optarg; |
| 122 | break; |
Kiyoung Kim | 722dad6 | 2019-12-19 15:59:55 +0900 | [diff] [blame] | 123 | case 'y': |
| 124 | args->is_recovery = true; |
| 125 | break; |
Kiyoung Kim | e9a77fe | 2019-05-23 11:04:20 +0900 | [diff] [blame] | 126 | case 'h': |
| 127 | PrintUsage(); |
| 128 | default: |
| 129 | return false; |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | if (optind < argc) { |
| 134 | return false; |
| 135 | } |
| 136 | |
| 137 | return true; |
| 138 | } |
| 139 | |
Kiyoung Kim | 5c8366d | 2019-12-30 18:43:00 +0900 | [diff] [blame] | 140 | void LoadVariables(ProgramArgs args) { |
Kiyoung Kim | 722dad6 | 2019-12-19 15:59:55 +0900 | [diff] [blame] | 141 | #ifndef __ANDROID__ |
Jooyung Han | 71b4bf3 | 2020-04-02 15:40:41 +0900 | [diff] [blame] | 142 | if (!args.is_recovery && args.root == "") { |
Kiyoung Kim | 722dad6 | 2019-12-19 15:59:55 +0900 | [diff] [blame] | 143 | PrintUsage(); |
| 144 | } |
| 145 | android::linkerconfig::modules::Variables::AddValue("ro.vndk.version", |
| 146 | args.vndk_version); |
Jooyung Han | 0441fd3 | 2020-03-31 16:14:56 +0900 | [diff] [blame] | 147 | android::linkerconfig::modules::Variables::AddValue( |
| 148 | "ro.product.vndk.version", args.product_vndk_version); |
| 149 | if (args.vndk_lite) { |
| 150 | android::linkerconfig::modules::Variables::AddValue("ro.vndk.lite", "true"); |
| 151 | } |
Kiyoung Kim | 722dad6 | 2019-12-19 15:59:55 +0900 | [diff] [blame] | 152 | #endif |
Kiyoung Kim | 5c8366d | 2019-12-30 18:43:00 +0900 | [diff] [blame] | 153 | if (!args.is_recovery) { |
| 154 | android::linkerconfig::generator::LoadVariables(args.root); |
| 155 | } |
| 156 | } |
Kiyoung Kim | 722dad6 | 2019-12-19 15:59:55 +0900 | [diff] [blame] | 157 | |
Kiyoung Kim | 5c8366d | 2019-12-30 18:43:00 +0900 | [diff] [blame] | 158 | Result<void> WriteConfigurationToFile(Configuration& conf, |
| 159 | std::string file_path) { |
| 160 | std::ostream* out = &std::cout; |
| 161 | std::ofstream file_out; |
| 162 | |
| 163 | if (file_path != "") { |
| 164 | file_out.open(file_path); |
| 165 | if (file_out.fail()) { |
| 166 | return ErrnoError() << "Failed to open file " << file_path; |
| 167 | } |
| 168 | out = &file_out; |
| 169 | } |
| 170 | |
| 171 | android::linkerconfig::modules::ConfigWriter config_writer; |
| 172 | |
| 173 | conf.WriteConfig(config_writer); |
| 174 | *out << config_writer.ToString(); |
| 175 | if (!out->good()) { |
| 176 | return ErrnoError() << "Failed to write content to " << file_path; |
| 177 | } |
| 178 | |
| 179 | return {}; |
| 180 | } |
| 181 | |
Jooyung Han | 5f24636 | 2020-01-28 15:44:14 +0900 | [diff] [blame] | 182 | Result<void> UpdatePermission([[maybe_unused]] const std::string& file_path) { |
| 183 | #ifdef __ANDROID__ |
Kiyoung Kim | 5c8366d | 2019-12-30 18:43:00 +0900 | [diff] [blame] | 184 | if (fchmodat(AT_FDCWD, |
| 185 | file_path.c_str(), |
| 186 | S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH, |
| 187 | AT_SYMLINK_NOFOLLOW) < 0) { |
| 188 | return ErrnoError() << "Failed to update permission of " << file_path; |
| 189 | } |
Jooyung Han | 5f24636 | 2020-01-28 15:44:14 +0900 | [diff] [blame] | 190 | #endif |
Kiyoung Kim | 5c8366d | 2019-12-30 18:43:00 +0900 | [diff] [blame] | 191 | |
| 192 | return {}; |
| 193 | } |
| 194 | |
Jooyung Han | 87e7df8 | 2020-02-03 14:23:06 +0900 | [diff] [blame] | 195 | Context GetContext(ProgramArgs args) { |
Jooyung Han | 471aeb9 | 2020-02-20 18:21:03 +0900 | [diff] [blame] | 196 | auto apex_list = android::linkerconfig::modules::ScanActiveApexes(args.root); |
Jooyung Han | 87e7df8 | 2020-02-03 14:23:06 +0900 | [diff] [blame] | 197 | Context ctx; |
| 198 | for (auto const& apex_item : apex_list) { |
| 199 | auto apex_info = apex_item.second; |
| 200 | if (apex_info.has_bin || apex_info.has_lib) { |
| 201 | ctx.AddApexModule(std::move(apex_info)); |
| 202 | } |
| 203 | } |
Jooyung Han | b4af747 | 2020-02-03 18:07:12 +0900 | [diff] [blame] | 204 | if (args.strict) { |
| 205 | ctx.SetStrictMode(true); |
| 206 | } |
Jooyung Han | 9960aca | 2020-02-06 20:17:53 +0900 | [diff] [blame] | 207 | android::linkerconfig::contents::RegisterApexNamespaceBuilders(ctx); |
Jooyung Han | 87e7df8 | 2020-02-03 14:23:06 +0900 | [diff] [blame] | 208 | return ctx; |
| 209 | } |
| 210 | |
| 211 | Configuration GetConfiguration(Context& ctx) { |
Kiyoung Kim | 5c8366d | 2019-12-30 18:43:00 +0900 | [diff] [blame] | 212 | if (android::linkerconfig::modules::IsRecoveryMode()) { |
Jooyung Han | 87e7df8 | 2020-02-03 14:23:06 +0900 | [diff] [blame] | 213 | return android::linkerconfig::contents::CreateRecoveryConfiguration(ctx); |
Kiyoung Kim | 5c8366d | 2019-12-30 18:43:00 +0900 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | if (android::linkerconfig::modules::IsLegacyDevice()) { |
Jooyung Han | 87e7df8 | 2020-02-03 14:23:06 +0900 | [diff] [blame] | 217 | return android::linkerconfig::contents::CreateLegacyConfiguration(ctx); |
Kiyoung Kim | e655807 | 2019-09-30 16:58:39 +0900 | [diff] [blame] | 218 | } |
Kiyoung Kim | e9a77fe | 2019-05-23 11:04:20 +0900 | [diff] [blame] | 219 | |
Kiyoung Kim | e9a77fe | 2019-05-23 11:04:20 +0900 | [diff] [blame] | 220 | // Use base configuration in default |
Jooyung Han | 87e7df8 | 2020-02-03 14:23:06 +0900 | [diff] [blame] | 221 | return android::linkerconfig::contents::CreateBaseConfiguration(ctx); |
Kiyoung Kim | e9a77fe | 2019-05-23 11:04:20 +0900 | [diff] [blame] | 222 | } |
Kiyoung Kim | e3bad04 | 2019-07-23 13:38:34 +0900 | [diff] [blame] | 223 | |
Kiyoung Kim | 5c8366d | 2019-12-30 18:43:00 +0900 | [diff] [blame] | 224 | Result<void> GenerateConfiguration(Configuration config, std::string dir_path, |
| 225 | bool update_permission) { |
| 226 | std::string file_path = ""; |
| 227 | if (dir_path != "") { |
| 228 | file_path = dir_path + "/ld.config.txt"; |
| 229 | } |
| 230 | |
| 231 | auto write_config = WriteConfigurationToFile(config, file_path); |
Bernie Innocenti | 5c32556 | 2020-02-06 23:16:23 +0900 | [diff] [blame] | 232 | if (!write_config.ok()) { |
Kiyoung Kim | 5c8366d | 2019-12-30 18:43:00 +0900 | [diff] [blame] | 233 | return write_config; |
| 234 | } else if (update_permission && file_path != "") { |
| 235 | return UpdatePermission(file_path); |
| 236 | } |
| 237 | |
| 238 | return {}; |
| 239 | } |
| 240 | |
Jooyung Han | 87e7df8 | 2020-02-03 14:23:06 +0900 | [diff] [blame] | 241 | Result<void> GenerateBaseLinkerConfiguration(Context& ctx, |
| 242 | const std::string& dir_path) { |
| 243 | return GenerateConfiguration(GetConfiguration(ctx), dir_path, true); |
Kiyoung Kim | 5c8366d | 2019-12-30 18:43:00 +0900 | [diff] [blame] | 244 | } |
| 245 | |
Jooyung Han | 87e7df8 | 2020-02-03 14:23:06 +0900 | [diff] [blame] | 246 | Result<void> GenerateRecoveryLinkerConfiguration(Context& ctx, |
| 247 | const std::string& dir_path) { |
Kiyoung Kim | 5c8366d | 2019-12-30 18:43:00 +0900 | [diff] [blame] | 248 | return GenerateConfiguration( |
Jooyung Han | 87e7df8 | 2020-02-03 14:23:06 +0900 | [diff] [blame] | 249 | android::linkerconfig::contents::CreateRecoveryConfiguration(ctx), |
Kiyoung Kim | 5c8366d | 2019-12-30 18:43:00 +0900 | [diff] [blame] | 250 | dir_path, |
| 251 | false); |
| 252 | } |
| 253 | |
Kiyoung Kim | 284bc72 | 2020-01-20 13:33:00 +0900 | [diff] [blame] | 254 | Result<void> GenerateApexConfiguration( |
| 255 | const std::string& base_dir, android::linkerconfig::contents::Context& ctx, |
| 256 | const android::linkerconfig::modules::ApexInfo& target_apex) { |
| 257 | std::string dir_path = base_dir + "/" + target_apex.name; |
Jooyung Han | a59fbd5 | 2020-01-30 12:57:34 +0900 | [diff] [blame] | 258 | if (auto ret = mkdir(dir_path.c_str(), 0755); ret != 0 && errno != EEXIST) { |
Kiyoung Kim | 284bc72 | 2020-01-20 13:33:00 +0900 | [diff] [blame] | 259 | return ErrnoError() << "Failed to create directory " << dir_path; |
| 260 | } |
| 261 | |
| 262 | return GenerateConfiguration( |
| 263 | android::linkerconfig::contents::CreateApexConfiguration(ctx, target_apex), |
| 264 | dir_path, |
| 265 | true); |
| 266 | } |
| 267 | |
Jooyung Han | 87e7df8 | 2020-02-03 14:23:06 +0900 | [diff] [blame] | 268 | void GenerateApexConfigurations(Context& ctx, const std::string& dir_path) { |
| 269 | for (auto const& apex_item : ctx.GetApexModules()) { |
| 270 | if (apex_item.has_bin) { |
| 271 | auto result = GenerateApexConfiguration(dir_path, ctx, apex_item); |
Bernie Innocenti | 5c32556 | 2020-02-06 23:16:23 +0900 | [diff] [blame] | 272 | if (!result.ok()) { |
Kiyoung Kim | 284bc72 | 2020-01-20 13:33:00 +0900 | [diff] [blame] | 273 | LOG(WARNING) << result.error(); |
| 274 | } |
| 275 | } |
| 276 | } |
| 277 | } |
| 278 | |
Jooyung Han | 8e5cc8d | 2020-03-03 00:34:32 +0900 | [diff] [blame] | 279 | void GenerateJniConfig(Context& ctx, const std::string& dir_path) { |
| 280 | if (dir_path == "") { |
| 281 | return; |
| 282 | } |
| 283 | std::string file_path = dir_path + "/jni.config.txt"; |
| 284 | std::ofstream out(file_path); |
| 285 | for (auto const& apex_item : ctx.GetApexModules()) { |
| 286 | if (!apex_item.jni_libs.empty()) { |
| 287 | out << apex_item.namespace_name << " " << Join(apex_item.jni_libs, ":") |
| 288 | << '\n'; |
| 289 | } |
| 290 | } |
| 291 | out.close(); |
| 292 | UpdatePermission(file_path); |
| 293 | } |
| 294 | |
Kiyoung Kim | 5c8366d | 2019-12-30 18:43:00 +0900 | [diff] [blame] | 295 | void ExitOnFailure(Result<void> task) { |
Bernie Innocenti | 5c32556 | 2020-02-06 23:16:23 +0900 | [diff] [blame] | 296 | if (!task.ok()) { |
Kiyoung Kim | 5c8366d | 2019-12-30 18:43:00 +0900 | [diff] [blame] | 297 | LOG(FATAL) << task.error(); |
| 298 | exit(EXIT_FAILURE); |
| 299 | } |
| 300 | } |
| 301 | |
Jooyung Han | a3d5d09 | 2019-09-26 23:23:50 +0900 | [diff] [blame] | 302 | #ifdef __ANDROID__ |
Kiyoung Kim | e3bad04 | 2019-07-23 13:38:34 +0900 | [diff] [blame] | 303 | struct CombinedLogger { |
| 304 | android::base::LogdLogger logd; |
| 305 | |
| 306 | void operator()(android::base::LogId id, android::base::LogSeverity severity, |
| 307 | const char* tag, const char* file, unsigned int line, |
| 308 | const char* message) { |
| 309 | logd(id, severity, tag, file, line, message); |
| 310 | KernelLogger(id, severity, tag, file, line, message); |
| 311 | } |
| 312 | }; |
Jooyung Han | a3d5d09 | 2019-09-26 23:23:50 +0900 | [diff] [blame] | 313 | #endif |
Kiyoung Kim | e9a77fe | 2019-05-23 11:04:20 +0900 | [diff] [blame] | 314 | } // namespace |
| 315 | |
| 316 | int main(int argc, char* argv[]) { |
Jooyung Han | a3d5d09 | 2019-09-26 23:23:50 +0900 | [diff] [blame] | 317 | android::base::InitLogging(argv |
| 318 | #ifdef __ANDROID__ |
| 319 | , |
| 320 | CombinedLogger() |
| 321 | #endif |
| 322 | ); |
Kiyoung Kim | e3bad04 | 2019-07-23 13:38:34 +0900 | [diff] [blame] | 323 | |
Jooyung Han | 5bbb123 | 2019-12-23 13:35:00 +0900 | [diff] [blame] | 324 | ProgramArgs args = {}; |
Kiyoung Kim | e9a77fe | 2019-05-23 11:04:20 +0900 | [diff] [blame] | 325 | |
| 326 | if (!ParseArgs(argc, argv, &args)) { |
| 327 | PrintUsage(EXIT_FAILURE); |
| 328 | } |
| 329 | |
Kiyoung Kim | 5c8366d | 2019-12-30 18:43:00 +0900 | [diff] [blame] | 330 | LoadVariables(args); |
Jooyung Han | 87e7df8 | 2020-02-03 14:23:06 +0900 | [diff] [blame] | 331 | Context ctx = GetContext(args); |
Kiyoung Kim | e9a77fe | 2019-05-23 11:04:20 +0900 | [diff] [blame] | 332 | |
Jiyong Park | d601820 | 2020-02-21 13:56:52 +0900 | [diff] [blame] | 333 | // when exec'ed from init, this is 0x0077, which makes the subdirectories |
| 334 | // inaccessible for others. set umask to 0x0022 so that they can be |
| 335 | // accessible. |
| 336 | umask(0x0022); |
| 337 | |
Kiyoung Kim | 5c8366d | 2019-12-30 18:43:00 +0900 | [diff] [blame] | 338 | if (args.is_recovery) { |
Jooyung Han | 87e7df8 | 2020-02-03 14:23:06 +0900 | [diff] [blame] | 339 | ExitOnFailure( |
| 340 | GenerateRecoveryLinkerConfiguration(ctx, args.target_directory)); |
Kiyoung Kim | 5c8366d | 2019-12-30 18:43:00 +0900 | [diff] [blame] | 341 | } else { |
Jooyung Han | 87e7df8 | 2020-02-03 14:23:06 +0900 | [diff] [blame] | 342 | ExitOnFailure(GenerateBaseLinkerConfiguration(ctx, args.target_directory)); |
| 343 | GenerateApexConfigurations(ctx, args.target_directory); |
Jooyung Han | 8e5cc8d | 2020-03-03 00:34:32 +0900 | [diff] [blame] | 344 | GenerateJniConfig(ctx, args.target_directory); |
Kiyoung Kim | e9a77fe | 2019-05-23 11:04:20 +0900 | [diff] [blame] | 345 | } |
| 346 | |
| 347 | return EXIT_SUCCESS; |
Josh Gao | 76614bb | 2019-12-11 15:28:30 -0800 | [diff] [blame] | 348 | } |