Dimitry Ivanov | 3f66057 | 2016-09-09 10:00:39 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 The Android Open Source Project |
| 3 | * All rights reserved. |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions |
| 7 | * are met: |
| 8 | * * Redistributions of source code must retain the above copyright |
| 9 | * notice, this list of conditions and the following disclaimer. |
| 10 | * * Redistributions in binary form must reproduce the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer in |
| 12 | * the documentation and/or other materials provided with the |
| 13 | * distribution. |
| 14 | * |
| 15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 16 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 17 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
| 18 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
| 19 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
| 21 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS |
| 22 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
| 23 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 24 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT |
| 25 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 26 | * SUCH DAMAGE. |
| 27 | */ |
| 28 | |
| 29 | #include "linker_main.h" |
| 30 | |
Ryan Prichard | 701bd0c | 2018-11-21 16:23:03 -0800 | [diff] [blame] | 31 | #include <link.h> |
chenxinyuanchen | 8d7c0f4 | 2024-04-19 15:58:23 +0800 | [diff] [blame] | 32 | #include <stdlib.h> |
Ryan Prichard | 701bd0c | 2018-11-21 16:23:03 -0800 | [diff] [blame] | 33 | #include <sys/auxv.h> |
| 34 | |
Collin Fijalkovich | 47d27aa | 2021-03-24 10:17:39 -0700 | [diff] [blame] | 35 | #include "linker.h" |
Elliott Hughes | 838dbac | 2023-08-22 14:07:48 -0700 | [diff] [blame] | 36 | #include "linker_auxv.h" |
Collin Fijalkovich | 47d27aa | 2021-03-24 10:17:39 -0700 | [diff] [blame] | 37 | #include "linker_cfi.h" |
Dimitry Ivanov | 3f66057 | 2016-09-09 10:00:39 -0700 | [diff] [blame] | 38 | #include "linker_debug.h" |
Ryan Prichard | 80e40f0 | 2019-10-31 19:54:46 -0700 | [diff] [blame] | 39 | #include "linker_debuggerd.h" |
Dimitry Ivanov | 3f66057 | 2016-09-09 10:00:39 -0700 | [diff] [blame] | 40 | #include "linker_gdb_support.h" |
| 41 | #include "linker_globals.h" |
| 42 | #include "linker_phdr.h" |
Ryan Prichard | 339ecef | 2020-01-02 16:36:06 -0800 | [diff] [blame] | 43 | #include "linker_relocate.h" |
Peter Collingbourne | 1583cd2 | 2021-08-18 17:04:23 -0700 | [diff] [blame] | 44 | #include "linker_relocs.h" |
Ryan Prichard | 45d1349 | 2019-01-03 02:51:30 -0800 | [diff] [blame] | 45 | #include "linker_tls.h" |
Dimitry Ivanov | 3f66057 | 2016-09-09 10:00:39 -0700 | [diff] [blame] | 46 | #include "linker_utils.h" |
| 47 | |
Ryan Prichard | 9a027c7 | 2023-07-21 23:04:50 -0700 | [diff] [blame] | 48 | #include "private/KernelArgumentBlock.h" |
Ryan Prichard | 249757b | 2019-11-01 17:18:28 -0700 | [diff] [blame] | 49 | #include "private/bionic_call_ifunc_resolver.h" |
Dimitry Ivanov | 3f66057 | 2016-09-09 10:00:39 -0700 | [diff] [blame] | 50 | #include "private/bionic_globals.h" |
| 51 | #include "private/bionic_tls.h" |
Dimitry Ivanov | 3f66057 | 2016-09-09 10:00:39 -0700 | [diff] [blame] | 52 | |
Ryan Prichard | 8f639a4 | 2018-10-01 23:10:05 -0700 | [diff] [blame] | 53 | #include "android-base/unique_fd.h" |
Dimitry Ivanov | 3f66057 | 2016-09-09 10:00:39 -0700 | [diff] [blame] | 54 | #include "android-base/strings.h" |
| 55 | #include "android-base/stringprintf.h" |
Dimitry Ivanov | 3f66057 | 2016-09-09 10:00:39 -0700 | [diff] [blame] | 56 | |
Christopher Ferris | 7a3681e | 2017-04-24 17:48:32 -0700 | [diff] [blame] | 57 | #include <async_safe/log.h> |
Ryan Prichard | 701bd0c | 2018-11-21 16:23:03 -0800 | [diff] [blame] | 58 | #include <bionic/libc_init_common.h> |
Ryan Prichard | 45d1349 | 2019-01-03 02:51:30 -0800 | [diff] [blame] | 59 | #include <bionic/pthread_internal.h> |
Christopher Ferris | 7a3681e | 2017-04-24 17:48:32 -0700 | [diff] [blame] | 60 | |
Dimitry Ivanov | 3f66057 | 2016-09-09 10:00:39 -0700 | [diff] [blame] | 61 | #include <vector> |
| 62 | |
Ryan Prichard | 8f639a4 | 2018-10-01 23:10:05 -0700 | [diff] [blame] | 63 | __LIBC_HIDDEN__ extern "C" void _start(); |
Dimitry Ivanov | 3f66057 | 2016-09-09 10:00:39 -0700 | [diff] [blame] | 64 | |
| 65 | static ElfW(Addr) get_elf_exec_load_bias(const ElfW(Ehdr)* elf); |
| 66 | |
Ryan Prichard | 9729f35 | 2018-07-13 22:40:26 -0700 | [diff] [blame] | 67 | static void get_elf_base_from_phdr(const ElfW(Phdr)* phdr_table, size_t phdr_count, |
| 68 | ElfW(Addr)* base, ElfW(Addr)* load_bias); |
| 69 | |
Vic Yang | 1bf62b2 | 2019-08-13 14:53:28 -0700 | [diff] [blame] | 70 | static void set_bss_vma_name(soinfo* si); |
| 71 | |
Mitch Phillips | 7c1f377 | 2023-09-28 13:45:59 +0200 | [diff] [blame] | 72 | void __libc_init_mte(const memtag_dynamic_entries_t* memtag_dynamic_entries, const void* phdr_start, |
| 73 | size_t phdr_count, uintptr_t load_bias, void* stack_top); |
Evgenii Stepanov | 8564b8d | 2020-12-15 13:55:32 -0800 | [diff] [blame] | 74 | |
Dimitry Ivanov | 3f66057 | 2016-09-09 10:00:39 -0700 | [diff] [blame] | 75 | // These should be preserved static to avoid emitting |
| 76 | // RELATIVE relocations for the part of the code running |
| 77 | // before linker links itself. |
| 78 | |
| 79 | // TODO (dimtiry): remove somain, rename solist to solist_head |
| 80 | static soinfo* solist; |
| 81 | static soinfo* sonext; |
Evgenii Stepanov | 6bbb75a | 2023-12-06 18:54:45 +0000 | [diff] [blame] | 82 | static soinfo* somain; // main process, always the one after libdl_info |
Ryan Prichard | 0489645 | 2018-08-20 17:44:42 -0700 | [diff] [blame] | 83 | static soinfo* solinker; |
dimitry | 8b14256 | 2018-05-09 15:22:38 +0200 | [diff] [blame] | 84 | static soinfo* vdso; // vdso if present |
Dimitry Ivanov | 3f66057 | 2016-09-09 10:00:39 -0700 | [diff] [blame] | 85 | |
| 86 | void solist_add_soinfo(soinfo* si) { |
| 87 | sonext->next = si; |
| 88 | sonext = si; |
| 89 | } |
| 90 | |
| 91 | bool solist_remove_soinfo(soinfo* si) { |
| 92 | soinfo *prev = nullptr, *trav; |
| 93 | for (trav = solist; trav != nullptr; trav = trav->next) { |
| 94 | if (trav == si) { |
| 95 | break; |
| 96 | } |
| 97 | prev = trav; |
| 98 | } |
| 99 | |
| 100 | if (trav == nullptr) { |
| 101 | // si was not in solist |
| 102 | PRINT("name \"%s\"@%p is not in solist!", si->get_realpath(), si); |
| 103 | return false; |
| 104 | } |
| 105 | |
| 106 | // prev will never be null, because the first entry in solist is |
| 107 | // always the static libdl_info. |
George Burgess IV | 7059100 | 2017-06-27 16:23:45 -0700 | [diff] [blame] | 108 | CHECK(prev != nullptr); |
Dimitry Ivanov | 3f66057 | 2016-09-09 10:00:39 -0700 | [diff] [blame] | 109 | prev->next = si->next; |
| 110 | if (si == sonext) { |
| 111 | sonext = prev; |
| 112 | } |
| 113 | |
| 114 | return true; |
| 115 | } |
| 116 | |
| 117 | soinfo* solist_get_head() { |
| 118 | return solist; |
| 119 | } |
| 120 | |
| 121 | soinfo* solist_get_somain() { |
| 122 | return somain; |
| 123 | } |
| 124 | |
dimitry | 8b14256 | 2018-05-09 15:22:38 +0200 | [diff] [blame] | 125 | soinfo* solist_get_vdso() { |
| 126 | return vdso; |
| 127 | } |
| 128 | |
Elliott Hughes | 90f96b9 | 2019-05-09 15:56:39 -0700 | [diff] [blame] | 129 | bool g_is_ldd; |
Dimitry Ivanov | 3f66057 | 2016-09-09 10:00:39 -0700 | [diff] [blame] | 130 | int g_ld_debug_verbosity; |
Dimitry Ivanov | 3f66057 | 2016-09-09 10:00:39 -0700 | [diff] [blame] | 131 | |
| 132 | static std::vector<std::string> g_ld_preload_names; |
| 133 | |
| 134 | static std::vector<soinfo*> g_ld_preloads; |
| 135 | |
| 136 | static void parse_path(const char* path, const char* delimiters, |
| 137 | std::vector<std::string>* resolved_paths) { |
| 138 | std::vector<std::string> paths; |
| 139 | split_path(path, delimiters, &paths); |
| 140 | resolve_paths(paths, resolved_paths); |
| 141 | } |
| 142 | |
| 143 | static void parse_LD_LIBRARY_PATH(const char* path) { |
| 144 | std::vector<std::string> ld_libary_paths; |
| 145 | parse_path(path, ":", &ld_libary_paths); |
| 146 | g_default_namespace.set_ld_library_paths(std::move(ld_libary_paths)); |
| 147 | } |
| 148 | |
| 149 | static void parse_LD_PRELOAD(const char* path) { |
| 150 | g_ld_preload_names.clear(); |
| 151 | if (path != nullptr) { |
| 152 | // We have historically supported ':' as well as ' ' in LD_PRELOAD. |
| 153 | g_ld_preload_names = android::base::Split(path, " :"); |
Josh Gao | 44f6e18 | 2017-10-18 17:25:24 -0700 | [diff] [blame] | 154 | g_ld_preload_names.erase(std::remove_if(g_ld_preload_names.begin(), g_ld_preload_names.end(), |
Josh Gao | 27242c6 | 2017-10-20 17:45:13 -0700 | [diff] [blame] | 155 | [](const std::string& s) { return s.empty(); }), |
| 156 | g_ld_preload_names.end()); |
Dimitry Ivanov | 3f66057 | 2016-09-09 10:00:39 -0700 | [diff] [blame] | 157 | } |
| 158 | } |
| 159 | |
| 160 | // An empty list of soinfos |
| 161 | static soinfo_list_t g_empty_list; |
| 162 | |
Ryan Prichard | 07440a8 | 2018-11-22 03:16:06 -0800 | [diff] [blame] | 163 | static void add_vdso() { |
| 164 | ElfW(Ehdr)* ehdr_vdso = reinterpret_cast<ElfW(Ehdr)*>(getauxval(AT_SYSINFO_EHDR)); |
Dimitry Ivanov | 3f66057 | 2016-09-09 10:00:39 -0700 | [diff] [blame] | 165 | if (ehdr_vdso == nullptr) { |
| 166 | return; |
| 167 | } |
| 168 | |
| 169 | soinfo* si = soinfo_alloc(&g_default_namespace, "[vdso]", nullptr, 0, 0); |
| 170 | |
| 171 | si->phdr = reinterpret_cast<ElfW(Phdr)*>(reinterpret_cast<char*>(ehdr_vdso) + ehdr_vdso->e_phoff); |
| 172 | si->phnum = ehdr_vdso->e_phnum; |
| 173 | si->base = reinterpret_cast<ElfW(Addr)>(ehdr_vdso); |
| 174 | si->size = phdr_table_get_load_size(si->phdr, si->phnum); |
| 175 | si->load_bias = get_elf_exec_load_bias(ehdr_vdso); |
| 176 | |
| 177 | si->prelink_image(); |
Ryan Prichard | 339ecef | 2020-01-02 16:36:06 -0800 | [diff] [blame] | 178 | si->link_image(SymbolLookupList(si), si, nullptr, nullptr); |
dimitry | c18de1b | 2017-09-26 14:31:35 +0200 | [diff] [blame] | 179 | // prevents accidental unloads... |
| 180 | si->set_dt_flags_1(si->get_dt_flags_1() | DF_1_NODELETE); |
| 181 | si->set_linked(); |
| 182 | si->call_constructors(); |
dimitry | 8b14256 | 2018-05-09 15:22:38 +0200 | [diff] [blame] | 183 | |
| 184 | vdso = si; |
Dimitry Ivanov | 3f66057 | 2016-09-09 10:00:39 -0700 | [diff] [blame] | 185 | } |
| 186 | |
Ryan Prichard | 0489645 | 2018-08-20 17:44:42 -0700 | [diff] [blame] | 187 | // Initializes an soinfo's link_map_head field using other fields from the |
Ryan Prichard | cf9ed12 | 2019-06-04 20:56:56 -0700 | [diff] [blame] | 188 | // soinfo (phdr, phnum, load_bias). The soinfo's realpath must not change after |
| 189 | // this function is called. |
| 190 | static void init_link_map_head(soinfo& info) { |
Ryan Prichard | 0489645 | 2018-08-20 17:44:42 -0700 | [diff] [blame] | 191 | auto& map = info.link_map_head; |
| 192 | map.l_addr = info.load_bias; |
Ryan Prichard | cf9ed12 | 2019-06-04 20:56:56 -0700 | [diff] [blame] | 193 | map.l_name = const_cast<char*>(info.get_realpath()); |
Ryan Prichard | 0489645 | 2018-08-20 17:44:42 -0700 | [diff] [blame] | 194 | phdr_table_get_dynamic_section(info.phdr, info.phnum, info.load_bias, &map.l_ld, nullptr); |
Dimitry Ivanov | 3f66057 | 2016-09-09 10:00:39 -0700 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | extern "C" int __system_properties_init(void); |
| 198 | |
Ryan Prichard | 8f639a4 | 2018-10-01 23:10:05 -0700 | [diff] [blame] | 199 | struct ExecutableInfo { |
| 200 | std::string path; |
| 201 | struct stat file_stat; |
| 202 | const ElfW(Phdr)* phdr; |
| 203 | size_t phdr_count; |
| 204 | ElfW(Addr) entry_point; |
Kalesh Singh | 4084b55 | 2024-03-13 13:35:49 -0700 | [diff] [blame] | 205 | bool should_pad_segments; |
Ryan Prichard | 8f639a4 | 2018-10-01 23:10:05 -0700 | [diff] [blame] | 206 | }; |
| 207 | |
Vincent Donnefort | 2efa017 | 2023-01-24 18:00:03 +0000 | [diff] [blame] | 208 | static ExecutableInfo get_executable_info(const char* arg_path) { |
Ryan Prichard | 8f639a4 | 2018-10-01 23:10:05 -0700 | [diff] [blame] | 209 | ExecutableInfo result = {}; |
Vincent Donnefort | 2efa017 | 2023-01-24 18:00:03 +0000 | [diff] [blame] | 210 | char const* exe_path = "/proc/self/exe"; |
Ryan Prichard | 8f639a4 | 2018-10-01 23:10:05 -0700 | [diff] [blame] | 211 | |
Vincent Donnefort | 2efa017 | 2023-01-24 18:00:03 +0000 | [diff] [blame] | 212 | // Stat "/proc/self/exe" instead of executable_path because |
| 213 | // the executable could be unlinked by this point and it should |
| 214 | // not cause a crash (see http://b/31084669) |
| 215 | if (TEMP_FAILURE_RETRY(stat(exe_path, &result.file_stat) == -1)) { |
| 216 | // Fallback to argv[0] for the case where /proc isn't available |
| 217 | if (TEMP_FAILURE_RETRY(stat(arg_path, &result.file_stat) == -1)) { |
| 218 | async_safe_fatal("unable to stat either \"/proc/self/exe\" or \"%s\": %s", |
| 219 | arg_path, strerror(errno)); |
Tom Cherry | 66bc428 | 2018-11-08 13:40:52 -0800 | [diff] [blame] | 220 | } |
Vincent Donnefort | 2efa017 | 2023-01-24 18:00:03 +0000 | [diff] [blame] | 221 | exe_path = arg_path; |
| 222 | } |
| 223 | |
Elliott Hughes | 33de273 | 2024-04-25 16:44:48 +0000 | [diff] [blame^] | 224 | // Path might be a symlink; we need the target so that we get the right |
| 225 | // linker configuration later. |
Vincent Donnefort | 2efa017 | 2023-01-24 18:00:03 +0000 | [diff] [blame] | 226 | char sym_path[PATH_MAX]; |
Elliott Hughes | 33de273 | 2024-04-25 16:44:48 +0000 | [diff] [blame^] | 227 | result.path = std::string(realpath(exe_path, sym_path) != nullptr ? sym_path : exe_path); |
Dimitry Ivanov | 3f66057 | 2016-09-09 10:00:39 -0700 | [diff] [blame] | 228 | |
Ryan Prichard | 07440a8 | 2018-11-22 03:16:06 -0800 | [diff] [blame] | 229 | result.phdr = reinterpret_cast<const ElfW(Phdr)*>(getauxval(AT_PHDR)); |
| 230 | result.phdr_count = getauxval(AT_PHNUM); |
| 231 | result.entry_point = getauxval(AT_ENTRY); |
Ryan Prichard | 8f639a4 | 2018-10-01 23:10:05 -0700 | [diff] [blame] | 232 | return result; |
Dimitry Ivanov | 3f66057 | 2016-09-09 10:00:39 -0700 | [diff] [blame] | 233 | } |
| 234 | |
Dimitry Ivanov | d9e427c | 2016-11-22 16:55:25 -0800 | [diff] [blame] | 235 | #if defined(__LP64__) |
Ryan Prichard | cf9ed12 | 2019-06-04 20:56:56 -0700 | [diff] [blame] | 236 | static char kFallbackLinkerPath[] = "/system/bin/linker64"; |
Dimitry Ivanov | d9e427c | 2016-11-22 16:55:25 -0800 | [diff] [blame] | 237 | #else |
Ryan Prichard | cf9ed12 | 2019-06-04 20:56:56 -0700 | [diff] [blame] | 238 | static char kFallbackLinkerPath[] = "/system/bin/linker"; |
Dimitry Ivanov | d9e427c | 2016-11-22 16:55:25 -0800 | [diff] [blame] | 239 | #endif |
| 240 | |
Ryan Prichard | 8f639a4 | 2018-10-01 23:10:05 -0700 | [diff] [blame] | 241 | __printflike(1, 2) |
| 242 | static void __linker_error(const char* fmt, ...) { |
| 243 | va_list ap; |
dimitry | 04f7a79 | 2017-09-29 11:52:17 +0200 | [diff] [blame] | 244 | |
Ryan Prichard | 8f639a4 | 2018-10-01 23:10:05 -0700 | [diff] [blame] | 245 | va_start(ap, fmt); |
| 246 | async_safe_format_fd_va_list(STDERR_FILENO, fmt, ap); |
| 247 | va_end(ap); |
| 248 | |
| 249 | va_start(ap, fmt); |
| 250 | async_safe_format_log_va_list(ANDROID_LOG_FATAL, "linker", fmt, ap); |
| 251 | va_end(ap); |
| 252 | |
dimitry | 04f7a79 | 2017-09-29 11:52:17 +0200 | [diff] [blame] | 253 | _exit(EXIT_FAILURE); |
Elliott Hughes | ad2d038 | 2017-07-31 11:43:34 -0700 | [diff] [blame] | 254 | } |
| 255 | |
Ryan Prichard | 8f639a4 | 2018-10-01 23:10:05 -0700 | [diff] [blame] | 256 | static void __linker_cannot_link(const char* argv0) { |
| 257 | __linker_error("CANNOT LINK EXECUTABLE \"%s\": %s\n", |
| 258 | argv0, |
| 259 | linker_get_error_buffer()); |
| 260 | } |
| 261 | |
| 262 | // Load an executable. Normally the kernel has already loaded the executable when the linker |
| 263 | // starts. The linker can be invoked directly on an executable, though, and then the linker must |
| 264 | // load it. This function doesn't load dependencies or resolve relocations. |
| 265 | static ExecutableInfo load_executable(const char* orig_path) { |
| 266 | ExecutableInfo result = {}; |
| 267 | |
| 268 | if (orig_path[0] != '/') { |
| 269 | __linker_error("error: expected absolute path: \"%s\"\n", orig_path); |
| 270 | } |
| 271 | |
| 272 | off64_t file_offset; |
| 273 | android::base::unique_fd fd(open_executable(orig_path, &file_offset, &result.path)); |
| 274 | if (fd.get() == -1) { |
| 275 | __linker_error("error: unable to open file \"%s\"\n", orig_path); |
| 276 | } |
| 277 | |
| 278 | if (TEMP_FAILURE_RETRY(fstat(fd.get(), &result.file_stat)) == -1) { |
| 279 | __linker_error("error: unable to stat \"%s\": %s\n", result.path.c_str(), strerror(errno)); |
| 280 | } |
| 281 | |
| 282 | ElfReader elf_reader; |
| 283 | if (!elf_reader.Read(result.path.c_str(), fd.get(), file_offset, result.file_stat.st_size)) { |
| 284 | __linker_error("error: %s\n", linker_get_error_buffer()); |
| 285 | } |
Torne (Richard Coles) | efbe9a5 | 2018-10-17 15:59:38 -0400 | [diff] [blame] | 286 | address_space_params address_space; |
| 287 | if (!elf_reader.Load(&address_space)) { |
Ryan Prichard | 8f639a4 | 2018-10-01 23:10:05 -0700 | [diff] [blame] | 288 | __linker_error("error: %s\n", linker_get_error_buffer()); |
| 289 | } |
| 290 | |
| 291 | result.phdr = elf_reader.loaded_phdr(); |
| 292 | result.phdr_count = elf_reader.phdr_count(); |
| 293 | result.entry_point = elf_reader.entry_point(); |
Kalesh Singh | 4084b55 | 2024-03-13 13:35:49 -0700 | [diff] [blame] | 294 | result.should_pad_segments = elf_reader.should_pad_segments(); |
Ryan Prichard | 8f639a4 | 2018-10-01 23:10:05 -0700 | [diff] [blame] | 295 | return result; |
| 296 | } |
| 297 | |
Tamas Petz | 8d55d18 | 2020-02-24 14:15:25 +0100 | [diff] [blame] | 298 | static void platform_properties_init() { |
| 299 | #if defined(__aarch64__) |
| 300 | const unsigned long hwcap2 = getauxval(AT_HWCAP2); |
| 301 | g_platform_properties.bti_supported = (hwcap2 & HWCAP2_BTI) != 0; |
| 302 | #endif |
| 303 | } |
| 304 | |
Ryan Prichard | 8f639a4 | 2018-10-01 23:10:05 -0700 | [diff] [blame] | 305 | static ElfW(Addr) linker_main(KernelArgumentBlock& args, const char* exe_to_load) { |
Dimitry Ivanov | 4cabfaa | 2017-03-07 11:19:05 -0800 | [diff] [blame] | 306 | ProtectedDataGuard guard; |
| 307 | |
Dimitry Ivanov | 3f66057 | 2016-09-09 10:00:39 -0700 | [diff] [blame] | 308 | #if TIMING |
| 309 | struct timeval t0, t1; |
| 310 | gettimeofday(&t0, 0); |
| 311 | #endif |
| 312 | |
| 313 | // Sanitize the environment. |
Ryan Prichard | 48b1159 | 2018-11-22 02:41:36 -0800 | [diff] [blame] | 314 | __libc_init_AT_SECURE(args.envp); |
Dimitry Ivanov | 3f66057 | 2016-09-09 10:00:39 -0700 | [diff] [blame] | 315 | |
| 316 | // Initialize system properties |
| 317 | __system_properties_init(); // may use 'environ' |
| 318 | |
Tamas Petz | 8d55d18 | 2020-02-24 14:15:25 +0100 | [diff] [blame] | 319 | // Initialize platform properties. |
| 320 | platform_properties_init(); |
| 321 | |
Dimitry Ivanov | 3f66057 | 2016-09-09 10:00:39 -0700 | [diff] [blame] | 322 | // Register the debuggerd signal handler. |
Ryan Prichard | 80e40f0 | 2019-10-31 19:54:46 -0700 | [diff] [blame] | 323 | linker_debuggerd_init(); |
Dimitry Ivanov | 3f66057 | 2016-09-09 10:00:39 -0700 | [diff] [blame] | 324 | |
| 325 | g_linker_logger.ResetState(); |
| 326 | |
Elliott Hughes | 838dbac | 2023-08-22 14:07:48 -0700 | [diff] [blame] | 327 | // Enable debugging logs? |
Dimitry Ivanov | 3f66057 | 2016-09-09 10:00:39 -0700 | [diff] [blame] | 328 | const char* LD_DEBUG = getenv("LD_DEBUG"); |
| 329 | if (LD_DEBUG != nullptr) { |
| 330 | g_ld_debug_verbosity = atoi(LD_DEBUG); |
| 331 | } |
| 332 | |
Elliott Hughes | 838dbac | 2023-08-22 14:07:48 -0700 | [diff] [blame] | 333 | if (getenv("LD_SHOW_AUXV") != nullptr) ld_show_auxv(args.auxv); |
| 334 | |
Dimitry Ivanov | 3f66057 | 2016-09-09 10:00:39 -0700 | [diff] [blame] | 335 | #if defined(__LP64__) |
| 336 | INFO("[ Android dynamic linker (64-bit) ]"); |
| 337 | #else |
| 338 | INFO("[ Android dynamic linker (32-bit) ]"); |
| 339 | #endif |
| 340 | |
| 341 | // These should have been sanitized by __libc_init_AT_SECURE, but the test |
| 342 | // doesn't cost us anything. |
| 343 | const char* ldpath_env = nullptr; |
| 344 | const char* ldpreload_env = nullptr; |
| 345 | if (!getauxval(AT_SECURE)) { |
| 346 | ldpath_env = getenv("LD_LIBRARY_PATH"); |
| 347 | if (ldpath_env != nullptr) { |
| 348 | INFO("[ LD_LIBRARY_PATH set to \"%s\" ]", ldpath_env); |
| 349 | } |
| 350 | ldpreload_env = getenv("LD_PRELOAD"); |
| 351 | if (ldpreload_env != nullptr) { |
| 352 | INFO("[ LD_PRELOAD set to \"%s\" ]", ldpreload_env); |
| 353 | } |
| 354 | } |
| 355 | |
Ryan Prichard | 8f639a4 | 2018-10-01 23:10:05 -0700 | [diff] [blame] | 356 | const ExecutableInfo exe_info = exe_to_load ? load_executable(exe_to_load) : |
Vincent Donnefort | 2efa017 | 2023-01-24 18:00:03 +0000 | [diff] [blame] | 357 | get_executable_info(args.argv[0]); |
Ryan Prichard | 8f639a4 | 2018-10-01 23:10:05 -0700 | [diff] [blame] | 358 | |
Ryan Prichard | cf9ed12 | 2019-06-04 20:56:56 -0700 | [diff] [blame] | 359 | INFO("[ Linking executable \"%s\" ]", exe_info.path.c_str()); |
Martin Stjernholm | 95252ee | 2019-02-22 22:48:59 +0000 | [diff] [blame] | 360 | |
Ryan Prichard | 0489645 | 2018-08-20 17:44:42 -0700 | [diff] [blame] | 361 | // Initialize the main exe's soinfo. |
Ryan Prichard | 8f639a4 | 2018-10-01 23:10:05 -0700 | [diff] [blame] | 362 | soinfo* si = soinfo_alloc(&g_default_namespace, |
Ryan Prichard | cf9ed12 | 2019-06-04 20:56:56 -0700 | [diff] [blame] | 363 | exe_info.path.c_str(), &exe_info.file_stat, |
Ryan Prichard | 8f639a4 | 2018-10-01 23:10:05 -0700 | [diff] [blame] | 364 | 0, RTLD_GLOBAL); |
Ryan Prichard | 0489645 | 2018-08-20 17:44:42 -0700 | [diff] [blame] | 365 | somain = si; |
Ryan Prichard | 8f639a4 | 2018-10-01 23:10:05 -0700 | [diff] [blame] | 366 | si->phdr = exe_info.phdr; |
| 367 | si->phnum = exe_info.phdr_count; |
Kalesh Singh | 4084b55 | 2024-03-13 13:35:49 -0700 | [diff] [blame] | 368 | si->set_should_pad_segments(exe_info.should_pad_segments); |
Ryan Prichard | 0489645 | 2018-08-20 17:44:42 -0700 | [diff] [blame] | 369 | get_elf_base_from_phdr(si->phdr, si->phnum, &si->base, &si->load_bias); |
| 370 | si->size = phdr_table_get_load_size(si->phdr, si->phnum); |
| 371 | si->dynamic = nullptr; |
Dimitry Ivanov | 3f66057 | 2016-09-09 10:00:39 -0700 | [diff] [blame] | 372 | si->set_main_executable(); |
Ryan Prichard | cf9ed12 | 2019-06-04 20:56:56 -0700 | [diff] [blame] | 373 | init_link_map_head(*si); |
| 374 | |
Vic Yang | 1bf62b2 | 2019-08-13 14:53:28 -0700 | [diff] [blame] | 375 | set_bss_vma_name(si); |
| 376 | |
Ryan Prichard | cf9ed12 | 2019-06-04 20:56:56 -0700 | [diff] [blame] | 377 | // Use the executable's PT_INTERP string as the solinker filename in the |
| 378 | // dynamic linker's module list. gdb reads both PT_INTERP and the module list, |
| 379 | // and if the paths for the linker are different, gdb will report that the |
| 380 | // PT_INTERP linker path was unloaded once the module list is initialized. |
| 381 | // There are three situations to handle: |
| 382 | // - the APEX linker (/system/bin/linker[64] -> /apex/.../linker[64]) |
| 383 | // - the ASAN linker (/system/bin/linker_asan[64] -> /apex/.../linker[64]) |
| 384 | // - the bootstrap linker (/system/bin/bootstrap/linker[64]) |
| 385 | const char *interp = phdr_table_get_interpreter_name(somain->phdr, somain->phnum, |
| 386 | somain->load_bias); |
| 387 | if (interp == nullptr) { |
| 388 | // This case can happen if the linker attempts to execute itself |
| 389 | // (e.g. "linker64 /system/bin/linker64"). |
| 390 | interp = kFallbackLinkerPath; |
| 391 | } |
| 392 | solinker->set_realpath(interp); |
| 393 | init_link_map_head(*solinker); |
Dimitry Ivanov | 3f66057 | 2016-09-09 10:00:39 -0700 | [diff] [blame] | 394 | |
Tamas Petz | 8d55d18 | 2020-02-24 14:15:25 +0100 | [diff] [blame] | 395 | #if defined(__aarch64__) |
| 396 | if (exe_to_load == nullptr) { |
| 397 | // Kernel does not add PROT_BTI to executable pages of the loaded ELF. |
| 398 | // Apply appropriate protections here if it is needed. |
| 399 | auto note_gnu_property = GnuPropertySection(somain); |
| 400 | if (note_gnu_property.IsBTICompatible() && |
| 401 | (phdr_table_protect_segments(somain->phdr, somain->phnum, somain->load_bias, |
Kalesh Singh | 4084b55 | 2024-03-13 13:35:49 -0700 | [diff] [blame] | 402 | somain->should_pad_segments(), ¬e_gnu_property) < 0)) { |
Tamas Petz | 8d55d18 | 2020-02-24 14:15:25 +0100 | [diff] [blame] | 403 | __linker_error("error: can't protect segments for \"%s\": %s", exe_info.path.c_str(), |
| 404 | strerror(errno)); |
| 405 | } |
| 406 | } |
| 407 | #endif |
| 408 | |
Dimitry Ivanov | 3f66057 | 2016-09-09 10:00:39 -0700 | [diff] [blame] | 409 | // Register the main executable and the linker upfront to have |
| 410 | // gdb aware of them before loading the rest of the dependency |
| 411 | // tree. |
Ryan Prichard | 0489645 | 2018-08-20 17:44:42 -0700 | [diff] [blame] | 412 | // |
| 413 | // gdb expects the linker to be in the debug shared object list. |
| 414 | // Without this, gdb has trouble locating the linker's ".text" |
| 415 | // and ".plt" sections. Gdb could also potentially use this to |
| 416 | // relocate the offset of our exported 'rtld_db_dlactivity' symbol. |
| 417 | // |
| 418 | insert_link_map_into_debug_map(&si->link_map_head); |
| 419 | insert_link_map_into_debug_map(&solinker->link_map_head); |
Dimitry Ivanov | 3f66057 | 2016-09-09 10:00:39 -0700 | [diff] [blame] | 420 | |
Ryan Prichard | 07440a8 | 2018-11-22 03:16:06 -0800 | [diff] [blame] | 421 | add_vdso(); |
Ryan Prichard | 14dd992 | 2018-08-20 17:43:44 -0700 | [diff] [blame] | 422 | |
Dimitry Ivanov | 3f66057 | 2016-09-09 10:00:39 -0700 | [diff] [blame] | 423 | ElfW(Ehdr)* elf_hdr = reinterpret_cast<ElfW(Ehdr)*>(si->base); |
Elliott Hughes | 3bdb31b | 2017-01-07 10:38:20 -0800 | [diff] [blame] | 424 | |
| 425 | // We haven't supported non-PIE since Lollipop for security reasons. |
Dimitry Ivanov | 3f66057 | 2016-09-09 10:00:39 -0700 | [diff] [blame] | 426 | if (elf_hdr->e_type != ET_DYN) { |
Elliott Hughes | ad2d038 | 2017-07-31 11:43:34 -0700 | [diff] [blame] | 427 | // We don't use async_safe_fatal here because we don't want a tombstone: |
| 428 | // even after several years we still find ourselves on app compatibility |
Elliott Hughes | 3bdb31b | 2017-01-07 10:38:20 -0800 | [diff] [blame] | 429 | // investigations because some app's trying to launch an executable that |
| 430 | // hasn't worked in at least three years, and we've "helpfully" dropped a |
| 431 | // tombstone for them. The tombstone never provided any detail relevant to |
| 432 | // fixing the problem anyway, and the utility of drawing extra attention |
| 433 | // to the problem is non-existent at this late date. |
Christopher Ferris | 7a3681e | 2017-04-24 17:48:32 -0700 | [diff] [blame] | 434 | async_safe_format_fd(STDERR_FILENO, |
Elliott Hughes | ad2d038 | 2017-07-31 11:43:34 -0700 | [diff] [blame] | 435 | "\"%s\": error: Android 5.0 and later only support " |
| 436 | "position-independent executables (-fPIE).\n", |
| 437 | g_argv[0]); |
Elliott Hughes | 90f96b9 | 2019-05-09 15:56:39 -0700 | [diff] [blame] | 438 | _exit(EXIT_FAILURE); |
Dimitry Ivanov | 3f66057 | 2016-09-09 10:00:39 -0700 | [diff] [blame] | 439 | } |
| 440 | |
| 441 | // Use LD_LIBRARY_PATH and LD_PRELOAD (but only if we aren't setuid/setgid). |
| 442 | parse_LD_LIBRARY_PATH(ldpath_env); |
| 443 | parse_LD_PRELOAD(ldpreload_env); |
| 444 | |
Ryan Prichard | cf9ed12 | 2019-06-04 20:56:56 -0700 | [diff] [blame] | 445 | std::vector<android_namespace_t*> namespaces = init_default_namespaces(exe_info.path.c_str()); |
Dimitry Ivanov | 3f66057 | 2016-09-09 10:00:39 -0700 | [diff] [blame] | 446 | |
Elliott Hughes | ad2d038 | 2017-07-31 11:43:34 -0700 | [diff] [blame] | 447 | if (!si->prelink_image()) __linker_cannot_link(g_argv[0]); |
Dimitry Ivanov | 3f66057 | 2016-09-09 10:00:39 -0700 | [diff] [blame] | 448 | |
| 449 | // add somain to global group |
| 450 | si->set_dt_flags_1(si->get_dt_flags_1() | DF_1_GLOBAL); |
Jiyong Park | 02586a2 | 2017-05-20 01:01:24 +0900 | [diff] [blame] | 451 | // ... and add it to all other linked namespaces |
| 452 | for (auto linked_ns : namespaces) { |
| 453 | if (linked_ns != &g_default_namespace) { |
| 454 | linked_ns->add_soinfo(somain); |
| 455 | somain->add_secondary_namespace(linked_ns); |
| 456 | } |
| 457 | } |
Dimitry Ivanov | 3f66057 | 2016-09-09 10:00:39 -0700 | [diff] [blame] | 458 | |
Ryan Prichard | e5e69e0 | 2019-01-01 18:53:48 -0800 | [diff] [blame] | 459 | linker_setup_exe_static_tls(g_argv[0]); |
| 460 | |
Dimitry Ivanov | 3f66057 | 2016-09-09 10:00:39 -0700 | [diff] [blame] | 461 | // Load ld_preloads and dependencies. |
| 462 | std::vector<const char*> needed_library_name_list; |
| 463 | size_t ld_preloads_count = 0; |
| 464 | |
| 465 | for (const auto& ld_preload_name : g_ld_preload_names) { |
| 466 | needed_library_name_list.push_back(ld_preload_name.c_str()); |
| 467 | ++ld_preloads_count; |
| 468 | } |
| 469 | |
| 470 | for_each_dt_needed(si, [&](const char* name) { |
| 471 | needed_library_name_list.push_back(name); |
| 472 | }); |
| 473 | |
| 474 | const char** needed_library_names = &needed_library_name_list[0]; |
| 475 | size_t needed_libraries_count = needed_library_name_list.size(); |
| 476 | |
| 477 | if (needed_libraries_count > 0 && |
Dimitry Ivanov | 7d429d3 | 2017-02-01 15:28:52 -0800 | [diff] [blame] | 478 | !find_libraries(&g_default_namespace, |
| 479 | si, |
| 480 | needed_library_names, |
| 481 | needed_libraries_count, |
| 482 | nullptr, |
| 483 | &g_ld_preloads, |
| 484 | ld_preloads_count, |
| 485 | RTLD_GLOBAL, |
| 486 | nullptr, |
| 487 | true /* add_as_children */, |
Jiyong Park | 02586a2 | 2017-05-20 01:01:24 +0900 | [diff] [blame] | 488 | &namespaces)) { |
Elliott Hughes | ad2d038 | 2017-07-31 11:43:34 -0700 | [diff] [blame] | 489 | __linker_cannot_link(g_argv[0]); |
Dimitry Ivanov | 3f66057 | 2016-09-09 10:00:39 -0700 | [diff] [blame] | 490 | } else if (needed_libraries_count == 0) { |
Ryan Prichard | 339ecef | 2020-01-02 16:36:06 -0800 | [diff] [blame] | 491 | if (!si->link_image(SymbolLookupList(si), si, nullptr, nullptr)) { |
Elliott Hughes | ad2d038 | 2017-07-31 11:43:34 -0700 | [diff] [blame] | 492 | __linker_cannot_link(g_argv[0]); |
Dimitry Ivanov | 3f66057 | 2016-09-09 10:00:39 -0700 | [diff] [blame] | 493 | } |
| 494 | si->increment_ref_count(); |
| 495 | } |
Ryan Prichard | 32bb367 | 2024-03-08 16:53:06 -0800 | [diff] [blame] | 496 | |
| 497 | // Exit early for ldd. We don't want to run the code that was loaded, so skip |
| 498 | // the constructor calls. Skip CFI setup because it would call __cfi_init in |
| 499 | // libdl.so. |
| 500 | if (g_is_ldd) _exit(EXIT_SUCCESS); |
| 501 | |
Florian Mayer | e65e193 | 2024-02-15 22:20:54 +0000 | [diff] [blame] | 502 | #if defined(__aarch64__) |
| 503 | // This has to happen after the find_libraries, which will have collected any possible |
| 504 | // libraries that request memtag_stack in the dynamic section. |
| 505 | __libc_init_mte(somain->memtag_dynamic_entries(), somain->phdr, somain->phnum, somain->load_bias, |
| 506 | args.argv); |
| 507 | #endif |
Dimitry Ivanov | 3f66057 | 2016-09-09 10:00:39 -0700 | [diff] [blame] | 508 | |
Ryan Prichard | e5e69e0 | 2019-01-01 18:53:48 -0800 | [diff] [blame] | 509 | linker_finalize_static_tls(); |
Ryan Prichard | 45d1349 | 2019-01-03 02:51:30 -0800 | [diff] [blame] | 510 | __libc_init_main_thread_final(); |
| 511 | |
Elliott Hughes | ad2d038 | 2017-07-31 11:43:34 -0700 | [diff] [blame] | 512 | if (!get_cfi_shadow()->InitialLinkDone(solist)) __linker_cannot_link(g_argv[0]); |
Evgenii Stepanov | 0a3637d | 2016-07-06 13:20:59 -0700 | [diff] [blame] | 513 | |
Dimitry Ivanov | 4cabfaa | 2017-03-07 11:19:05 -0800 | [diff] [blame] | 514 | si->call_pre_init_constructors(); |
Dimitry Ivanov | 4cabfaa | 2017-03-07 11:19:05 -0800 | [diff] [blame] | 515 | si->call_constructors(); |
Dimitry Ivanov | 3f66057 | 2016-09-09 10:00:39 -0700 | [diff] [blame] | 516 | |
| 517 | #if TIMING |
| 518 | gettimeofday(&t1, nullptr); |
Vic Yang | 7b9db34 | 2019-04-16 14:54:58 -0700 | [diff] [blame] | 519 | PRINT("LINKER TIME: %s: %d microseconds", g_argv[0], |
| 520 | static_cast<int>(((static_cast<long long>(t1.tv_sec) * 1000000LL) + |
| 521 | static_cast<long long>(t1.tv_usec)) - |
| 522 | ((static_cast<long long>(t0.tv_sec) * 1000000LL) + |
| 523 | static_cast<long long>(t0.tv_usec)))); |
Dimitry Ivanov | 3f66057 | 2016-09-09 10:00:39 -0700 | [diff] [blame] | 524 | #endif |
| 525 | #if STATS |
Vic Yang | 542db79 | 2019-07-25 10:39:27 -0700 | [diff] [blame] | 526 | print_linker_stats(); |
Dimitry Ivanov | 3f66057 | 2016-09-09 10:00:39 -0700 | [diff] [blame] | 527 | #endif |
Ryan Prichard | 78cd283 | 2019-10-25 17:46:43 -0700 | [diff] [blame] | 528 | #if TIMING || STATS |
Dimitry Ivanov | 3f66057 | 2016-09-09 10:00:39 -0700 | [diff] [blame] | 529 | fflush(stdout); |
| 530 | #endif |
| 531 | |
Vic Yang | bb7e123 | 2019-01-29 20:23:16 -0800 | [diff] [blame] | 532 | // We are about to hand control over to the executable loaded. We don't want |
| 533 | // to leave dirty pages behind unnecessarily. |
| 534 | purge_unused_memory(); |
| 535 | |
Ryan Prichard | 8f639a4 | 2018-10-01 23:10:05 -0700 | [diff] [blame] | 536 | ElfW(Addr) entry = exe_info.entry_point; |
Dimitry Ivanov | 3f66057 | 2016-09-09 10:00:39 -0700 | [diff] [blame] | 537 | TRACE("[ Ready to execute \"%s\" @ %p ]", si->get_realpath(), reinterpret_cast<void*>(entry)); |
| 538 | return entry; |
| 539 | } |
| 540 | |
| 541 | /* Compute the load-bias of an existing executable. This shall only |
| 542 | * be used to compute the load bias of an executable or shared library |
| 543 | * that was loaded by the kernel itself. |
| 544 | * |
| 545 | * Input: |
| 546 | * elf -> address of ELF header, assumed to be at the start of the file. |
| 547 | * Return: |
| 548 | * load bias, i.e. add the value of any p_vaddr in the file to get |
| 549 | * the corresponding address in memory. |
| 550 | */ |
| 551 | static ElfW(Addr) get_elf_exec_load_bias(const ElfW(Ehdr)* elf) { |
| 552 | ElfW(Addr) offset = elf->e_phoff; |
| 553 | const ElfW(Phdr)* phdr_table = |
| 554 | reinterpret_cast<const ElfW(Phdr)*>(reinterpret_cast<uintptr_t>(elf) + offset); |
| 555 | const ElfW(Phdr)* phdr_end = phdr_table + elf->e_phnum; |
| 556 | |
| 557 | for (const ElfW(Phdr)* phdr = phdr_table; phdr < phdr_end; phdr++) { |
| 558 | if (phdr->p_type == PT_LOAD) { |
| 559 | return reinterpret_cast<ElfW(Addr)>(elf) + phdr->p_offset - phdr->p_vaddr; |
| 560 | } |
| 561 | } |
| 562 | return 0; |
| 563 | } |
| 564 | |
Ryan Prichard | 9729f35 | 2018-07-13 22:40:26 -0700 | [diff] [blame] | 565 | /* Find the load bias and base address of an executable or shared object loaded |
| 566 | * by the kernel. The ELF file's PHDR table must have a PT_PHDR entry. |
| 567 | * |
| 568 | * A VDSO doesn't have a PT_PHDR entry in its PHDR table. |
| 569 | */ |
| 570 | static void get_elf_base_from_phdr(const ElfW(Phdr)* phdr_table, size_t phdr_count, |
| 571 | ElfW(Addr)* base, ElfW(Addr)* load_bias) { |
| 572 | for (size_t i = 0; i < phdr_count; ++i) { |
| 573 | if (phdr_table[i].p_type == PT_PHDR) { |
| 574 | *load_bias = reinterpret_cast<ElfW(Addr)>(phdr_table) - phdr_table[i].p_vaddr; |
| 575 | *base = reinterpret_cast<ElfW(Addr)>(phdr_table) - phdr_table[i].p_offset; |
| 576 | return; |
| 577 | } |
| 578 | } |
| 579 | async_safe_fatal("Could not find a PHDR: broken executable?"); |
| 580 | } |
| 581 | |
Vic Yang | 1bf62b2 | 2019-08-13 14:53:28 -0700 | [diff] [blame] | 582 | /* |
| 583 | * Set anonymous VMA name for .bss section. For DSOs loaded by the linker, this |
| 584 | * is done by ElfReader. This function is here for DSOs loaded by the kernel, |
| 585 | * namely the linker itself and the main executable. |
| 586 | */ |
| 587 | static void set_bss_vma_name(soinfo* si) { |
| 588 | for (size_t i = 0; i < si->phnum; ++i) { |
| 589 | auto phdr = &si->phdr[i]; |
| 590 | |
| 591 | if (phdr->p_type != PT_LOAD) { |
| 592 | continue; |
| 593 | } |
| 594 | |
| 595 | ElfW(Addr) seg_start = phdr->p_vaddr + si->load_bias; |
Peter Collingbourne | bb11ee6 | 2022-05-02 12:26:16 -0700 | [diff] [blame] | 596 | ElfW(Addr) seg_page_end = page_end(seg_start + phdr->p_memsz); |
| 597 | ElfW(Addr) seg_file_end = page_end(seg_start + phdr->p_filesz); |
Vic Yang | 1bf62b2 | 2019-08-13 14:53:28 -0700 | [diff] [blame] | 598 | |
| 599 | if (seg_page_end > seg_file_end) { |
| 600 | prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME, |
| 601 | reinterpret_cast<void*>(seg_file_end), seg_page_end - seg_file_end, |
| 602 | ".bss"); |
| 603 | } |
| 604 | } |
| 605 | } |
| 606 | |
Ryan Prichard | 249757b | 2019-11-01 17:18:28 -0700 | [diff] [blame] | 607 | #if defined(USE_RELA) |
Peter Collingbourne | 1583cd2 | 2021-08-18 17:04:23 -0700 | [diff] [blame] | 608 | using RelType = ElfW(Rela); |
| 609 | const unsigned kRelTag = DT_RELA; |
| 610 | const unsigned kRelSzTag = DT_RELASZ; |
Ryan Prichard | 249757b | 2019-11-01 17:18:28 -0700 | [diff] [blame] | 611 | #else |
Peter Collingbourne | 1583cd2 | 2021-08-18 17:04:23 -0700 | [diff] [blame] | 612 | using RelType = ElfW(Rel); |
| 613 | const unsigned kRelTag = DT_REL; |
| 614 | const unsigned kRelSzTag = DT_RELSZ; |
| 615 | #endif |
Ryan Prichard | 249757b | 2019-11-01 17:18:28 -0700 | [diff] [blame] | 616 | |
Evgenii Stepanov | 6bbb75a | 2023-12-06 18:54:45 +0000 | [diff] [blame] | 617 | extern __LIBC_HIDDEN__ ElfW(Ehdr) __ehdr_start; |
Peter Collingbourne | 1583cd2 | 2021-08-18 17:04:23 -0700 | [diff] [blame] | 618 | |
| 619 | static void call_ifunc_resolvers_for_section(RelType* begin, RelType* end) { |
| 620 | auto ehdr = reinterpret_cast<ElfW(Addr)>(&__ehdr_start); |
| 621 | for (RelType *r = begin; r != end; ++r) { |
| 622 | if (ELFW(R_TYPE)(r->r_info) != R_GENERIC_IRELATIVE) { |
| 623 | continue; |
| 624 | } |
| 625 | ElfW(Addr)* offset = reinterpret_cast<ElfW(Addr)*>(ehdr + r->r_offset); |
| 626 | #if defined(USE_RELA) |
| 627 | ElfW(Addr) resolver = ehdr + r->r_addend; |
| 628 | #else |
| 629 | ElfW(Addr) resolver = ehdr + *offset; |
| 630 | #endif |
Ryan Prichard | 249757b | 2019-11-01 17:18:28 -0700 | [diff] [blame] | 631 | *offset = __bionic_call_ifunc_resolver(resolver); |
| 632 | } |
| 633 | } |
Peter Collingbourne | 1583cd2 | 2021-08-18 17:04:23 -0700 | [diff] [blame] | 634 | |
Ryan Prichard | 2a901e6 | 2024-04-04 03:05:35 -0700 | [diff] [blame] | 635 | static void relocate_linker() { |
| 636 | // The linker should only have relative relocations (in RELR) and IRELATIVE |
| 637 | // relocations. Find the IRELATIVE relocations using the DT_JMPREL and |
| 638 | // DT_PLTRELSZ, or DT_RELA/DT_RELASZ (DT_REL/DT_RELSZ on ILP32). |
Peter Collingbourne | 1583cd2 | 2021-08-18 17:04:23 -0700 | [diff] [blame] | 639 | auto ehdr = reinterpret_cast<ElfW(Addr)>(&__ehdr_start); |
| 640 | auto* phdr = reinterpret_cast<ElfW(Phdr)*>(ehdr + __ehdr_start.e_phoff); |
| 641 | for (size_t i = 0; i != __ehdr_start.e_phnum; ++i) { |
| 642 | if (phdr[i].p_type != PT_DYNAMIC) { |
| 643 | continue; |
| 644 | } |
| 645 | auto *dyn = reinterpret_cast<ElfW(Dyn)*>(ehdr + phdr[i].p_vaddr); |
Ryan Prichard | 2a901e6 | 2024-04-04 03:05:35 -0700 | [diff] [blame] | 646 | ElfW(Addr) relr = 0, relrsz = 0, pltrel = 0, pltrelsz = 0, rel = 0, relsz = 0; |
Peter Collingbourne | 1583cd2 | 2021-08-18 17:04:23 -0700 | [diff] [blame] | 647 | for (size_t j = 0, size = phdr[i].p_filesz / sizeof(ElfW(Dyn)); j != size; ++j) { |
Ryan Prichard | 2a901e6 | 2024-04-04 03:05:35 -0700 | [diff] [blame] | 648 | const auto tag = dyn[j].d_tag; |
| 649 | const auto val = dyn[j].d_un.d_ptr; |
Elliott Hughes | f67f27b | 2024-03-28 14:54:30 +0000 | [diff] [blame] | 650 | // We don't currently handle IRELATIVE relocations in DT_ANDROID_REL[A]. |
Peter Collingbourne | c630da5 | 2024-03-26 13:24:06 -0700 | [diff] [blame] | 651 | // We disabled DT_ANDROID_REL[A] at build time; verify that it was actually disabled. |
Ryan Prichard | 2a901e6 | 2024-04-04 03:05:35 -0700 | [diff] [blame] | 652 | CHECK(tag != DT_ANDROID_REL && tag != DT_ANDROID_RELA); |
| 653 | if (tag == DT_RELR || tag == DT_ANDROID_RELR) { |
| 654 | relr = val; |
| 655 | } else if (tag == DT_RELRSZ || tag == DT_ANDROID_RELRSZ) { |
| 656 | relrsz = val; |
| 657 | } else if (tag == DT_JMPREL) { |
| 658 | pltrel = val; |
| 659 | } else if (tag == DT_PLTRELSZ) { |
| 660 | pltrelsz = val; |
| 661 | } else if (tag == kRelTag) { |
| 662 | rel = val; |
| 663 | } else if (tag == kRelSzTag) { |
| 664 | relsz = val; |
Peter Collingbourne | 1583cd2 | 2021-08-18 17:04:23 -0700 | [diff] [blame] | 665 | } |
| 666 | } |
Ryan Prichard | 2a901e6 | 2024-04-04 03:05:35 -0700 | [diff] [blame] | 667 | // Apply RELR relocations first so that the GOT is initialized for ifunc |
| 668 | // resolvers. |
| 669 | if (relr && relrsz) { |
| 670 | relocate_relr(reinterpret_cast<ElfW(Relr*)>(ehdr + relr), |
| 671 | reinterpret_cast<ElfW(Relr*)>(ehdr + relr + relrsz), ehdr); |
| 672 | } |
Peter Collingbourne | 1583cd2 | 2021-08-18 17:04:23 -0700 | [diff] [blame] | 673 | if (pltrel && pltrelsz) { |
| 674 | call_ifunc_resolvers_for_section(reinterpret_cast<RelType*>(ehdr + pltrel), |
| 675 | reinterpret_cast<RelType*>(ehdr + pltrel + pltrelsz)); |
| 676 | } |
| 677 | if (rel && relsz) { |
| 678 | call_ifunc_resolvers_for_section(reinterpret_cast<RelType*>(ehdr + rel), |
| 679 | reinterpret_cast<RelType*>(ehdr + rel + relsz)); |
| 680 | } |
| 681 | } |
| 682 | } |
Ryan Prichard | 249757b | 2019-11-01 17:18:28 -0700 | [diff] [blame] | 683 | |
Ryan Prichard | 94a8e85 | 2019-11-05 14:19:18 -0800 | [diff] [blame] | 684 | // Usable before ifunc resolvers have been called. This function is compiled with -ffreestanding. |
| 685 | static void linker_memclr(void* dst, size_t cnt) { |
| 686 | for (size_t i = 0; i < cnt; ++i) { |
| 687 | reinterpret_cast<char*>(dst)[i] = '\0'; |
| 688 | } |
| 689 | } |
| 690 | |
Ryan Prichard | 1990ba5 | 2019-02-07 21:31:31 -0800 | [diff] [blame] | 691 | // Detect an attempt to run the linker on itself. e.g.: |
| 692 | // /system/bin/linker64 /system/bin/linker64 |
| 693 | // Use priority-1 to run this constructor before other constructors. |
| 694 | __attribute__((constructor(1))) static void detect_self_exec() { |
| 695 | // Normally, the linker initializes the auxv global before calling its |
| 696 | // constructors. If the linker loads itself, though, the first loader calls |
| 697 | // the second loader's constructors before calling __linker_init. |
| 698 | if (__libc_shared_globals()->auxv != nullptr) { |
| 699 | return; |
| 700 | } |
| 701 | #if defined(__i386__) |
| 702 | // We don't have access to the auxv struct from here, so use the int 0x80 |
| 703 | // fallback. |
| 704 | __libc_sysinfo = reinterpret_cast<void*>(__libc_int0x80); |
| 705 | #endif |
| 706 | __linker_error("error: linker cannot load itself\n"); |
| 707 | } |
| 708 | |
Ryan Prichard | 742982d | 2018-05-30 22:32:17 -0700 | [diff] [blame] | 709 | static ElfW(Addr) __attribute__((noinline)) |
Ryan Prichard | 0489645 | 2018-08-20 17:44:42 -0700 | [diff] [blame] | 710 | __linker_init_post_relocation(KernelArgumentBlock& args, soinfo& linker_so); |
Ryan Prichard | 742982d | 2018-05-30 22:32:17 -0700 | [diff] [blame] | 711 | |
Dimitry Ivanov | 3f66057 | 2016-09-09 10:00:39 -0700 | [diff] [blame] | 712 | /* |
| 713 | * This is the entry point for the linker, called from begin.S. This |
| 714 | * method is responsible for fixing the linker's own relocations, and |
| 715 | * then calling __linker_init_post_relocation(). |
| 716 | * |
| 717 | * Because this method is called before the linker has fixed it's own |
| 718 | * relocations, any attempt to reference an extern variable, extern |
| 719 | * function, or other GOT reference will generate a segfault. |
| 720 | */ |
| 721 | extern "C" ElfW(Addr) __linker_init(void* raw_args) { |
Ryan Prichard | 67e8f22 | 2023-08-18 16:21:48 -0700 | [diff] [blame] | 722 | // Unlock the loader mutex immediately before transferring to the executable's |
| 723 | // entry point. This must happen after destructors are called in this function |
| 724 | // (e.g. ~soinfo), so declare this variable very early. |
| 725 | struct DlMutexUnlocker { |
| 726 | ~DlMutexUnlocker() { pthread_mutex_unlock(&g_dl_mutex); } |
| 727 | } unlocker; |
| 728 | |
Ryan Prichard | 9cfca86 | 2018-11-22 02:44:09 -0800 | [diff] [blame] | 729 | // Initialize TLS early so system calls and errno work. |
Dimitry Ivanov | 3f66057 | 2016-09-09 10:00:39 -0700 | [diff] [blame] | 730 | KernelArgumentBlock args(raw_args); |
Ryan Prichard | 94a8e85 | 2019-11-05 14:19:18 -0800 | [diff] [blame] | 731 | bionic_tcb temp_tcb __attribute__((uninitialized)); |
| 732 | linker_memclr(&temp_tcb, sizeof(temp_tcb)); |
Ryan Prichard | 45d1349 | 2019-01-03 02:51:30 -0800 | [diff] [blame] | 733 | __libc_init_main_thread_early(args, &temp_tcb); |
Ryan Prichard | 27475b5 | 2018-05-17 17:14:18 -0700 | [diff] [blame] | 734 | |
Ryan Prichard | 8f639a4 | 2018-10-01 23:10:05 -0700 | [diff] [blame] | 735 | // When the linker is run by itself (rather than as an interpreter for |
| 736 | // another program), AT_BASE is 0. |
Ryan Prichard | 07440a8 | 2018-11-22 03:16:06 -0800 | [diff] [blame] | 737 | ElfW(Addr) linker_addr = getauxval(AT_BASE); |
Ryan Prichard | 9729f35 | 2018-07-13 22:40:26 -0700 | [diff] [blame] | 738 | if (linker_addr == 0) { |
Ryan Prichard | 1990ba5 | 2019-02-07 21:31:31 -0800 | [diff] [blame] | 739 | // The AT_PHDR and AT_PHNUM aux values describe this linker instance, so use |
| 740 | // the phdr to find the linker's base address. |
Ryan Prichard | 9729f35 | 2018-07-13 22:40:26 -0700 | [diff] [blame] | 741 | ElfW(Addr) load_bias; |
| 742 | get_elf_base_from_phdr( |
Ryan Prichard | 07440a8 | 2018-11-22 03:16:06 -0800 | [diff] [blame] | 743 | reinterpret_cast<ElfW(Phdr)*>(getauxval(AT_PHDR)), getauxval(AT_PHNUM), |
Ryan Prichard | 9729f35 | 2018-07-13 22:40:26 -0700 | [diff] [blame] | 744 | &linker_addr, &load_bias); |
| 745 | } |
George Burgess IV | 7059100 | 2017-06-27 16:23:45 -0700 | [diff] [blame] | 746 | |
Dimitry Ivanov | 3f66057 | 2016-09-09 10:00:39 -0700 | [diff] [blame] | 747 | ElfW(Ehdr)* elf_hdr = reinterpret_cast<ElfW(Ehdr)*>(linker_addr); |
| 748 | ElfW(Phdr)* phdr = reinterpret_cast<ElfW(Phdr)*>(linker_addr + elf_hdr->e_phoff); |
| 749 | |
Ryan Prichard | 2a901e6 | 2024-04-04 03:05:35 -0700 | [diff] [blame] | 750 | // Relocate the linker. This step will initialize the GOT, which is needed for |
| 751 | // accessing non-hidden global variables. (On some targets, the stack |
| 752 | // protector uses GOT accesses rather than TLS.) Relocating the linker will |
| 753 | // also call the linker's ifunc resolvers so that string.h functions can be |
| 754 | // used. |
| 755 | relocate_linker(); |
Ryan Prichard | 249757b | 2019-11-01 17:18:28 -0700 | [diff] [blame] | 756 | |
Ryan Prichard | 0489645 | 2018-08-20 17:44:42 -0700 | [diff] [blame] | 757 | soinfo tmp_linker_so(nullptr, nullptr, nullptr, 0, 0); |
Dimitry Ivanov | 3f66057 | 2016-09-09 10:00:39 -0700 | [diff] [blame] | 758 | |
Ryan Prichard | 0489645 | 2018-08-20 17:44:42 -0700 | [diff] [blame] | 759 | tmp_linker_so.base = linker_addr; |
| 760 | tmp_linker_so.size = phdr_table_get_load_size(phdr, elf_hdr->e_phnum); |
Peter Collingbourne | 1583cd2 | 2021-08-18 17:04:23 -0700 | [diff] [blame] | 761 | tmp_linker_so.load_bias = get_elf_exec_load_bias(elf_hdr); |
Ryan Prichard | 0489645 | 2018-08-20 17:44:42 -0700 | [diff] [blame] | 762 | tmp_linker_so.dynamic = nullptr; |
| 763 | tmp_linker_so.phdr = phdr; |
| 764 | tmp_linker_so.phnum = elf_hdr->e_phnum; |
| 765 | tmp_linker_so.set_linker_flag(); |
Dimitry Ivanov | 3f66057 | 2016-09-09 10:00:39 -0700 | [diff] [blame] | 766 | |
Ryan Prichard | 0489645 | 2018-08-20 17:44:42 -0700 | [diff] [blame] | 767 | if (!tmp_linker_so.prelink_image()) __linker_cannot_link(args.argv[0]); |
Ryan Prichard | 339ecef | 2020-01-02 16:36:06 -0800 | [diff] [blame] | 768 | if (!tmp_linker_so.link_image(SymbolLookupList(&tmp_linker_so), &tmp_linker_so, nullptr, nullptr)) __linker_cannot_link(args.argv[0]); |
Dimitry Ivanov | 3f66057 | 2016-09-09 10:00:39 -0700 | [diff] [blame] | 769 | |
Ryan Prichard | 0489645 | 2018-08-20 17:44:42 -0700 | [diff] [blame] | 770 | return __linker_init_post_relocation(args, tmp_linker_so); |
Ryan Prichard | 742982d | 2018-05-30 22:32:17 -0700 | [diff] [blame] | 771 | } |
| 772 | |
| 773 | /* |
| 774 | * This code is called after the linker has linked itself and fixed its own |
| 775 | * GOT. It is safe to make references to externs and other non-local data at |
| 776 | * this point. The compiler sometimes moves GOT references earlier in a |
| 777 | * function, so avoid inlining this function (http://b/80503879). |
| 778 | */ |
| 779 | static ElfW(Addr) __attribute__((noinline)) |
Ryan Prichard | 0489645 | 2018-08-20 17:44:42 -0700 | [diff] [blame] | 780 | __linker_init_post_relocation(KernelArgumentBlock& args, soinfo& tmp_linker_so) { |
Ryan Prichard | 9cfca86 | 2018-11-22 02:44:09 -0800 | [diff] [blame] | 781 | // Finish initializing the main thread. |
Ryan Prichard | 07440a8 | 2018-11-22 03:16:06 -0800 | [diff] [blame] | 782 | __libc_init_main_thread_late(); |
Dimitry Ivanov | 3f66057 | 2016-09-09 10:00:39 -0700 | [diff] [blame] | 783 | |
| 784 | // We didn't protect the linker's RELRO pages in link_image because we |
| 785 | // couldn't make system calls on x86 at that point, but we can now... |
Ryan Prichard | 0489645 | 2018-08-20 17:44:42 -0700 | [diff] [blame] | 786 | if (!tmp_linker_so.protect_relro()) __linker_cannot_link(args.argv[0]); |
Dimitry Ivanov | 3f66057 | 2016-09-09 10:00:39 -0700 | [diff] [blame] | 787 | |
Vic Yang | 1bf62b2 | 2019-08-13 14:53:28 -0700 | [diff] [blame] | 788 | // And we can set VMA name for the bss section now |
| 789 | set_bss_vma_name(&tmp_linker_so); |
| 790 | |
Dimitry Ivanov | 3f66057 | 2016-09-09 10:00:39 -0700 | [diff] [blame] | 791 | // Initialize the linker's static libc's globals |
Ryan Prichard | 07440a8 | 2018-11-22 03:16:06 -0800 | [diff] [blame] | 792 | __libc_init_globals(); |
Dimitry Ivanov | 3f66057 | 2016-09-09 10:00:39 -0700 | [diff] [blame] | 793 | |
Ryan Prichard | 67e8f22 | 2023-08-18 16:21:48 -0700 | [diff] [blame] | 794 | // A constructor could spawn a thread that calls into the loader, so as soon |
| 795 | // as we've called a constructor, we need to hold the lock until transferring |
| 796 | // to the entry point. |
| 797 | pthread_mutex_lock(&g_dl_mutex); |
| 798 | |
Dimitry Ivanov | 3f66057 | 2016-09-09 10:00:39 -0700 | [diff] [blame] | 799 | // Initialize the linker's own global variables |
Ryan Prichard | 0489645 | 2018-08-20 17:44:42 -0700 | [diff] [blame] | 800 | tmp_linker_so.call_constructors(); |
Dimitry Ivanov | 3f66057 | 2016-09-09 10:00:39 -0700 | [diff] [blame] | 801 | |
Ryan Prichard | bb1e373 | 2021-01-12 23:09:10 -0800 | [diff] [blame] | 802 | // Setting the linker soinfo's soname can allocate heap memory, so delay it until here. |
| 803 | for (const ElfW(Dyn)* d = tmp_linker_so.dynamic; d->d_tag != DT_NULL; ++d) { |
| 804 | if (d->d_tag == DT_SONAME) { |
| 805 | tmp_linker_so.set_soname(tmp_linker_so.get_string(d->d_un.d_val)); |
| 806 | } |
| 807 | } |
| 808 | |
Ryan Prichard | 8f639a4 | 2018-10-01 23:10:05 -0700 | [diff] [blame] | 809 | // When the linker is run directly rather than acting as PT_INTERP, parse |
| 810 | // arguments and determine the executable to load. When it's instead acting |
| 811 | // as PT_INTERP, AT_ENTRY will refer to the loaded executable rather than the |
| 812 | // linker's _start. |
| 813 | const char* exe_to_load = nullptr; |
Ryan Prichard | 07440a8 | 2018-11-22 03:16:06 -0800 | [diff] [blame] | 814 | if (getauxval(AT_ENTRY) == reinterpret_cast<uintptr_t>(&_start)) { |
Elliott Hughes | 90f96b9 | 2019-05-09 15:56:39 -0700 | [diff] [blame] | 815 | if (args.argc == 3 && !strcmp(args.argv[1], "--list")) { |
| 816 | // We're being asked to behave like ldd(1). |
| 817 | g_is_ldd = true; |
| 818 | exe_to_load = args.argv[2]; |
| 819 | } else if (args.argc <= 1 || !strcmp(args.argv[1], "--help")) { |
Ryan Prichard | 8f639a4 | 2018-10-01 23:10:05 -0700 | [diff] [blame] | 820 | async_safe_format_fd(STDOUT_FILENO, |
Elliott Hughes | 90f96b9 | 2019-05-09 15:56:39 -0700 | [diff] [blame] | 821 | "Usage: %s [--list] PROGRAM [ARGS-FOR-PROGRAM...]\n" |
| 822 | " %s [--list] path.zip!/PROGRAM [ARGS-FOR-PROGRAM...]\n" |
Ryan Prichard | 8f639a4 | 2018-10-01 23:10:05 -0700 | [diff] [blame] | 823 | "\n" |
| 824 | "A helper program for linking dynamic executables. Typically, the kernel loads\n" |
| 825 | "this program because it's the PT_INTERP of a dynamic executable.\n" |
| 826 | "\n" |
| 827 | "This program can also be run directly to load and run a dynamic executable. The\n" |
| 828 | "executable can be inside a zip file if it's stored uncompressed and at a\n" |
Elliott Hughes | 90f96b9 | 2019-05-09 15:56:39 -0700 | [diff] [blame] | 829 | "page-aligned offset.\n" |
| 830 | "\n" |
| 831 | "The --list option gives behavior equivalent to ldd(1) on other systems.\n", |
Ryan Prichard | 8f639a4 | 2018-10-01 23:10:05 -0700 | [diff] [blame] | 832 | args.argv[0], args.argv[0]); |
Elliott Hughes | 90f96b9 | 2019-05-09 15:56:39 -0700 | [diff] [blame] | 833 | _exit(EXIT_SUCCESS); |
| 834 | } else { |
| 835 | exe_to_load = args.argv[1]; |
| 836 | __libc_shared_globals()->initial_linker_arg_count = 1; |
Ryan Prichard | 8f639a4 | 2018-10-01 23:10:05 -0700 | [diff] [blame] | 837 | } |
Dimitry Ivanov | 9b1cc4b | 2017-03-23 16:17:15 -0700 | [diff] [blame] | 838 | } |
| 839 | |
Ryan Prichard | 8f639a4 | 2018-10-01 23:10:05 -0700 | [diff] [blame] | 840 | // store argc/argv/envp to use them for calling constructors |
Ryan Prichard | abf736a | 2018-11-22 02:40:17 -0800 | [diff] [blame] | 841 | g_argc = args.argc - __libc_shared_globals()->initial_linker_arg_count; |
| 842 | g_argv = args.argv + __libc_shared_globals()->initial_linker_arg_count; |
Ryan Prichard | 8f639a4 | 2018-10-01 23:10:05 -0700 | [diff] [blame] | 843 | g_envp = args.envp; |
Ryan Prichard | 48b1159 | 2018-11-22 02:41:36 -0800 | [diff] [blame] | 844 | __libc_shared_globals()->init_progname = g_argv[0]; |
Ryan Prichard | 8f639a4 | 2018-10-01 23:10:05 -0700 | [diff] [blame] | 845 | |
Dimitry Ivanov | 3f66057 | 2016-09-09 10:00:39 -0700 | [diff] [blame] | 846 | // Initialize static variables. Note that in order to |
| 847 | // get correct libdl_info we need to call constructors |
| 848 | // before get_libdl_info(). |
Ryan Prichard | cf9ed12 | 2019-06-04 20:56:56 -0700 | [diff] [blame] | 849 | sonext = solist = solinker = get_libdl_info(tmp_linker_so); |
Ryan Prichard | 0489645 | 2018-08-20 17:44:42 -0700 | [diff] [blame] | 850 | g_default_namespace.add_soinfo(solinker); |
Dimitry Ivanov | 3f66057 | 2016-09-09 10:00:39 -0700 | [diff] [blame] | 851 | |
Ryan Prichard | 8f639a4 | 2018-10-01 23:10:05 -0700 | [diff] [blame] | 852 | ElfW(Addr) start_address = linker_main(args, exe_to_load); |
Dimitry Ivanov | 3f66057 | 2016-09-09 10:00:39 -0700 | [diff] [blame] | 853 | |
Dimitry Ivanov | 3f66057 | 2016-09-09 10:00:39 -0700 | [diff] [blame] | 854 | INFO("[ Jumping to _start (%p)... ]", reinterpret_cast<void*>(start_address)); |
| 855 | |
| 856 | // Return the address that the calling assembly stub should jump to. |
| 857 | return start_address; |
| 858 | } |