| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 1 | /* | 
 | 2 |  * Copyright (C) 2008 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 | #ifndef _LINKER_H_ | 
 | 30 | #define _LINKER_H_ | 
 | 31 |  | 
| Nick Kralevich | 9ec0f03 | 2012-02-28 10:40:00 -0800 | [diff] [blame] | 32 | #include <elf.h> | 
| Dmitriy Ivanov | 0d15094 | 2014-08-22 12:25:04 -0700 | [diff] [blame] | 33 | #include <inttypes.h> | 
| Pavel Chupin | b7beb69 | 2012-08-17 12:53:29 +0400 | [diff] [blame] | 34 | #include <link.h> | 
| Elliott Hughes | 1272dbd | 2014-01-09 15:45:07 -0800 | [diff] [blame] | 35 | #include <unistd.h> | 
| Torne (Richard Coles) | 012cb45 | 2014-02-06 14:34:21 +0000 | [diff] [blame] | 36 | #include <android/dlext.h> | 
| Dmitriy Ivanov | d59e500 | 2014-05-09 09:10:14 -0700 | [diff] [blame] | 37 | #include <sys/stat.h> | 
| Elliott Hughes | 4688279 | 2012-08-03 16:49:39 -0700 | [diff] [blame] | 38 |  | 
| Elliott Hughes | 8f2a5a0 | 2013-03-15 15:30:25 -0700 | [diff] [blame] | 39 | #include "private/libc_logging.h" | 
| Dmitriy Ivanov | d59e500 | 2014-05-09 09:10:14 -0700 | [diff] [blame] | 40 | #include "linked_list.h" | 
| Elliott Hughes | 650be4e | 2013-03-05 18:47:58 -0800 | [diff] [blame] | 41 |  | 
| Dmitriy Ivanov | aae859c | 2015-03-31 11:14:03 -0700 | [diff] [blame] | 42 | #include <string> | 
| Dmitriy Ivanov | 2a81536 | 2015-04-09 13:42:33 -0700 | [diff] [blame] | 43 | #include <vector> | 
| Dmitriy Ivanov | aae859c | 2015-03-31 11:14:03 -0700 | [diff] [blame] | 44 |  | 
| Elliott Hughes | 650be4e | 2013-03-05 18:47:58 -0800 | [diff] [blame] | 45 | #define DL_ERR(fmt, x...) \ | 
 | 46 |     do { \ | 
 | 47 |       __libc_format_buffer(linker_get_error_buffer(), linker_get_error_buffer_size(), fmt, ##x); \ | 
 | 48 |       /* If LD_DEBUG is set high enough, log every dlerror(3) message. */ \ | 
 | 49 |       DEBUG("%s\n", linker_get_error_buffer()); \ | 
