blob: c669c46a6dfff3ce94976e85ba224885d42d5f9b [file] [log] [blame]
The Android Open Source Project1dc9e472009-03-03 19:28:35 -08001/*
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
Dimitry Ivanov4a2c5aa2015-12-10 16:08:14 -080032#include <dlfcn.h>
Elliott Hughesafab3ff2015-07-28 14:58:37 -070033#include <android/dlext.h>
Nick Kralevich9ec0f032012-02-28 10:40:00 -080034#include <elf.h>
Dmitriy Ivanov0d150942014-08-22 12:25:04 -070035#include <inttypes.h>
Pavel Chupinb7beb692012-08-17 12:53:29 +040036#include <link.h>
Dmitriy Ivanovd59e5002014-05-09 09:10:14 -070037#include <sys/stat.h>
Elliott Hughesafab3ff2015-07-28 14:58:37 -070038#include <unistd.h>
Elliott Hughes46882792012-08-03 16:49:39 -070039
Elliott Hughesafab3ff2015-07-28 14:58:37 -070040#include "private/bionic_page.h"
Elliott Hughes8f2a5a02013-03-15 15:30:25 -070041#include "private/libc_logging.h"
Dmitriy Ivanovd59e5002014-05-09 09:10:14 -070042#include "linked_list.h"
Elliott Hughes650be4e2013-03-05 18:47:58 -080043
Dmitriy Ivanovaae859c2015-03-31 11:14:03 -070044#include <string>
Dmitriy Ivanov2a815362015-04-09 13:42:33 -070045#include <vector>
Dmitriy Ivanovaae859c2015-03-31 11:14:03 -070046
Elliott Hughes650be4e2013-03-05 18:47:58 -080047#define DL_ERR(fmt, x...) \
48 do { \
49 __libc_format_buffer(linker_get_error_buffer(), linker_get_error_buffer_size(), fmt, ##x); \
50 /* If LD_DEBUG is set high enough, log every dlerror(3) message. */ \
51 DEBUG("%s\n", linker_get_error_buffer()); \
Elliott Hughes7e5a8cc2013-06-18 13:15:00 -070052 } while (false)
53
54#define DL_WARN(fmt, x...) \
55 do { \
56 __libc_format_log(ANDROID_LOG_WARN, "linker", fmt, ##x); \
57 __libc_format_fd(2, "WARNING: linker: "); \
58 __libc_format_fd(2, fmt, ##x); \
59 __libc_format_fd(2, "\n"); \
60 } while (false)
61
Elliott Hughes0266ae52014-02-10 17:46:57 -080062#if defined(__LP64__)
63#define ELFW(what) ELF64_ ## what
64#else
65#define ELFW(what) ELF32_ ## what
66#endif
Elliott Hughes650be4e2013-03-05 18:47:58 -080067
Chris Dearman99186652014-02-06 20:36:51 -080068// mips64 interprets Elf64_Rel structures' r_info field differently.
69// bionic (like other C libraries) has macros that assume regular ELF files,
70// but the dynamic linker needs to be able to load mips64 ELF files.
71#if defined(__mips__) && defined(__LP64__)
72#undef ELF64_R_SYM
73#undef ELF64_R_TYPE
74#undef ELF64_R_INFO
75#define ELF64_R_SYM(info) (((info) >> 0) & 0xffffffff)
76#define ELF64_R_SSYM(info) (((info) >> 32) & 0xff)
77#define ELF64_R_TYPE3(info) (((info) >> 40) & 0xff)
78#define ELF64_R_TYPE2(info) (((info) >> 48) & 0xff)
79#define ELF64_R_TYPE(info) (((info) >> 56) & 0xff)
80#endif
81
Dimitry Ivanovf45b0e92016-01-15 11:13:35 -080082#define FLAG_LINKED 0x00000001
83#define FLAG_EXE 0x00000004 // The main executable
84#define FLAG_LINKER 0x00000010 // The linker itself
85#define FLAG_GNU_HASH 0x00000040 // uses gnu hash
86#define FLAG_MAPPED_BY_CALLER 0x00000080 // the map is reserved by the caller
87 // and should not be unmapped
88#define FLAG_NEW_SOINFO 0x40000000 // new soinfo format
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080089
Dmitriy Ivanovd225a5e2014-08-28 14:12:12 -070090#define SUPPORTED_DT_FLAGS_1 (DF_1_NOW | DF_1_GLOBAL | DF_1_NODELETE)
91
Dmitriy Ivanov42d5fcb2015-10-29 17:01:24 -070092#define SOINFO_VERSION 3
Dmitriy Ivanov0d150942014-08-22 12:25:04 -070093
Dmitriy Ivanov280d5462015-09-28 10:14:17 -070094#if defined(__work_around_b_24465209__)
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080095#define SOINFO_NAME_LEN 128
Dmitriy Ivanovaae859c2015-03-31 11:14:03 -070096#endif
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080097
Elliott Hughesca0c11b2013-03-12 10:40:45 -070098typedef void (*linker_function_t)();
99
Chris Dearman99186652014-02-06 20:36:51 -0800100// Android uses RELA for aarch64 and x86_64. mips64 still uses REL.
101#if defined(__aarch64__) || defined(__x86_64__)
Elliott Hughes4eeb1f12013-10-25 17:38:02 -0700102#define USE_RELA 1
103#endif
104
Dmitriy Ivanovd59e5002014-05-09 09:10:14 -0700105struct soinfo;
106
107class SoinfoListAllocator {
Dmitriy Ivanovec18ce02014-11-09 19:27:20 -0800108 public:
Dmitriy Ivanovd59e5002014-05-09 09:10:14 -0700109 static LinkedListEntry<soinfo>* alloc();
110 static void free(LinkedListEntry<soinfo>* entry);
Dmitriy Ivanovec18ce02014-11-09 19:27:20 -0800111
112 private:
Dmitriy Ivanovd59e5002014-05-09 09:10:14 -0700113 // unconstructable
114 DISALLOW_IMPLICIT_CONSTRUCTORS(SoinfoListAllocator);
115};
116
Dmitriy Ivanovec18ce02014-11-09 19:27:20 -0800117class SymbolName {
118 public:
119 explicit SymbolName(const char* name)
120 : name_(name), has_elf_hash_(false), has_gnu_hash_(false),
121 elf_hash_(0), gnu_hash_(0) { }
122
123 const char* get_name() {
124 return name_;
125 }
126
127 uint32_t elf_hash();
128 uint32_t gnu_hash();
129
130 private:
131 const char* name_;
132 bool has_elf_hash_;
133 bool has_gnu_hash_;
134 uint32_t elf_hash_;
135 uint32_t gnu_hash_;
136
137 DISALLOW_IMPLICIT_CONSTRUCTORS(SymbolName);
138};
139
Dmitriy Ivanov2a815362015-04-09 13:42:33 -0700140struct version_info {
Dimitry Ivanov4a2c5aa2015-12-10 16:08:14 -0800141 constexpr version_info() : elf_hash(0), name(nullptr), target_si(nullptr) {}
Dmitriy Ivanov2a815362015-04-09 13:42:33 -0700142
143 uint32_t elf_hash;
144 const char* name;
145 const soinfo* target_si;
146};
147
148// Class used construct version dependency graph.
149class VersionTracker {
150 public:
151 VersionTracker() = default;
152 bool init(const soinfo* si_from);
153
154 const version_info* get_version_info(ElfW(Versym) source_symver) const;
155 private:
156 bool init_verneed(const soinfo* si_from);
157 bool init_verdef(const soinfo* si_from);
158 void add_version_info(size_t source_index, ElfW(Word) elf_hash,
159 const char* ver_name, const soinfo* target_si);
160
161 std::vector<version_info> version_infos;
162
163 DISALLOW_COPY_AND_ASSIGN(VersionTracker);
164};
165
Elliott Hughes18a206c2012-10-29 17:37:13 -0700166struct soinfo {
Elliott Hughesca0c11b2013-03-12 10:40:45 -0700167 public:
Dmitriy Ivanovd59e5002014-05-09 09:10:14 -0700168 typedef LinkedList<soinfo, SoinfoListAllocator> soinfo_list_t;
Dmitriy Ivanov280d5462015-09-28 10:14:17 -0700169#if defined(__work_around_b_24465209__)
Dmitriy Ivanovaae859c2015-03-31 11:14:03 -0700170 private:
171 char old_name_[SOINFO_NAME_LEN];
172#endif
Dmitriy Ivanovd59e5002014-05-09 09:10:14 -0700173 public:
Elliott Hughes0266ae52014-02-10 17:46:57 -0800174 const ElfW(Phdr)* phdr;
Elliott Hughesca0c11b2013-03-12 10:40:45 -0700175 size_t phnum;
Dimitry Ivanove687d062016-02-16 13:25:29 -0800176#if defined(__work_around_b_24465209__)
177 ElfW(Addr) unused0; // DO NOT USE, maintained for compatibility.
178#endif
Elliott Hughes0266ae52014-02-10 17:46:57 -0800179 ElfW(Addr) base;
Weiwu Chen5ceb8892013-12-03 19:47:34 +0800180 size_t size;
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800181
Dmitriy Ivanov280d5462015-09-28 10:14:17 -0700182#if defined(__work_around_b_24465209__)
Elliott Hughesca0c11b2013-03-12 10:40:45 -0700183 uint32_t unused1; // DO NOT USE, maintained for compatibility.
Elliott Hughesc6200592013-09-30 18:43:46 -0700184#endif
Nick Kralevich38bccb22011-08-29 13:49:22 -0700185
Elliott Hughes0266ae52014-02-10 17:46:57 -0800186 ElfW(Dyn)* dynamic;
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800187
Dmitriy Ivanov280d5462015-09-28 10:14:17 -0700188#if defined(__work_around_b_24465209__)
Elliott Hughesca0c11b2013-03-12 10:40:45 -0700189 uint32_t unused2; // DO NOT USE, maintained for compatibility
190 uint32_t unused3; // DO NOT USE, maintained for compatibility
Elliott Hughesc6200592013-09-30 18:43:46 -0700191#endif
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800192
Elliott Hughesd23736e2012-11-01 15:16:56 -0700193 soinfo* next;
Dmitriy Ivanov6cdeb522014-09-29 19:14:45 -0700194 private:
Dmitriy Ivanovab972b92014-11-29 13:57:41 -0800195 uint32_t flags_;
196
Dmitriy Ivanov047b5932014-11-13 09:39:20 -0800197 const char* strtab_;
198 ElfW(Sym)* symtab_;
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800199
Dmitriy Ivanov047b5932014-11-13 09:39:20 -0800200 size_t nbucket_;
201 size_t nchain_;
202 uint32_t* bucket_;
203 uint32_t* chain_;
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800204
Chris Dearman99186652014-02-06 20:36:51 -0800205#if defined(__mips__) || !defined(__LP64__)
206 // This is only used by mips and mips64, but needs to be here for
Elliott Hughes4eeb1f12013-10-25 17:38:02 -0700207 // all 32-bit architectures to preserve binary compatibility.
Dmitriy Ivanov047b5932014-11-13 09:39:20 -0800208 ElfW(Addr)** plt_got_;
Elliott Hughes4eeb1f12013-10-25 17:38:02 -0700209#endif
210
211#if defined(USE_RELA)
Dmitriy Ivanov047b5932014-11-13 09:39:20 -0800212 ElfW(Rela)* plt_rela_;
213 size_t plt_rela_count_;
Elliott Hughesc00f2cb2013-10-04 17:01:33 -0700214
Dmitriy Ivanov047b5932014-11-13 09:39:20 -0800215 ElfW(Rela)* rela_;
216 size_t rela_count_;
Elliott Hughesc00f2cb2013-10-04 17:01:33 -0700217#else
Dmitriy Ivanov047b5932014-11-13 09:39:20 -0800218 ElfW(Rel)* plt_rel_;
219 size_t plt_rel_count_;
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800220
Dmitriy Ivanov047b5932014-11-13 09:39:20 -0800221 ElfW(Rel)* rel_;
222 size_t rel_count_;
Elliott Hughesc00f2cb2013-10-04 17:01:33 -0700223#endif
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800224
Dmitriy Ivanov047b5932014-11-13 09:39:20 -0800225 linker_function_t* preinit_array_;
226 size_t preinit_array_count_;
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800227
Dmitriy Ivanov047b5932014-11-13 09:39:20 -0800228 linker_function_t* init_array_;
229 size_t init_array_count_;
230 linker_function_t* fini_array_;
231 size_t fini_array_count_;
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800232
Dmitriy Ivanov047b5932014-11-13 09:39:20 -0800233 linker_function_t init_func_;
234 linker_function_t fini_func_;
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800235
Elliott Hughes4eeb1f12013-10-25 17:38:02 -0700236#if defined(__arm__)
Dmitriy Ivanovab972b92014-11-29 13:57:41 -0800237 public:
Elliott Hughesd23736e2012-11-01 15:16:56 -0700238 // ARM EABI section used for stack unwinding.
Dmitriy Ivanov1b20daf2014-05-19 15:06:58 -0700239 uint32_t* ARM_exidx;
Elliott Hughesca0c11b2013-03-12 10:40:45 -0700240 size_t ARM_exidx_count;
Dmitriy Ivanov88940912014-11-12 18:20:39 -0800241 private:
Dmitriy Ivanovab972b92014-11-29 13:57:41 -0800242#elif defined(__mips__)
Dmitriy Ivanov047b5932014-11-13 09:39:20 -0800243 uint32_t mips_symtabno_;
244 uint32_t mips_local_gotno_;
245 uint32_t mips_gotsym_;
Dmitriy Ivanovf39cb632015-04-30 20:17:03 -0700246 bool mips_relocate_got(const VersionTracker& version_tracker,
247 const soinfo_list_t& global_group,
248 const soinfo_list_t& local_group);
Duane Sandbc425c72015-06-01 16:29:14 -0700249#if !defined(__LP64__)
250 bool mips_check_and_adjust_fp_modes();
251#endif
Elliott Hughesd23736e2012-11-01 15:16:56 -0700252#endif
Dmitriy Ivanovab972b92014-11-29 13:57:41 -0800253 size_t ref_count_;
Dmitriy Ivanov047b5932014-11-13 09:39:20 -0800254 public:
Elliott Hughes3a9c5d62014-02-10 13:31:13 -0800255 link_map link_map_head;
Evgeniy Stepanove83c56d2011-12-21 13:03:54 +0400256
Elliott Hughesd23736e2012-11-01 15:16:56 -0700257 bool constructors_called;
Nick Kralevich9ec0f032012-02-28 10:40:00 -0800258
Elliott Hughesd23736e2012-11-01 15:16:56 -0700259 // 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 Hughes0266ae52014-02-10 17:46:57 -0800261 ElfW(Addr) load_bias;
Ard Biesheuvel5ae44f32012-08-30 12:48:32 +0200262
Dimitry Ivanov56be6ed2015-04-01 21:18:48 +0000263#if !defined(__LP64__)
264 bool has_text_relocations;
Elliott Hughese4d792a2013-10-28 14:19:05 -0700265#endif
Dmitriy Ivanov96bc37f2014-09-29 12:10:36 -0700266 bool has_DT_SYMBOLIC;
Dmitriy Ivanov0d150942014-08-22 12:25:04 -0700267
Dmitriy Ivanov047b5932014-11-13 09:39:20 -0800268 public:
Dmitriy Ivanov42d5fcb2015-10-29 17:01:24 -0700269 soinfo(android_namespace_t* ns, const char* name, const struct stat* file_stat,
270 off64_t file_offset, int rtld_flags);
Dmitriy Ivanov0d150942014-08-22 12:25:04 -0700271
Dmitriy Ivanov047b5932014-11-13 09:39:20 -0800272 void call_constructors();
273 void call_destructors();
274 void call_pre_init_constructors();
275 bool prelink_image();
Dmitriy Ivanov20d89cb2015-03-30 18:43:38 -0700276 bool link_image(const soinfo_list_t& global_group, const soinfo_list_t& local_group,
277 const android_dlextinfo* extinfo);
Elliott Hughesd23736e2012-11-01 15:16:56 -0700278
Dmitriy Ivanovd59e5002014-05-09 09:10:14 -0700279 void add_child(soinfo* child);
280 void remove_all_links();
281
Dmitriy Ivanovd225a5e2014-08-28 14:12:12 -0700282 ino_t get_st_ino() const;
283 dev_t get_st_dev() const;
284 off64_t get_file_offset() const;
Brigid Smithc5a13ef2014-07-23 11:22:25 -0700285
Dmitriy Ivanovd225a5e2014-08-28 14:12:12 -0700286 uint32_t get_rtld_flags() const;
287 uint32_t get_dt_flags_1() const;
288 void set_dt_flags_1(uint32_t dt_flags_1);
Dmitriy Ivanove8ba50f2014-09-15 17:00:10 -0700289
Dmitriy Ivanovd59e5002014-05-09 09:10:14 -0700290 soinfo_list_t& get_children();
Dmitriy Ivanov2a815362015-04-09 13:42:33 -0700291 const soinfo_list_t& get_children() const;
292
Dmitriy Ivanov14669a92014-09-05 16:42:53 -0700293 soinfo_list_t& get_parents();
Dmitriy Ivanovd59e5002014-05-09 09:10:14 -0700294
Dmitriy Ivanov2a815362015-04-09 13:42:33 -0700295 bool find_symbol_by_name(SymbolName& symbol_name,
296 const version_info* vi,
297 const ElfW(Sym)** symbol) const;
298
Dmitriy Ivanovec18ce02014-11-09 19:27:20 -0800299 ElfW(Sym)* find_symbol_by_address(const void* addr);
Dmitriy Ivanov2a815362015-04-09 13:42:33 -0700300 ElfW(Addr) resolve_symbol_address(const ElfW(Sym)* s) const;
Dmitriy Ivanov9aea1642014-09-11 15:16:03 -0700301
Dmitriy Ivanov6cdeb522014-09-29 19:14:45 -0700302 const char* get_string(ElfW(Word) index) const;
Dmitriy Ivanov1b20daf2014-05-19 15:06:58 -0700303 bool can_unload() const;
Dmitriy Ivanovec18ce02014-11-09 19:27:20 -0800304 bool is_gnu_hash() const;
Dmitriy Ivanov6cdeb522014-09-29 19:14:45 -0700305
Dmitriy Ivanovaae859c2015-03-31 11:14:03 -0700306 bool inline has_min_version(uint32_t min_version __unused) const {
Dmitriy Ivanov280d5462015-09-28 10:14:17 -0700307#if defined(__work_around_b_24465209__)
Dmitriy Ivanovab972b92014-11-29 13:57:41 -0800308 return (flags_ & FLAG_NEW_SOINFO) != 0 && version_ >= min_version;
Dmitriy Ivanovaae859c2015-03-31 11:14:03 -0700309#else
310 return true;
311#endif
Dmitriy Ivanov0d150942014-08-22 12:25:04 -0700312 }
Dmitriy Ivanov1b20daf2014-05-19 15:06:58 -0700313
Dmitriy Ivanovab972b92014-11-29 13:57:41 -0800314 bool is_linked() const;
315 bool is_main_executable() const;
316
317 void set_linked();
318 void set_linker_flag();
319 void set_main_executable();
Dmitriy Ivanov42d5fcb2015-10-29 17:01:24 -0700320 void set_nodelete();
Dmitriy Ivanovab972b92014-11-29 13:57:41 -0800321
322 void increment_ref_count();
323 size_t decrement_ref_count();
324
325 soinfo* get_local_group_root() const;
326
Dmitriy Ivanov4f7a7ad2015-10-15 12:07:25 -0700327 void set_soname(const char* soname);
Dmitriy Ivanovaae859c2015-03-31 11:14:03 -0700328 const char* get_soname() const;
329 const char* get_realpath() const;
Dmitriy Ivanov2a815362015-04-09 13:42:33 -0700330 const ElfW(Versym)* get_versym(size_t n) const;
331 ElfW(Addr) get_verneed_ptr() const;
332 size_t get_verneed_cnt() const;
333 ElfW(Addr) get_verdef_ptr() const;
334 size_t get_verdef_cnt() const;
335
336 bool find_verdef_version_index(const version_info* vi, ElfW(Versym)* versym) const;
Dmitriy Ivanov618f1a32015-03-17 20:06:36 -0700337
Dmitriy Ivanov19133522015-06-02 17:36:54 -0700338 uint32_t get_target_sdk_version() const;
339
Dmitriy Ivanov4f7a7ad2015-10-15 12:07:25 -0700340 void set_dt_runpath(const char *);
Evgenii Stepanov68650822015-06-10 13:38:39 -0700341 const std::vector<std::string>& get_dt_runpath() const;
Dmitriy Ivanov42d5fcb2015-10-29 17:01:24 -0700342 android_namespace_t* get_namespace();
Evgenii Stepanov68650822015-06-10 13:38:39 -0700343
Dimitry Ivanovf45b0e92016-01-15 11:13:35 -0800344 void set_mapped_by_caller(bool reserved_map);
345 bool is_mapped_by_caller() const;
346
Elliott Hughesd23736e2012-11-01 15:16:56 -0700347 private:
Dmitriy Ivanov2a815362015-04-09 13:42:33 -0700348 bool elf_lookup(SymbolName& symbol_name, const version_info* vi, uint32_t* symbol_index) const;
Dmitriy Ivanovec18ce02014-11-09 19:27:20 -0800349 ElfW(Sym)* elf_addr_lookup(const void* addr);
Dmitriy Ivanov2a815362015-04-09 13:42:33 -0700350 bool gnu_lookup(SymbolName& symbol_name, const version_info* vi, uint32_t* symbol_index) const;
Dmitriy Ivanovec18ce02014-11-09 19:27:20 -0800351 ElfW(Sym)* gnu_addr_lookup(const void* addr);
352
Dmitriy Ivanov31b408d2015-04-30 16:11:48 -0700353 bool lookup_version_info(const VersionTracker& version_tracker, ElfW(Word) sym,
354 const char* sym_name, const version_info** vi);
355
Dmitriy Ivanov047b5932014-11-13 09:39:20 -0800356 void call_array(const char* array_name, linker_function_t* functions, size_t count, bool reverse);
357 void call_function(const char* function_name, linker_function_t function);
Dmitriy Ivanovfa26eee2015-02-03 16:06:47 -0800358 template<typename ElfRelIteratorT>
Dmitriy Ivanov7e4bbba2015-04-30 19:49:19 -0700359 bool relocate(const VersionTracker& version_tracker, ElfRelIteratorT&& rel_iterator,
360 const soinfo_list_t& global_group, const soinfo_list_t& local_group);
Dmitriy Ivanovd59e5002014-05-09 09:10:14 -0700361
362 private:
363 // This part of the structure is only available
364 // when FLAG_NEW_SOINFO is set in this->flags.
Dmitriy Ivanov047b5932014-11-13 09:39:20 -0800365 uint32_t version_;
Dmitriy Ivanovd59e5002014-05-09 09:10:14 -0700366
Dmitriy Ivanov0d150942014-08-22 12:25:04 -0700367 // version >= 0
Dmitriy Ivanov047b5932014-11-13 09:39:20 -0800368 dev_t st_dev_;
369 ino_t st_ino_;
Dmitriy Ivanovd59e5002014-05-09 09:10:14 -0700370
371 // dependency graph
Dmitriy Ivanov047b5932014-11-13 09:39:20 -0800372 soinfo_list_t children_;
373 soinfo_list_t parents_;
Dmitriy Ivanovd59e5002014-05-09 09:10:14 -0700374
Dmitriy Ivanov0d150942014-08-22 12:25:04 -0700375 // version >= 1
Dmitriy Ivanov047b5932014-11-13 09:39:20 -0800376 off64_t file_offset_;
377 uint32_t rtld_flags_;
378 uint32_t dt_flags_1_;
379 size_t strtab_size_;
Dmitriy Ivanov6cdeb522014-09-29 19:14:45 -0700380
Dmitriy Ivanovec18ce02014-11-09 19:27:20 -0800381 // version >= 2
Dmitriy Ivanov3597b802015-03-09 12:02:02 -0700382
383 size_t gnu_nbucket_;
384 uint32_t* gnu_bucket_;
385 uint32_t* gnu_chain_;
Dmitriy Ivanov047b5932014-11-13 09:39:20 -0800386 uint32_t gnu_maskwords_;
387 uint32_t gnu_shift2_;
Dmitriy Ivanov047b5932014-11-13 09:39:20 -0800388 ElfW(Addr)* gnu_bloom_filter_;
Dmitriy Ivanovec18ce02014-11-09 19:27:20 -0800389
Dmitriy Ivanovab972b92014-11-29 13:57:41 -0800390 soinfo* local_group_root_;
391
Dmitriy Ivanov18a69562015-02-04 16:05:30 -0800392 uint8_t* android_relocs_;
393 size_t android_relocs_size_;
394
Dmitriy Ivanov618f1a32015-03-17 20:06:36 -0700395 const char* soname_;
Dmitriy Ivanovaae859c2015-03-31 11:14:03 -0700396 std::string realpath_;
Dmitriy Ivanov618f1a32015-03-17 20:06:36 -0700397
Dmitriy Ivanov2a815362015-04-09 13:42:33 -0700398 const ElfW(Versym)* versym_;
399
400 ElfW(Addr) verdef_ptr_;
401 size_t verdef_cnt_;
402
403 ElfW(Addr) verneed_ptr_;
404 size_t verneed_cnt_;
405
Dmitriy Ivanov19133522015-06-02 17:36:54 -0700406 uint32_t target_sdk_version_;
407
Dmitriy Ivanov42d5fcb2015-10-29 17:01:24 -0700408 // version >= 3
Evgenii Stepanov68650822015-06-10 13:38:39 -0700409 std::vector<std::string> dt_runpath_;
Dmitriy Ivanov42d5fcb2015-10-29 17:01:24 -0700410 android_namespace_t* namespace_;
Evgenii Stepanov68650822015-06-10 13:38:39 -0700411
Dmitriy Ivanov6cdeb522014-09-29 19:14:45 -0700412 friend soinfo* get_libdl_info();
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800413};
414
Dmitriy Ivanov2a815362015-04-09 13:42:33 -0700415bool soinfo_do_lookup(soinfo* si_from, const char* name, const version_info* vi,
416 soinfo** si_found_in, const soinfo::soinfo_list_t& global_group,
417 const soinfo::soinfo_list_t& local_group, const ElfW(Sym)** symbol);
Dmitriy Ivanov114ff692015-01-14 11:36:38 -0800418
419enum RelocationKind {
420 kRelocAbsolute = 0,
421 kRelocRelative,
422 kRelocCopy,
423 kRelocSymbol,
424 kRelocMax
425};
426
427void count_relocation(RelocationKind kind);
428
Dmitriy Ivanov1b20daf2014-05-19 15:06:58 -0700429soinfo* get_libdl_info();
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800430
Elliott Hughesa4aafd12014-01-13 16:37:47 -0800431void do_android_get_LD_LIBRARY_PATH(char*, size_t);
Elliott Hughescade4c32012-12-20 14:42:14 -0800432void do_android_update_LD_LIBRARY_PATH(const char* ld_library_path);
Dimitry Ivanov4a2c5aa2015-12-10 16:08:14 -0800433soinfo* do_dlopen(const char* name, int flags, const android_dlextinfo* extinfo, void* caller_addr);
Dmitriy Ivanovb648a8a2014-05-19 15:06:58 -0700434void do_dlclose(soinfo* si);
David 'Digit' Turner16084162012-06-12 16:25:37 +0200435
Dmitriy Ivanov7271caf2015-06-29 14:48:25 -0700436int do_dl_iterate_phdr(int (*cb)(dl_phdr_info* info, size_t size, void* data), void* data);
437
Dimitry Ivanov4a2c5aa2015-12-10 16:08:14 -0800438bool do_dlsym(void* handle, const char* sym_name, const char* sym_ver,
439 void* caller_addr, void** symbol);
Dmitriy Ivanov42d5fcb2015-10-29 17:01:24 -0700440
Dimitry Ivanov4a2c5aa2015-12-10 16:08:14 -0800441int do_dladdr(const void* addr, Dl_info* info);
Elliott Hughesd23736e2012-11-01 15:16:56 -0700442
Brian Carlstromd4ee82d2013-02-28 15:58:45 -0800443void debuggerd_init();
Elliott Hughes1728b232014-05-14 10:02:03 -0700444extern "C" abort_msg_t* g_abort_message;
Elliott Hughes18a206c2012-10-29 17:37:13 -0700445extern "C" void notify_gdb_of_libraries();
Elliott Hughes46882792012-08-03 16:49:39 -0700446
Elliott Hughes650be4e2013-03-05 18:47:58 -0800447char* linker_get_error_buffer();
448size_t linker_get_error_buffer_size();
449
Dmitriy Ivanov79fd6682015-05-21 17:43:49 -0700450void set_application_target_sdk_version(uint32_t target);
451uint32_t get_application_target_sdk_version();
452
Dmitriy Ivanov1ffec1c2015-11-23 11:26:35 -0800453bool init_namespaces(const char* public_ns_sonames, const char* anon_ns_library_path);
Dimitry Ivanov7331fe12015-12-14 14:11:17 -0800454android_namespace_t* create_namespace(const void* caller_addr, const char* name,
455 const char* ld_library_path, const char* default_library_path,
456 uint64_t type, const char* permitted_when_isolated_path);
Dmitriy Ivanov42d5fcb2015-10-29 17:01:24 -0700457
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800458#endif