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