| Elliott Hughes | 7e5a8cc | 2013-06-18 13:15:00 -0700 | [diff] [blame] | 50 |     } while (false) | 
 | 51 |  | 
 | 52 | #define DL_WARN(fmt, x...) \ | 
 | 53 |     do { \ | 
 | 54 |       __libc_format_log(ANDROID_LOG_WARN, "linker", fmt, ##x); \ | 
 | 55 |       __libc_format_fd(2, "WARNING: linker: "); \ | 
 | 56 |       __libc_format_fd(2, fmt, ##x); \ | 
 | 57 |       __libc_format_fd(2, "\n"); \ | 
 | 58 |     } while (false) | 
 | 59 |  | 
| Elliott Hughes | 0266ae5 | 2014-02-10 17:46:57 -0800 | [diff] [blame] | 60 | #if defined(__LP64__) | 
 | 61 | #define ELFW(what) ELF64_ ## what | 
 | 62 | #else | 
 | 63 | #define ELFW(what) ELF32_ ## what | 
 | 64 | #endif | 
| Elliott Hughes | 650be4e | 2013-03-05 18:47:58 -0800 | [diff] [blame] | 65 |  | 
| Chris Dearman | 9918665 | 2014-02-06 20:36:51 -0800 | [diff] [blame] | 66 | // mips64 interprets Elf64_Rel structures' r_info field differently. | 
 | 67 | // bionic (like other C libraries) has macros that assume regular ELF files, | 
 | 68 | // but the dynamic linker needs to be able to load mips64 ELF files. | 
 | 69 | #if defined(__mips__) && defined(__LP64__) | 
 | 70 | #undef ELF64_R_SYM | 
 | 71 | #undef ELF64_R_TYPE | 
 | 72 | #undef ELF64_R_INFO | 
 | 73 | #define ELF64_R_SYM(info)   (((info) >> 0) & 0xffffffff) | 
 | 74 | #define ELF64_R_SSYM(info)  (((info) >> 32) & 0xff) | 
 | 75 | #define ELF64_R_TYPE3(info) (((info) >> 40) & 0xff) | 
 | 76 | #define ELF64_R_TYPE2(info) (((info) >> 48) & 0xff) | 
 | 77 | #define ELF64_R_TYPE(info)  (((info) >> 56) & 0xff) | 
 | 78 | #endif | 
 | 79 |  | 
| Elliott Hughes | 1a69616 | 2012-11-01 13:49:32 -0700 | [diff] [blame] | 80 | // Returns the address of the page containing address 'x'. | 
 | 81 | #define PAGE_START(x)  ((x) & PAGE_MASK) | 
| David 'Digit' Turner | c1bd559 | 2012-06-19 11:21:29 +0200 | [diff] [blame] | 82 |  | 
| Elliott Hughes | 1a69616 | 2012-11-01 13:49:32 -0700 | [diff] [blame] | 83 | // Returns the offset of address 'x' in its page. | 
 | 84 | #define PAGE_OFFSET(x) ((x) & ~PAGE_MASK) | 
| David 'Digit' Turner | c1bd559 | 2012-06-19 11:21:29 +0200 | [diff] [blame] | 85 |  | 
| Elliott Hughes | 1a69616 | 2012-11-01 13:49:32 -0700 | [diff] [blame] | 86 | // Returns the address of the next page after address 'x', unless 'x' is | 
 | 87 | // itself at the start of a page. | 
| David 'Digit' Turner | c1bd559 | 2012-06-19 11:21:29 +0200 | [diff] [blame] | 88 | #define PAGE_END(x)    PAGE_START((x) + (PAGE_SIZE-1)) | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 89 |  | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 90 | #define FLAG_LINKED     0x00000001 | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 91 | #define FLAG_EXE        0x00000004 // The main executable | 
| Nick Kralevich | 468319c | 2011-11-11 15:53:17 -0800 | [diff] [blame] | 92 | #define FLAG_LINKER     0x00000010 // The linker itself | 
| Dmitriy Ivanov | ec18ce0 | 2014-11-09 19:27:20 -0800 | [diff] [blame] | 93 | #define FLAG_GNU_HASH   0x00000040 // uses gnu hash | 
| Dmitriy Ivanov | d59e500 | 2014-05-09 09:10:14 -0700 | [diff] [blame] | 94 | #define FLAG_NEW_SOINFO 0x40000000 // new soinfo format | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 95 |  | 
| Dmitriy Ivanov | d225a5e | 2014-08-28 14:12:12 -0700 | [diff] [blame] | 96 | #define SUPPORTED_DT_FLAGS_1 (DF_1_NOW | DF_1_GLOBAL | DF_1_NODELETE) | 
 | 97 |  | 
| Dmitriy Ivanov | 618f1a3 | 2015-03-17 20:06:36 -0700 | [diff] [blame] | 98 | #define SOINFO_VERSION 2 | 
| Dmitriy Ivanov | 0d15094 | 2014-08-22 12:25:04 -0700 | [diff] [blame] | 99 |  | 
| Dmitriy Ivanov | aae859c | 2015-03-31 11:14:03 -0700 | [diff] [blame] | 100 | #if defined(__arm__) | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 101 | #define SOINFO_NAME_LEN 128 | 
| Dmitriy Ivanov | aae859c | 2015-03-31 11:14:03 -0700 | [diff] [blame] | 102 | #endif | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 103 |  | 
| Elliott Hughes | ca0c11b | 2013-03-12 10:40:45 -0700 | [diff] [blame] | 104 | typedef void (*linker_function_t)(); | 
 | 105 |  | 
| Chris Dearman | 9918665 | 2014-02-06 20:36:51 -0800 | [diff] [blame] | 106 | // Android uses RELA for aarch64 and x86_64. mips64 still uses REL. | 
 | 107 | #if defined(__aarch64__) || defined(__x86_64__) | 
| Elliott Hughes | 4eeb1f1 | 2013-10-25 17:38:02 -0700 | [diff] [blame] | 108 | #define USE_RELA 1 | 
 | 109 | #endif | 
 | 110 |  | 
| Dmitriy Ivanov | d59e500 | 2014-05-09 09:10:14 -0700 | [diff] [blame] | 111 | struct soinfo; | 
 | 112 |  | 
 | 113 | class SoinfoListAllocator { | 
| Dmitriy Ivanov | ec18ce0 | 2014-11-09 19:27:20 -0800 | [diff] [blame] | 114 |  public: | 
| Dmitriy Ivanov | d59e500 | 2014-05-09 09:10:14 -0700 | [diff] [blame] | 115 |   static LinkedListEntry<soinfo>* alloc(); | 
 | 116 |   static void free(LinkedListEntry<soinfo>* entry); | 
| Dmitriy Ivanov | ec18ce0 | 2014-11-09 19:27:20 -0800 | [diff] [blame] | 117 |  | 
 | 118 |  private: | 
| Dmitriy Ivanov | d59e500 | 2014-05-09 09:10:14 -0700 | [diff] [blame] | 119 |   // unconstructable | 
 | 120 |   DISALLOW_IMPLICIT_CONSTRUCTORS(SoinfoListAllocator); | 
 | 121 | }; | 
 | 122 |  | 
| Dmitriy Ivanov | ec18ce0 | 2014-11-09 19:27:20 -0800 | [diff] [blame] | 123 | class SymbolName { | 
 | 124 |  public: | 
 | 125 |   explicit SymbolName(const char* name) | 
 | 126 |       : name_(name), has_elf_hash_(false), has_gnu_hash_(false), | 
 | 127 |         elf_hash_(0), gnu_hash_(0) { } | 
 | 128 |  | 
 | 129 |   const char* get_name() { | 
 | 130 |     return name_; | 
 | 131 |   } | 
 | 132 |  | 
 | 133 |   uint32_t elf_hash(); | 
 | 134 |   uint32_t gnu_hash(); | 
 | 135 |  | 
 | 136 |  private: | 
 | 137 |   const char* name_; | 
 | 138 |   bool has_elf_hash_; | 
 | 139 |   bool has_gnu_hash_; | 
 | 140 |   uint32_t elf_hash_; | 
 | 141 |   uint32_t gnu_hash_; | 
 | 142 |  | 
 | 143 |   DISALLOW_IMPLICIT_CONSTRUCTORS(SymbolName); | 
 | 144 | }; | 
 | 145 |  | 
| Dmitriy Ivanov | 2a81536 | 2015-04-09 13:42:33 -0700 | [diff] [blame] | 146 | struct version_info { | 
 | 147 |   version_info() : elf_hash(0), name(nullptr), target_si(nullptr) {} | 
 | 148 |  | 
 | 149 |   uint32_t elf_hash; | 
 | 150 |   const char* name; | 
 | 151 |   const soinfo* target_si; | 
 | 152 | }; | 
 | 153 |  | 
 | 154 | // Class used construct version dependency graph. | 
 | 155 | class VersionTracker { | 
 | 156 |  public: | 
 | 157 |   VersionTracker() = default; | 
 | 158 |   bool init(const soinfo* si_from); | 
 | 159 |  | 
 | 160 |   const version_info* get_version_info(ElfW(Versym) source_symver) const; | 
 | 161 |  private: | 
 | 162 |   bool init_verneed(const soinfo* si_from); | 
 | 163 |   bool init_verdef(const soinfo* si_from); | 
 | 164 |   void add_version_info(size_t source_index, ElfW(Word) elf_hash, | 
 | 165 |       const char* ver_name, const soinfo* target_si); | 
 | 166 |  | 
 | 167 |   std::vector<version_info> version_infos; | 
 | 168 |  | 
 | 169 |   DISALLOW_COPY_AND_ASSIGN(VersionTracker); | 
 | 170 | }; | 
 | 171 |  | 
| Elliott Hughes | 18a206c | 2012-10-29 17:37:13 -0700 | [diff] [blame] | 172 | struct soinfo { | 
| Elliott Hughes | ca0c11b | 2013-03-12 10:40:45 -0700 | [diff] [blame] | 173 |  public: | 
| Dmitriy Ivanov | d59e500 | 2014-05-09 09:10:14 -0700 | [diff] [blame] | 174 |   typedef LinkedList<soinfo, SoinfoListAllocator> soinfo_list_t; | 
| Dmitriy Ivanov | aae859c | 2015-03-31 11:14:03 -0700 | [diff] [blame] | 175 | #if defined(__arm__) | 
 | 176 |  private: | 
 | 177 |   char old_name_[SOINFO_NAME_LEN]; | 
 | 178 | #endif | 
| Dmitriy Ivanov | d59e500 | 2014-05-09 09:10:14 -0700 | [diff] [blame] | 179 |  public: | 
| Elliott Hughes | 0266ae5 | 2014-02-10 17:46:57 -0800 | [diff] [blame] | 180 |   const ElfW(Phdr)* phdr; | 
| Elliott Hughes | ca0c11b | 2013-03-12 10:40:45 -0700 | [diff] [blame] | 181 |   size_t phnum; | 
| Elliott Hughes | 0266ae5 | 2014-02-10 17:46:57 -0800 | [diff] [blame] | 182 |   ElfW(Addr) entry; | 
 | 183 |   ElfW(Addr) base; | 
| Weiwu Chen | 5ceb889 | 2013-12-03 19:47:34 +0800 | [diff] [blame] | 184 |   size_t size; | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 185 |  | 
| Dmitriy Ivanov | e631f91 | 2015-03-19 17:50:29 -0700 | [diff] [blame] | 186 | #if defined(__arm__) | 
| Elliott Hughes | ca0c11b | 2013-03-12 10:40:45 -0700 | [diff] [blame] | 187 |   uint32_t unused1;  // DO NOT USE, maintained for compatibility. | 
| Elliott Hughes | c620059 | 2013-09-30 18:43:46 -0700 | [diff] [blame] | 188 | #endif | 
| Nick Kralevich | 38bccb2 | 2011-08-29 13:49:22 -0700 | [diff] [blame] | 189 |  | 
| Elliott Hughes | 0266ae5 | 2014-02-10 17:46:57 -0800 | [diff] [blame] | 190 |   ElfW(Dyn)* dynamic; | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 191 |  | 
| Dmitriy Ivanov | e631f91 | 2015-03-19 17:50:29 -0700 | [diff] [blame] | 192 | #if defined(__arm__) | 
| Elliott Hughes | ca0c11b | 2013-03-12 10:40:45 -0700 | [diff] [blame] | 193 |   uint32_t unused2; // DO NOT USE, maintained for compatibility | 
 | 194 |   uint32_t unused3; // DO NOT USE, maintained for compatibility | 
| Elliott Hughes | c620059 | 2013-09-30 18:43:46 -0700 | [diff] [blame] | 195 | #endif | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 196 |  | 
| Elliott Hughes | d23736e | 2012-11-01 15:16:56 -0700 | [diff] [blame] | 197 |   soinfo* next; | 
| Dmitriy Ivanov | 6cdeb52 | 2014-09-29 19:14:45 -0700 | [diff] [blame] | 198 |  private: | 
| Dmitriy Ivanov | ab972b9 | 2014-11-29 13:57:41 -0800 | [diff] [blame] | 199 |   uint32_t flags_; | 
 | 200 |  | 
| Dmitriy Ivanov | 047b593 | 2014-11-13 09:39:20 -0800 | [diff] [blame] | 201 |   const char* strtab_; | 
 | 202 |   ElfW(Sym)* symtab_; | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 203 |  | 
| Dmitriy Ivanov | 047b593 | 2014-11-13 09:39:20 -0800 | [diff] [blame] | 204 |   size_t nbucket_; | 
 | 205 |   size_t nchain_; | 
 | 206 |   uint32_t* bucket_; | 
 | 207 |   uint32_t* chain_; | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 208 |  | 
| Chris Dearman | 9918665 | 2014-02-06 20:36:51 -0800 | [diff] [blame] | 209 | #if defined(__mips__) || !defined(__LP64__) | 
 | 210 |   // This is only used by mips and mips64, but needs to be here for | 
| Elliott Hughes | 4eeb1f1 | 2013-10-25 17:38:02 -0700 | [diff] [blame] | 211 |   // all 32-bit architectures to preserve binary compatibility. | 
| Dmitriy Ivanov | 047b593 | 2014-11-13 09:39:20 -0800 | [diff] [blame] | 212 |   ElfW(Addr)** plt_got_; | 
| Elliott Hughes | 4eeb1f1 | 2013-10-25 17:38:02 -0700 | [diff] [blame] | 213 | #endif | 
 | 214 |  | 
 | 215 | #if defined(USE_RELA) | 
| Dmitriy Ivanov | 047b593 | 2014-11-13 09:39:20 -0800 | [diff] [blame] | 216 |   ElfW(Rela)* plt_rela_; | 
 | 217 |   size_t plt_rela_count_; | 
| Elliott Hughes | c00f2cb | 2013-10-04 17:01:33 -0700 | [diff] [blame] | 218 |  | 
| Dmitriy Ivanov | 047b593 | 2014-11-13 09:39:20 -0800 | [diff] [blame] | 219 |   ElfW(Rela)* rela_; | 
 | 220 |   size_t rela_count_; | 
| Elliott Hughes | c00f2cb | 2013-10-04 17:01:33 -0700 | [diff] [blame] | 221 | #else | 
| Dmitriy Ivanov | 047b593 | 2014-11-13 09:39:20 -0800 | [diff] [blame] | 222 |   ElfW(Rel)* plt_rel_; | 
 | 223 |   size_t plt_rel_count_; | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 224 |  | 
| Dmitriy Ivanov | 047b593 | 2014-11-13 09:39:20 -0800 | [diff] [blame] | 225 |   ElfW(Rel)* rel_; | 
 | 226 |   size_t rel_count_; | 
| Elliott Hughes | c00f2cb | 2013-10-04 17:01:33 -0700 | [diff] [blame] | 227 | #endif | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 228 |  | 
| Dmitriy Ivanov | 047b593 | 2014-11-13 09:39:20 -0800 | [diff] [blame] | 229 |   linker_function_t* preinit_array_; | 
 | 230 |   size_t preinit_array_count_; | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 231 |  | 
| Dmitriy Ivanov | 047b593 | 2014-11-13 09:39:20 -0800 | [diff] [blame] | 232 |   linker_function_t* init_array_; | 
 | 233 |   size_t init_array_count_; | 
 | 234 |   linker_function_t* fini_array_; | 
 | 235 |   size_t fini_array_count_; | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 236 |  | 
| Dmitriy Ivanov | 047b593 | 2014-11-13 09:39:20 -0800 | [diff] [blame] | 237 |   linker_function_t init_func_; | 
 | 238 |   linker_function_t fini_func_; | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 239 |  | 
| Elliott Hughes | 4eeb1f1 | 2013-10-25 17:38:02 -0700 | [diff] [blame] | 240 | #if defined(__arm__) | 
| Dmitriy Ivanov | ab972b9 | 2014-11-29 13:57:41 -0800 | [diff] [blame] | 241 |  public: | 
| Elliott Hughes | d23736e | 2012-11-01 15:16:56 -0700 | [diff] [blame] | 242 |   // ARM EABI section used for stack unwinding. | 
| Dmitriy Ivanov | 1b20daf | 2014-05-19 15:06:58 -0700 | [diff] [blame] | 243 |   uint32_t* ARM_exidx; | 
| Elliott Hughes | ca0c11b | 2013-03-12 10:40:45 -0700 | [diff] [blame] | 244 |   size_t ARM_exidx_count; | 
| Dmitriy Ivanov | 8894091 | 2014-11-12 18:20:39 -0800 | [diff] [blame] | 245 |  private: | 
| Dmitriy Ivanov | ab972b9 | 2014-11-29 13:57:41 -0800 | [diff] [blame] | 246 | #elif defined(__mips__) | 
| Dmitriy Ivanov | 047b593 | 2014-11-13 09:39:20 -0800 | [diff] [blame] | 247 |   uint32_t mips_symtabno_; | 
 | 248 |   uint32_t mips_local_gotno_; | 
 | 249 |   uint32_t mips_gotsym_; | 
| Dmitriy Ivanov | 8894091 | 2014-11-12 18:20:39 -0800 | [diff] [blame] | 250 |   bool mips_relocate_got(const soinfo_list_t& global_group, const soinfo_list_t& local_group); | 
 | 251 |  | 
| Elliott Hughes | d23736e | 2012-11-01 15:16:56 -0700 | [diff] [blame] | 252 | #endif | 
| Dmitriy Ivanov | ab972b9 | 2014-11-29 13:57:41 -0800 | [diff] [blame] | 253 |   size_t ref_count_; | 
| Dmitriy Ivanov | 047b593 | 2014-11-13 09:39:20 -0800 | [diff] [blame] | 254 |  public: | 
| Elliott Hughes | 3a9c5d6 | 2014-02-10 13:31:13 -0800 | [diff] [blame] | 255 |   link_map link_map_head; | 
| Evgeniy Stepanov | e83c56d | 2011-12-21 13:03:54 +0400 | [diff] [blame] | 256 |  | 
| Elliott Hughes | d23736e | 2012-11-01 15:16:56 -0700 | [diff] [blame] | 257 |   bool constructors_called; | 
| Nick Kralevich | 9ec0f03 | 2012-02-28 10:40:00 -0800 | [diff] [blame] | 258 |  | 
| Elliott Hughes | d23736e | 2012-11-01 15:16:56 -0700 | [diff] [blame] | 259 |   // When you read a virtual address from the ELF file, add this | 
 | 260 |   // value to get the corresponding address in the process' address space. | 
| Elliott Hughes | 0266ae5 | 2014-02-10 17:46:57 -0800 | [diff] [blame] | 261 |   ElfW(Addr) load_bias; | 
| Ard Biesheuvel | 5ae44f3 | 2012-08-30 12:48:32 +0200 | [diff] [blame] | 262 |  | 
| Dimitry Ivanov | 56be6ed | 2015-04-01 21:18:48 +0000 | [diff] [blame] | 263 | #if !defined(__LP64__) | 
 | 264 |   bool has_text_relocations; | 
| Elliott Hughes | e4d792a | 2013-10-28 14:19:05 -0700 | [diff] [blame] | 265 | #endif | 
| Dmitriy Ivanov | 96bc37f | 2014-09-29 12:10:36 -0700 | [diff] [blame] | 266 |   bool has_DT_SYMBOLIC; | 
| Dmitriy Ivanov | 0d15094 | 2014-08-22 12:25:04 -0700 | [diff] [blame] | 267 |  | 
| Dmitriy Ivanov | 047b593 | 2014-11-13 09:39:20 -0800 | [diff] [blame] | 268 |  public: | 
| Dmitriy Ivanov | 07e5bc1 | 2014-10-03 17:52:44 -0700 | [diff] [blame] | 269 |   soinfo(const char* name, const struct stat* file_stat, off64_t file_offset, int rtld_flags); | 
| Dmitriy Ivanov | 0d15094 | 2014-08-22 12:25:04 -0700 | [diff] [blame] | 270 |  | 
| Dmitriy Ivanov | 047b593 | 2014-11-13 09:39:20 -0800 | [diff] [blame] | 271 |   void call_constructors(); | 
 | 272 |   void call_destructors(); | 
 | 273 |   void call_pre_init_constructors(); | 
 | 274 |   bool prelink_image(); | 
| Dmitriy Ivanov | 20d89cb | 2015-03-30 18:43:38 -0700 | [diff] [blame] | 275 |   bool link_image(const soinfo_list_t& global_group, const soinfo_list_t& local_group, | 
 | 276 |                   const android_dlextinfo* extinfo); | 
| Elliott Hughes | d23736e | 2012-11-01 15:16:56 -0700 | [diff] [blame] | 277 |  | 
| Dmitriy Ivanov | d59e500 | 2014-05-09 09:10:14 -0700 | [diff] [blame] | 278 |   void add_child(soinfo* child); | 
 | 279 |   void remove_all_links(); | 
 | 280 |  | 
| Dmitriy Ivanov | d225a5e | 2014-08-28 14:12:12 -0700 | [diff] [blame] | 281 |   ino_t get_st_ino() const; | 
 | 282 |   dev_t get_st_dev() const; | 
 | 283 |   off64_t get_file_offset() const; | 
| Brigid Smith | c5a13ef | 2014-07-23 11:22:25 -0700 | [diff] [blame] | 284 |  | 
| Dmitriy Ivanov | d225a5e | 2014-08-28 14:12:12 -0700 | [diff] [blame] | 285 |   uint32_t get_rtld_flags() const; | 
 | 286 |   uint32_t get_dt_flags_1() const; | 
 | 287 |   void set_dt_flags_1(uint32_t dt_flags_1); | 
| Dmitriy Ivanov | e8ba50f | 2014-09-15 17:00:10 -0700 | [diff] [blame] | 288 |  | 
| Dmitriy Ivanov | d59e500 | 2014-05-09 09:10:14 -0700 | [diff] [blame] | 289 |   soinfo_list_t& get_children(); | 
| Dmitriy Ivanov | 2a81536 | 2015-04-09 13:42:33 -0700 | [diff] [blame] | 290 |   const soinfo_list_t& get_children() const; | 
 | 291 |  | 
| Dmitriy Ivanov | 14669a9 | 2014-09-05 16:42:53 -0700 | [diff] [blame] | 292 |   soinfo_list_t& get_parents(); | 
| Dmitriy Ivanov | d59e500 | 2014-05-09 09:10:14 -0700 | [diff] [blame] | 293 |  | 
| Dmitriy Ivanov | 2a81536 | 2015-04-09 13:42:33 -0700 | [diff] [blame] | 294 |   bool find_symbol_by_name(SymbolName& symbol_name, | 
 | 295 |                            const version_info* vi, | 
 | 296 |                            const ElfW(Sym)** symbol) const; | 
 | 297 |  | 
| Dmitriy Ivanov | ec18ce0 | 2014-11-09 19:27:20 -0800 | [diff] [blame] | 298 |   ElfW(Sym)* find_symbol_by_address(const void* addr); | 
| Dmitriy Ivanov | 2a81536 | 2015-04-09 13:42:33 -0700 | [diff] [blame] | 299 |   ElfW(Addr) resolve_symbol_address(const ElfW(Sym)* s) const; | 
| Dmitriy Ivanov | 9aea164 | 2014-09-11 15:16:03 -0700 | [diff] [blame] | 300 |  | 
| Dmitriy Ivanov | 6cdeb52 | 2014-09-29 19:14:45 -0700 | [diff] [blame] | 301 |   const char* get_string(ElfW(Word) index) const; | 
| Dmitriy Ivanov | 1b20daf | 2014-05-19 15:06:58 -0700 | [diff] [blame] | 302 |   bool can_unload() const; | 
| Dmitriy Ivanov | ec18ce0 | 2014-11-09 19:27:20 -0800 | [diff] [blame] | 303 |   bool is_gnu_hash() const; | 
| Dmitriy Ivanov | 6cdeb52 | 2014-09-29 19:14:45 -0700 | [diff] [blame] | 304 |  | 
| Dmitriy Ivanov | aae859c | 2015-03-31 11:14:03 -0700 | [diff] [blame] | 305 |   bool inline has_min_version(uint32_t min_version __unused) const { | 
 | 306 | #if defined(__arm__) | 
| Dmitriy Ivanov | ab972b9 | 2014-11-29 13:57:41 -0800 | [diff] [blame] | 307 |     return (flags_ & FLAG_NEW_SOINFO) != 0 && version_ >= min_version; | 
| Dmitriy Ivanov | aae859c | 2015-03-31 11:14:03 -0700 | [diff] [blame] | 308 | #else | 
 | 309 |     return true; | 
 | 310 | #endif | 
| Dmitriy Ivanov | 0d15094 | 2014-08-22 12:25:04 -0700 | [diff] [blame] | 311 |   } | 
| Dmitriy Ivanov | 1b20daf | 2014-05-19 15:06:58 -0700 | [diff] [blame] | 312 |  | 
| Dmitriy Ivanov | ab972b9 | 2014-11-29 13:57:41 -0800 | [diff] [blame] | 313 |   bool is_linked() const; | 
 | 314 |   bool is_main_executable() const; | 
 | 315 |  | 
 | 316 |   void set_linked(); | 
 | 317 |   void set_linker_flag(); | 
 | 318 |   void set_main_executable(); | 
 | 319 |  | 
 | 320 |   void increment_ref_count(); | 
 | 321 |   size_t decrement_ref_count(); | 
 | 322 |  | 
 | 323 |   soinfo* get_local_group_root() const; | 
 | 324 |  | 
| Dmitriy Ivanov | aae859c | 2015-03-31 11:14:03 -0700 | [diff] [blame] | 325 |   const char* get_soname() const; | 
 | 326 |   const char* get_realpath() const; | 
| Dmitriy Ivanov | 2a81536 | 2015-04-09 13:42:33 -0700 | [diff] [blame] | 327 |   const ElfW(Versym)* get_versym(size_t n) const; | 
 | 328 |   ElfW(Addr) get_verneed_ptr() const; | 
 | 329 |   size_t get_verneed_cnt() const; | 
 | 330 |   ElfW(Addr) get_verdef_ptr() const; | 
 | 331 |   size_t get_verdef_cnt() const; | 
 | 332 |  | 
 | 333 |   bool find_verdef_version_index(const version_info* vi, ElfW(Versym)* versym) const; | 
| Dmitriy Ivanov | 618f1a3 | 2015-03-17 20:06:36 -0700 | [diff] [blame] | 334 |  | 
| Elliott Hughes | d23736e | 2012-11-01 15:16:56 -0700 | [diff] [blame] | 335 |  private: | 
| Dmitriy Ivanov | 2a81536 | 2015-04-09 13:42:33 -0700 | [diff] [blame] | 336 |   bool elf_lookup(SymbolName& symbol_name, const version_info* vi, uint32_t* symbol_index) const; | 
| Dmitriy Ivanov | ec18ce0 | 2014-11-09 19:27:20 -0800 | [diff] [blame] | 337 |   ElfW(Sym)* elf_addr_lookup(const void* addr); | 
| Dmitriy Ivanov | 2a81536 | 2015-04-09 13:42:33 -0700 | [diff] [blame] | 338 |   bool gnu_lookup(SymbolName& symbol_name, const version_info* vi, uint32_t* symbol_index) const; | 
| Dmitriy Ivanov | ec18ce0 | 2014-11-09 19:27:20 -0800 | [diff] [blame] | 339 |   ElfW(Sym)* gnu_addr_lookup(const void* addr); | 
 | 340 |  | 
| Dmitriy Ivanov | 114bd83 | 2015-04-30 16:11:48 -0700 | [diff] [blame^] | 341 |   bool lookup_version_info(const VersionTracker& version_tracker, ElfW(Word) sym, | 
 | 342 |                            const char* sym_name, const version_info** vi); | 
 | 343 |  | 
| Dmitriy Ivanov | 047b593 | 2014-11-13 09:39:20 -0800 | [diff] [blame] | 344 |   void call_array(const char* array_name, linker_function_t* functions, size_t count, bool reverse); | 
 | 345 |   void call_function(const char* function_name, linker_function_t function); | 
| Dmitriy Ivanov | fa26eee | 2015-02-03 16:06:47 -0800 | [diff] [blame] | 346 |   template<typename ElfRelIteratorT> | 
| Dmitriy Ivanov | 20d89cb | 2015-03-30 18:43:38 -0700 | [diff] [blame] | 347 |   bool relocate(ElfRelIteratorT&& rel_iterator, const soinfo_list_t& global_group, | 
 | 348 |                 const soinfo_list_t& local_group); | 
| Dmitriy Ivanov | d59e500 | 2014-05-09 09:10:14 -0700 | [diff] [blame] | 349 |  | 
 | 350 |  private: | 
 | 351 |   // This part of the structure is only available | 
 | 352 |   // when FLAG_NEW_SOINFO is set in this->flags. | 
| Dmitriy Ivanov | 047b593 | 2014-11-13 09:39:20 -0800 | [diff] [blame] | 353 |   uint32_t version_; | 
| Dmitriy Ivanov | d59e500 | 2014-05-09 09:10:14 -0700 | [diff] [blame] | 354 |  | 
| Dmitriy Ivanov | 0d15094 | 2014-08-22 12:25:04 -0700 | [diff] [blame] | 355 |   // version >= 0 | 
| Dmitriy Ivanov | 047b593 | 2014-11-13 09:39:20 -0800 | [diff] [blame] | 356 |   dev_t st_dev_; | 
 | 357 |   ino_t st_ino_; | 
| Dmitriy Ivanov | d59e500 | 2014-05-09 09:10:14 -0700 | [diff] [blame] | 358 |  | 
 | 359 |   // dependency graph | 
| Dmitriy Ivanov | 047b593 | 2014-11-13 09:39:20 -0800 | [diff] [blame] | 360 |   soinfo_list_t children_; | 
 | 361 |   soinfo_list_t parents_; | 
| Dmitriy Ivanov | d59e500 | 2014-05-09 09:10:14 -0700 | [diff] [blame] | 362 |  | 
| Dmitriy Ivanov | 0d15094 | 2014-08-22 12:25:04 -0700 | [diff] [blame] | 363 |   // version >= 1 | 
| Dmitriy Ivanov | 047b593 | 2014-11-13 09:39:20 -0800 | [diff] [blame] | 364 |   off64_t file_offset_; | 
 | 365 |   uint32_t rtld_flags_; | 
 | 366 |   uint32_t dt_flags_1_; | 
 | 367 |   size_t strtab_size_; | 
| Dmitriy Ivanov | 6cdeb52 | 2014-09-29 19:14:45 -0700 | [diff] [blame] | 368 |  | 
| Dmitriy Ivanov | ec18ce0 | 2014-11-09 19:27:20 -0800 | [diff] [blame] | 369 |   // version >= 2 | 
| Dmitriy Ivanov | 3597b80 | 2015-03-09 12:02:02 -0700 | [diff] [blame] | 370 |  | 
 | 371 |   size_t gnu_nbucket_; | 
 | 372 |   uint32_t* gnu_bucket_; | 
 | 373 |   uint32_t* gnu_chain_; | 
| Dmitriy Ivanov | 047b593 | 2014-11-13 09:39:20 -0800 | [diff] [blame] | 374 |   uint32_t gnu_maskwords_; | 
 | 375 |   uint32_t gnu_shift2_; | 
| Dmitriy Ivanov | 047b593 | 2014-11-13 09:39:20 -0800 | [diff] [blame] | 376 |   ElfW(Addr)* gnu_bloom_filter_; | 
| Dmitriy Ivanov | ec18ce0 | 2014-11-09 19:27:20 -0800 | [diff] [blame] | 377 |  | 
| Dmitriy Ivanov | ab972b9 | 2014-11-29 13:57:41 -0800 | [diff] [blame] | 378 |   soinfo* local_group_root_; | 
 | 379 |  | 
| Dmitriy Ivanov | 18a6956 | 2015-02-04 16:05:30 -0800 | [diff] [blame] | 380 |   uint8_t* android_relocs_; | 
 | 381 |   size_t android_relocs_size_; | 
 | 382 |  | 
| Dmitriy Ivanov | 618f1a3 | 2015-03-17 20:06:36 -0700 | [diff] [blame] | 383 |   const char* soname_; | 
| Dmitriy Ivanov | aae859c | 2015-03-31 11:14:03 -0700 | [diff] [blame] | 384 |   std::string realpath_; | 
| Dmitriy Ivanov | 618f1a3 | 2015-03-17 20:06:36 -0700 | [diff] [blame] | 385 |  | 
| Dmitriy Ivanov | 2a81536 | 2015-04-09 13:42:33 -0700 | [diff] [blame] | 386 |   const ElfW(Versym)* versym_; | 
 | 387 |  | 
 | 388 |   ElfW(Addr) verdef_ptr_; | 
 | 389 |   size_t verdef_cnt_; | 
 | 390 |  | 
 | 391 |   ElfW(Addr) verneed_ptr_; | 
 | 392 |   size_t verneed_cnt_; | 
 | 393 |  | 
| Dmitriy Ivanov | 6cdeb52 | 2014-09-29 19:14:45 -0700 | [diff] [blame] | 394 |   friend soinfo* get_libdl_info(); | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 395 | }; | 
 | 396 |  | 
| Dmitriy Ivanov | 2a81536 | 2015-04-09 13:42:33 -0700 | [diff] [blame] | 397 | bool soinfo_do_lookup(soinfo* si_from, const char* name, const version_info* vi, | 
 | 398 |                       soinfo** si_found_in, const soinfo::soinfo_list_t& global_group, | 
 | 399 |                       const soinfo::soinfo_list_t& local_group, const ElfW(Sym)** symbol); | 
| Dmitriy Ivanov | 114ff69 | 2015-01-14 11:36:38 -0800 | [diff] [blame] | 400 |  | 
 | 401 | enum RelocationKind { | 
 | 402 |   kRelocAbsolute = 0, | 
 | 403 |   kRelocRelative, | 
 | 404 |   kRelocCopy, | 
 | 405 |   kRelocSymbol, | 
 | 406 |   kRelocMax | 
 | 407 | }; | 
 | 408 |  | 
 | 409 | void count_relocation(RelocationKind kind); | 
 | 410 |  | 
| Dmitriy Ivanov | 1b20daf | 2014-05-19 15:06:58 -0700 | [diff] [blame] | 411 | soinfo* get_libdl_info(); | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 412 |  | 
| Elliott Hughes | a4aafd1 | 2014-01-13 16:37:47 -0800 | [diff] [blame] | 413 | void do_android_get_LD_LIBRARY_PATH(char*, size_t); | 
| Elliott Hughes | cade4c3 | 2012-12-20 14:42:14 -0800 | [diff] [blame] | 414 | void do_android_update_LD_LIBRARY_PATH(const char* ld_library_path); | 
| Elliott Hughes | 1a58629 | 2014-06-03 16:23:08 -0700 | [diff] [blame] | 415 | soinfo* do_dlopen(const char* name, int flags, const android_dlextinfo* extinfo); | 
| Dmitriy Ivanov | b648a8a | 2014-05-19 15:06:58 -0700 | [diff] [blame] | 416 | void do_dlclose(soinfo* si); | 
| David 'Digit' Turner | 1608416 | 2012-06-12 16:25:37 +0200 | [diff] [blame] | 417 |  | 
| Dmitriy Ivanov | 2a81536 | 2015-04-09 13:42:33 -0700 | [diff] [blame] | 418 | const ElfW(Sym)* dlsym_linear_lookup(const char* name, soinfo** found, soinfo* caller, void* handle); | 
| Elliott Hughes | d23736e | 2012-11-01 15:16:56 -0700 | [diff] [blame] | 419 | soinfo* find_containing_library(const void* addr); | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 420 |  | 
| Dmitriy Ivanov | 2a81536 | 2015-04-09 13:42:33 -0700 | [diff] [blame] | 421 | const ElfW(Sym)* dlsym_handle_lookup(soinfo* si, soinfo** found, const char* name); | 
| Elliott Hughes | d23736e | 2012-11-01 15:16:56 -0700 | [diff] [blame] | 422 |  | 
| Brian Carlstrom | d4ee82d | 2013-02-28 15:58:45 -0800 | [diff] [blame] | 423 | void debuggerd_init(); | 
| Elliott Hughes | 1728b23 | 2014-05-14 10:02:03 -0700 | [diff] [blame] | 424 | extern "C" abort_msg_t* g_abort_message; | 
| Elliott Hughes | 18a206c | 2012-10-29 17:37:13 -0700 | [diff] [blame] | 425 | extern "C" void notify_gdb_of_libraries(); | 
| Elliott Hughes | 4688279 | 2012-08-03 16:49:39 -0700 | [diff] [blame] | 426 |  | 
| Elliott Hughes | 650be4e | 2013-03-05 18:47:58 -0800 | [diff] [blame] | 427 | char* linker_get_error_buffer(); | 
 | 428 | size_t linker_get_error_buffer_size(); | 
 | 429 |  | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 430 | #endif |