blob: b64f42c2a3965bb3effe87611b49d89d3186ebe8 [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
Nick Kralevich9ec0f032012-02-28 10:40:00 -080032#include <elf.h>
Dmitriy Ivanov0d150942014-08-22 12:25:04 -070033#include <inttypes.h>
Pavel Chupinb7beb692012-08-17 12:53:29 +040034#include <link.h>
Elliott Hughes1272dbd2014-01-09 15:45:07 -080035#include <unistd.h>
Torne (Richard Coles)012cb452014-02-06 14:34:21 +000036#include <android/dlext.h>
Dmitriy Ivanovd59e5002014-05-09 09:10:14 -070037#include <sys/stat.h>
Elliott Hughes46882792012-08-03 16:49:39 -070038
Elliott Hughes8f2a5a02013-03-15 15:30:25 -070039#include "private/libc_logging.h"
Dmitriy Ivanovd59e5002014-05-09 09:10:14 -070040#include "linked_list.h"
Elliott Hughes650be4e2013-03-05 18:47:58 -080041
Dmitriy Ivanovaae859c2015-03-31 11:14:03 -070042#include <string>
Dmitriy Ivanov2a815362015-04-09 13:42:33 -070043#include <vector>
Dmitriy Ivanovaae859c2015-03-31 11:14:03 -070044
Elliott Hughes650be4e2013-03-05 18:47:58 -080045#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 Hughes7e5a8cc2013-06-18 13:15:00 -070050 } 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 Hughes0266ae52014-02-10 17:46:57 -080060#if defined(__LP64__)
61#define ELFW(what) ELF64_ ## what
62#else
63#define ELFW(what) ELF32_ ## what
64#endif
Elliott Hughes650be4e2013-03-05 18:47:58 -080065
Chris Dearman99186652014-02-06 20:36:51 -080066// 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 Hughes1a696162012-11-01 13:49:32 -070080// Returns the address of the page containing address 'x'.
81#define PAGE_START(x) ((x) & PAGE_MASK)
David 'Digit' Turnerc1bd5592012-06-19 11:21:29 +020082
Elliott Hughes1a696162012-11-01 13:49:32 -070083// Returns the offset of address 'x' in its page.
84#define PAGE_OFFSET(x) ((x) & ~PAGE_MASK)
David 'Digit' Turnerc1bd5592012-06-19 11:21:29 +020085
Elliott Hughes1a696162012-11-01 13:49:32 -070086// Returns the address of the next page after address 'x', unless 'x' is
87// itself at the start of a page.
David 'Digit' Turnerc1bd5592012-06-19 11:21:29 +020088#define PAGE_END(x) PAGE_START((x) + (PAGE_SIZE-1))
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080089
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080090#define FLAG_LINKED 0x00000001
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080091#define FLAG_EXE 0x00000004 // The main executable
Nick Kralevich468319c2011-11-11 15:53:17 -080092#define FLAG_LINKER 0x00000010 // The linker itself
Dmitriy Ivanovec18ce02014-11-09 19:27:20 -080093#define FLAG_GNU_HASH 0x00000040 // uses gnu hash
Dmitriy Ivanovd59e5002014-05-09 09:10:14 -070094#define FLAG_NEW_SOINFO 0x40000000 // new soinfo format
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080095
Dmitriy Ivanovd225a5e2014-08-28 14:12:12 -070096#define SUPPORTED_DT_FLAGS_1 (DF_1_NOW | DF_1_GLOBAL | DF_1_NODELETE)
97
Dmitriy Ivanov618f1a32015-03-17 20:06:36 -070098#define SOINFO_VERSION 2
Dmitriy Ivanov0d150942014-08-22 12:25:04 -070099
Dmitriy Ivanov9185e042015-05-15 17:53:39 -0700100#if defined(__work_around_b_19059885__)
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800101#define SOINFO_NAME_LEN 128
Dmitriy Ivanovaae859c2015-03-31 11:14:03 -0700102#endif
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800103
Elliott Hughesca0c11b2013-03-12 10:40:45 -0700104typedef void (*linker_function_t)();
105
Chris Dearman99186652014-02-06 20:36:51 -0800106// Android uses RELA for aarch64 and x86_64. mips64 still uses REL.
107#if defined(__aarch64__) || defined(__x86_64__)
Elliott Hughes4eeb1f12013-10-25 17:38:02 -0700108#define USE_RELA 1
109#endif
110
Dmitriy Ivanovd59e5002014-05-09 09:10:14 -0700111struct soinfo;
112
113class SoinfoListAllocator {
Dmitriy Ivanovec18ce02014-11-09 19:27:20 -0800114 public:
Dmitriy Ivanovd59e5002014-05-09 09:10:14 -0700115 static LinkedListEntry<soinfo>* alloc();
116 static void free(LinkedListEntry<soinfo>* entry);
Dmitriy Ivanovec18ce02014-11-09 19:27:20 -0800117
118 private:
Dmitriy Ivanovd59e5002014-05-09 09:10:14 -0700119 // unconstructable
120 DISALLOW_IMPLICIT_CONSTRUCTORS(SoinfoListAllocator);
121};
122
Dmitriy Ivanovec18ce02014-11-09 19:27:20 -0800123class 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 Ivanov2a815362015-04-09 13:42:33 -0700146struct 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.
155class 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 Hughes18a206c2012-10-29 17:37:13 -0700172struct soinfo {
Elliott Hughesca0c11b2013-03-12 10:40:45 -0700173 public:
Dmitriy Ivanovd59e5002014-05-09 09:10:14 -0700174 typedef LinkedList<soinfo, SoinfoListAllocator> soinfo_list_t;
Dmitriy Ivanov9185e042015-05-15 17:53:39 -0700175#if defined(__work_around_b_19059885__)
Dmitriy Ivanovaae859c2015-03-31 11:14:03 -0700176 private:
177 char old_name_[SOINFO_NAME_LEN];
178#endif
Dmitriy Ivanovd59e5002014-05-09 09:10:14 -0700179 public:
Elliott Hughes0266ae52014-02-10 17:46:57 -0800180 const ElfW(Phdr)* phdr;
Elliott Hughesca0c11b2013-03-12 10:40:45 -0700181 size_t phnum;
Elliott Hughes0266ae52014-02-10 17:46:57 -0800182 ElfW(Addr) entry;
183 ElfW(Addr) base;
Weiwu Chen5ceb8892013-12-03 19:47:34 +0800184 size_t size;
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800185
Dmitriy Ivanov9185e042015-05-15 17:53:39 -0700186#if defined(__work_around_b_19059885__)
Elliott Hughesca0c11b2013-03-12 10:40:45 -0700187 uint32_t unused1; // DO NOT USE, maintained for compatibility.
Elliott Hughesc6200592013-09-30 18:43:46 -0700188#endif
Nick Kralevich38bccb22011-08-29 13:49:22 -0700189
Elliott Hughes0266ae52014-02-10 17:46:57 -0800190 ElfW(Dyn)* dynamic;
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800191
Dmitriy Ivanov9185e042015-05-15 17:53:39 -0700192#if defined(__work_around_b_19059885__)
Elliott Hughesca0c11b2013-03-12 10:40:45 -0700193 uint32_t unused2; // DO NOT USE, maintained for compatibility
194 uint32_t unused3; // DO NOT USE, maintained for compatibility
Elliott Hughesc6200592013-09-30 18:43:46 -0700195#endif
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800196
Elliott Hughesd23736e2012-11-01 15:16:56 -0700197 soinfo* next;
Dmitriy Ivanov6cdeb522014-09-29 19:14:45 -0700198 private:
Dmitriy Ivanovab972b92014-11-29 13:57:41 -0800199 uint32_t flags_;
200
Dmitriy Ivanov047b5932014-11-13 09:39:20 -0800201 const char* strtab_;
202 ElfW(Sym)* symtab_;
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800203
Dmitriy Ivanov047b5932014-11-13 09:39:20 -0800204 size_t nbucket_;
205 size_t nchain_;
206 uint32_t* bucket_;
207 uint32_t* chain_;
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800208
Chris Dearman99186652014-02-06 20:36:51 -0800209#if defined(__mips__) || !defined(__LP64__)
210 // This is only used by mips and mips64, but needs to be here for
Elliott Hughes4eeb1f12013-10-25 17:38:02 -0700211 // all 32-bit architectures to preserve binary compatibility.
Dmitriy Ivanov047b5932014-11-13 09:39:20 -0800212 ElfW(Addr)** plt_got_;
Elliott Hughes4eeb1f12013-10-25 17:38:02 -0700213#endif
214
215#if defined(USE_RELA)
Dmitriy Ivanov047b5932014-11-13 09:39:20 -0800216 ElfW(Rela)* plt_rela_;
217 size_t plt_rela_count_;
Elliott Hughesc00f2cb2013-10-04 17:01:33 -0700218
Dmitriy Ivanov047b5932014-11-13 09:39:20 -0800219 ElfW(Rela)* rela_;
220 size_t rela_count_;
Elliott Hughesc00f2cb2013-10-04 17:01:33 -0700221#else
Dmitriy Ivanov047b5932014-11-13 09:39:20 -0800222 ElfW(Rel)* plt_rel_;
223 size_t plt_rel_count_;
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800224
Dmitriy Ivanov047b5932014-11-13 09:39:20 -0800225 ElfW(Rel)* rel_;
226 size_t rel_count_;
Elliott Hughesc00f2cb2013-10-04 17:01:33 -0700227#endif
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800228
Dmitriy Ivanov047b5932014-11-13 09:39:20 -0800229 linker_function_t* preinit_array_;
230 size_t preinit_array_count_;
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800231
Dmitriy Ivanov047b5932014-11-13 09:39:20 -0800232 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 Project1dc9e472009-03-03 19:28:35 -0800236
Dmitriy Ivanov047b5932014-11-13 09:39:20 -0800237 linker_function_t init_func_;
238 linker_function_t fini_func_;
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800239
Elliott Hughes4eeb1f12013-10-25 17:38:02 -0700240#if defined(__arm__)
Dmitriy Ivanovab972b92014-11-29 13:57:41 -0800241 public:
Elliott Hughesd23736e2012-11-01 15:16:56 -0700242 // ARM EABI section used for stack unwinding.
Dmitriy Ivanov1b20daf2014-05-19 15:06:58 -0700243 uint32_t* ARM_exidx;
Elliott Hughesca0c11b2013-03-12 10:40:45 -0700244 size_t ARM_exidx_count;
Dmitriy Ivanov88940912014-11-12 18:20:39 -0800245 private:
Dmitriy Ivanovab972b92014-11-29 13:57:41 -0800246#elif defined(__mips__)
Dmitriy Ivanov047b5932014-11-13 09:39:20 -0800247 uint32_t mips_symtabno_;
248 uint32_t mips_local_gotno_;
249 uint32_t mips_gotsym_;
Dmitriy Ivanovf39cb632015-04-30 20:17:03 -0700250 bool mips_relocate_got(const VersionTracker& version_tracker,
251 const soinfo_list_t& global_group,
252 const soinfo_list_t& local_group);
Dmitriy Ivanov88940912014-11-12 18:20:39 -0800253
Elliott Hughesd23736e2012-11-01 15:16:56 -0700254#endif
Dmitriy Ivanovab972b92014-11-29 13:57:41 -0800255 size_t ref_count_;
Dmitriy Ivanov047b5932014-11-13 09:39:20 -0800256 public:
Elliott Hughes3a9c5d62014-02-10 13:31:13 -0800257 link_map link_map_head;
Evgeniy Stepanove83c56d2011-12-21 13:03:54 +0400258
Elliott Hughesd23736e2012-11-01 15:16:56 -0700259 bool constructors_called;
Nick Kralevich9ec0f032012-02-28 10:40:00 -0800260
Elliott Hughesd23736e2012-11-01 15:16:56 -0700261 // When you read a virtual address from the ELF file, add this
262 // value to get the corresponding address in the process' address space.
Elliott Hughes0266ae52014-02-10 17:46:57 -0800263 ElfW(Addr) load_bias;
Ard Biesheuvel5ae44f32012-08-30 12:48:32 +0200264
Dimitry Ivanov56be6ed2015-04-01 21:18:48 +0000265#if !defined(__LP64__)
266 bool has_text_relocations;
Elliott Hughese4d792a2013-10-28 14:19:05 -0700267#endif
Dmitriy Ivanov96bc37f2014-09-29 12:10:36 -0700268 bool has_DT_SYMBOLIC;
Dmitriy Ivanov0d150942014-08-22 12:25:04 -0700269
Dmitriy Ivanov047b5932014-11-13 09:39:20 -0800270 public:
Dmitriy Ivanov07e5bc12014-10-03 17:52:44 -0700271 soinfo(const char* name, const struct stat* file_stat, off64_t file_offset, int rtld_flags);
Dmitriy Ivanov0d150942014-08-22 12:25:04 -0700272
Dmitriy Ivanov047b5932014-11-13 09:39:20 -0800273 void call_constructors();
274 void call_destructors();
275 void call_pre_init_constructors();
276 bool prelink_image();
Dmitriy Ivanov20d89cb2015-03-30 18:43:38 -0700277 bool link_image(const soinfo_list_t& global_group, const soinfo_list_t& local_group,
278 const android_dlextinfo* extinfo);
Elliott Hughesd23736e2012-11-01 15:16:56 -0700279
Dmitriy Ivanovd59e5002014-05-09 09:10:14 -0700280 void add_child(soinfo* child);
281 void remove_all_links();
282
Dmitriy Ivanovd225a5e2014-08-28 14:12:12 -0700283 ino_t get_st_ino() const;
284 dev_t get_st_dev() const;
285 off64_t get_file_offset() const;
Brigid Smithc5a13ef2014-07-23 11:22:25 -0700286
Dmitriy Ivanovd225a5e2014-08-28 14:12:12 -0700287 uint32_t get_rtld_flags() const;
288 uint32_t get_dt_flags_1() const;
289 void set_dt_flags_1(uint32_t dt_flags_1);
Dmitriy Ivanove8ba50f2014-09-15 17:00:10 -0700290
Dmitriy Ivanovd59e5002014-05-09 09:10:14 -0700291 soinfo_list_t& get_children();
Dmitriy Ivanov2a815362015-04-09 13:42:33 -0700292 const soinfo_list_t& get_children() const;
293
Dmitriy Ivanov14669a92014-09-05 16:42:53 -0700294 soinfo_list_t& get_parents();
Dmitriy Ivanovd59e5002014-05-09 09:10:14 -0700295
Dmitriy Ivanov2a815362015-04-09 13:42:33 -0700296 bool find_symbol_by_name(SymbolName& symbol_name,
297 const version_info* vi,
298 const ElfW(Sym)** symbol) const;
299
Dmitriy Ivanovec18ce02014-11-09 19:27:20 -0800300 ElfW(Sym)* find_symbol_by_address(const void* addr);
Dmitriy Ivanov2a815362015-04-09 13:42:33 -0700301 ElfW(Addr) resolve_symbol_address(const ElfW(Sym)* s) const;
Dmitriy Ivanov9aea1642014-09-11 15:16:03 -0700302
Dmitriy Ivanov6cdeb522014-09-29 19:14:45 -0700303 const char* get_string(ElfW(Word) index) const;
Dmitriy Ivanov1b20daf2014-05-19 15:06:58 -0700304 bool can_unload() const;
Dmitriy Ivanovec18ce02014-11-09 19:27:20 -0800305 bool is_gnu_hash() const;
Dmitriy Ivanov6cdeb522014-09-29 19:14:45 -0700306
Dmitriy Ivanovaae859c2015-03-31 11:14:03 -0700307 bool inline has_min_version(uint32_t min_version __unused) const {
Dmitriy Ivanov9185e042015-05-15 17:53:39 -0700308#if defined(__work_around_b_19059885__)
Dmitriy Ivanovab972b92014-11-29 13:57:41 -0800309 return (flags_ & FLAG_NEW_SOINFO) != 0 && version_ >= min_version;
Dmitriy Ivanovaae859c2015-03-31 11:14:03 -0700310#else
311 return true;
312#endif
Dmitriy Ivanov0d150942014-08-22 12:25:04 -0700313 }
Dmitriy Ivanov1b20daf2014-05-19 15:06:58 -0700314
Dmitriy Ivanovab972b92014-11-29 13:57:41 -0800315 bool is_linked() const;
316 bool is_main_executable() const;
317
318 void set_linked();
319 void set_linker_flag();
320 void set_main_executable();
321
322 void increment_ref_count();
323 size_t decrement_ref_count();
324
325 soinfo* get_local_group_root() const;
326
Dmitriy Ivanovaae859c2015-03-31 11:14:03 -0700327 const char* get_soname() const;
328 const char* get_realpath() const;
Dmitriy Ivanov2a815362015-04-09 13:42:33 -0700329 const ElfW(Versym)* get_versym(size_t n) const;
330 ElfW(Addr) get_verneed_ptr() const;
331 size_t get_verneed_cnt() const;
332 ElfW(Addr) get_verdef_ptr() const;
333 size_t get_verdef_cnt() const;
334
335 bool find_verdef_version_index(const version_info* vi, ElfW(Versym)* versym) const;
Dmitriy Ivanov618f1a32015-03-17 20:06:36 -0700336
Dmitriy Ivanov19133522015-06-02 17:36:54 -0700337 uint32_t get_target_sdk_version() const;
338
Evgenii Stepanov68650822015-06-10 13:38:39 -0700339 const std::vector<std::string>& get_dt_runpath() const;
340
Elliott Hughesd23736e2012-11-01 15:16:56 -0700341 private:
Dmitriy Ivanov2a815362015-04-09 13:42:33 -0700342 bool elf_lookup(SymbolName& symbol_name, const version_info* vi, uint32_t* symbol_index) const;
Dmitriy Ivanovec18ce02014-11-09 19:27:20 -0800343 ElfW(Sym)* elf_addr_lookup(const void* addr);
Dmitriy Ivanov2a815362015-04-09 13:42:33 -0700344 bool gnu_lookup(SymbolName& symbol_name, const version_info* vi, uint32_t* symbol_index) const;
Dmitriy Ivanovec18ce02014-11-09 19:27:20 -0800345 ElfW(Sym)* gnu_addr_lookup(const void* addr);
346
Dmitriy Ivanov31b408d2015-04-30 16:11:48 -0700347 bool lookup_version_info(const VersionTracker& version_tracker, ElfW(Word) sym,
348 const char* sym_name, const version_info** vi);
349
Dmitriy Ivanov047b5932014-11-13 09:39:20 -0800350 void call_array(const char* array_name, linker_function_t* functions, size_t count, bool reverse);
351 void call_function(const char* function_name, linker_function_t function);
Dmitriy Ivanovfa26eee2015-02-03 16:06:47 -0800352 template<typename ElfRelIteratorT>
Dmitriy Ivanov7e4bbba2015-04-30 19:49:19 -0700353 bool relocate(const VersionTracker& version_tracker, ElfRelIteratorT&& rel_iterator,
354 const soinfo_list_t& global_group, const soinfo_list_t& local_group);
Dmitriy Ivanovd59e5002014-05-09 09:10:14 -0700355
356 private:
357 // This part of the structure is only available
358 // when FLAG_NEW_SOINFO is set in this->flags.
Dmitriy Ivanov047b5932014-11-13 09:39:20 -0800359 uint32_t version_;
Dmitriy Ivanovd59e5002014-05-09 09:10:14 -0700360
Dmitriy Ivanov0d150942014-08-22 12:25:04 -0700361 // version >= 0
Dmitriy Ivanov047b5932014-11-13 09:39:20 -0800362 dev_t st_dev_;
363 ino_t st_ino_;
Dmitriy Ivanovd59e5002014-05-09 09:10:14 -0700364
365 // dependency graph
Dmitriy Ivanov047b5932014-11-13 09:39:20 -0800366 soinfo_list_t children_;
367 soinfo_list_t parents_;
Dmitriy Ivanovd59e5002014-05-09 09:10:14 -0700368
Dmitriy Ivanov0d150942014-08-22 12:25:04 -0700369 // version >= 1
Dmitriy Ivanov047b5932014-11-13 09:39:20 -0800370 off64_t file_offset_;
371 uint32_t rtld_flags_;
372 uint32_t dt_flags_1_;
373 size_t strtab_size_;
Dmitriy Ivanov6cdeb522014-09-29 19:14:45 -0700374
Dmitriy Ivanovec18ce02014-11-09 19:27:20 -0800375 // version >= 2
Dmitriy Ivanov3597b802015-03-09 12:02:02 -0700376
377 size_t gnu_nbucket_;
378 uint32_t* gnu_bucket_;
379 uint32_t* gnu_chain_;
Dmitriy Ivanov047b5932014-11-13 09:39:20 -0800380 uint32_t gnu_maskwords_;
381 uint32_t gnu_shift2_;
Dmitriy Ivanov047b5932014-11-13 09:39:20 -0800382 ElfW(Addr)* gnu_bloom_filter_;
Dmitriy Ivanovec18ce02014-11-09 19:27:20 -0800383
Dmitriy Ivanovab972b92014-11-29 13:57:41 -0800384 soinfo* local_group_root_;
385
Dmitriy Ivanov18a69562015-02-04 16:05:30 -0800386 uint8_t* android_relocs_;
387 size_t android_relocs_size_;
388
Dmitriy Ivanov618f1a32015-03-17 20:06:36 -0700389 const char* soname_;
Dmitriy Ivanovaae859c2015-03-31 11:14:03 -0700390 std::string realpath_;
Dmitriy Ivanov618f1a32015-03-17 20:06:36 -0700391
Dmitriy Ivanov2a815362015-04-09 13:42:33 -0700392 const ElfW(Versym)* versym_;
393
394 ElfW(Addr) verdef_ptr_;
395 size_t verdef_cnt_;
396
397 ElfW(Addr) verneed_ptr_;
398 size_t verneed_cnt_;
399
Dmitriy Ivanov19133522015-06-02 17:36:54 -0700400 uint32_t target_sdk_version_;
401
Evgenii Stepanov68650822015-06-10 13:38:39 -0700402 void set_dt_runpath(const char *);
403 std::vector<std::string> dt_runpath_;
404
Dmitriy Ivanov6cdeb522014-09-29 19:14:45 -0700405 friend soinfo* get_libdl_info();
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800406};
407
Dmitriy Ivanov2a815362015-04-09 13:42:33 -0700408bool soinfo_do_lookup(soinfo* si_from, const char* name, const version_info* vi,
409 soinfo** si_found_in, const soinfo::soinfo_list_t& global_group,
410 const soinfo::soinfo_list_t& local_group, const ElfW(Sym)** symbol);
Dmitriy Ivanov114ff692015-01-14 11:36:38 -0800411
412enum RelocationKind {
413 kRelocAbsolute = 0,
414 kRelocRelative,
415 kRelocCopy,
416 kRelocSymbol,
417 kRelocMax
418};
419
420void count_relocation(RelocationKind kind);
421
Dmitriy Ivanov1b20daf2014-05-19 15:06:58 -0700422soinfo* get_libdl_info();
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800423
Elliott Hughesa4aafd12014-01-13 16:37:47 -0800424void do_android_get_LD_LIBRARY_PATH(char*, size_t);
Elliott Hughescade4c32012-12-20 14:42:14 -0800425void do_android_update_LD_LIBRARY_PATH(const char* ld_library_path);
Elliott Hughes1a586292014-06-03 16:23:08 -0700426soinfo* do_dlopen(const char* name, int flags, const android_dlextinfo* extinfo);
Dmitriy Ivanovb648a8a2014-05-19 15:06:58 -0700427void do_dlclose(soinfo* si);
David 'Digit' Turner16084162012-06-12 16:25:37 +0200428
Dmitriy Ivanov2a815362015-04-09 13:42:33 -0700429const ElfW(Sym)* dlsym_linear_lookup(const char* name, soinfo** found, soinfo* caller, void* handle);
Elliott Hughesd23736e2012-11-01 15:16:56 -0700430soinfo* find_containing_library(const void* addr);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800431
Dmitriy Ivanov2a815362015-04-09 13:42:33 -0700432const ElfW(Sym)* dlsym_handle_lookup(soinfo* si, soinfo** found, const char* name);
Elliott Hughesd23736e2012-11-01 15:16:56 -0700433
Brian Carlstromd4ee82d2013-02-28 15:58:45 -0800434void debuggerd_init();
Elliott Hughes1728b232014-05-14 10:02:03 -0700435extern "C" abort_msg_t* g_abort_message;
Elliott Hughes18a206c2012-10-29 17:37:13 -0700436extern "C" void notify_gdb_of_libraries();
Elliott Hughes46882792012-08-03 16:49:39 -0700437
Elliott Hughes650be4e2013-03-05 18:47:58 -0800438char* linker_get_error_buffer();
439size_t linker_get_error_buffer_size();
440
Dmitriy Ivanov79fd6682015-05-21 17:43:49 -0700441void set_application_target_sdk_version(uint32_t target);
442uint32_t get_application_target_sdk_version();
443
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800444#endif