blob: ab2c38566b034799388ec247ab06688e8be3d715 [file] [log] [blame]
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -07001#ifndef _LINKER_H_
2#define _LINKER_H_
3
4#include <unistd.h>
5#include <sys/types.h>
6#include <linux/elf.h>
7
8#undef PAGE_MASK
9#undef PAGE_SIZE
10#define PAGE_SIZE 4096
11#define PAGE_MASK 4095
12
13void debugger_init();
14const char *addr_to_name(unsigned addr);
15
16/* magic shared structures that GDB knows about */
17
18struct link_map
19{
20 uintptr_t l_addr;
21 char * l_name;
22 uintptr_t l_ld;
23 struct link_map * l_next;
24 struct link_map * l_prev;
25};
26
27/* needed for dl_iterate_phdr to be passed to the callbacks provided */
28struct dl_phdr_info
29{
30 Elf32_Addr dlpi_addr;
31 const char *dlpi_name;
32 const Elf32_Phdr *dlpi_phdr;
33 Elf32_Half dlpi_phnum;
34};
35
36
37// Values for r_debug->state
38enum {
39 RT_CONSISTENT,
40 RT_ADD,
41 RT_DELETE
42};
43
44struct r_debug
45{
46 int32_t r_version;
47 struct link_map * r_map;
48 void (*r_brk)(void);
49 int32_t r_state;
50 uintptr_t r_ldbase;
51};
52
53typedef struct soinfo soinfo;
54
55#define FLAG_LINKED 0x00000001
56#define FLAG_ERROR 0x00000002
57#define FLAG_EXE 0x00000004 // The main executable
58#define FLAG_PRELINKED 0x00000008 // This is a pre-linked lib
59
60#define SOINFO_NAME_LEN 128
61
62struct soinfo
63{
64 const char name[SOINFO_NAME_LEN];
65 Elf32_Phdr *phdr;
66 int phnum;
67 unsigned entry;
68 unsigned base;
69 unsigned size;
70
71 unsigned *dynamic;
72
73 unsigned wrprotect_start;
74 unsigned wrprotect_end;
75
76 soinfo *next;
77 unsigned flags;
78
79 const char *strtab;
80 Elf32_Sym *symtab;
81
82 unsigned nbucket;
83 unsigned nchain;
84 unsigned *bucket;
85 unsigned *chain;
86
87 unsigned *plt_got;
88
89 Elf32_Rel *plt_rel;
90 unsigned plt_rel_count;
91
92 Elf32_Rel *rel;
93 unsigned rel_count;
94
95 unsigned *preinit_array;
96 unsigned preinit_array_count;
97
98 unsigned *init_array;
99 unsigned init_array_count;
100 unsigned *fini_array;
101 unsigned fini_array_count;
102
103 void (*init_func)(void);
104 void (*fini_func)(void);
105
106#ifdef ANDROID_ARM_LINKER
107 /* ARM EABI section used for stack unwinding. */
108 unsigned *ARM_exidx;
109 unsigned ARM_exidx_count;
110#endif
111
112 unsigned refcount;
113 struct link_map linkmap;
114};
115
116
117extern soinfo libdl_info;
118
119/* these must all be powers of two */
120#define LIBBASE 0x80000000
121#define LIBLAST 0x90000000
122#define LIBINC 0x00100000
123
124
125#ifdef ANDROID_ARM_LINKER
126
127#define R_ARM_COPY 20
128#define R_ARM_GLOB_DAT 21
129#define R_ARM_JUMP_SLOT 22
130#define R_ARM_RELATIVE 23
131
132#elif defined(ANDROID_X86_LINKER)
133
134#define R_386_32 1
135#define R_386_PC32 2
136#define R_386_GLOB_DAT 6
137#define R_386_JUMP_SLOT 7
138#define R_386_RELATIVE 8
139
140#endif /* ANDROID_*_LINKER */
141
142
143#ifndef DT_INIT_ARRAY
144#define DT_INIT_ARRAY 25
145#endif
146
147#ifndef DT_FINI_ARRAY
148#define DT_FINI_ARRAY 26
149#endif
150
151#ifndef DT_INIT_ARRAYSZ
152#define DT_INIT_ARRAYSZ 27
153#endif
154
155#ifndef DT_FINI_ARRAYSZ
156#define DT_FINI_ARRAYSZ 28
157#endif
158
159#ifndef DT_PREINIT_ARRAY
160#define DT_PREINIT_ARRAY 32
161#endif
162
163#ifndef DT_PREINIT_ARRAYSZ
164#define DT_PREINIT_ARRAYSZ 33
165#endif
166
167/* in theory we only need the above relative relocations,
168 but in practice the following one turns up from time
169 to time. fushigi na.
170*/
171#define R_ARM_ABS32 2
172
173soinfo *find_library(const char *name);
174unsigned unload_library(soinfo *si);
175Elf32_Sym *lookup_in_library(soinfo *si, const char *name);
176Elf32_Sym *lookup(const char *name, unsigned *base);
177
178#ifdef ANDROID_ARM_LINKER
179typedef long unsigned int *_Unwind_Ptr;
180_Unwind_Ptr dl_unwind_find_exidx(_Unwind_Ptr pc, int *pcount);
181#elif defined(ANDROID_X86_LINKER)
182int dl_iterate_phdr(int (*cb)(struct dl_phdr_info *, size_t, void *), void *);
183#endif
184
185#endif