rtld.c (165916) | rtld.c (168312) |
---|---|
1/*- 2 * Copyright 1996, 1997, 1998, 1999, 2000 John D. Polstra. 3 * Copyright 2003 Alexander Kabaev <kan@FreeBSD.ORG>. 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: --- 9 unchanged lines hidden (view full) --- 18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 * | 1/*- 2 * Copyright 1996, 1997, 1998, 1999, 2000 John D. Polstra. 3 * Copyright 2003 Alexander Kabaev <kan@FreeBSD.ORG>. 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: --- 9 unchanged lines hidden (view full) --- 18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 * |
26 * $FreeBSD: head/libexec/rtld-elf/rtld.c 165916 2007-01-09 17:50:05Z jhb $ | 26 * $FreeBSD: head/libexec/rtld-elf/rtld.c 168312 2007-04-03 18:31:20Z kan $ |
27 */ 28 29/* 30 * Dynamic linker for ELF. 31 * 32 * John Polstra <jdp@polstra.com>. 33 */ 34 --- 124 unchanged lines hidden (view full) --- 159 load first */ 160static char *ld_tracing; /* Called from ldd to print libs */ 161static char *ld_utrace; /* Use utrace() to log events. */ 162static Obj_Entry *obj_list; /* Head of linked list of shared objects */ 163static Obj_Entry **obj_tail; /* Link field of last object in list */ 164static Obj_Entry *obj_main; /* The main program shared object */ 165static Obj_Entry obj_rtld; /* The dynamic linker shared object */ 166static unsigned int obj_count; /* Number of objects in obj_list */ | 27 */ 28 29/* 30 * Dynamic linker for ELF. 31 * 32 * John Polstra <jdp@polstra.com>. 33 */ 34 --- 124 unchanged lines hidden (view full) --- 159 load first */ 160static char *ld_tracing; /* Called from ldd to print libs */ 161static char *ld_utrace; /* Use utrace() to log events. */ 162static Obj_Entry *obj_list; /* Head of linked list of shared objects */ 163static Obj_Entry **obj_tail; /* Link field of last object in list */ 164static Obj_Entry *obj_main; /* The main program shared object */ 165static Obj_Entry obj_rtld; /* The dynamic linker shared object */ 166static unsigned int obj_count; /* Number of objects in obj_list */ |
167static unsigned int obj_loads; /* Number of objects in obj_list */ |
|
167 168static Objlist list_global = /* Objects dlopened with RTLD_GLOBAL */ 169 STAILQ_HEAD_INITIALIZER(list_global); 170static Objlist list_main = /* Objects loaded at program startup */ 171 STAILQ_HEAD_INITIALIZER(list_main); 172static Objlist list_fini = /* Objects needing fini() calls */ 173 STAILQ_HEAD_INITIALIZER(list_fini); 174 --- 24 unchanged lines hidden (view full) --- 199 (func_ptr_type) &dlinfo, 200 (func_ptr_type) &_rtld_thread_init, 201#ifdef __i386__ 202 (func_ptr_type) &___tls_get_addr, 203#endif 204 (func_ptr_type) &__tls_get_addr, 205 (func_ptr_type) &_rtld_allocate_tls, 206 (func_ptr_type) &_rtld_free_tls, | 168 169static Objlist list_global = /* Objects dlopened with RTLD_GLOBAL */ 170 STAILQ_HEAD_INITIALIZER(list_global); 171static Objlist list_main = /* Objects loaded at program startup */ 172 STAILQ_HEAD_INITIALIZER(list_main); 173static Objlist list_fini = /* Objects needing fini() calls */ 174 STAILQ_HEAD_INITIALIZER(list_fini); 175 --- 24 unchanged lines hidden (view full) --- 200 (func_ptr_type) &dlinfo, 201 (func_ptr_type) &_rtld_thread_init, 202#ifdef __i386__ 203 (func_ptr_type) &___tls_get_addr, 204#endif 205 (func_ptr_type) &__tls_get_addr, 206 (func_ptr_type) &_rtld_allocate_tls, 207 (func_ptr_type) &_rtld_free_tls, |
208 (func_ptr_type) &dl_iterate_phdr, |
|
207 NULL 208}; 209 210/* 211 * Global declarations normally provided by crt1. The dynamic linker is 212 * not built with crt1, so we have to provide them ourselves. 213 */ 214char *__progname; --- 203 unchanged lines hidden (view full) --- 418 419 linkmap_add(obj_main); 420 linkmap_add(&obj_rtld); 421 422 /* Link the main program into the list of objects. */ 423 *obj_tail = obj_main; 424 obj_tail = &obj_main->next; 425 obj_count++; | 209 NULL 210}; 211 212/* 213 * Global declarations normally provided by crt1. The dynamic linker is 214 * not built with crt1, so we have to provide them ourselves. 215 */ 216char *__progname; --- 203 unchanged lines hidden (view full) --- 420 421 linkmap_add(obj_main); 422 linkmap_add(&obj_rtld); 423 424 /* Link the main program into the list of objects. */ 425 *obj_tail = obj_main; 426 obj_tail = &obj_main->next; 427 obj_count++; |
428 obj_loads++; |
|
426 /* Make sure we don't call the main program's init and fini functions. */ 427 obj_main->init = obj_main->fini = (Elf_Addr)NULL; 428 429 /* Initialize a fake symbol for resolving undefined weak references. */ 430 sym_zero.st_info = ELF_ST_INFO(STB_GLOBAL, STT_NOTYPE); 431 sym_zero.st_shndx = SHN_UNDEF; 432 433 if (!libmap_disable) --- 948 unchanged lines hidden (view full) --- 1382 1383 object_add_name(obj, name); 1384 obj->path = path; 1385 digest_dynamic(obj, 0); 1386 1387 *obj_tail = obj; 1388 obj_tail = &obj->next; 1389 obj_count++; | 429 /* Make sure we don't call the main program's init and fini functions. */ 430 obj_main->init = obj_main->fini = (Elf_Addr)NULL; 431 432 /* Initialize a fake symbol for resolving undefined weak references. */ 433 sym_zero.st_info = ELF_ST_INFO(STB_GLOBAL, STT_NOTYPE); 434 sym_zero.st_shndx = SHN_UNDEF; 435 436 if (!libmap_disable) --- 948 unchanged lines hidden (view full) --- 1385 1386 object_add_name(obj, name); 1387 obj->path = path; 1388 digest_dynamic(obj, 0); 1389 1390 *obj_tail = obj; 1391 obj_tail = &obj->next; 1392 obj_count++; |
1393 obj_loads++; |
|
1390 linkmap_add(obj); /* for GDB & dlinfo() */ 1391 1392 dbg(" %p .. %p: %s", obj->mapbase, 1393 obj->mapbase + obj->mapsize - 1, obj->path); 1394 if (obj->textrel) 1395 dbg(" WARNING: %s has impure text", obj->path); 1396 LD_UTRACE(UTRACE_LOAD_OBJECT, obj, obj->mapbase, obj->mapsize, 0, 1397 obj->path); --- 676 unchanged lines hidden (view full) --- 2074 error = -1; 2075 } 2076 2077 rlock_release(rtld_bind_lock, lockstate); 2078 2079 return (error); 2080} 2081 | 1394 linkmap_add(obj); /* for GDB & dlinfo() */ 1395 1396 dbg(" %p .. %p: %s", obj->mapbase, 1397 obj->mapbase + obj->mapsize - 1, obj->path); 1398 if (obj->textrel) 1399 dbg(" WARNING: %s has impure text", obj->path); 1400 LD_UTRACE(UTRACE_LOAD_OBJECT, obj, obj->mapbase, obj->mapsize, 0, 1401 obj->path); --- 676 unchanged lines hidden (view full) --- 2078 error = -1; 2079 } 2080 2081 rlock_release(rtld_bind_lock, lockstate); 2082 2083 return (error); 2084} 2085 |
2086int 2087dl_iterate_phdr(__dl_iterate_hdr_callback callback, void *param) 2088{ 2089 struct dl_phdr_info phdr_info; 2090 const Obj_Entry *obj; 2091 int error, lockstate; 2092 2093 lockstate = rlock_acquire(rtld_bind_lock); 2094 2095 error = 0; 2096 2097 for (obj = obj_list; obj != NULL; obj = obj->next) { 2098 phdr_info.dlpi_addr = (Elf_Addr)obj->relocbase; 2099 phdr_info.dlpi_name = STAILQ_FIRST(&obj->names) ? 2100 STAILQ_FIRST(&obj->names)->name : obj->path; 2101 phdr_info.dlpi_phdr = obj->phdr; 2102 phdr_info.dlpi_phnum = obj->phsize / sizeof(obj->phdr[0]); 2103 phdr_info.dlpi_tls_modid = obj->tlsindex; 2104 phdr_info.dlpi_tls_data = obj->tlsinit; 2105 phdr_info.dlpi_adds = obj_loads; 2106 phdr_info.dlpi_subs = obj_loads - obj_count; 2107 2108 if ((error = callback(&phdr_info, sizeof phdr_info, param)) != 0) 2109 break; 2110 2111 } 2112 rlock_release(rtld_bind_lock, lockstate); 2113 2114 return (error); 2115} 2116 |
|
2082struct fill_search_info_args { 2083 int request; 2084 unsigned int flags; 2085 Dl_serinfo *serinfo; 2086 Dl_serpath *serpath; 2087 char *strspace; 2088}; 2089 --- 1237 unchanged lines hidden --- | 2117struct fill_search_info_args { 2118 int request; 2119 unsigned int flags; 2120 Dl_serinfo *serinfo; 2121 Dl_serpath *serpath; 2122 char *strspace; 2123}; 2124 --- 1237 unchanged lines hidden --- |