FreeBSD/libexec/rtld-elf/rtld.c
/*
 * Initialize the dynamic linker.  The argument is the address at which
 * the dynamic linker has been mapped into memory.  The primary task of
 * this function is to relocate the dynamic linker.
 */
Initialize the dynamic linker.  The argument is the address at which
the dynamic linker has been mapped into memory.  The primary task of
this function is to relocate the dynamic linker.
Initialize the dynamic linker . The argument is the address at which the dynamic linker has been mapped into memory . The primary task of this function is to relocate the dynamic linker .
static void
init_rtld(caddr_t mapbase, Elf_Auxinfo **aux_info)
{
    Obj_Entry objtmp;	
    const Elf_Ehdr *ehdr;
    const Elf_Dyn *dyn_rpath;
    const Elf_Dyn *dyn_soname;
    const Elf_Dyn *dyn_runpath;
#ifdef RTLD_INIT_PAGESIZES_EARLY
    init_pagesizes(aux_info);
#endif
    memset(&objtmp, 0, sizeof(objtmp));
    objtmp.path = NULL;
    objtmp.rtld = true;
    objtmp.mapbase = mapbase;
#ifdef PIC
    objtmp.relocbase = mapbase;
#endif
    if (RTLD_IS_DYNAMIC()) {
	objtmp.dynamic = rtld_dynamic(&objtmp);
	digest_dynamic1(&objtmp, 1, &dyn_rpath, &dyn_soname, &dyn_runpath);
	assert(objtmp.needed == NULL);
#if !defined(__mips__)
	assert(!objtmp.textrel);
#endif
	relocate_objects(&objtmp, true, &objtmp, 0, NULL);
    }
    ehdr = (Elf_Ehdr *)mapbase;
    objtmp.phdr = (Elf_Phdr *)((char *)mapbase + ehdr->e_phoff);
    objtmp.phsize = ehdr->e_phnum * sizeof(objtmp.phdr[0]);
    TAILQ_INIT(&obj_list);
    memcpy(&obj_rtld, &objtmp, sizeof(obj_rtld));
#ifndef RTLD_INIT_PAGESIZES_EARLY
    init_pagesizes(aux_info);
#endif
    if (aux_info[AT_OSRELDATE] != NULL)
	    osreldate = aux_info[AT_OSRELDATE]->a_un.a_val;
    digest_dynamic2(&obj_rtld, dyn_rpath, dyn_soname, dyn_runpath);
    obj_rtld.path = xstrdup(ld_path_rtld);
    r_debug.r_brk = r_debug_state;
    r_debug.r_state = RT_CONSISTENT;
}
static void init_rtld ( caddr_t mapbase , Elf_Auxinfo * * aux_info ) { Obj_Entry objtmp ; const Elf_Ehdr * ehdr ; const Elf_Dyn * dyn_rpath ; const Elf_Dyn * dyn_soname ; const Elf_Dyn * dyn_runpath ; #ifdef RTLD_INIT_PAGESIZES_EARLY init_pagesizes ( aux_info ) ; #endif memset ( & objtmp , 0 , sizeof ( objtmp ) ) ; objtmp . path = NULL ; objtmp . rtld = true ; objtmp . mapbase = mapbase ; #ifdef PIC objtmp . relocbase = mapbase ; #endif if ( RTLD_IS_DYNAMIC ( ) ) { objtmp . dynamic = rtld_dynamic ( & objtmp ) ; digest_dynamic1 ( & objtmp , 1 , & dyn_rpath , & dyn_soname , & dyn_runpath ) ; assert ( objtmp . needed == NULL ) ; #if ! defined ( __mips__ ) assert ( ! objtmp . textrel ) ; #endif relocate_objects ( & objtmp , true , & objtmp , 0 , NULL ) ; } ehdr = ( Elf_Ehdr * ) mapbase ; objtmp . phdr = ( Elf_Phdr * ) ( ( char * ) mapbase + ehdr -> e_phoff ) ; objtmp . phsize = ehdr -> e_phnum * sizeof ( objtmp . phdr [ 0 ] ) ; TAILQ_INIT ( & obj_list ) ; memcpy ( & obj_rtld , & objtmp , sizeof ( obj_rtld ) ) ; #ifndef RTLD_INIT_PAGESIZES_EARLY init_pagesizes ( aux_info ) ; #endif if ( aux_info [ AT_OSRELDATE ] != NULL ) osreldate = aux_info [ AT_OSRELDATE ] -> a_un . a_val ; digest_dynamic2 ( & obj_rtld , dyn_rpath , dyn_soname , dyn_runpath ) ; obj_rtld . path = xstrdup ( ld_path_rtld ) ; r_debug . r_brk = r_debug_state ; r_debug . r_state = RT_CONSISTENT ; }
Initialize the dynamic linker.
Initialize the dynamic linker .
/* Temporary rtld object */ /* The page size is required by the dynamic memory allocator. */ /*
     * Conjure up an Obj_Entry structure for the dynamic linker.
     *
     * The "path" member can't be initialized yet because string constants
     * cannot yet be accessed. Below we will set it correctly.
     */ /* MIPS has a bogus DT_TEXTREL. */ /*
	 * Temporarily put the dynamic linker entry into the object list, so
	 * that symbols can be found.
	 */ /* Initialize the object list. */ /* Now that non-local variables can be accesses, copy out obj_rtld. */ /* The page size is required by the dynamic memory allocator. */ /* Replace the path with a dynamically allocated copy. */