Home | History | Annotate | Line # | Download | only in sh3
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(GOT32):
     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 		tmp = (Elf_Addr)(defobj->relocbase + def->st_value +
     37  1.2  mycroft 		    rela->r_addend);
     38  1.2  mycroft 		if (*where != tmp)
     39  1.2  mycroft 			*where = tmp;
     40  1.2  mycroft 		rdbg(dodebug, ("GOT32 %s in %s --> %p in %s",
     41  1.2  mycroft 		    defobj->strtab + def->st_name, obj->path,
     42  1.2  mycroft 		    (void *)*where, defobj->path));
     43  1.2  mycroft 		break;
     44  1.2  mycroft 
     45  1.2  mycroft 	case R_TYPE(REL32):
     46  1.2  mycroft 		def = _rtld_find_symdef(rela->r_info, obj, &defobj, false);
     47  1.2  mycroft 		if (def == NULL)
     48  1.2  mycroft 			return -1;
     49  1.2  mycroft 
     50  1.2  mycroft 		*where += (Elf_Addr)(defobj->relocbase + def->st_value +
     51  1.2  mycroft 		    rela->r_addend) - (Elf_Addr)where;
     52  1.2  mycroft 		rdbg(dodebug, ("PC32 %s in %s --> %p in %s",
     53  1.2  mycroft 		    defobj->strtab + def->st_name, obj->path,
     54  1.2  mycroft 		    (void *)*where, defobj->path));
     55  1.2  mycroft 		break;
     56  1.2  mycroft #endif
     57  1.2  mycroft 
     58  1.2  mycroft 	case R_TYPE(DIR32):
     59  1.2  mycroft 		def = _rtld_find_symdef(rela->r_info, obj, &defobj, false);
     60  1.2  mycroft 		if (def == NULL)
     61  1.2  mycroft 			return -1;
     62  1.2  mycroft 
     63  1.2  mycroft 		*where += (Elf_Addr)(defobj->relocbase + def->st_value +
     64  1.2  mycroft 		    rela->r_addend);
     65  1.2  mycroft 		rdbg(dodebug, ("32 %s in %s --> %p in %s",
     66  1.2  mycroft 		    defobj->strtab + def->st_name, obj->path,
     67  1.2  mycroft 		    (void *)*where, defobj->path));
     68  1.2  mycroft 		break;
     69  1.2  mycroft 
     70  1.2  mycroft 	case R_TYPE(GLOB_DAT):
     71  1.2  mycroft 		def = _rtld_find_symdef(rela->r_info, obj, &defobj, false);
     72  1.2  mycroft 		if (def == NULL)
     73  1.2  mycroft 			return -1;
     74  1.2  mycroft 
     75  1.2  mycroft 		tmp = (Elf_Addr)(defobj->relocbase + def->st_value) +
     76  1.2  mycroft 		    rela->r_addend;
     77  1.2  mycroft 		if (*where != tmp)
     78  1.2  mycroft 			*where = tmp;
     79  1.2  mycroft 		rdbg(dodebug, ("GLOB_DAT %s in %s --> %p in %s",
     80  1.2  mycroft 		    defobj->strtab + def->st_name, obj->path,
     81  1.2  mycroft 		    (void *)*where, defobj->path));
     82  1.2  mycroft 		break;
     83  1.2  mycroft 
     84  1.2  mycroft 	case R_TYPE(RELATIVE):
     85  1.2  mycroft 		if (rela->r_addend)
     86  1.2  mycroft 			*where = (Elf_Addr)obj->relocbase + rela->r_addend;
     87  1.2  mycroft 		else
     88  1.2  mycroft 			*where += (Elf_Addr)obj->relocbase;
     89  1.2  mycroft 		rdbg(dodebug, ("RELATIVE in %s --> %p", obj->path,
     90  1.2  mycroft 		    (void *)*where));
     91  1.2  mycroft 		break;
     92  1.2  mycroft 
     93  1.2  mycroft 	case R_TYPE(COPY):
     94  1.2  mycroft 		/*
     95  1.2  mycroft 		 * These are deferred until all other relocations have
     96  1.2  mycroft 		 * been done.  All we do here is make sure that the COPY
     97  1.2  mycroft 		 * relocation is not in a shared library.  They are allowed
     98  1.2  mycroft 		 * only in executable files.
     99  1.2  mycroft 		 */
    100  1.2  mycroft 		if (!obj->mainprog) {
    101  1.2  mycroft 			_rtld_error(
    102  1.2  mycroft 			"%s: Unexpected R_COPY relocation in shared library",
    103  1.2  mycroft 			    obj->path);
    104  1.2  mycroft 			return -1;
    105  1.2  mycroft 		}
    106  1.2  mycroft 		rdbg(dodebug, ("COPY (avoid in main)"));
    107  1.2  mycroft 		break;
    108  1.2  mycroft 
    109  1.2  mycroft 	default:
    110  1.2  mycroft 		def = _rtld_find_symdef(rela->r_info, obj, &defobj, true);
    111  1.2  mycroft 		rdbg(dodebug, ("sym = %lu, type = %lu, offset = %p, "
    112  1.2  mycroft 		    "addend = %p, contents = %p, symbol = %s",
    113  1.2  mycroft 		    (u_long)ELF_R_SYM(rela->r_info),
    114  1.2  mycroft 		    (u_long)ELF_R_TYPE(rela->r_info),
    115  1.2  mycroft 		    (void *)rela->r_offset, (void *)rela->r_addend,
    116  1.2  mycroft 		    (void *)*where,
    117  1.2  mycroft 		    def ? defobj->strtab + def->st_name : "??"));
    118  1.2  mycroft 		_rtld_error("%s: Unsupported relocation type %ld "
    119  1.2  mycroft 		    "in non-PLT relocations\n",
    120  1.2  mycroft 		    obj->path, (u_long) ELF_R_TYPE(rela->r_info));
    121  1.2  mycroft 		return -1;
    122  1.2  mycroft 	}
    123  1.2  mycroft 	return 0;
    124  1.2  mycroft }
    125