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