FreeBSD/libexec/rtld-elf/rtld.c
/*
 * Relocate single object.
 * Returns 0 on success, or -1 on failure.
 */
Relocate single object.
Returns 0 on success, or -1 on failure.
Relocate single object . Returns 0 on success or - 1 on failure .
static int
relocate_object(Obj_Entry *obj, bool bind_now, Obj_Entry *rtldobj,
    int flags, RtldLockState *lockstate)
{
	if (obj->relocated)
		return (0);
	obj->relocated = true;
	if (obj != rtldobj)
		dbg("relocating \"%s\"", obj->path);
	if (obj->symtab == NULL || obj->strtab == NULL ||
	    !(obj->valid_hash_sysv || obj->valid_hash_gnu)) {
		_rtld_error("%s: Shared object has no run-time symbol table",
			    obj->path);
		return (-1);
	}
	if (obj->textrel && reloc_textrel_prot(obj, true) != 0)
		return (-1);
	if (reloc_non_plt(obj, rtldobj, flags, lockstate))
		return (-1);
	if (obj->textrel && reloc_textrel_prot(obj, false) != 0)
		return (-1);
	init_pltgot(obj);
	if (reloc_plt(obj) == -1)
		return (-1);
	if (obj->bind_now || bind_now)
		if (reloc_jmpslots(obj, flags, lockstate) == -1)
			return (-1);
	if (obj->non_plt_gnu_ifunc &&
	    reloc_non_plt(obj, rtldobj, flags | SYMLOOK_IFUNC, lockstate))
		return (-1);
	if (obj->relro_size > 0) {
		if (mprotect(obj->relro_page, obj->relro_size,
		    PROT_READ) == -1) {
			_rtld_error("%s: Cannot enforce relro protection: %s",
			    obj->path, rtld_strerror(errno));
			return (-1);
		}
	}
	obj->magic = RTLD_MAGIC;
	obj->version = RTLD_VERSION;
	return (0);
}
static int relocate_object ( Obj_Entry * obj , bool bind_now , Obj_Entry * rtldobj , int flags , RtldLockState * lockstate ) { if ( obj -> relocated ) return ( 0 ) ; obj -> relocated = true ; if ( obj != rtldobj ) dbg ( " \" \" " , obj -> path ) ; if ( obj -> symtab == NULL || obj -> strtab == NULL || ! ( obj -> valid_hash_sysv || obj -> valid_hash_gnu ) ) { _rtld_error ( " " , obj -> path ) ; return ( -1 ) ; } if ( obj -> textrel && reloc_textrel_prot ( obj , true ) != 0 ) return ( -1 ) ; if ( reloc_non_plt ( obj , rtldobj , flags , lockstate ) ) return ( -1 ) ; if ( obj -> textrel && reloc_textrel_prot ( obj , false ) != 0 ) return ( -1 ) ; init_pltgot ( obj ) ; if ( reloc_plt ( obj ) == -1 ) return ( -1 ) ; if ( obj -> bind_now || bind_now ) if ( reloc_jmpslots ( obj , flags , lockstate ) == -1 ) return ( -1 ) ; if ( obj -> non_plt_gnu_ifunc && reloc_non_plt ( obj , rtldobj , flags | SYMLOOK_IFUNC , lockstate ) ) return ( -1 ) ; if ( obj -> relro_size > 0 ) { if ( mprotect ( obj -> relro_page , obj -> relro_size , PROT_READ ) == -1 ) { _rtld_error ( " " , obj -> path , rtld_strerror ( errno ) ) ; return ( -1 ) ; } } obj -> magic = RTLD_MAGIC ; obj -> version = RTLD_VERSION ; return ( 0 ) ; }
Relocate single object.
Relocate single object .
/* There are relocations to the write-protected text segment. */ /* Process the non-PLT non-IFUNC relocations. */ /* Re-protected the text segment. */ /* Set the special PLT or GOT entries. */ /* Process the PLT relocations. */ /* Relocate the jump slots if we are doing immediate binding. */ /*
	 * Process the non-PLT IFUNC relocations.  The relocations are
	 * processed in two phases, because IFUNC resolvers may
	 * reference other symbols, which must be readily processed
	 * before resolvers are called.
	 */ /*
	 * Set up the magic number and version in the Obj_Entry.  These
	 * were checked in the crt1.o from the original ElfKit, so we
	 * set them for backward compatibility.
	 */