linker.h revision d225a5e65223b375a63548c4b780f04d8f3d7b60
11dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project/*
21dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * Copyright (C) 2008 The Android Open Source Project
31dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * All rights reserved.
41dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project *
51dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * Redistribution and use in source and binary forms, with or without
61dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * modification, are permitted provided that the following conditions
71dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * are met:
81dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project *  * Redistributions of source code must retain the above copyright
91dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project *    notice, this list of conditions and the following disclaimer.
101dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project *  * Redistributions in binary form must reproduce the above copyright
111dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project *    notice, this list of conditions and the following disclaimer in
121dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project *    the documentation and/or other materials provided with the
131dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project *    distribution.
141dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project *
151dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
161dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
171dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
181dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
191dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
201dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
211dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
221dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
231dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
241dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
251dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
261dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * SUCH DAMAGE.
271dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project */
281dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
291dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#ifndef _LINKER_H_
301dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define _LINKER_H_
311dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
329ec0f03a0d0b17bbb94ac0b9fef6add28a133c3aNick Kralevich#include <elf.h>
330d15094287fe0f288d9c258953143fc1998b6b5aDmitriy Ivanov#include <inttypes.h>
34b7beb6907599b36809effe1b4db76039ac649518Pavel Chupin#include <link.h>
351272dbd1d76c979358fff3beae9de0c1462345afElliott Hughes#include <unistd.h>
36012cb4583a5f8564059142bb1900ea3a31e7cfa9Torne (Richard Coles)#include <android/dlext.h>
37d59e50063ad708509f3ad83350be33f5612c4f54Dmitriy Ivanov#include <sys/stat.h>
384688279db5dcc4004941e7f133c4a1c3617d842cElliott Hughes
398f2a5a0b40fc82126c691d5c30131d908772aab7Elliott Hughes#include "private/libc_logging.h"
40d59e50063ad708509f3ad83350be33f5612c4f54Dmitriy Ivanov#include "linked_list.h"
41650be4e584eeab3591b9e273bfd6d169eea60853Elliott Hughes
42650be4e584eeab3591b9e273bfd6d169eea60853Elliott Hughes#define DL_ERR(fmt, x...) \
43650be4e584eeab3591b9e273bfd6d169eea60853Elliott Hughes    do { \
44650be4e584eeab3591b9e273bfd6d169eea60853Elliott Hughes      __libc_format_buffer(linker_get_error_buffer(), linker_get_error_buffer_size(), fmt, ##x); \
45650be4e584eeab3591b9e273bfd6d169eea60853Elliott Hughes      /* If LD_DEBUG is set high enough, log every dlerror(3) message. */ \
46650be4e584eeab3591b9e273bfd6d169eea60853Elliott Hughes      DEBUG("%s\n", linker_get_error_buffer()); \
477e5a8cc5230dcc027686813e51a1b001cee4c602Elliott Hughes    } while (false)
487e5a8cc5230dcc027686813e51a1b001cee4c602Elliott Hughes
497e5a8cc5230dcc027686813e51a1b001cee4c602Elliott Hughes#define DL_WARN(fmt, x...) \
507e5a8cc5230dcc027686813e51a1b001cee4c602Elliott Hughes    do { \
517e5a8cc5230dcc027686813e51a1b001cee4c602Elliott Hughes      __libc_format_log(ANDROID_LOG_WARN, "linker", fmt, ##x); \
527e5a8cc5230dcc027686813e51a1b001cee4c602Elliott Hughes      __libc_format_fd(2, "WARNING: linker: "); \
537e5a8cc5230dcc027686813e51a1b001cee4c602Elliott Hughes      __libc_format_fd(2, fmt, ##x); \
547e5a8cc5230dcc027686813e51a1b001cee4c602Elliott Hughes      __libc_format_fd(2, "\n"); \
557e5a8cc5230dcc027686813e51a1b001cee4c602Elliott Hughes    } while (false)
567e5a8cc5230dcc027686813e51a1b001cee4c602Elliott Hughes
570266ae5f884d72da58f33a072e865ba131234a5eElliott Hughes#if defined(__LP64__)
580266ae5f884d72da58f33a072e865ba131234a5eElliott Hughes#define ELFW(what) ELF64_ ## what
590266ae5f884d72da58f33a072e865ba131234a5eElliott Hughes#else
600266ae5f884d72da58f33a072e865ba131234a5eElliott Hughes#define ELFW(what) ELF32_ ## what
610266ae5f884d72da58f33a072e865ba131234a5eElliott Hughes#endif
62650be4e584eeab3591b9e273bfd6d169eea60853Elliott Hughes
639918665a45095ad135576f005c0e5307feb366a1Chris Dearman// mips64 interprets Elf64_Rel structures' r_info field differently.
649918665a45095ad135576f005c0e5307feb366a1Chris Dearman// bionic (like other C libraries) has macros that assume regular ELF files,
659918665a45095ad135576f005c0e5307feb366a1Chris Dearman// but the dynamic linker needs to be able to load mips64 ELF files.
669918665a45095ad135576f005c0e5307feb366a1Chris Dearman#if defined(__mips__) && defined(__LP64__)
679918665a45095ad135576f005c0e5307feb366a1Chris Dearman#undef ELF64_R_SYM
689918665a45095ad135576f005c0e5307feb366a1Chris Dearman#undef ELF64_R_TYPE
699918665a45095ad135576f005c0e5307feb366a1Chris Dearman#undef ELF64_R_INFO
709918665a45095ad135576f005c0e5307feb366a1Chris Dearman#define ELF64_R_SYM(info)   (((info) >> 0) & 0xffffffff)
719918665a45095ad135576f005c0e5307feb366a1Chris Dearman#define ELF64_R_SSYM(info)  (((info) >> 32) & 0xff)
729918665a45095ad135576f005c0e5307feb366a1Chris Dearman#define ELF64_R_TYPE3(info) (((info) >> 40) & 0xff)
739918665a45095ad135576f005c0e5307feb366a1Chris Dearman#define ELF64_R_TYPE2(info) (((info) >> 48) & 0xff)
749918665a45095ad135576f005c0e5307feb366a1Chris Dearman#define ELF64_R_TYPE(info)  (((info) >> 56) & 0xff)
759918665a45095ad135576f005c0e5307feb366a1Chris Dearman#endif
769918665a45095ad135576f005c0e5307feb366a1Chris Dearman
771a6961650c82168864afe040dbdc05977db701dfElliott Hughes// Returns the address of the page containing address 'x'.
781a6961650c82168864afe040dbdc05977db701dfElliott Hughes#define PAGE_START(x)  ((x) & PAGE_MASK)
79c1bd559d5b0fdcc25db2b6ae2705914103b24699David 'Digit' Turner
801a6961650c82168864afe040dbdc05977db701dfElliott Hughes// Returns the offset of address 'x' in its page.
811a6961650c82168864afe040dbdc05977db701dfElliott Hughes#define PAGE_OFFSET(x) ((x) & ~PAGE_MASK)
82c1bd559d5b0fdcc25db2b6ae2705914103b24699David 'Digit' Turner
831a6961650c82168864afe040dbdc05977db701dfElliott Hughes// Returns the address of the next page after address 'x', unless 'x' is
841a6961650c82168864afe040dbdc05977db701dfElliott Hughes// itself at the start of a page.
85c1bd559d5b0fdcc25db2b6ae2705914103b24699David 'Digit' Turner#define PAGE_END(x)    PAGE_START((x) + (PAGE_SIZE-1))
861dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
871dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define FLAG_LINKED     0x00000001
881dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define FLAG_EXE        0x00000004 // The main executable
89468319ce4f3f7383d788b76c09cda2a405311f36Nick Kralevich#define FLAG_LINKER     0x00000010 // The linker itself
90d59e50063ad708509f3ad83350be33f5612c4f54Dmitriy Ivanov#define FLAG_NEW_SOINFO 0x40000000 // new soinfo format
911dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
92d225a5e65223b375a63548c4b780f04d8f3d7b60Dmitriy Ivanov#define SUPPORTED_DT_FLAGS_1 (DF_1_NOW | DF_1_GLOBAL | DF_1_NODELETE)
93d225a5e65223b375a63548c4b780f04d8f3d7b60Dmitriy Ivanov
940d15094287fe0f288d9c258953143fc1998b6b5aDmitriy Ivanov#define SOINFO_VERSION 1
950d15094287fe0f288d9c258953143fc1998b6b5aDmitriy Ivanov
961dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#define SOINFO_NAME_LEN 128
971dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
98ca0c11bd823f37f03cc8067cb182876827d5275aElliott Hughestypedef void (*linker_function_t)();
99ca0c11bd823f37f03cc8067cb182876827d5275aElliott Hughes
1009918665a45095ad135576f005c0e5307feb366a1Chris Dearman// Android uses RELA for aarch64 and x86_64. mips64 still uses REL.
1019918665a45095ad135576f005c0e5307feb366a1Chris Dearman#if defined(__aarch64__) || defined(__x86_64__)
1024eeb1f12a8b63afc0d0ad4d466b16fbffb21cd5aElliott Hughes#define USE_RELA 1
1034eeb1f12a8b63afc0d0ad4d466b16fbffb21cd5aElliott Hughes#endif
1044eeb1f12a8b63afc0d0ad4d466b16fbffb21cd5aElliott Hughes
105d59e50063ad708509f3ad83350be33f5612c4f54Dmitriy Ivanovstruct soinfo;
106d59e50063ad708509f3ad83350be33f5612c4f54Dmitriy Ivanov
107d59e50063ad708509f3ad83350be33f5612c4f54Dmitriy Ivanovclass SoinfoListAllocator {
108d59e50063ad708509f3ad83350be33f5612c4f54Dmitriy Ivanovpublic:
109d59e50063ad708509f3ad83350be33f5612c4f54Dmitriy Ivanov  static LinkedListEntry<soinfo>* alloc();
110d59e50063ad708509f3ad83350be33f5612c4f54Dmitriy Ivanov  static void free(LinkedListEntry<soinfo>* entry);
111d59e50063ad708509f3ad83350be33f5612c4f54Dmitriy Ivanovprivate:
112d59e50063ad708509f3ad83350be33f5612c4f54Dmitriy Ivanov  // unconstructable
113d59e50063ad708509f3ad83350be33f5612c4f54Dmitriy Ivanov  DISALLOW_IMPLICIT_CONSTRUCTORS(SoinfoListAllocator);
114d59e50063ad708509f3ad83350be33f5612c4f54Dmitriy Ivanov};
115d59e50063ad708509f3ad83350be33f5612c4f54Dmitriy Ivanov
11618a206c81d9743481e364384affd43306911283dElliott Hughesstruct soinfo {
117ca0c11bd823f37f03cc8067cb182876827d5275aElliott Hughes public:
118d59e50063ad708509f3ad83350be33f5612c4f54Dmitriy Ivanov  typedef LinkedList<soinfo, SoinfoListAllocator> soinfo_list_t;
119d59e50063ad708509f3ad83350be33f5612c4f54Dmitriy Ivanov public:
120d23736e4f228e46304b7cbc674a1d0094d73e0f5Elliott Hughes  char name[SOINFO_NAME_LEN];
1210266ae5f884d72da58f33a072e865ba131234a5eElliott Hughes  const ElfW(Phdr)* phdr;
122ca0c11bd823f37f03cc8067cb182876827d5275aElliott Hughes  size_t phnum;
1230266ae5f884d72da58f33a072e865ba131234a5eElliott Hughes  ElfW(Addr) entry;
1240266ae5f884d72da58f33a072e865ba131234a5eElliott Hughes  ElfW(Addr) base;
1255ceb889ac9a36e74e4e00c34c57cbb58d73e228cWeiwu Chen  size_t size;
1261dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
127c620059479c47a78d57086d73726c9adc2f337adElliott Hughes#ifndef __LP64__
128ca0c11bd823f37f03cc8067cb182876827d5275aElliott Hughes  uint32_t unused1;  // DO NOT USE, maintained for compatibility.
129c620059479c47a78d57086d73726c9adc2f337adElliott Hughes#endif
13038bccb271f121fc06eaa0d8fbd3c982bc44c36b7Nick Kralevich
1310266ae5f884d72da58f33a072e865ba131234a5eElliott Hughes  ElfW(Dyn)* dynamic;
1321dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
133c620059479c47a78d57086d73726c9adc2f337adElliott Hughes#ifndef __LP64__
134ca0c11bd823f37f03cc8067cb182876827d5275aElliott Hughes  uint32_t unused2; // DO NOT USE, maintained for compatibility
135ca0c11bd823f37f03cc8067cb182876827d5275aElliott Hughes  uint32_t unused3; // DO NOT USE, maintained for compatibility
136c620059479c47a78d57086d73726c9adc2f337adElliott Hughes#endif
1371dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
138d23736e4f228e46304b7cbc674a1d0094d73e0f5Elliott Hughes  soinfo* next;
1391b20dafdbe65e43b9f4c95057e8482380833ea91Dmitriy Ivanov  uint32_t flags;
1401dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
1416cdeb5234d7f4523fe9d83974f265d80f10512a6Dmitriy Ivanov private:
142d23736e4f228e46304b7cbc674a1d0094d73e0f5Elliott Hughes  const char* strtab;
1436cdeb5234d7f4523fe9d83974f265d80f10512a6Dmitriy Ivanov public:
1440266ae5f884d72da58f33a072e865ba131234a5eElliott Hughes  ElfW(Sym)* symtab;
1451dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
146ca0c11bd823f37f03cc8067cb182876827d5275aElliott Hughes  size_t nbucket;
147ca0c11bd823f37f03cc8067cb182876827d5275aElliott Hughes  size_t nchain;
1481b20dafdbe65e43b9f4c95057e8482380833ea91Dmitriy Ivanov  uint32_t* bucket;
1491b20dafdbe65e43b9f4c95057e8482380833ea91Dmitriy Ivanov  uint32_t* chain;
1501dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
1519918665a45095ad135576f005c0e5307feb366a1Chris Dearman#if defined(__mips__) || !defined(__LP64__)
1529918665a45095ad135576f005c0e5307feb366a1Chris Dearman  // This is only used by mips and mips64, but needs to be here for
1534eeb1f12a8b63afc0d0ad4d466b16fbffb21cd5aElliott Hughes  // all 32-bit architectures to preserve binary compatibility.
1549918665a45095ad135576f005c0e5307feb366a1Chris Dearman  ElfW(Addr)** plt_got;
1554eeb1f12a8b63afc0d0ad4d466b16fbffb21cd5aElliott Hughes#endif
1564eeb1f12a8b63afc0d0ad4d466b16fbffb21cd5aElliott Hughes
1574eeb1f12a8b63afc0d0ad4d466b16fbffb21cd5aElliott Hughes#if defined(USE_RELA)
1580266ae5f884d72da58f33a072e865ba131234a5eElliott Hughes  ElfW(Rela)* plt_rela;
159c00f2cb587630d5e954c7f548749f1e3170b3cb1Elliott Hughes  size_t plt_rela_count;
160c00f2cb587630d5e954c7f548749f1e3170b3cb1Elliott Hughes
1610266ae5f884d72da58f33a072e865ba131234a5eElliott Hughes  ElfW(Rela)* rela;
162c00f2cb587630d5e954c7f548749f1e3170b3cb1Elliott Hughes  size_t rela_count;
163c00f2cb587630d5e954c7f548749f1e3170b3cb1Elliott Hughes#else
1640266ae5f884d72da58f33a072e865ba131234a5eElliott Hughes  ElfW(Rel)* plt_rel;
165ca0c11bd823f37f03cc8067cb182876827d5275aElliott Hughes  size_t plt_rel_count;
1661dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
1670266ae5f884d72da58f33a072e865ba131234a5eElliott Hughes  ElfW(Rel)* rel;
168ca0c11bd823f37f03cc8067cb182876827d5275aElliott Hughes  size_t rel_count;
169c00f2cb587630d5e954c7f548749f1e3170b3cb1Elliott Hughes#endif
1701dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
171ca0c11bd823f37f03cc8067cb182876827d5275aElliott Hughes  linker_function_t* preinit_array;
172ca0c11bd823f37f03cc8067cb182876827d5275aElliott Hughes  size_t preinit_array_count;
1731dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
174ca0c11bd823f37f03cc8067cb182876827d5275aElliott Hughes  linker_function_t* init_array;
175ca0c11bd823f37f03cc8067cb182876827d5275aElliott Hughes  size_t init_array_count;
176ca0c11bd823f37f03cc8067cb182876827d5275aElliott Hughes  linker_function_t* fini_array;
177ca0c11bd823f37f03cc8067cb182876827d5275aElliott Hughes  size_t fini_array_count;
1781dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
179ca0c11bd823f37f03cc8067cb182876827d5275aElliott Hughes  linker_function_t init_func;
180ca0c11bd823f37f03cc8067cb182876827d5275aElliott Hughes  linker_function_t fini_func;
1811dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
1824eeb1f12a8b63afc0d0ad4d466b16fbffb21cd5aElliott Hughes#if defined(__arm__)
183d23736e4f228e46304b7cbc674a1d0094d73e0f5Elliott Hughes  // ARM EABI section used for stack unwinding.
1841b20dafdbe65e43b9f4c95057e8482380833ea91Dmitriy Ivanov  uint32_t* ARM_exidx;
185ca0c11bd823f37f03cc8067cb182876827d5275aElliott Hughes  size_t ARM_exidx_count;
1864eeb1f12a8b63afc0d0ad4d466b16fbffb21cd5aElliott Hughes#elif defined(__mips__)
1871b20dafdbe65e43b9f4c95057e8482380833ea91Dmitriy Ivanov  uint32_t mips_symtabno;
1881b20dafdbe65e43b9f4c95057e8482380833ea91Dmitriy Ivanov  uint32_t mips_local_gotno;
1891b20dafdbe65e43b9f4c95057e8482380833ea91Dmitriy Ivanov  uint32_t mips_gotsym;
1901dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#endif
1911dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
192ca0c11bd823f37f03cc8067cb182876827d5275aElliott Hughes  size_t ref_count;
1933a9c5d66dc8d41272f51482b713717af7049697eElliott Hughes  link_map link_map_head;
194e83c56dfbb6a9a61f0f18031620322af97e80162Evgeniy Stepanov
195d23736e4f228e46304b7cbc674a1d0094d73e0f5Elliott Hughes  bool constructors_called;
1969ec0f03a0d0b17bbb94ac0b9fef6add28a133c3aNick Kralevich
197d23736e4f228e46304b7cbc674a1d0094d73e0f5Elliott Hughes  // When you read a virtual address from the ELF file, add this
198d23736e4f228e46304b7cbc674a1d0094d73e0f5Elliott Hughes  // value to get the corresponding address in the process' address space.
1990266ae5f884d72da58f33a072e865ba131234a5eElliott Hughes  ElfW(Addr) load_bias;
2005ae44f302b7d1d19f25c4c6f125e32dc369961d9Ard Biesheuvel
201e4d792adb8d6f9228b9ac9dc1ad7f43b271f085fElliott Hughes#if !defined(__LP64__)
202d23736e4f228e46304b7cbc674a1d0094d73e0f5Elliott Hughes  bool has_text_relocations;
203e4d792adb8d6f9228b9ac9dc1ad7f43b271f085fElliott Hughes#endif
20496bc37f2e1093416a432135265fd7a4db6c3df17Dmitriy Ivanov  bool has_DT_SYMBOLIC;
2050d15094287fe0f288d9c258953143fc1998b6b5aDmitriy Ivanov
20607e5bc152d8a3ad4c50808bb86f3c0f2c5e2f514Dmitriy Ivanov  soinfo(const char* name, const struct stat* file_stat, off64_t file_offset, int rtld_flags);
2070d15094287fe0f288d9c258953143fc1998b6b5aDmitriy Ivanov
208d23736e4f228e46304b7cbc674a1d0094d73e0f5Elliott Hughes  void CallConstructors();
209d23736e4f228e46304b7cbc674a1d0094d73e0f5Elliott Hughes  void CallDestructors();
210d23736e4f228e46304b7cbc674a1d0094d73e0f5Elliott Hughes  void CallPreInitConstructors();
21114669a939d113214a4a20b9318fca0992d5453f0Dmitriy Ivanov  bool PrelinkImage();
212d225a5e65223b375a63548c4b780f04d8f3d7b60Dmitriy Ivanov  bool LinkImage(const soinfo_list_t& global_group, const soinfo_list_t& local_group, const android_dlextinfo* extinfo);
213d23736e4f228e46304b7cbc674a1d0094d73e0f5Elliott Hughes
214d59e50063ad708509f3ad83350be33f5612c4f54Dmitriy Ivanov  void add_child(soinfo* child);
215d59e50063ad708509f3ad83350be33f5612c4f54Dmitriy Ivanov  void remove_all_links();
216d59e50063ad708509f3ad83350be33f5612c4f54Dmitriy Ivanov
217d225a5e65223b375a63548c4b780f04d8f3d7b60Dmitriy Ivanov  ino_t get_st_ino() const;
218d225a5e65223b375a63548c4b780f04d8f3d7b60Dmitriy Ivanov  dev_t get_st_dev() const;
219d225a5e65223b375a63548c4b780f04d8f3d7b60Dmitriy Ivanov  off64_t get_file_offset() const;
220c5a13efa9bc4264be0a9a9e37c00633af01584edBrigid Smith
221d225a5e65223b375a63548c4b780f04d8f3d7b60Dmitriy Ivanov  uint32_t get_rtld_flags() const;
222d225a5e65223b375a63548c4b780f04d8f3d7b60Dmitriy Ivanov  uint32_t get_dt_flags_1() const;
223d225a5e65223b375a63548c4b780f04d8f3d7b60Dmitriy Ivanov  void set_dt_flags_1(uint32_t dt_flags_1);
224e8ba50fe0d51fbefee1a8f5bb62bf51d841512c8Dmitriy Ivanov
225d59e50063ad708509f3ad83350be33f5612c4f54Dmitriy Ivanov  soinfo_list_t& get_children();
22614669a939d113214a4a20b9318fca0992d5453f0Dmitriy Ivanov  soinfo_list_t& get_parents();
227d59e50063ad708509f3ad83350be33f5612c4f54Dmitriy Ivanov
2289aea164457c269c475592da36b4655d45f55c7bcDmitriy Ivanov  ElfW(Addr) resolve_symbol_address(ElfW(Sym)* s);
2299aea164457c269c475592da36b4655d45f55c7bcDmitriy Ivanov
2306cdeb5234d7f4523fe9d83974f265d80f10512a6Dmitriy Ivanov  const char* get_string(ElfW(Word) index) const;
2311b20dafdbe65e43b9f4c95057e8482380833ea91Dmitriy Ivanov  bool can_unload() const;
2326cdeb5234d7f4523fe9d83974f265d80f10512a6Dmitriy Ivanov
2336cdeb5234d7f4523fe9d83974f265d80f10512a6Dmitriy Ivanov  bool inline has_min_version(uint32_t min_version) const {
2340d15094287fe0f288d9c258953143fc1998b6b5aDmitriy Ivanov    return (flags & FLAG_NEW_SOINFO) != 0 && version >= min_version;
2350d15094287fe0f288d9c258953143fc1998b6b5aDmitriy Ivanov  }
2361b20dafdbe65e43b9f4c95057e8482380833ea91Dmitriy Ivanov
237d23736e4f228e46304b7cbc674a1d0094d73e0f5Elliott Hughes private:
238ca0c11bd823f37f03cc8067cb182876827d5275aElliott Hughes  void CallArray(const char* array_name, linker_function_t* functions, size_t count, bool reverse);
239ca0c11bd823f37f03cc8067cb182876827d5275aElliott Hughes  void CallFunction(const char* function_name, linker_function_t function);
24029bbc9dd4c606de9187e46d8899a2a744715c967Dmitriy Ivanov#if defined(USE_RELA)
241d225a5e65223b375a63548c4b780f04d8f3d7b60Dmitriy Ivanov  int Relocate(ElfW(Rela)* rela, unsigned count, const soinfo_list_t& global_group, const soinfo_list_t& local_group);
24229bbc9dd4c606de9187e46d8899a2a744715c967Dmitriy Ivanov#else
243d225a5e65223b375a63548c4b780f04d8f3d7b60Dmitriy Ivanov  int Relocate(ElfW(Rel)* rel, unsigned count, const soinfo_list_t& global_group, const soinfo_list_t& local_group);
24429bbc9dd4c606de9187e46d8899a2a744715c967Dmitriy Ivanov#endif
245d59e50063ad708509f3ad83350be33f5612c4f54Dmitriy Ivanov
246d59e50063ad708509f3ad83350be33f5612c4f54Dmitriy Ivanov private:
247d59e50063ad708509f3ad83350be33f5612c4f54Dmitriy Ivanov  // This part of the structure is only available
248d59e50063ad708509f3ad83350be33f5612c4f54Dmitriy Ivanov  // when FLAG_NEW_SOINFO is set in this->flags.
2490d15094287fe0f288d9c258953143fc1998b6b5aDmitriy Ivanov  uint32_t version;
250c5a13efa9bc4264be0a9a9e37c00633af01584edBrigid Smith
2510d15094287fe0f288d9c258953143fc1998b6b5aDmitriy Ivanov  // version >= 0
252d59e50063ad708509f3ad83350be33f5612c4f54Dmitriy Ivanov  dev_t st_dev;
253d59e50063ad708509f3ad83350be33f5612c4f54Dmitriy Ivanov  ino_t st_ino;
254d59e50063ad708509f3ad83350be33f5612c4f54Dmitriy Ivanov
255d59e50063ad708509f3ad83350be33f5612c4f54Dmitriy Ivanov  // dependency graph
256d59e50063ad708509f3ad83350be33f5612c4f54Dmitriy Ivanov  soinfo_list_t children;
257d59e50063ad708509f3ad83350be33f5612c4f54Dmitriy Ivanov  soinfo_list_t parents;
258d59e50063ad708509f3ad83350be33f5612c4f54Dmitriy Ivanov
2590d15094287fe0f288d9c258953143fc1998b6b5aDmitriy Ivanov  // version >= 1
26007e5bc152d8a3ad4c50808bb86f3c0f2c5e2f514Dmitriy Ivanov  off64_t file_offset;
261d225a5e65223b375a63548c4b780f04d8f3d7b60Dmitriy Ivanov  uint32_t rtld_flags;
262d225a5e65223b375a63548c4b780f04d8f3d7b60Dmitriy Ivanov  uint32_t dt_flags_1;
2636cdeb5234d7f4523fe9d83974f265d80f10512a6Dmitriy Ivanov  size_t strtab_size;
2646cdeb5234d7f4523fe9d83974f265d80f10512a6Dmitriy Ivanov
2656cdeb5234d7f4523fe9d83974f265d80f10512a6Dmitriy Ivanov  friend soinfo* get_libdl_info();
2661dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project};
2671dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
2681b20dafdbe65e43b9f4c95057e8482380833ea91Dmitriy Ivanovsoinfo* get_libdl_info();
2691dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
270a4aafd156068ee174012f28cd894dbecf0e4ab90Elliott Hughesvoid do_android_get_LD_LIBRARY_PATH(char*, size_t);
271cade4c36e7c9c62db3f476a0f9cfc329bac9acb7Elliott Hughesvoid do_android_update_LD_LIBRARY_PATH(const char* ld_library_path);
2721a586293400d0e1d73e6eb82f7dfe9d2d9ed3c4bElliott Hughessoinfo* do_dlopen(const char* name, int flags, const android_dlextinfo* extinfo);
273b648a8a57ee42533a5bf127225a252f73ca2cbbcDmitriy Ivanovvoid do_dlclose(soinfo* si);
27416084168111cd7d2ac8a6b92e6fa6df5696928a5David 'Digit' Turner
27502aa70589d22fa9b65da43de705d6de2715870c6Dmitriy IvanovElfW(Sym)* dlsym_linear_lookup(const char* name, soinfo** found, soinfo* start);
276d23736e4f228e46304b7cbc674a1d0094d73e0f5Elliott Hughessoinfo* find_containing_library(const void* addr);
2771dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project
2780266ae5f884d72da58f33a072e865ba131234a5eElliott HughesElfW(Sym)* dladdr_find_symbol(soinfo* si, const void* addr);
27902aa70589d22fa9b65da43de705d6de2715870c6Dmitriy IvanovElfW(Sym)* dlsym_handle_lookup(soinfo* si, soinfo** found, const char* name);
280d23736e4f228e46304b7cbc674a1d0094d73e0f5Elliott Hughes
281d4ee82dfa3ba01baa10e3ca48fcb31a27b8a4e81Brian Carlstromvoid debuggerd_init();
2821728b2396591853345507a063ed6075dfd251706Elliott Hughesextern "C" abort_msg_t* g_abort_message;
28318a206c81d9743481e364384affd43306911283dElliott Hughesextern "C" void notify_gdb_of_libraries();
2844688279db5dcc4004941e7f133c4a1c3617d842cElliott Hughes
285650be4e584eeab3591b9e273bfd6d169eea60853Elliott Hugheschar* linker_get_error_buffer();
286650be4e584eeab3591b9e273bfd6d169eea60853Elliott Hughessize_t linker_get_error_buffer_size();
287650be4e584eeab3591b9e273bfd6d169eea60853Elliott Hughes
2881dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#endif
289