1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
|
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved.
*/
#define ELF_TARGET_SPARC
#include <stdio.h>
#include <string.h>
#include <alloca.h>
#include <sys/types.h>
#include <debug.h>
#include "msg.h"
#include "_libld.h"
#include "machsym.sparc.h"
/*
* Matrix of legal combinations of usage of a given register:
*
* Obj1 \ Obj2 Scratch Named
* Scratch OK NO
* Named NO *
*
* (*) OK if the symbols are identical, NO if they are not. Two symbols
* are identical if and only if one of the following is true:
* A. They are both global and have the same name.
* B. They are both local, have the same name, and are defined in the same
* object. (Note that a local symbol in one object is never identical to
* a local symbol in another object, even if the name is the same.)
*
* Matrix of legal combinations of st_shndx for the same register symbol:
*
* Obj1 \ Obj2 UNDEF ABS
* UNDEF OK OK
* ABS OK NO
*
*/
int
ld_reg_check_sparc(Sym_desc *sdp, Sym *nsym, const char *nname, Ifl_desc *ifl,
Ofl_desc *ofl)
{
Sym *osym = sdp->sd_sym;
const char *oname = sdp->sd_name;
Conv_inv_buf_t inv_buf1, inv_buf2;
/*
* Scratch register definitions are compatible.
*/
if ((osym->st_name == 0) && (nsym->st_name == 0))
return (0);
/*
* A local and a global, or another local is incompatible.
*/
if ((ELF_ST_BIND(osym->st_info) == STB_LOCAL) ||
(ELF_ST_BIND(nsym->st_info) == STB_LOCAL)) {
if (osym->st_value == nsym->st_value) {
ld_eprintf(ofl, ERR_FATAL,
MSG_INTL(MSG_SYM_INCOMPREG3),
conv_sym_SPARC_value(osym->st_value, 0, &inv_buf1),
sdp->sd_file->ifl_name, demangle(oname),
ifl->ifl_name, demangle(nname));
return (1);
}
return (0);
}
if (osym->st_value == nsym->st_value) {
/*
* A scratch register and a named register are incompatible.
* So are two different named registers.
*/
if (((osym->st_name == 0) || (nsym->st_name == 0)) ||
(strcmp(oname, nname) != 0)) {
ld_eprintf(ofl, ERR_FATAL, MSG_INTL(MSG_SYM_INCOMPREG1),
conv_sym_SPARC_value(osym->st_value, 0, &inv_buf1),
sdp->sd_file->ifl_name, demangle(oname),
ifl->ifl_name, demangle(nname));
return (1);
}
/*
* A multiply initialized symbol is also illegal.
*/
if ((osym->st_shndx == SHN_ABS) &&
(nsym->st_shndx == SHN_ABS)) {
ld_eprintf(ofl, ERR_FATAL, MSG_INTL(MSG_SYM_MULTINIREG),
conv_sym_SPARC_value(osym->st_value, 0, &inv_buf1),
demangle(nname), sdp->sd_file->ifl_name,
ifl->ifl_name);
return (1);
}
} else if (strcmp(oname, nname) == 0) {
ld_eprintf(ofl, ERR_FATAL, MSG_INTL(MSG_SYM_INCOMPREG2),
demangle(sdp->sd_name), sdp->sd_file->ifl_name,
conv_sym_SPARC_value(osym->st_value, 0, &inv_buf1),
ifl->ifl_name,
conv_sym_SPARC_value(nsym->st_value, 0, &inv_buf2));
return (1);
}
return (0);
}
int
ld_mach_sym_typecheck_sparc(Sym_desc *sdp, Sym *nsym, Ifl_desc *ifl,
Ofl_desc *ofl)
{
Conv_inv_buf_t inv_buf1, inv_buf2;
Sym *osym = sdp->sd_sym;
Byte otype = ELF_ST_TYPE(osym->st_info);
Byte ntype = ELF_ST_TYPE(nsym->st_info);
if (otype != ntype) {
if ((otype == STT_SPARC_REGISTER) ||
(ntype == STT_SPARC_REGISTER)) {
ld_eprintf(ofl, ERR_FATAL, MSG_INTL(MSG_SYM_DIFFTYPE),
demangle(sdp->sd_name));
ld_eprintf(ofl, ERR_NONE, MSG_INTL(MSG_SYM_FILETYPES),
sdp->sd_file->ifl_name, conv_sym_info_type(
sdp->sd_file->ifl_ehdr->e_machine, otype,
0, &inv_buf1), ifl->ifl_name,
conv_sym_info_type(ifl->ifl_ehdr->e_machine,
ntype, 0, &inv_buf2));
return (1);
}
} else if (otype == STT_SPARC_REGISTER)
return (ld_reg_check_sparc(sdp, nsym, sdp->sd_name, ifl, ofl));
return (0);
}
static const char *registers[] = { 0,
MSG_ORIG(MSG_STO_REGISTERG1), MSG_ORIG(MSG_STO_REGISTERG2),
MSG_ORIG(MSG_STO_REGISTERG3), MSG_ORIG(MSG_STO_REGISTERG4),
MSG_ORIG(MSG_STO_REGISTERG5), MSG_ORIG(MSG_STO_REGISTERG6),
MSG_ORIG(MSG_STO_REGISTERG7)
};
const char *
ld_is_regsym_sparc(Ofl_desc *ofl, Ifl_desc *ifl, Sym *sym, const char *strs,
int symndx, Word shndx, const char *symsecname, sd_flag_t *flags)
{
const char *name;
/*
* Only do something if this is a register symbol.
*/
if (ELF_ST_TYPE(sym->st_info) != STT_SPARC_REGISTER)
return (0);
/*
* Check for bogus register number.
*/
if ((sym->st_value < STO_SPARC_REGISTER_G1) ||
(sym->st_value > STO_SPARC_REGISTER_G7)) {
ld_eprintf(ofl, ERR_FATAL, MSG_INTL(MSG_SYM_BADREG),
ifl->ifl_name, symsecname, symndx, EC_XWORD(sym->st_value));
return ((const char *)S_ERROR);
}
/*
* A register symbol can only be undefined or defined (absolute).
*/
if ((shndx != SHN_ABS) && (shndx != SHN_UNDEF)) {
ld_eprintf(ofl, ERR_FATAL, MSG_INTL(MSG_SYM_BADREG),
ifl->ifl_name, symsecname, symndx, EC_XWORD(sym->st_value));
return ((const char *)S_ERROR);
}
/*
* Determine whether this is a scratch (unnamed) definition.
*/
if (sym->st_name == 0) {
/*
* Check for bogus scratch register definitions.
*/
if ((ELF_ST_BIND(sym->st_info) != STB_GLOBAL) ||
(shndx != SHN_UNDEF)) {
Conv_inv_buf_t inv_buf;
ld_eprintf(ofl, ERR_FATAL, MSG_INTL(MSG_SYM_BADSCRATCH),
ifl->ifl_name, symsecname, symndx,
conv_sym_SPARC_value(sym->st_value, 0, &inv_buf));
return ((const char *)S_ERROR);
}
/*
* Fabricate a name for this register so that this definition
* can be processed through the symbol resolution engine.
*/
name = registers[sym->st_value];
} else
name = strs + sym->st_name;
/*
* Indicate we're dealing with a register and return its name.
*/
*flags |= FLG_SY_REGSYM;
return (name);
}
Sym_desc *
ld_reg_find_sparc(Sym *sym, Ofl_desc *ofl)
{
if (ofl->ofl_regsyms == NULL)
return (NULL);
return (ofl->ofl_regsyms[sym->st_value]);
}
int
ld_reg_enter_sparc(Sym_desc *sdp, Ofl_desc *ofl)
{
if (ofl->ofl_regsyms == NULL) {
ofl->ofl_regsymsno = STO_SPARC_REGISTER_G7 + 1;
if ((ofl->ofl_regsyms = libld_calloc(ofl->ofl_regsymsno,
sizeof (Sym_desc *))) == NULL) {
ofl->ofl_flags |= FLG_OF_FATAL;
return (0);
}
}
ofl->ofl_regsyms[sdp->sd_sym->st_value] = sdp;
return (1);
}
|