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