mips_reloc.c revision 1.2 1 /* $NetBSD: mips_reloc.c,v 1.2 1999/10/25 13:57:12 kleink Exp $ */
2
3 /*
4 * Copyright 1997 Michael L. Hitch <mhitch (at) montana.edu>
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30
31 #include <stdarg.h>
32 #include <sys/types.h>
33
34 #include "debug.h"
35 #include "rtld.h"
36
37 /*
38 * Relocate a MIPS GOT
39 */
40
41 void
42 _rtld_relocate_mips_got(obj)
43 Obj_Entry *obj;
44 {
45 Elf_Addr *got = obj->pltgot;
46 const Elf_Sym *sym = obj->symtab;
47 const Elf_Sym *def;
48 const Obj_Entry *defobj;
49 int i;
50
51 i = (got[1] & 0x80000000) ? 2 : 1;
52 /* Relocate the local GOT entries */
53 while (i < obj->local_gotno)
54 got[i++] += (Elf_Word)obj->relocbase;
55 got += obj->local_gotno;
56 i = obj->symtabno - obj->gotsym;
57 sym += obj->gotsym;
58 /* Now do the global GOT entries */
59 while (i--) {
60 def = _rtld_find_symdef(_rtld_objlist, 0,
61 sym->st_name + obj->strtab, obj, &defobj, true);
62 if (def != NULL) {
63 if (sym->st_shndx == SHN_UNDEF) {
64 #if 0 /* These don't seem to work? */
65
66 if (ELFDEFNNAME(ST_TYPE)(sym->st_info) ==
67 STT_FUNC) {
68 if (sym->st_value)
69 *got = sym->st_value +
70 (Elf_Word)obj->relocbase;
71 else
72 *got = def->st_value +
73 (Elf_Word)defobj->relocbase;
74 } else
75 #endif
76 *got = def->st_value +
77 (Elf_Word)defobj->relocbase;
78 } else if (sym->st_shndx == SHN_COMMON) {
79 *got = def->st_value +
80 (Elf_Word)defobj->relocbase;
81 } else if (ELFDEFNNAME(ST_TYPE)(sym->st_info) ==
82 STT_FUNC &&
83 *got != sym->st_value) {
84 *got += (Elf_Word)obj->relocbase;
85 } else if (ELFDEFNNAME(ST_TYPE)(sym->st_info) ==
86 STT_SECTION && ELFDEFNNAME(ST_BIND)(sym->st_info) ==
87 STB_GLOBAL) {
88 if (sym->st_shndx == SHN_ABS)
89 *got = sym->st_value +
90 (Elf_Word)obj->relocbase;
91 /* else SGI stuff ignored */
92 } else
93 *got = def->st_value +
94 (Elf_Word)defobj->relocbase;
95 }
96 ++sym;
97 ++got;
98 }
99 }
100
101 /*
102 * _rtld_bind_mips(symbol_index, return_address, old_gp, stub_return_addr)
103 */
104
105 caddr_t
106 _rtld_bind_mips(a0, a1, a2, a3)
107 Elf_Word a0;
108 Elf_Addr a1, a2, a3;
109 {
110 Elf_Addr *u = (Elf_Addr *)(a2 - 0x7ff0);
111 Obj_Entry *obj = (Obj_Entry *)(u[1] & 0x7fffffff);
112 const Elf_Sym *def;
113 const Obj_Entry *defobj;
114
115 def = _rtld_find_symdef(_rtld_objlist, a0 << 8, NULL, obj, &defobj,
116 true);
117 if (def) {
118 u[obj->local_gotno + a0 - obj->gotsym] = (Elf_Addr)
119 (def->st_value + defobj->relocbase);
120 return((caddr_t)(def->st_value + defobj->relocbase));
121 }
122
123 return(NULL); /* XXX */
124 }
125