Print this page
3616 SHF_GROUP sections should not be discarded via other COMDAT mechanisms
3709 need sloppy relocation for GNU .debug_macro
Reviewed by: Joshua M. Clulow <josh@sysmgr.org>
Reviewed by: Robert Mustacchi <rm@joyent.com>
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/cmd/sgs/libld/common/groups.c
+++ new/usr/src/cmd/sgs/libld/common/groups.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21
22 22 /*
23 23 * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
24 24 */
25 25
26 26 #include <stdio.h>
27 27 #include <string.h>
28 28 #include <link.h>
29 29 #include <debug.h>
30 30 #include "msg.h"
31 31 #include "_libld.h"
32 32
33 33 /*
34 34 * Determine whether a (COMDAT) group has already been encountered. If so,
35 35 * indicate that the group descriptor has an overriding group (gd_oisc). This
36 36 * indication triggers the ld_place_section() to discard this group, while the
37 37 * gd_oisc information provides for complete diagnostics of the override.
38 38 * Otherwise, this is the first occurrence of this group, therefore the group
39 39 * descriptor is saved for future comparisons.
40 40 */
41 41 static uintptr_t
42 42 gpavl_loaded(Ofl_desc *ofl, Group_desc *gdp)
43 43 {
44 44 Isd_node isd, *isdp;
45 45 avl_tree_t *avlt;
46 46 avl_index_t where;
47 47
48 48 /*
49 49 * Create a groups avl tree if required.
50 50 */
51 51 if ((avlt = ofl->ofl_groups) == NULL) {
52 52 if ((avlt = libld_calloc(sizeof (avl_tree_t), 1)) == NULL)
53 53 return (S_ERROR);
54 54 avl_create(avlt, isdavl_compare, sizeof (Isd_node),
55 55 SGSOFFSETOF(Isd_node, isd_avl));
56 56 ofl->ofl_groups = avlt;
57 57 }
58 58
59 59 /*
60 60 * An SHT_GROUP section is identified by the name of its signature
61 61 * symbol rather than section name. Although the section names are
62 62 * often unique, this is not required, and some compilers set it to
63 63 * a generic name like ".group".
64 64 */
65 65 isd.isd_name = gdp->gd_name;
66 66 isd.isd_hash = sgs_str_hash(isd.isd_name);
67 67
68 68 if ((isdp = avl_find(avlt, &isd, &where)) != NULL) {
69 69 gdp->gd_oisc = isdp->isd_isp;
70 70 return (1);
71 71 }
72 72
73 73 /*
74 74 * This is a new group - so keep it.
75 75 */
76 76 if ((isdp = libld_calloc(sizeof (Isd_node), 1)) == NULL)
77 77 return (S_ERROR);
78 78
79 79 isdp->isd_name = isd.isd_name;
80 80 isdp->isd_hash = isd.isd_hash;
81 81 isdp->isd_isp = gdp->gd_isc;
82 82
83 83 avl_insert(avlt, isdp, where);
84 84 return (0);
85 85 }
86 86
87 87 Group_desc *
88 88 ld_get_group(Ofl_desc *ofl, Is_desc *isp)
89 89 {
90 90 Ifl_desc *ifl = isp->is_file;
91 91 uint_t scnndx = isp->is_scnndx;
92 92 Group_desc *gdp;
93 93 Aliste idx;
94 94
95 95 /*
96 96 * Scan the GROUP sections associated with this file to find the
97 97 * matching group section.
98 98 */
99 99 for (ALIST_TRAVERSE(ifl->ifl_groups, idx, gdp)) {
100 100 size_t ndx;
101 101 Word *data;
102 102
103 103 if (isp->is_shdr->sh_type == SHT_GROUP) {
104 104 if (isp->is_scnndx == gdp->gd_isc->is_scnndx)
105 105 return (gdp);
106 106 continue;
107 107 }
108 108
109 109 data = gdp->gd_data;
110 110 for (ndx = 1; ndx < gdp->gd_cnt; ndx++) {
↓ open down ↓ |
110 lines elided |
↑ open up ↑ |
111 111 if (data[ndx] == scnndx)
112 112 return (gdp);
113 113 }
114 114 }
115 115
116 116 ld_eprintf(ofl, ERR_FATAL, MSG_INTL(MSG_ELF_NOGROUPSECT),
117 117 ifl->ifl_name, EC_WORD(isp->is_scnndx), isp->is_name);
118 118 return (NULL);
119 119 }
120 120
121 +/*
122 + * When creating a .debug_macro section, in an attempt to make certain DWARF
123 + * macro information shareable, the GNU compiler must construct group sections
124 + * with a repeatable signature symbol while nevertheless having no actual
125 + * symbol to refer to (because it relates to macros).
126 + *
127 + * We use this as yet another way to clue ourselves in that sloppy relocation
128 + * will likely be required.
129 + *
130 + * The format of these gensym'd names is:
131 + * wm<offset size>.<encoded path name>.<lineno>.<32byte hash>
132 + * Where the encoded file name may be absent.
133 + */
134 +static boolean_t
135 +is_header_gensym(const char *name)
136 +{
137 + const char *c = NULL;
138 +
139 + /* No room for leader, hash, and periods */
140 + if (strlen(name) < 37)
141 + return (B_FALSE);
142 +
143 + if ((strncmp(name, "wm4.", 4) != 0) &&
144 + strncmp(name, "wm8.", 4) != 0)
145 + return (B_FALSE);
146 +
147 + c = &name[strlen(name) - 33];
148 + if (*c++ != '.')
149 + return (B_FALSE);
150 +
151 + for (; *c != '\0'; c++) {
152 + if (!(((*c >= 'a') && (*c <= 'f')) ||
153 + ((*c >= '0') && (*c <= '9')))) {
154 + return (B_FALSE);
155 + }
156 + }
157 +
158 + return (B_TRUE);
159 +}
160 +
121 161 uintptr_t
122 162 ld_group_process(Is_desc *gisc, Ofl_desc *ofl)
123 163 {
124 164 Ifl_desc *gifl = gisc->is_file;
125 165 Shdr *sshdr, *gshdr = gisc->is_shdr;
126 166 Is_desc *isc;
127 167 Sym *sym;
128 168 const char *str;
129 169 Group_desc gd;
130 170 size_t ndx;
131 171 int gnu_stt_section;
132 172
133 173 /*
134 174 * Confirm that the sh_link points to a valid section.
135 175 */
136 176 if ((gshdr->sh_link == SHN_UNDEF) ||
137 177 (gshdr->sh_link >= gifl->ifl_shnum) ||
138 178 ((isc = gifl->ifl_isdesc[gshdr->sh_link]) == NULL)) {
139 179 ld_eprintf(ofl, ERR_FATAL, MSG_INTL(MSG_FIL_INVSHLINK),
140 180 gifl->ifl_name, EC_WORD(gisc->is_scnndx),
141 181 gisc->is_name, EC_XWORD(gshdr->sh_link));
142 182 return (0);
143 183 }
144 184 if (gshdr->sh_entsize == 0) {
145 185 ld_eprintf(ofl, ERR_FATAL, MSG_INTL(MSG_FIL_INVSHENTSIZE),
146 186 gifl->ifl_name, EC_WORD(gisc->is_scnndx), gisc->is_name,
147 187 EC_XWORD(gshdr->sh_entsize));
148 188 return (0);
149 189 }
150 190
151 191 /*
152 192 * Get the associated symbol table. Sanity check the sh_info field
153 193 * (which points to the signature symbol table entry) against the size
154 194 * of the symbol table.
155 195 */
156 196 sshdr = isc->is_shdr;
157 197 sym = (Sym *)isc->is_indata->d_buf;
158 198
159 199 if ((sshdr->sh_info == SHN_UNDEF) ||
160 200 (gshdr->sh_info >= (Word)(sshdr->sh_size / sshdr->sh_entsize)) ||
161 201 ((isc = gifl->ifl_isdesc[sshdr->sh_link]) == NULL)) {
162 202 ld_eprintf(ofl, ERR_FATAL, MSG_INTL(MSG_FIL_INVSHINFO),
163 203 gifl->ifl_name, EC_WORD(gisc->is_scnndx), gisc->is_name,
164 204 EC_XWORD(gshdr->sh_info));
165 205 return (0);
166 206 }
167 207
168 208 sym += gshdr->sh_info;
169 209
170 210 /*
171 211 * Get the symbol name from the associated string table.
172 212 */
173 213 str = (char *)isc->is_indata->d_buf;
174 214 str += sym->st_name;
175 215
176 216 /*
177 217 * The GNU assembler can use section symbols as the signature symbol
178 218 * as described by this comment in the gold linker (found via google):
179 219 *
180 220 * It seems that some versions of gas will create a section group
181 221 * associated with a section symbol, and then fail to give a name
182 222 * to the section symbol. In such a case, use the name of the
183 223 * section.
184 224 *
185 225 * In order to support such objects, we do the same.
186 226 */
187 227 gnu_stt_section = ((sym->st_name == 0) || (*str == '\0')) &&
188 228 (ELF_ST_TYPE(sym->st_info) == STT_SECTION);
189 229 if (gnu_stt_section)
190 230 str = gisc->is_name;
191 231
192 232
193 233 /*
194 234 * Generate a group descriptor.
195 235 */
196 236 gd.gd_isc = gisc;
197 237 gd.gd_oisc = NULL;
198 238 gd.gd_name = str;
199 239 gd.gd_data = gisc->is_indata->d_buf;
200 240 gd.gd_cnt = gisc->is_indata->d_size / sizeof (Word);
201 241
202 242 /*
203 243 * If this group is a COMDAT group, validate the signature symbol.
204 244 */
205 245 if ((gd.gd_data[0] & GRP_COMDAT) && !gnu_stt_section &&
206 246 ((ELF_ST_BIND(sym->st_info) == STB_LOCAL) ||
207 247 (sym->st_shndx == SHN_UNDEF))) {
208 248 /* If section symbol, construct a printable name for it */
209 249 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION) {
210 250 if (gisc->is_sym_name == NULL)
211 251 (void) ld_stt_section_sym_name(gisc);
212 252
213 253 if (gisc->is_sym_name != NULL)
↓ open down ↓ |
83 lines elided |
↑ open up ↑ |
214 254 str = gisc->is_sym_name;
215 255 }
216 256
217 257 ld_eprintf(ofl, ERR_FATAL, MSG_INTL(MSG_GRP_INVALSYM),
218 258 gifl->ifl_name, EC_WORD(gisc->is_scnndx),
219 259 gisc->is_name, str);
220 260 return (0);
221 261 }
222 262
223 263 /*
264 + * If the signature symbol is a name generated by the GNU compiler to
265 + * refer to a header, we need sloppy relocation.
266 + */
267 + if (is_header_gensym(str)) {
268 + if ((ofl->ofl_flags1 & FLG_OF1_NRLXREL) == 0)
269 + ofl->ofl_flags1 |= FLG_OF1_RLXREL;
270 + DBG_CALL(Dbg_sec_gnu_comdat(ofl->ofl_lml, gisc, TRUE,
271 + (ofl->ofl_flags1 & FLG_OF1_RLXREL) != 0));
272 + }
273 +
274 + /*
224 275 * Validate the section indices within the group. If this is a COMDAT
225 276 * group, mark each section as COMDAT.
226 277 */
227 278 for (ndx = 1; ndx < gd.gd_cnt; ndx++) {
228 279 Word gndx;
229 280
230 281 if ((gndx = gd.gd_data[ndx]) >= gifl->ifl_shnum) {
231 282 ld_eprintf(ofl, ERR_FATAL,
232 283 MSG_INTL(MSG_GRP_INVALNDX), gifl->ifl_name,
233 284 EC_WORD(gisc->is_scnndx), gisc->is_name, ndx, gndx);
234 285 return (0);
235 286 }
236 287
237 288 if (gd.gd_data[0] & GRP_COMDAT)
238 289 gifl->ifl_isdesc[gndx]->is_flags |= FLG_IS_COMDAT;
239 290 }
240 291
241 292 /*
242 293 * If this is a COMDAT group, determine whether this group has already
243 294 * been encountered, or whether this is the first instance of the group.
244 295 */
245 296 if ((gd.gd_data[0] & GRP_COMDAT) &&
246 297 (gpavl_loaded(ofl, &gd) == S_ERROR))
247 298 return (S_ERROR);
248 299
249 300 /*
250 301 * Associate the group descriptor with this input file.
251 302 */
252 303 if (alist_append(&(gifl->ifl_groups), &gd, sizeof (Group_desc),
253 304 AL_CNT_IFL_GROUPS) == NULL)
254 305 return (S_ERROR);
255 306
256 307 return (1);
257 308 }
↓ open down ↓ |
24 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX