Rich Felker | 4f4bf0a | 2011-09-18 16:42:06 -0400 | [diff] [blame] | 1 | #ifdef __PIC__ |
Rich Felker | 51e2d83 | 2011-06-18 19:48:42 -0400 | [diff] [blame] | 2 | #include <stdio.h> |
| 3 | #include <stdlib.h> |
| 4 | #include <string.h> |
| 5 | #include <unistd.h> |
| 6 | #include <stdint.h> |
| 7 | #include <elf.h> |
| 8 | #include <sys/mman.h> |
| 9 | #include <limits.h> |
| 10 | #include <stdint.h> |
| 11 | #include <fcntl.h> |
| 12 | #include <sys/stat.h> |
| 13 | #include <errno.h> |
| 14 | #include <limits.h> |
| 15 | #include <elf.h> |
Rich Felker | 6b3d5e5 | 2011-06-26 17:39:17 -0400 | [diff] [blame] | 16 | #include <setjmp.h> |
Rich Felker | 59ab43f | 2011-06-26 19:23:28 -0400 | [diff] [blame] | 17 | #include <pthread.h> |
Rich Felker | 2719cc8 | 2011-08-16 00:24:36 -0400 | [diff] [blame] | 18 | #include <ctype.h> |
Rich Felker | 59ab43f | 2011-06-26 19:23:28 -0400 | [diff] [blame] | 19 | #include <dlfcn.h> |
Rich Felker | 51e2d83 | 2011-06-18 19:48:42 -0400 | [diff] [blame] | 20 | |
| 21 | #include "reloc.h" |
| 22 | |
| 23 | #if ULONG_MAX == 0xffffffff |
| 24 | typedef Elf32_Ehdr Ehdr; |
| 25 | typedef Elf32_Phdr Phdr; |
| 26 | typedef Elf32_Sym Sym; |
| 27 | #define R_TYPE(x) ((x)&255) |
| 28 | #define R_SYM(x) ((x)>>8) |
| 29 | #else |
| 30 | typedef Elf64_Ehdr Ehdr; |
| 31 | typedef Elf64_Phdr Phdr; |
| 32 | typedef Elf64_Sym Sym; |
| 33 | #define R_TYPE(x) ((x)&0xffffffff) |
| 34 | #define R_SYM(x) ((x)>>32) |
| 35 | #endif |
| 36 | |
| 37 | struct dso |
| 38 | { |
| 39 | struct dso *next, *prev; |
| 40 | int refcnt; |
| 41 | size_t *dynv; |
| 42 | Sym *syms; |
Rich Felker | 596d60c | 2011-06-18 22:52:01 -0400 | [diff] [blame] | 43 | uint32_t *hashtab; |
Rich Felker | 51e2d83 | 2011-06-18 19:48:42 -0400 | [diff] [blame] | 44 | char *strings; |
| 45 | unsigned char *base; |
| 46 | unsigned char *map; |
| 47 | size_t map_len; |
| 48 | dev_t dev; |
| 49 | ino_t ino; |
| 50 | int global; |
| 51 | int relocated; |
Rich Felker | 59ab43f | 2011-06-26 19:23:28 -0400 | [diff] [blame] | 52 | struct dso **deps; |
Rich Felker | 6b3d5e5 | 2011-06-26 17:39:17 -0400 | [diff] [blame] | 53 | char *name; |
| 54 | char buf[]; |
Rich Felker | 51e2d83 | 2011-06-18 19:48:42 -0400 | [diff] [blame] | 55 | }; |
| 56 | |
| 57 | static struct dso *head, *tail, *libc; |
Rich Felker | 191ebca | 2011-06-30 23:02:27 -0400 | [diff] [blame] | 58 | static char *env_path, *sys_path, *r_path; |
Rich Felker | 59ab43f | 2011-06-26 19:23:28 -0400 | [diff] [blame] | 59 | static int rtld_used; |
Rich Felker | 6b3d5e5 | 2011-06-26 17:39:17 -0400 | [diff] [blame] | 60 | static int runtime; |
| 61 | static jmp_buf rtld_fail; |
Rich Felker | 59ab43f | 2011-06-26 19:23:28 -0400 | [diff] [blame] | 62 | static pthread_rwlock_t lock; |
Rich Felker | 51e2d83 | 2011-06-18 19:48:42 -0400 | [diff] [blame] | 63 | |
Rich Felker | a045883 | 2011-08-16 07:46:42 -0400 | [diff] [blame] | 64 | #define AUX_CNT 24 |
Rich Felker | 51e2d83 | 2011-06-18 19:48:42 -0400 | [diff] [blame] | 65 | #define DYN_CNT 34 |
| 66 | |
| 67 | static void decode_vec(size_t *v, size_t *a, size_t cnt) |
| 68 | { |
| 69 | memset(a, 0, cnt*sizeof(size_t)); |
| 70 | for (; v[0]; v+=2) if (v[0]<cnt) { |
| 71 | a[0] |= 1ULL<<v[0]; |
| 72 | a[v[0]] = v[1]; |
| 73 | } |
| 74 | } |
| 75 | |
Rich Felker | 2adf2fb | 2012-01-17 00:34:58 -0500 | [diff] [blame] | 76 | static uint32_t hash(const char *s0) |
Rich Felker | 51e2d83 | 2011-06-18 19:48:42 -0400 | [diff] [blame] | 77 | { |
Rich Felker | 2adf2fb | 2012-01-17 00:34:58 -0500 | [diff] [blame] | 78 | const unsigned char *s = (void *)s0; |
Rich Felker | 51e2d83 | 2011-06-18 19:48:42 -0400 | [diff] [blame] | 79 | uint_fast32_t h = 0; |
| 80 | while (*s) { |
| 81 | h = 16*h + *s++; |
| 82 | h ^= h>>24 & 0xf0; |
| 83 | } |
| 84 | return h & 0xfffffff; |
| 85 | } |
| 86 | |
Rich Felker | 596d60c | 2011-06-18 22:52:01 -0400 | [diff] [blame] | 87 | static Sym *lookup(const char *s, uint32_t h, Sym *syms, uint32_t *hashtab, char *strings) |
Rich Felker | 51e2d83 | 2011-06-18 19:48:42 -0400 | [diff] [blame] | 88 | { |
| 89 | size_t i; |
| 90 | for (i=hashtab[2+h%hashtab[0]]; i; i=hashtab[2+hashtab[0]+i]) { |
| 91 | if (!strcmp(s, strings+syms[i].st_name)) |
| 92 | return syms+i; |
| 93 | } |
| 94 | return 0; |
| 95 | } |
| 96 | |
| 97 | #define OK_TYPES (1<<STT_NOTYPE | 1<<STT_OBJECT | 1<<STT_FUNC | 1<<STT_COMMON) |
Rich Felker | 427173b | 2011-07-24 02:19:47 -0400 | [diff] [blame] | 98 | #define OK_BINDS (1<<STB_GLOBAL | 1<<STB_WEAK) |
Rich Felker | 51e2d83 | 2011-06-18 19:48:42 -0400 | [diff] [blame] | 99 | |
| 100 | static void *find_sym(struct dso *dso, const char *s, int need_def) |
| 101 | { |
| 102 | uint32_t h = hash(s); |
Rich Felker | 427173b | 2011-07-24 02:19:47 -0400 | [diff] [blame] | 103 | void *def = 0; |
Rich Felker | 59ab43f | 2011-06-26 19:23:28 -0400 | [diff] [blame] | 104 | if (h==0x6b366be && !strcmp(s, "dlopen")) rtld_used = 1; |
| 105 | if (h==0x6b3afd && !strcmp(s, "dlsym")) rtld_used = 1; |
Rich Felker | 51e2d83 | 2011-06-18 19:48:42 -0400 | [diff] [blame] | 106 | for (; dso; dso=dso->next) { |
Rich Felker | 59ab43f | 2011-06-26 19:23:28 -0400 | [diff] [blame] | 107 | Sym *sym; |
| 108 | if (!dso->global) continue; |
| 109 | sym = lookup(s, h, dso->syms, dso->hashtab, dso->strings); |
Rich Felker | 51e2d83 | 2011-06-18 19:48:42 -0400 | [diff] [blame] | 110 | if (sym && (!need_def || sym->st_shndx) && sym->st_value |
Rich Felker | 427173b | 2011-07-24 02:19:47 -0400 | [diff] [blame] | 111 | && (1<<(sym->st_info&0xf) & OK_TYPES) |
| 112 | && (1<<(sym->st_info>>4) & OK_BINDS)) { |
Rich Felker | e01ac67 | 2011-07-25 09:22:05 -0400 | [diff] [blame] | 113 | if (def && sym->st_info>>4 == STB_WEAK) continue; |
Rich Felker | 427173b | 2011-07-24 02:19:47 -0400 | [diff] [blame] | 114 | def = dso->base + sym->st_value; |
| 115 | if (sym->st_info>>4 == STB_GLOBAL) break; |
| 116 | } |
Rich Felker | 51e2d83 | 2011-06-18 19:48:42 -0400 | [diff] [blame] | 117 | } |
Rich Felker | 427173b | 2011-07-24 02:19:47 -0400 | [diff] [blame] | 118 | return def; |
Rich Felker | 51e2d83 | 2011-06-18 19:48:42 -0400 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | static void do_relocs(unsigned char *base, size_t *rel, size_t rel_size, size_t stride, Sym *syms, char *strings, struct dso *dso) |
| 122 | { |
| 123 | Sym *sym; |
| 124 | const char *name; |
| 125 | size_t sym_val, sym_size; |
| 126 | size_t *reloc_addr; |
| 127 | void *ctx; |
| 128 | int type; |
| 129 | int sym_index; |
| 130 | |
| 131 | for (; rel_size; rel+=stride, rel_size-=stride*sizeof(size_t)) { |
| 132 | reloc_addr = (void *)(base + rel[0]); |
| 133 | type = R_TYPE(rel[1]); |
| 134 | sym_index = R_SYM(rel[1]); |
| 135 | if (sym_index) { |
| 136 | sym = syms + sym_index; |
| 137 | name = strings + sym->st_name; |
| 138 | ctx = IS_COPY(type) ? dso->next : dso; |
Rich Felker | 32de61e | 2011-06-25 22:36:21 -0400 | [diff] [blame] | 139 | sym_val = (size_t)find_sym(ctx, name, IS_PLT(type)); |
Rich Felker | 6b3d5e5 | 2011-06-26 17:39:17 -0400 | [diff] [blame] | 140 | if (!sym_val && sym->st_info>>4 != STB_WEAK) { |
| 141 | if (runtime) longjmp(rtld_fail, 1); |
| 142 | dprintf(2, "%s: symbol not found\n", name); |
| 143 | _exit(127); |
| 144 | } |
Rich Felker | 51e2d83 | 2011-06-18 19:48:42 -0400 | [diff] [blame] | 145 | sym_size = sym->st_size; |
| 146 | } |
| 147 | do_single_reloc(reloc_addr, type, sym_val, sym_size, base, rel[2]); |
| 148 | } |
| 149 | } |
| 150 | |
Rich Felker | 6717e62 | 2011-06-28 19:40:14 -0400 | [diff] [blame] | 151 | /* A huge hack: to make up for the wastefulness of shared libraries |
| 152 | * needing at least a page of dirty memory even if they have no global |
| 153 | * data, we reclaim the gaps at the beginning and end of writable maps |
| 154 | * and "donate" them to the heap by setting up minimal malloc |
| 155 | * structures and then freeing them. */ |
| 156 | |
| 157 | static void reclaim(unsigned char *base, size_t start, size_t end) |
| 158 | { |
| 159 | size_t *a, *z; |
| 160 | start = start + 6*sizeof(size_t)-1 & -4*sizeof(size_t); |
| 161 | end = (end & -4*sizeof(size_t)) - 2*sizeof(size_t); |
| 162 | if (start>end || end-start < 4*sizeof(size_t)) return; |
| 163 | a = (size_t *)(base + start); |
| 164 | z = (size_t *)(base + end); |
| 165 | a[-2] = 1; |
| 166 | a[-1] = z[0] = end-start + 2*sizeof(size_t) | 1; |
| 167 | z[1] = 1; |
| 168 | free(a); |
| 169 | } |
| 170 | |
| 171 | static void reclaim_gaps(unsigned char *base, Phdr *ph, size_t phent, size_t phcnt) |
| 172 | { |
| 173 | for (; phcnt--; ph=(void *)((char *)ph+phent)) { |
| 174 | if (ph->p_type!=PT_LOAD) continue; |
| 175 | if ((ph->p_flags&(PF_R|PF_W))!=(PF_R|PF_W)) continue; |
| 176 | reclaim(base, ph->p_vaddr & -PAGE_SIZE, ph->p_vaddr); |
| 177 | reclaim(base, ph->p_vaddr+ph->p_memsz, |
| 178 | ph->p_vaddr+ph->p_memsz+PAGE_SIZE-1 & -PAGE_SIZE); |
| 179 | } |
| 180 | } |
| 181 | |
Rich Felker | 51e2d83 | 2011-06-18 19:48:42 -0400 | [diff] [blame] | 182 | static void *map_library(int fd, size_t *lenp, unsigned char **basep, size_t *dynp) |
| 183 | { |
Rich Felker | 59633c7 | 2011-06-25 12:26:08 -0400 | [diff] [blame] | 184 | Ehdr buf[(896+sizeof(Ehdr))/sizeof(Ehdr)]; |
Rich Felker | 51e2d83 | 2011-06-18 19:48:42 -0400 | [diff] [blame] | 185 | size_t phsize; |
| 186 | size_t addr_min=SIZE_MAX, addr_max=0, map_len; |
| 187 | size_t this_min, this_max; |
| 188 | off_t off_start; |
| 189 | Ehdr *eh; |
| 190 | Phdr *ph; |
| 191 | unsigned prot; |
| 192 | unsigned char *map, *base; |
| 193 | size_t dyn; |
| 194 | size_t i; |
| 195 | |
| 196 | ssize_t l = read(fd, buf, sizeof buf); |
| 197 | if (l<sizeof *eh) return 0; |
Rich Felker | 59633c7 | 2011-06-25 12:26:08 -0400 | [diff] [blame] | 198 | eh = buf; |
Rich Felker | 51e2d83 | 2011-06-18 19:48:42 -0400 | [diff] [blame] | 199 | phsize = eh->e_phentsize * eh->e_phnum; |
| 200 | if (phsize + sizeof *eh > l) return 0; |
| 201 | if (eh->e_phoff + phsize > l) { |
Rich Felker | 59633c7 | 2011-06-25 12:26:08 -0400 | [diff] [blame] | 202 | l = pread(fd, buf+1, phsize, eh->e_phoff); |
Rich Felker | 51e2d83 | 2011-06-18 19:48:42 -0400 | [diff] [blame] | 203 | if (l != phsize) return 0; |
| 204 | eh->e_phoff = sizeof *eh; |
| 205 | } |
| 206 | ph = (void *)((char *)buf + eh->e_phoff); |
| 207 | for (i=eh->e_phnum; i; i--, ph=(void *)((char *)ph+eh->e_phentsize)) { |
| 208 | if (ph->p_type == PT_DYNAMIC) |
| 209 | dyn = ph->p_vaddr; |
| 210 | if (ph->p_type != PT_LOAD) continue; |
| 211 | if (ph->p_vaddr < addr_min) { |
| 212 | addr_min = ph->p_vaddr; |
| 213 | off_start = ph->p_offset; |
| 214 | prot = (((ph->p_flags&PF_R) ? PROT_READ : 0) | |
| 215 | ((ph->p_flags&PF_W) ? PROT_WRITE: 0) | |
| 216 | ((ph->p_flags&PF_X) ? PROT_EXEC : 0)); |
| 217 | } |
| 218 | if (ph->p_vaddr+ph->p_memsz > addr_max) { |
| 219 | addr_max = ph->p_vaddr+ph->p_memsz; |
| 220 | } |
| 221 | } |
| 222 | if (!dyn) return 0; |
| 223 | addr_max += PAGE_SIZE-1; |
| 224 | addr_max &= -PAGE_SIZE; |
| 225 | addr_min &= -PAGE_SIZE; |
| 226 | off_start &= -PAGE_SIZE; |
| 227 | map_len = addr_max - addr_min + off_start; |
| 228 | /* The first time, we map too much, possibly even more than |
| 229 | * the length of the file. This is okay because we will not |
| 230 | * use the invalid part; we just need to reserve the right |
| 231 | * amount of virtual address space to map over later. */ |
Rich Felker | bf30100 | 2011-06-28 14:20:41 -0400 | [diff] [blame] | 232 | map = mmap((void *)addr_min, map_len, prot, MAP_PRIVATE, fd, off_start); |
Rich Felker | 51e2d83 | 2011-06-18 19:48:42 -0400 | [diff] [blame] | 233 | if (map==MAP_FAILED) return 0; |
| 234 | base = map - addr_min; |
| 235 | ph = (void *)((char *)buf + eh->e_phoff); |
| 236 | for (i=eh->e_phnum; i; i--, ph=(void *)((char *)ph+eh->e_phentsize)) { |
| 237 | if (ph->p_type != PT_LOAD) continue; |
| 238 | /* Reuse the existing mapping for the lowest-address LOAD */ |
| 239 | if ((ph->p_vaddr & -PAGE_SIZE) == addr_min) continue; |
| 240 | this_min = ph->p_vaddr & -PAGE_SIZE; |
| 241 | this_max = ph->p_vaddr+ph->p_memsz+PAGE_SIZE-1 & -PAGE_SIZE; |
| 242 | off_start = ph->p_offset & -PAGE_SIZE; |
| 243 | prot = (((ph->p_flags&PF_R) ? PROT_READ : 0) | |
| 244 | ((ph->p_flags&PF_W) ? PROT_WRITE: 0) | |
| 245 | ((ph->p_flags&PF_X) ? PROT_EXEC : 0)); |
| 246 | if (mmap(base+this_min, this_max-this_min, prot, MAP_PRIVATE|MAP_FIXED, fd, off_start) == MAP_FAILED) { |
| 247 | munmap(map, map_len); |
| 248 | return 0; |
| 249 | } |
| 250 | if (ph->p_memsz > ph->p_filesz) { |
| 251 | size_t brk = (size_t)base+ph->p_vaddr+ph->p_filesz; |
| 252 | size_t pgbrk = brk+PAGE_SIZE-1 & -PAGE_SIZE; |
| 253 | memset((void *)brk, 0, pgbrk-brk & PAGE_SIZE-1); |
| 254 | if (pgbrk-(size_t)base < this_max && mmap((void *)pgbrk, (size_t)base+this_max-pgbrk, prot, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) == MAP_FAILED) { |
| 255 | munmap(map, map_len); |
| 256 | return 0; |
| 257 | } |
| 258 | } |
| 259 | } |
Rich Felker | 9f17413 | 2011-06-29 00:29:08 -0400 | [diff] [blame] | 260 | for (i=0; ((size_t *)(base+dyn))[i]; i+=2) |
| 261 | if (((size_t *)(base+dyn))[i]==DT_TEXTREL) { |
| 262 | mprotect(map, map_len, PROT_READ|PROT_WRITE|PROT_EXEC); |
| 263 | break; |
| 264 | } |
Rich Felker | 6717e62 | 2011-06-28 19:40:14 -0400 | [diff] [blame] | 265 | if (!runtime) reclaim_gaps(base, (void *)((char *)buf + eh->e_phoff), |
| 266 | eh->e_phentsize, eh->e_phnum); |
Rich Felker | 51e2d83 | 2011-06-18 19:48:42 -0400 | [diff] [blame] | 267 | *lenp = map_len; |
| 268 | *basep = base; |
| 269 | *dynp = dyn; |
| 270 | return map; |
| 271 | } |
| 272 | |
Rich Felker | 568b807 | 2011-06-25 01:56:34 -0400 | [diff] [blame] | 273 | static int path_open(const char *name, const char *search) |
| 274 | { |
| 275 | char buf[2*NAME_MAX+2]; |
Rich Felker | 49388f3 | 2011-06-25 17:49:16 -0400 | [diff] [blame] | 276 | const char *s=search, *z; |
Rich Felker | 568b807 | 2011-06-25 01:56:34 -0400 | [diff] [blame] | 277 | int l, fd; |
Rich Felker | 49388f3 | 2011-06-25 17:49:16 -0400 | [diff] [blame] | 278 | for (;;) { |
| 279 | while (*s==':') s++; |
| 280 | if (!*s) return -1; |
Rich Felker | 568b807 | 2011-06-25 01:56:34 -0400 | [diff] [blame] | 281 | z = strchr(s, ':'); |
| 282 | l = z ? z-s : strlen(s); |
| 283 | snprintf(buf, sizeof buf, "%.*s/%s", l, s, name); |
| 284 | if ((fd = open(buf, O_RDONLY))>=0) return fd; |
Rich Felker | 49388f3 | 2011-06-25 17:49:16 -0400 | [diff] [blame] | 285 | s += l; |
Rich Felker | 568b807 | 2011-06-25 01:56:34 -0400 | [diff] [blame] | 286 | } |
Rich Felker | 568b807 | 2011-06-25 01:56:34 -0400 | [diff] [blame] | 287 | } |
| 288 | |
Rich Felker | c82f4a3 | 2012-01-23 00:57:38 -0500 | [diff] [blame^] | 289 | static void decode_dyn(struct dso *p) |
| 290 | { |
| 291 | size_t dyn[DYN_CNT] = {0}; |
| 292 | decode_vec(p->dynv, dyn, DYN_CNT); |
| 293 | p->syms = (void *)(p->base + dyn[DT_SYMTAB]); |
| 294 | p->hashtab = (void *)(p->base + dyn[DT_HASH]); |
| 295 | p->strings = (void *)(p->base + dyn[DT_STRTAB]); |
| 296 | } |
| 297 | |
Rich Felker | 51e2d83 | 2011-06-18 19:48:42 -0400 | [diff] [blame] | 298 | static struct dso *load_library(const char *name) |
| 299 | { |
| 300 | unsigned char *base, *map; |
| 301 | size_t dyno, map_len; |
| 302 | struct dso *p; |
Rich Felker | 51e2d83 | 2011-06-18 19:48:42 -0400 | [diff] [blame] | 303 | int fd; |
| 304 | struct stat st; |
| 305 | |
| 306 | /* Catch and block attempts to reload the implementation itself */ |
| 307 | if (name[0]=='l' && name[1]=='i' && name[2]=='b') { |
| 308 | static const char *rp, reserved[] = |
| 309 | "c\0pthread\0rt\0m\0dl\0util\0xnet\0"; |
| 310 | char *z = strchr(name, '.'); |
| 311 | if (z) { |
| 312 | size_t l = z-name; |
| 313 | for (rp=reserved; *rp && memcmp(name+3, rp, l-3); rp+=strlen(rp)+1); |
| 314 | if (*rp) { |
| 315 | if (!libc->prev) { |
| 316 | tail->next = libc; |
| 317 | libc->prev = tail; |
Rich Felker | 6ab444d | 2011-07-24 00:54:55 -0400 | [diff] [blame] | 318 | tail = libc->next ? libc->next : libc; |
Rich Felker | 51e2d83 | 2011-06-18 19:48:42 -0400 | [diff] [blame] | 319 | } |
| 320 | return libc; |
| 321 | } |
| 322 | } |
| 323 | } |
| 324 | /* Search for the name to see if it's already loaded */ |
| 325 | for (p=head->next; p; p=p->next) { |
| 326 | if (!strcmp(p->name, name)) { |
| 327 | p->refcnt++; |
| 328 | return p; |
| 329 | } |
| 330 | } |
Rich Felker | 59ab43f | 2011-06-26 19:23:28 -0400 | [diff] [blame] | 331 | if (strchr(name, '/')) { |
Rich Felker | 51e2d83 | 2011-06-18 19:48:42 -0400 | [diff] [blame] | 332 | fd = open(name, O_RDONLY); |
| 333 | } else { |
Rich Felker | 59ab43f | 2011-06-26 19:23:28 -0400 | [diff] [blame] | 334 | if (strlen(name) > NAME_MAX) return 0; |
Rich Felker | 568b807 | 2011-06-25 01:56:34 -0400 | [diff] [blame] | 335 | fd = -1; |
Rich Felker | 191ebca | 2011-06-30 23:02:27 -0400 | [diff] [blame] | 336 | if (r_path) fd = path_open(name, r_path); |
| 337 | if (fd < 0 && env_path) fd = path_open(name, env_path); |
Rich Felker | 568b807 | 2011-06-25 01:56:34 -0400 | [diff] [blame] | 338 | if (fd < 0) { |
| 339 | if (!sys_path) { |
| 340 | FILE *f = fopen(ETC_LDSO_PATH, "r"); |
| 341 | if (f) { |
| 342 | if (getline(&sys_path, (size_t[1]){0}, f) > 0) |
| 343 | sys_path[strlen(sys_path)-1]=0; |
| 344 | fclose(f); |
| 345 | } |
| 346 | } |
| 347 | if (sys_path) fd = path_open(name, sys_path); |
| 348 | else fd = path_open(name, "/lib:/usr/local/lib:/usr/lib"); |
Rich Felker | 51e2d83 | 2011-06-18 19:48:42 -0400 | [diff] [blame] | 349 | } |
| 350 | } |
| 351 | if (fd < 0) return 0; |
| 352 | if (fstat(fd, &st) < 0) { |
| 353 | close(fd); |
| 354 | return 0; |
| 355 | } |
| 356 | for (p=head->next; p; p=p->next) { |
| 357 | if (p->dev == st.st_dev && p->ino == st.st_ino) { |
| 358 | close(fd); |
| 359 | p->refcnt++; |
| 360 | return p; |
| 361 | } |
| 362 | } |
| 363 | map = map_library(fd, &map_len, &base, &dyno); |
| 364 | close(fd); |
| 365 | if (!map) return 0; |
| 366 | p = calloc(1, sizeof *p + strlen(name) + 1); |
| 367 | if (!p) { |
| 368 | munmap(map, map_len); |
| 369 | return 0; |
| 370 | } |
| 371 | |
| 372 | p->map = map; |
| 373 | p->map_len = map_len; |
| 374 | p->base = base; |
| 375 | p->dynv = (void *)(base + dyno); |
Rich Felker | c82f4a3 | 2012-01-23 00:57:38 -0500 | [diff] [blame^] | 376 | decode_dyn(p); |
Rich Felker | 51e2d83 | 2011-06-18 19:48:42 -0400 | [diff] [blame] | 377 | |
Rich Felker | 51e2d83 | 2011-06-18 19:48:42 -0400 | [diff] [blame] | 378 | p->dev = st.st_dev; |
| 379 | p->ino = st.st_ino; |
Rich Felker | 51e2d83 | 2011-06-18 19:48:42 -0400 | [diff] [blame] | 380 | p->refcnt = 1; |
Rich Felker | 6b3d5e5 | 2011-06-26 17:39:17 -0400 | [diff] [blame] | 381 | p->name = p->buf; |
Rich Felker | 51e2d83 | 2011-06-18 19:48:42 -0400 | [diff] [blame] | 382 | strcpy(p->name, name); |
| 383 | |
| 384 | tail->next = p; |
| 385 | p->prev = tail; |
| 386 | tail = p; |
| 387 | |
| 388 | return p; |
| 389 | } |
| 390 | |
| 391 | static void load_deps(struct dso *p) |
| 392 | { |
Rich Felker | 59ab43f | 2011-06-26 19:23:28 -0400 | [diff] [blame] | 393 | size_t i, ndeps=0; |
| 394 | struct dso ***deps = &p->deps, **tmp, *dep; |
Rich Felker | 51e2d83 | 2011-06-18 19:48:42 -0400 | [diff] [blame] | 395 | for (; p; p=p->next) { |
| 396 | for (i=0; p->dynv[i]; i+=2) { |
Rich Felker | 191ebca | 2011-06-30 23:02:27 -0400 | [diff] [blame] | 397 | if (p->dynv[i] != DT_RPATH) continue; |
| 398 | r_path = (void *)(p->strings + p->dynv[i+1]); |
| 399 | } |
| 400 | for (i=0; p->dynv[i]; i+=2) { |
Rich Felker | 51e2d83 | 2011-06-18 19:48:42 -0400 | [diff] [blame] | 401 | if (p->dynv[i] != DT_NEEDED) continue; |
Rich Felker | 59ab43f | 2011-06-26 19:23:28 -0400 | [diff] [blame] | 402 | dep = load_library(p->strings + p->dynv[i+1]); |
| 403 | if (!dep) { |
Rich Felker | 6b3d5e5 | 2011-06-26 17:39:17 -0400 | [diff] [blame] | 404 | if (runtime) longjmp(rtld_fail, 1); |
| 405 | dprintf(2, "%s: %m (needed by %s)\n", |
| 406 | p->strings + p->dynv[i+1], p->name); |
| 407 | _exit(127); |
| 408 | } |
Rich Felker | 59ab43f | 2011-06-26 19:23:28 -0400 | [diff] [blame] | 409 | if (runtime) { |
| 410 | tmp = realloc(*deps, sizeof(*tmp)*(ndeps+2)); |
| 411 | if (!tmp) longjmp(rtld_fail, 1); |
| 412 | tmp[ndeps++] = dep; |
| 413 | tmp[ndeps] = 0; |
| 414 | *deps = tmp; |
| 415 | } |
Rich Felker | 51e2d83 | 2011-06-18 19:48:42 -0400 | [diff] [blame] | 416 | } |
Rich Felker | 191ebca | 2011-06-30 23:02:27 -0400 | [diff] [blame] | 417 | r_path = 0; |
Rich Felker | 51e2d83 | 2011-06-18 19:48:42 -0400 | [diff] [blame] | 418 | } |
| 419 | } |
| 420 | |
Rich Felker | 2719cc8 | 2011-08-16 00:24:36 -0400 | [diff] [blame] | 421 | static void load_preload(char *s) |
| 422 | { |
| 423 | int tmp; |
| 424 | char *z; |
| 425 | for (z=s; *z; s=z) { |
| 426 | for ( ; *s && isspace(*s); s++); |
| 427 | for (z=s; *z && !isspace(*z); z++); |
| 428 | tmp = *z; |
| 429 | *z = 0; |
| 430 | load_library(s); |
| 431 | *z = tmp; |
| 432 | } |
| 433 | } |
| 434 | |
Rich Felker | 59ab43f | 2011-06-26 19:23:28 -0400 | [diff] [blame] | 435 | static void make_global(struct dso *p) |
| 436 | { |
| 437 | for (; p; p=p->next) p->global = 1; |
| 438 | } |
| 439 | |
Rich Felker | 51e2d83 | 2011-06-18 19:48:42 -0400 | [diff] [blame] | 440 | static void reloc_all(struct dso *p) |
| 441 | { |
| 442 | size_t dyn[DYN_CNT] = {0}; |
| 443 | for (; p; p=p->next) { |
| 444 | if (p->relocated) continue; |
| 445 | decode_vec(p->dynv, dyn, DYN_CNT); |
| 446 | do_relocs(p->base, (void *)(p->base+dyn[DT_JMPREL]), dyn[DT_PLTRELSZ], |
Rich Felker | 32de61e | 2011-06-25 22:36:21 -0400 | [diff] [blame] | 447 | 2+(dyn[DT_PLTREL]==DT_RELA), p->syms, p->strings, head); |
Rich Felker | 51e2d83 | 2011-06-18 19:48:42 -0400 | [diff] [blame] | 448 | do_relocs(p->base, (void *)(p->base+dyn[DT_REL]), dyn[DT_RELSZ], |
Rich Felker | 32de61e | 2011-06-25 22:36:21 -0400 | [diff] [blame] | 449 | 2, p->syms, p->strings, head); |
Rich Felker | 51e2d83 | 2011-06-18 19:48:42 -0400 | [diff] [blame] | 450 | do_relocs(p->base, (void *)(p->base+dyn[DT_RELA]), dyn[DT_RELASZ], |
Rich Felker | 32de61e | 2011-06-25 22:36:21 -0400 | [diff] [blame] | 451 | 3, p->syms, p->strings, head); |
Rich Felker | 368ba4a | 2011-06-25 00:18:19 -0400 | [diff] [blame] | 452 | p->relocated = 1; |
Rich Felker | 51e2d83 | 2011-06-18 19:48:42 -0400 | [diff] [blame] | 453 | } |
| 454 | } |
| 455 | |
Rich Felker | e8dbf00 | 2011-06-25 00:47:28 -0400 | [diff] [blame] | 456 | static void free_all(struct dso *p) |
| 457 | { |
| 458 | struct dso *n; |
| 459 | while (p) { |
| 460 | n = p->next; |
| 461 | if (p->map) free(p); |
| 462 | p = n; |
| 463 | } |
| 464 | } |
| 465 | |
Rich Felker | c82f4a3 | 2012-01-23 00:57:38 -0500 | [diff] [blame^] | 466 | static size_t find_dyn(Phdr *ph, size_t cnt, size_t stride) |
| 467 | { |
| 468 | for (; cnt--; ph = (void *)((char *)ph + stride)) |
| 469 | if (ph->p_type == PT_DYNAMIC) |
| 470 | return ph->p_vaddr; |
| 471 | return 0; |
| 472 | } |
| 473 | |
| 474 | void *__dynlink(int argc, char **argv) |
Rich Felker | 51e2d83 | 2011-06-18 19:48:42 -0400 | [diff] [blame] | 475 | { |
| 476 | size_t *auxv, aux[AUX_CNT] = {0}; |
Rich Felker | 51e2d83 | 2011-06-18 19:48:42 -0400 | [diff] [blame] | 477 | size_t i; |
| 478 | Phdr *phdr; |
Rich Felker | 6717e62 | 2011-06-28 19:40:14 -0400 | [diff] [blame] | 479 | Ehdr *ehdr; |
Rich Felker | 6ab444d | 2011-07-24 00:54:55 -0400 | [diff] [blame] | 480 | static struct dso builtin_dsos[3]; |
Rich Felker | a53de81 | 2011-07-24 00:26:12 -0400 | [diff] [blame] | 481 | struct dso *const app = builtin_dsos+0; |
| 482 | struct dso *const lib = builtin_dsos+1; |
Rich Felker | 6ab444d | 2011-07-24 00:54:55 -0400 | [diff] [blame] | 483 | struct dso *const vdso = builtin_dsos+2; |
Rich Felker | 2719cc8 | 2011-08-16 00:24:36 -0400 | [diff] [blame] | 484 | char *env_preload=0; |
Rich Felker | 51e2d83 | 2011-06-18 19:48:42 -0400 | [diff] [blame] | 485 | |
| 486 | /* Find aux vector just past environ[] */ |
Rich Felker | 568b807 | 2011-06-25 01:56:34 -0400 | [diff] [blame] | 487 | for (i=argc+1; argv[i]; i++) |
| 488 | if (!memcmp(argv[i], "LD_LIBRARY_PATH=", 16)) |
| 489 | env_path = argv[i]+16; |
Rich Felker | 2719cc8 | 2011-08-16 00:24:36 -0400 | [diff] [blame] | 490 | else if (!memcmp(argv[i], "LD_PRELOAD=", 11)) |
| 491 | env_preload = argv[i]+11; |
Rich Felker | 51e2d83 | 2011-06-18 19:48:42 -0400 | [diff] [blame] | 492 | auxv = (void *)(argv+i+1); |
| 493 | |
| 494 | decode_vec(auxv, aux, AUX_CNT); |
| 495 | |
Rich Felker | 568b807 | 2011-06-25 01:56:34 -0400 | [diff] [blame] | 496 | /* Only trust user/env if kernel says we're not suid/sgid */ |
| 497 | if ((aux[0]&0x7800)!=0x7800 || aux[AT_UID]!=aux[AT_EUID] |
Rich Felker | a045883 | 2011-08-16 07:46:42 -0400 | [diff] [blame] | 498 | || aux[AT_GID]!=aux[AT_EGID] || aux[AT_SECURE]) { |
Rich Felker | 568b807 | 2011-06-25 01:56:34 -0400 | [diff] [blame] | 499 | env_path = 0; |
Rich Felker | 2719cc8 | 2011-08-16 00:24:36 -0400 | [diff] [blame] | 500 | env_preload = 0; |
Rich Felker | 568b807 | 2011-06-25 01:56:34 -0400 | [diff] [blame] | 501 | } |
| 502 | |
Rich Felker | c82f4a3 | 2012-01-23 00:57:38 -0500 | [diff] [blame^] | 503 | /* The dynamic linker load address is passed by the kernel |
| 504 | * in the AUX vector, so this is easy. */ |
| 505 | lib->base = (void *)aux[AT_BASE]; |
| 506 | lib->name = "libc.so"; |
| 507 | lib->global = 1; |
| 508 | ehdr = (void *)lib->base; |
| 509 | lib->dynv = (void *)(lib->base + find_dyn( |
| 510 | (void *)(aux[AT_BASE]+ehdr->e_phoff), |
| 511 | ehdr->e_phnum, ehdr->e_phentsize)); |
| 512 | decode_dyn(lib); |
| 513 | |
| 514 | /* Assume base address of 0 for the main program. This is not |
| 515 | * valid for PIE code; we will have to search the PHDR to get |
| 516 | * the correct load address in the PIE case (not yet supported). */ |
| 517 | app->base = 0; |
| 518 | app->name = argv[0]; |
| 519 | app->global = 1; |
| 520 | app->dynv = (void *)(app->base + find_dyn( |
| 521 | (void *)aux[AT_PHDR], aux[AT_PHNUM], aux[AT_PHENT])); |
| 522 | decode_dyn(app); |
| 523 | |
| 524 | /* Attach to vdso, if provided by the kernel */ |
Rich Felker | cf8506a | 2011-08-16 08:50:03 -0400 | [diff] [blame] | 525 | for (i=0; auxv[i]; i+=2) { |
Rich Felker | c82f4a3 | 2012-01-23 00:57:38 -0500 | [diff] [blame^] | 526 | size_t vdso_base = auxv[i+1]; |
| 527 | if (auxv[i] != AT_SYSINFO_EHDR) continue; |
Rich Felker | 6ab444d | 2011-07-24 00:54:55 -0400 | [diff] [blame] | 528 | ehdr = (void *)vdso_base; |
| 529 | phdr = (void *)(vdso_base + ehdr->e_phoff); |
| 530 | for (i=ehdr->e_phnum; i; i--, phdr=(void *)((char *)phdr + ehdr->e_phentsize)) { |
| 531 | if (phdr->p_type == PT_DYNAMIC) |
| 532 | vdso->dynv = (void *)(vdso_base + phdr->p_offset); |
| 533 | if (phdr->p_type == PT_LOAD) |
| 534 | vdso->base = (void *)(vdso_base - phdr->p_vaddr + phdr->p_offset); |
| 535 | } |
Rich Felker | 6ab444d | 2011-07-24 00:54:55 -0400 | [diff] [blame] | 536 | vdso->name = "linux-gate.so.1"; |
Rich Felker | 427173b | 2011-07-24 02:19:47 -0400 | [diff] [blame] | 537 | vdso->global = 1; |
Rich Felker | c82f4a3 | 2012-01-23 00:57:38 -0500 | [diff] [blame^] | 538 | decode_dyn(vdso); |
Rich Felker | 6ab444d | 2011-07-24 00:54:55 -0400 | [diff] [blame] | 539 | vdso->prev = lib; |
| 540 | lib->next = vdso; |
Rich Felker | c82f4a3 | 2012-01-23 00:57:38 -0500 | [diff] [blame^] | 541 | break; |
Rich Felker | 6ab444d | 2011-07-24 00:54:55 -0400 | [diff] [blame] | 542 | } |
| 543 | |
Rich Felker | c82f4a3 | 2012-01-23 00:57:38 -0500 | [diff] [blame^] | 544 | /* Initial dso chain consists only of the app. We temporarily |
| 545 | * append the dynamic linker/libc so we can relocate it, then |
| 546 | * restore the initial chain in preparation for loading third |
| 547 | * party libraries (preload/needed). */ |
| 548 | head = tail = app; |
| 549 | libc = lib; |
| 550 | app->next = lib; |
| 551 | reloc_all(lib); |
| 552 | app->next = 0; |
Rich Felker | 51e2d83 | 2011-06-18 19:48:42 -0400 | [diff] [blame] | 553 | |
Rich Felker | c82f4a3 | 2012-01-23 00:57:38 -0500 | [diff] [blame^] | 554 | /* PAST THIS POINT, ALL LIBC INTERFACES ARE FULLY USABLE. */ |
Rich Felker | 51e2d83 | 2011-06-18 19:48:42 -0400 | [diff] [blame] | 555 | |
Rich Felker | c82f4a3 | 2012-01-23 00:57:38 -0500 | [diff] [blame^] | 556 | /* Donate unused parts of app and library mapping to malloc */ |
Rich Felker | a53de81 | 2011-07-24 00:26:12 -0400 | [diff] [blame] | 557 | reclaim_gaps(app->base, (void *)aux[AT_PHDR], aux[AT_PHENT], aux[AT_PHNUM]); |
| 558 | ehdr = (void *)lib->base; |
| 559 | reclaim_gaps(lib->base, (void *)(lib->base+ehdr->e_phoff), |
Rich Felker | 6717e62 | 2011-06-28 19:40:14 -0400 | [diff] [blame] | 560 | ehdr->e_phentsize, ehdr->e_phnum); |
| 561 | |
Rich Felker | c82f4a3 | 2012-01-23 00:57:38 -0500 | [diff] [blame^] | 562 | /* Load preload/needed libraries, add their symbols to the global |
| 563 | * namespace, and perform all remaining relocations. */ |
Rich Felker | 2719cc8 | 2011-08-16 00:24:36 -0400 | [diff] [blame] | 564 | if (env_preload) load_preload(env_preload); |
Rich Felker | c82f4a3 | 2012-01-23 00:57:38 -0500 | [diff] [blame^] | 565 | load_deps(app); |
| 566 | make_global(app); |
| 567 | reloc_all(app); |
Rich Felker | 51e2d83 | 2011-06-18 19:48:42 -0400 | [diff] [blame] | 568 | |
Rich Felker | c82f4a3 | 2012-01-23 00:57:38 -0500 | [diff] [blame^] | 569 | /* Switch to runtime mode: any further failures in the dynamic |
| 570 | * linker are a reportable failure rather than a fatal startup |
| 571 | * error. If the dynamic loader (dlopen) will not be used, free |
| 572 | * all memory used by the dynamic linker. */ |
Rich Felker | a53de81 | 2011-07-24 00:26:12 -0400 | [diff] [blame] | 573 | runtime = 1; |
| 574 | if (!rtld_used) { |
Rich Felker | 59ab43f | 2011-06-26 19:23:28 -0400 | [diff] [blame] | 575 | free_all(head); |
| 576 | free(sys_path); |
Rich Felker | a53de81 | 2011-07-24 00:26:12 -0400 | [diff] [blame] | 577 | reclaim((void *)builtin_dsos, 0, sizeof builtin_dsos); |
Rich Felker | 59ab43f | 2011-06-26 19:23:28 -0400 | [diff] [blame] | 578 | } |
Rich Felker | e8dbf00 | 2011-06-25 00:47:28 -0400 | [diff] [blame] | 579 | |
Rich Felker | 51e2d83 | 2011-06-18 19:48:42 -0400 | [diff] [blame] | 580 | errno = 0; |
| 581 | return (void *)aux[AT_ENTRY]; |
| 582 | } |
Rich Felker | 59ab43f | 2011-06-26 19:23:28 -0400 | [diff] [blame] | 583 | |
| 584 | void *dlopen(const char *file, int mode) |
| 585 | { |
Rich Felker | 2fdea17 | 2011-07-01 22:40:00 -0400 | [diff] [blame] | 586 | struct dso *volatile p, *orig_tail = tail, *next; |
Rich Felker | 59ab43f | 2011-06-26 19:23:28 -0400 | [diff] [blame] | 587 | size_t i; |
| 588 | |
| 589 | if (!file) return head; |
| 590 | |
| 591 | pthread_rwlock_wrlock(&lock); |
| 592 | |
| 593 | if (setjmp(rtld_fail)) { |
| 594 | /* Clean up anything new that was (partially) loaded */ |
Rich Felker | 92ab5d8 | 2011-06-26 21:21:04 -0400 | [diff] [blame] | 595 | if (p->deps) for (i=0; p->deps[i]; i++) |
| 596 | if (p->deps[i]->global < 0) |
| 597 | p->deps[i]->global = 0; |
Rich Felker | 59ab43f | 2011-06-26 19:23:28 -0400 | [diff] [blame] | 598 | for (p=orig_tail->next; p; p=next) { |
| 599 | next = p->next; |
| 600 | munmap(p->map, p->map_len); |
| 601 | free(p->deps); |
| 602 | free(p); |
| 603 | } |
| 604 | tail = orig_tail; |
| 605 | tail->next = 0; |
| 606 | pthread_rwlock_unlock(&lock); |
| 607 | return 0; |
| 608 | } |
| 609 | |
| 610 | p = load_library(file); |
Rich Felker | 06933cc | 2011-06-26 22:09:32 -0400 | [diff] [blame] | 611 | if (!p) goto end; |
Rich Felker | 59ab43f | 2011-06-26 19:23:28 -0400 | [diff] [blame] | 612 | |
| 613 | /* First load handling */ |
| 614 | if (!p->deps) { |
| 615 | load_deps(p); |
Rich Felker | 0e4dae3 | 2011-06-26 21:36:44 -0400 | [diff] [blame] | 616 | if (p->deps) for (i=0; p->deps[i]; i++) |
Rich Felker | 92ab5d8 | 2011-06-26 21:21:04 -0400 | [diff] [blame] | 617 | if (!p->deps[i]->global) |
| 618 | p->deps[i]->global = -1; |
| 619 | if (!p->global) p->global = -1; |
Rich Felker | 59ab43f | 2011-06-26 19:23:28 -0400 | [diff] [blame] | 620 | reloc_all(p); |
Rich Felker | 0e4dae3 | 2011-06-26 21:36:44 -0400 | [diff] [blame] | 621 | if (p->deps) for (i=0; p->deps[i]; i++) |
Rich Felker | 92ab5d8 | 2011-06-26 21:21:04 -0400 | [diff] [blame] | 622 | if (p->deps[i]->global < 0) |
| 623 | p->deps[i]->global = 0; |
| 624 | if (p->global < 0) p->global = 0; |
Rich Felker | 59ab43f | 2011-06-26 19:23:28 -0400 | [diff] [blame] | 625 | } |
| 626 | |
| 627 | if (mode & RTLD_GLOBAL) { |
Rich Felker | 0e4dae3 | 2011-06-26 21:36:44 -0400 | [diff] [blame] | 628 | if (p->deps) for (i=0; p->deps[i]; i++) |
Rich Felker | 59ab43f | 2011-06-26 19:23:28 -0400 | [diff] [blame] | 629 | p->deps[i]->global = 1; |
| 630 | p->global = 1; |
| 631 | } |
| 632 | |
Rich Felker | 06933cc | 2011-06-26 22:09:32 -0400 | [diff] [blame] | 633 | end: |
Rich Felker | 59ab43f | 2011-06-26 19:23:28 -0400 | [diff] [blame] | 634 | pthread_rwlock_unlock(&lock); |
Rich Felker | 59ab43f | 2011-06-26 19:23:28 -0400 | [diff] [blame] | 635 | return p; |
| 636 | } |
| 637 | |
Rich Felker | 623753a | 2011-08-16 00:42:13 -0400 | [diff] [blame] | 638 | static void *do_dlsym(struct dso *p, const char *s, void *ra) |
Rich Felker | 59ab43f | 2011-06-26 19:23:28 -0400 | [diff] [blame] | 639 | { |
| 640 | size_t i; |
| 641 | uint32_t h; |
| 642 | Sym *sym; |
Rich Felker | 623753a | 2011-08-16 00:42:13 -0400 | [diff] [blame] | 643 | if (p == RTLD_NEXT) { |
| 644 | for (p=head; p && (unsigned char *)ra-p->map>p->map_len; p=p->next); |
| 645 | if (!p) p=head; |
| 646 | p=p->next; |
| 647 | } |
Rich Felker | 97507bd | 2011-06-26 21:50:01 -0400 | [diff] [blame] | 648 | if (p == head || p == RTLD_DEFAULT) |
| 649 | return find_sym(head, s, 0); |
Rich Felker | 59ab43f | 2011-06-26 19:23:28 -0400 | [diff] [blame] | 650 | h = hash(s); |
| 651 | sym = lookup(s, h, p->syms, p->hashtab, p->strings); |
| 652 | if (sym && sym->st_value && (1<<(sym->st_info&0xf) & OK_TYPES)) |
| 653 | return p->base + sym->st_value; |
| 654 | if (p->deps) for (i=0; p->deps[i]; i++) { |
| 655 | sym = lookup(s, h, p->deps[i]->syms, |
| 656 | p->deps[i]->hashtab, p->deps[i]->strings); |
| 657 | if (sym && sym->st_value && (1<<(sym->st_info&0xf) & OK_TYPES)) |
| 658 | return p->deps[i]->base + sym->st_value; |
| 659 | } |
| 660 | return 0; |
| 661 | } |
| 662 | |
Rich Felker | 623753a | 2011-08-16 00:42:13 -0400 | [diff] [blame] | 663 | void *__dlsym(void *p, const char *s, void *ra) |
Rich Felker | 59ab43f | 2011-06-26 19:23:28 -0400 | [diff] [blame] | 664 | { |
| 665 | void *res; |
| 666 | pthread_rwlock_rdlock(&lock); |
Rich Felker | 623753a | 2011-08-16 00:42:13 -0400 | [diff] [blame] | 667 | res = do_dlsym(p, s, ra); |
Rich Felker | 59ab43f | 2011-06-26 19:23:28 -0400 | [diff] [blame] | 668 | pthread_rwlock_unlock(&lock); |
| 669 | return res; |
| 670 | } |
| 671 | |
| 672 | char *dlerror() |
| 673 | { |
| 674 | return "unknown error"; |
| 675 | } |
| 676 | |
| 677 | int dlclose(void *p) |
| 678 | { |
| 679 | return 0; |
| 680 | } |
Rich Felker | 4f4bf0a | 2011-09-18 16:42:06 -0400 | [diff] [blame] | 681 | #endif |