Home | History | Annotate | Line # | Download | only in i386
mdreloc.c revision 1.2
      1  1.1  mycroft #include <sys/types.h>
      2  1.1  mycroft #include <sys/stat.h>
      3  1.1  mycroft 
      4  1.1  mycroft #include "debug.h"
      5  1.1  mycroft #include "rtld.h"
      6  1.1  mycroft 
      7  1.1  mycroft void
      8  1.1  mycroft _rtld_setup_pltgot(const Obj_Entry *obj)
      9  1.1  mycroft {
     10  1.1  mycroft 	obj->pltgot[1] = (Elf_Addr) obj;
     11  1.1  mycroft 	obj->pltgot[2] = (Elf_Addr) &_rtld_bind_start;
     12  1.1  mycroft }
     13  1.2  mycroft 
     14  1.2  mycroft int
     15  1.2  mycroft _rtld_relocate_nonplt_object(obj, rela, dodebug)
     16  1.2  mycroft 	Obj_Entry *obj;
     17  1.2  mycroft 	const Elf_Rela *rela;
     18  1.2  mycroft 	bool dodebug;
     19  1.2  mycroft {
     20  1.2  mycroft 	Elf_Addr        *where = (Elf_Addr *)(obj->relocbase + rela->r_offset);
     21  1.2  mycroft 	const Elf_Sym   *def;
     22  1.2  mycroft 	const Obj_Entry *defobj;
     23  1.2  mycroft 	Elf_Addr         tmp;
     24  1.2  mycroft 
     25  1.2  mycroft 	switch (ELF_R_TYPE(rela->r_info)) {
     26  1.2  mycroft 
     27  1.2  mycroft 	case R_TYPE(NONE):
     28  1.2  mycroft 		break;
     29  1.2  mycroft 
     30  1.2  mycroft #if 1 /* XXX should not occur */
     31  1.2  mycroft 	case R_TYPE(PC32):
     32  1.2  mycroft 		def = _rtld_find_symdef(rela->r_info, obj, &defobj, false);
     33  1.2  mycroft 		if (def == NULL)
     34  1.2  mycroft 			return -1;
     35  1.2  mycroft 
     36  1.2  mycroft 		*where += (Elf_Addr)(defobj->relocbase + def->st_value) -
     37  1.2  mycroft 		    (Elf_Addr)where;
     38  1.2  mycroft 		rdbg(dodebug, ("PC32 %s in %s --> %p in %s",
     39  1.2  mycroft 		    defobj->strtab + def->st_name, obj->path,
     40  1.2  mycroft 		    (void *)*where, defobj->path));
     41  1.2  mycroft 		break;
     42  1.2  mycroft 
     43  1.2  mycroft 	case R_TYPE(GOT32):
     44  1.2  mycroft #endif
     45  1.2  mycroft 	case R_TYPE(32):
     46  1.2  mycroft 	case R_TYPE(GLOB_DAT):
     47  1.2  mycroft 		def = _rtld_find_symdef(rela->r_info, obj, &defobj, false);
     48  1.2  mycroft 		if (def == NULL)
     49  1.2  mycroft 			return -1;
     50  1.2  mycroft 
     51  1.2  mycroft 		tmp = (Elf_Addr)(defobj->relocbase + def->st_value +
     52  1.2  mycroft 		    rela->r_addend);
     53  1.2  mycroft 		if (*where != tmp)
     54  1.2  mycroft 			*where = tmp;
     55  1.2  mycroft 		rdbg(dodebug, ("32/GLOB_DAT %s in %s --> %p in %s",
     56  1.2  mycroft 		    defobj->strtab + def->st_name, obj->path,
     57  1.2  mycroft 		    (void *)*where, defobj->path));
     58  1.2  mycroft 		break;
     59  1.2  mycroft 
     60  1.2  mycroft 	case R_TYPE(RELATIVE):
     61  1.2  mycroft 		*where += (Elf_Addr)obj->relocbase;
     62  1.2  mycroft 		rdbg(dodebug, ("RELATIVE in %s --> %p", obj->path,
     63  1.2  mycroft 		    (void *)*where));
     64  1.2  mycroft 		break;
     65  1.2  mycroft 
     66  1.2  mycroft 	case R_TYPE(COPY):
     67  1.2  mycroft 		/*
     68  1.2  mycroft 		 * These are deferred until all other relocations have
     69  1.2  mycroft 		 * been done.  All we do here is make sure that the COPY
     70  1.2  mycroft 		 * relocation is not in a shared library.  They are allowed
     71  1.2  mycroft 		 * only in executable files.
     72  1.2  mycroft 		 */
     73  1.2  mycroft 		if (!obj->mainprog) {
     74  1.2  mycroft 			_rtld_error(
     75  1.2  mycroft 			"%s: Unexpected R_COPY relocation in shared library",
     76  1.2  mycroft 			    obj->path);
     77  1.2  mycroft 			return -1;
     78  1.2  mycroft 		}
     79  1.2  mycroft 		rdbg(dodebug, ("COPY (avoid in main)"));
     80  1.2  mycroft 		break;
     81  1.2  mycroft 
     82  1.2  mycroft 	default:
     83  1.2  mycroft 		def = _rtld_find_symdef(rela->r_info, obj, &defobj, true);
     84  1.2  mycroft 		rdbg(dodebug, ("sym = %lu, type = %lu, offset = %p, "
     85  1.2  mycroft 		    "addend = %p, contents = %p, symbol = %s",
     86  1.2  mycroft 		    (u_long)ELF_R_SYM(rela->r_info),
     87  1.2  mycroft 		    (u_long)ELF_R_TYPE(rela->r_info),
     88  1.2  mycroft 		    (void *)rela->r_offset, (void *)rela->r_addend,
     89  1.2  mycroft 		    (void *)*where,
     90  1.2  mycroft 		    def ? defobj->strtab + def->st_name : "??"));
     91  1.2  mycroft 		_rtld_error("%s: Unsupported relocation type %ld "
     92  1.2  mycroft 		    "in non-PLT relocations\n",
     93  1.2  mycroft 		    obj->path, (u_long) ELF_R_TYPE(rela->r_info));
     94  1.2  mycroft 		return -1;
     95  1.2  mycroft 	}
     96  1.2  mycroft 	return 0;
     97  1.2  mycroft }
     98