xref: /illumos-gate/usr/src/cmd/sgs/liblddbg/common/syms.c (revision dd72704bd9e794056c558153663c739e2012d721)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright (c) 1991, 2010, Oracle and/or its affiliates. All rights reserved.
24  * Copyright 2022 Oxide Computer Company
25  */
26 
27 #include	<stdio.h>
28 #include	"msg.h"
29 #include	"_debug.h"
30 #include	"libld.h"
31 
32 void
33 Dbg_syms_lookup(Rt_map *lmp, const char *name, const char *type)
34 {
35 	Lm_list	*lml = LIST(lmp);
36 
37 	if (DBG_NOTCLASS(DBG_C_SYMBOLS))
38 		return;
39 
40 	dbg_print(lml, MSG_INTL(MSG_SYM_LOOKUP), Dbg_demangle_name(name),
41 	    NAME(lmp), type);
42 }
43 
44 static	const Msg captype[DBG_CAP_HW_3 + 1] = {
45 	MSG_CAP_SYM_DEFAULT,		/* MSG_INTL(MSG_CAP_SYM_DEFAULT) */
46 	MSG_CAP_SYM_USED,		/* MSG_INTL(MSG_CAP_SYM_USED) */
47 	MSG_CAP_SYM_CANDIDATE,		/* MSG_INTL(MSG_CAP_SYM_CANDIDATE) */
48 	MSG_CAP_SYM_REJECTED,		/* MSG_INTL(MSG_CAP_SYM_REJECTED) */
49 	MSG_CAP_SYM_HW_1,		/* MSG_INTL(MSG_CAP_SYM_HW_1) */
50 	MSG_CAP_SYM_SF_1,		/* MSG_INTL(MSG_CAP_SYM_SF_1) */
51 	MSG_CAP_SYM_HW_2,		/* MSG_INTL(MSG_CAP_SYM_HW_2) */
52 	MSG_CAP_SYM_PLAT,		/* MSG_INTL(MSG_CAP_SYM_PLAT) */
53 	MSG_CAP_SYM_MACH,		/* MSG_INTL(MSG_CAP_SYM_MACH) */
54 	MSG_CAP_SYM_HW_3		/* MSG_INTL(MSG_CAP_SYM_HW_3) */
55 };
56 
57 void
58 Dbg_syms_cap_lookup(Rt_map *lmp, uint_t type, const char *name, uint_t ndx,
59     Half mach, Syscapset *scapset)
60 {
61 	Lm_list			*lml = LIST(lmp);
62 	const char		*str = NULL;
63 	Conv_cap_val_buf_t	cap_val_buf;
64 
65 	if (DBG_NOTCLASS(DBG_C_CAP | DBG_C_SYMBOLS))
66 		return;
67 
68 	switch (type) {
69 	case DBG_CAP_HW_1:
70 		str = conv_cap_val_hw1(scapset->sc_hw_1, mach, 0,
71 		    &cap_val_buf.cap_val_hw1_buf);
72 		break;
73 	case DBG_CAP_SF_1:
74 		str = conv_cap_val_sf1(scapset->sc_sf_1, mach, 0,
75 		    &cap_val_buf.cap_val_sf1_buf);
76 		break;
77 	case DBG_CAP_HW_2:
78 		str = conv_cap_val_hw2(scapset->sc_hw_2, mach, 0,
79 		    &cap_val_buf.cap_val_hw2_buf);
80 		break;
81 	case DBG_CAP_MACH:
82 		str = scapset->sc_mach;
83 		break;
84 	case DBG_CAP_PLAT:
85 		str = scapset->sc_plat;
86 		break;
87 	case DBG_CAP_HW_3:
88 		str = conv_cap_val_hw3(scapset->sc_hw_3, mach, 0,
89 		    &cap_val_buf.cap_val_hw3_buf);
90 		break;
91 	}
92 
93 	dbg_print(lml, MSG_INTL(captype[type]), Dbg_demangle_name(name),
94 	    ndx, str);
95 }
96 
97 void
98 Dbg_syms_ignore_gnuver(Rt_map *lmp, const char *name, Word symndx,
99     Versym verndx)
100 {
101 	Lm_list	*lml = LIST(lmp);
102 
103 	if (DBG_NOTCLASS(DBG_C_SYMBOLS))
104 		return;
105 
106 	dbg_print(lml, MSG_INTL(MSG_SYM_IGNGNUVER), Dbg_demangle_name(name),
107 	    EC_WORD(symndx), EC_HALF(verndx), NAME(lmp));
108 }
109 
110 void
111 Dbg_syms_lazy_rescan(Lm_list *lml, const char *name)
112 {
113 	if (DBG_NOTCLASS(DBG_C_SYMBOLS | DBG_C_FILES))
114 		return;
115 
116 	Dbg_util_nl(lml, DBG_NL_STD);
117 	dbg_print(lml, MSG_INTL(MSG_SYM_LAZY_RESCAN), Dbg_demangle_name(name));
118 }
119 
120 void
121 Dbg_syms_ar_title(Lm_list *lml, const char *file, Boolean again)
122 {
123 	if (DBG_NOTCLASS(DBG_C_SYMBOLS))
124 		return;
125 
126 	dbg_print(lml, MSG_INTL(MSG_SYM_AR_FILE), file,
127 	    again ? MSG_INTL(MSG_STR_AGAIN) : MSG_ORIG(MSG_STR_EMPTY));
128 }
129 
130 void
131 Dbg_syms_ar_skip(Lm_list *lml, const char *archive, Elf_Arsym *arsym)
132 {
133 	if (DBG_NOTCLASS(DBG_C_SYMBOLS))
134 		return;
135 
136 	dbg_print(lml, MSG_INTL(MSG_SYM_AR_SKIP), archive,
137 	    Dbg_demangle_name(arsym->as_name));
138 }
139 
140 void
141 Dbg_syms_ar_checking(Lm_list *lml, const char *fname, const char *objname,
142     Elf_Arsym *arsym)
143 {
144 	if (DBG_NOTCLASS(DBG_C_SYMBOLS))
145 		return;
146 
147 	dbg_print(lml, MSG_INTL(MSG_SYM_AR_CHECK), fname, objname,
148 	    Dbg_demangle_name(arsym->as_name));
149 }
150 
151 void
152 Dbg_syms_ar_resolve(Lm_list *lml, const char *fname, const char *objname,
153     Elf_Arsym *arsym)
154 {
155 	if (DBG_NOTCLASS(DBG_C_SYMBOLS))
156 		return;
157 
158 	dbg_print(lml, MSG_INTL(MSG_SYM_AR_RESOLVE), fname, objname,
159 	    Dbg_demangle_name(arsym->as_name));
160 }
161 
162 void
163 Dbg_syms_ar_force(Lm_list *lml, const char *fname, const char *objname)
164 {
165 	if (DBG_NOTCLASS(DBG_C_SYMBOLS))
166 		return;
167 
168 	dbg_print(lml, MSG_INTL(MSG_SYM_AR_FORCE), fname, objname);
169 }
170 
171 void
172 Dbg_syms_spec_title(Lm_list *lml)
173 {
174 	if (DBG_NOTCLASS(DBG_C_SYMBOLS))
175 		return;
176 
177 	Dbg_util_nl(lml, DBG_NL_STD);
178 	dbg_print(lml, MSG_INTL(MSG_SYM_SPECIAL));
179 }
180 
181 void
182 Dbg_syms_discarded(Lm_list *lml, Sym_desc *sdp)
183 {
184 	dbg_isec_name_buf_t	buf;
185 	char			*alloc_mem;
186 	const char		*file;
187 
188 	if (DBG_NOTCLASS(DBG_C_SYMBOLS | DBG_C_UNUSED))
189 		return;
190 	if (DBG_NOTDETAIL())
191 		return;
192 
193 	if ((sdp->sd_file == NULL) || ((file = sdp->sd_file->ifl_name) == NULL))
194 		file = MSG_INTL(MSG_STR_UNKNOWN);
195 
196 	if (sdp->sd_isc) {
197 		dbg_print(lml, MSG_INTL(MSG_SYM_DISCARD_SEC),
198 		    Dbg_demangle_name(sdp->sd_name),
199 		    dbg_fmt_isec_name(sdp->sd_isc, buf, &alloc_mem), file);
200 		if (alloc_mem != NULL)
201 			free(alloc_mem);
202 	} else
203 		dbg_print(lml, MSG_INTL(MSG_SYM_DISCARD_FILE),
204 		    Dbg_demangle_name(sdp->sd_name), file);
205 }
206 
207 void
208 Dbg_syms_dup_discarded(Lm_list *lml, Word ndx, Sym_desc *sdp)
209 {
210 	const char	*file;
211 
212 	if (DBG_NOTCLASS(DBG_C_SYMBOLS | DBG_C_UNUSED))
213 		return;
214 	if (DBG_NOTDETAIL())
215 		return;
216 
217 	if ((sdp->sd_file == NULL) || ((file = sdp->sd_file->ifl_name) == NULL))
218 		file = MSG_INTL(MSG_STR_UNKNOWN);
219 
220 	dbg_print(lml, MSG_INTL(MSG_SYM_DISCARD_DUP), EC_WORD(ndx),
221 	    Dbg_demangle_name(sdp->sd_name), file);
222 }
223 
224 void
225 Dbg_syms_entered(Ofl_desc *ofl, Sym *sym, Sym_desc *sdp)
226 {
227 	Conv_inv_buf_t	inv_buf;
228 	Lm_list		*lml = ofl->ofl_lml;
229 
230 	if (DBG_NOTCLASS(DBG_C_SYMBOLS))
231 		return;
232 	if (DBG_NOTDETAIL())
233 		return;
234 
235 	Elf_syms_table_entry(lml, ELF_DBG_LD, MSG_INTL(MSG_STR_ENTERED),
236 	    ofl->ofl_dehdr->e_ident[EI_OSABI], ofl->ofl_dehdr->e_machine, sym,
237 	    sdp->sd_aux ? sdp->sd_aux->sa_overndx : 0, 0, NULL,
238 	    conv_def_tag(sdp->sd_ref, &inv_buf));
239 }
240 
241 void
242 Dbg_syms_process(Lm_list *lml, Ifl_desc *ifl)
243 {
244 	Conv_inv_buf_t	inv_buf;
245 
246 	if (DBG_NOTCLASS(DBG_C_SYMBOLS))
247 		return;
248 
249 	Dbg_util_nl(lml, DBG_NL_STD);
250 	dbg_print(lml, MSG_INTL(MSG_SYM_PROCESS), ifl->ifl_name,
251 	    conv_ehdr_type(ifl->ifl_ehdr->e_ident[EI_OSABI],
252 	    ifl->ifl_ehdr->e_type, 0, &inv_buf));
253 }
254 
255 void
256 Dbg_syms_entry(Lm_list *lml, Word ndx, Sym_desc *sdp)
257 {
258 	if (DBG_NOTCLASS(DBG_C_SYMBOLS))
259 		return;
260 
261 	dbg_print(lml, MSG_INTL(MSG_SYM_BASIC), EC_WORD(ndx),
262 	    Dbg_demangle_name(sdp->sd_name));
263 }
264 
265 void
266 Dbg_syms_global(Lm_list *lml, Word ndx, const char *name)
267 {
268 	if (DBG_NOTCLASS(DBG_C_SYMBOLS))
269 		return;
270 
271 	dbg_print(lml, MSG_INTL(MSG_SYM_ADDING), EC_WORD(ndx),
272 	    Dbg_demangle_name(name));
273 }
274 
275 void
276 Dbg_syms_cap_convert(Ofl_desc *ofl, Word ndx, const char *name, Sym *sym)
277 {
278 	if (DBG_NOTCLASS(DBG_C_CAP | DBG_C_SYMBOLS))
279 		return;
280 
281 	dbg_print(ofl->ofl_lml, MSG_INTL(MSG_SYM_CAP_ORIG), EC_WORD(ndx),
282 	    Dbg_demangle_name(name));
283 
284 	if (DBG_NOTDETAIL())
285 		return;
286 
287 	Elf_syms_table_entry(ofl->ofl_lml, ELF_DBG_LD,
288 	    MSG_INTL(MSG_STR_ORIGINAL), ofl->ofl_dehdr->e_ident[EI_OSABI],
289 	    ofl->ofl_dehdr->e_machine, sym, 0, 0, NULL,
290 	    MSG_ORIG(MSG_STR_EMPTY));
291 }
292 
293 void
294 Dbg_syms_cap_local(Ofl_desc *ofl, Word ndx, const char *name, Sym *sym,
295     Sym_desc *sdp)
296 {
297 	Conv_inv_buf_t	inv_buf;
298 
299 	if (DBG_NOTCLASS(DBG_C_CAP | DBG_C_SYMBOLS))
300 		return;
301 
302 	dbg_print(ofl->ofl_lml, MSG_INTL(MSG_SYM_CAP_LOCAL), EC_WORD(ndx),
303 	    Dbg_demangle_name(name));
304 
305 	if (DBG_NOTDETAIL())
306 		return;
307 
308 	Elf_syms_table_entry(ofl->ofl_lml, ELF_DBG_LD,
309 	    MSG_INTL(MSG_STR_ENTERED), ofl->ofl_dehdr->e_ident[EI_OSABI],
310 	    ofl->ofl_dehdr->e_machine, sym,
311 	    sdp->sd_aux ? sdp->sd_aux->sa_overndx : 0, 0, NULL,
312 	    conv_def_tag(sdp->sd_ref, &inv_buf));
313 }
314 
315 void
316 Dbg_syms_wrap(Lm_list *lml, Word ndx, const char *orig_name, const char *name)
317 {
318 	if (DBG_NOTCLASS(DBG_C_SYMBOLS))
319 		return;
320 
321 	dbg_print(lml, MSG_INTL(MSG_SYM_WRAP), EC_WORD(ndx),
322 	    Dbg_demangle_name(orig_name), Dbg_demangle_name(name));
323 }
324 
325 void
326 Dbg_syms_sec_title(Lm_list *lml)
327 {
328 	if (DBG_NOTCLASS(DBG_C_SYMBOLS))
329 		return;
330 	if (DBG_NOTDETAIL())
331 		return;
332 
333 	Dbg_util_nl(lml, DBG_NL_STD);
334 	dbg_print(lml, MSG_INTL(MSG_SYM_INDEX));
335 }
336 
337 void
338 Dbg_syms_sec_entry(Lm_list *lml, Word ndx, Sg_desc *sgp, Os_desc *osp)
339 {
340 	if (DBG_NOTCLASS(DBG_C_SYMBOLS))
341 		return;
342 	if (DBG_NOTDETAIL())
343 		return;
344 
345 	dbg_print(lml, MSG_INTL(MSG_SYM_SECTION), EC_WORD(ndx), osp->os_name,
346 	    (*sgp->sg_name ? sgp->sg_name : MSG_INTL(MSG_STR_NULL)));
347 }
348 
349 void
350 Dbg_syms_up_title(Lm_list *lml)
351 {
352 	if (DBG_NOTCLASS(DBG_C_SYMBOLS))
353 		return;
354 	if (DBG_NOTDETAIL())
355 		return;
356 
357 	Dbg_util_nl(lml, DBG_NL_STD);
358 	dbg_print(lml, MSG_INTL(MSG_SYM_FINAL));
359 	Elf_syms_table_title(lml, ELF_DBG_LD);
360 }
361 
362 void
363 Dbg_syms_ignore(Ofl_desc *ofl, Sym_desc *sdp)
364 {
365 	if (DBG_NOTCLASS(DBG_C_SYMBOLS))
366 		return;
367 	if (DBG_NOTDETAIL())
368 		return;
369 
370 	Elf_syms_table_entry(ofl->ofl_lml, ELF_DBG_LD, MSG_INTL(MSG_STR_IGNORE),
371 	    ofl->ofl_dehdr->e_ident[EI_OSABI], ofl->ofl_dehdr->e_machine,
372 	    sdp->sd_sym, 0, 0, NULL, MSG_INTL(MSG_STR_UNUSED));
373 }
374 
375 void
376 Dbg_syms_old(Ofl_desc *ofl, Sym_desc *sdp)
377 {
378 	if (DBG_NOTCLASS(DBG_C_SYMBOLS))
379 		return;
380 	if (DBG_NOTDETAIL())
381 		return;
382 
383 	Elf_syms_table_entry(ofl->ofl_lml, ELF_DBG_LD, MSG_INTL(MSG_STR_OLD),
384 	    ofl->ofl_dehdr->e_ident[EI_OSABI], ofl->ofl_dehdr->e_machine,
385 	    sdp->sd_sym, sdp->sd_aux ? sdp->sd_aux->sa_overndx : 0,
386 	    0, NULL, sdp->sd_name);
387 }
388 
389 void
390 Dbg_syms_new(Ofl_desc *ofl, Sym *sym, Sym_desc *sdp)
391 {
392 	Conv_inv_buf_t	inv_buf;
393 
394 	if (DBG_NOTCLASS(DBG_C_SYMBOLS))
395 		return;
396 	if (DBG_NOTDETAIL())
397 		return;
398 
399 	Elf_syms_table_entry(ofl->ofl_lml, ELF_DBG_LD, MSG_INTL(MSG_STR_NEW),
400 	    ofl->ofl_dehdr->e_ident[EI_OSABI], ofl->ofl_dehdr->e_machine, sym,
401 	    sdp->sd_aux ? sdp->sd_aux->sa_overndx : 0, 0, NULL,
402 	    conv_def_tag(sdp->sd_ref, &inv_buf));
403 }
404 
405 void
406 Dbg_syms_updated(Ofl_desc *ofl, Sym_desc *sdp, const char *name)
407 {
408 	Conv_inv_buf_t	inv_buf;
409 	Lm_list		*lml = ofl->ofl_lml;
410 
411 	if (DBG_NOTCLASS(DBG_C_SYMBOLS))
412 		return;
413 
414 	dbg_print(lml, MSG_INTL(MSG_SYM_UPDATE), name);
415 
416 	if (DBG_NOTDETAIL())
417 		return;
418 
419 	Elf_syms_table_entry(ofl->ofl_lml, ELF_DBG_LD, MSG_ORIG(MSG_STR_EMPTY),
420 	    ofl->ofl_dehdr->e_ident[EI_OSABI], ofl->ofl_dehdr->e_machine,
421 	    sdp->sd_sym, sdp->sd_aux ? sdp->sd_aux->sa_overndx : 0, 0, NULL,
422 	    conv_def_tag(sdp->sd_ref, &inv_buf));
423 }
424 
425 void
426 Dbg_syms_created(Lm_list *lml, const char *name)
427 {
428 	if (DBG_NOTCLASS(DBG_C_SYMBOLS))
429 		return;
430 
431 	dbg_print(lml, MSG_INTL(MSG_SYM_CREATE), Dbg_demangle_name(name));
432 }
433 
434 void
435 Dbg_syms_resolving(Ofl_desc *ofl, Word ndx, const char *name, int row,
436     int col, Sym *osym, Sym *nsym, Sym_desc *sdp, Ifl_desc *ifl)
437 {
438 	Lm_list	*lml = ofl->ofl_lml;
439 	uchar_t	osabi = ofl->ofl_dehdr->e_ident[EI_OSABI];
440 	Half	mach = ofl->ofl_dehdr->e_machine;
441 
442 	if (DBG_NOTCLASS(DBG_C_SYMBOLS))
443 		return;
444 
445 	dbg_print(lml, MSG_INTL(MSG_SYM_RESOLVING), EC_WORD(ndx),
446 	    Dbg_demangle_name(name), row, col);
447 
448 	if (DBG_NOTDETAIL())
449 		return;
450 
451 	Elf_syms_table_entry(ofl->ofl_lml, ELF_DBG_LD, MSG_INTL(MSG_STR_OLD),
452 	    osabi, mach, osym, sdp->sd_aux ? sdp->sd_aux->sa_overndx : 0,
453 	    0, NULL, sdp->sd_file->ifl_name);
454 
455 	Elf_syms_table_entry(ofl->ofl_lml, ELF_DBG_LD, MSG_INTL(MSG_STR_NEW),
456 	    osabi, mach, nsym, 0, 0, NULL, ifl->ifl_name);
457 }
458 
459 void
460 Dbg_syms_resolved(Ofl_desc *ofl, Sym_desc *sdp)
461 {
462 	Conv_inv_buf_t	inv_buf;
463 
464 	if (DBG_NOTCLASS(DBG_C_SYMBOLS))
465 		return;
466 	if (DBG_NOTDETAIL())
467 		return;
468 
469 	Elf_syms_table_entry(ofl->ofl_lml, ELF_DBG_LD,
470 	    MSG_INTL(MSG_STR_RESOLVED), ofl->ofl_dehdr->e_ident[EI_OSABI],
471 	    ofl->ofl_dehdr->e_machine, sdp->sd_sym,
472 	    sdp->sd_aux ? sdp->sd_aux->sa_overndx : 0, 0, NULL,
473 	    conv_def_tag(sdp->sd_ref, &inv_buf));
474 }
475 
476 void
477 Dbg_syms_copy_reloc(Ofl_desc *ofl, Sym_desc *sdp, Word align)
478 {
479 	static Boolean	symbol_title = TRUE;
480 	Conv_inv_buf_t	inv_buf;
481 	Lm_list	*lml = ofl->ofl_lml;
482 
483 	if (DBG_NOTCLASS(DBG_C_SYMBOLS))
484 		return;
485 
486 	if (symbol_title) {
487 		Dbg_util_nl(lml, DBG_NL_STD);
488 		dbg_print(lml, MSG_INTL(MSG_SYM_BSS));
489 
490 		symbol_title = FALSE;
491 	}
492 
493 	/*
494 	 * Copy relocation symbols come in pairs, the original reference
495 	 * (within a dependency), and the new destination (within the .bss of
496 	 * the executable).  The latter is accompanied with a computed
497 	 * alignment.
498 	 */
499 	if (align) {
500 		dbg_print(lml, MSG_INTL(MSG_SYM_COPY_DST),
501 		    Dbg_demangle_name(sdp->sd_name), EC_WORD(align));
502 	} else {
503 		dbg_print(lml, MSG_INTL(MSG_SYM_COPY_REF),
504 		    Dbg_demangle_name(sdp->sd_name));
505 	}
506 
507 	if (DBG_NOTDETAIL())
508 		return;
509 
510 	Elf_syms_table_entry(lml, ELF_DBG_LD, MSG_ORIG(MSG_SYM_COPY),
511 	    ofl->ofl_dehdr->e_ident[EI_OSABI], ofl->ofl_dehdr->e_machine,
512 	    sdp->sd_sym, sdp->sd_aux ? sdp->sd_aux->sa_overndx : 0, 0, NULL,
513 	    conv_def_tag(sdp->sd_ref, &inv_buf));
514 }
515 
516 void
517 Dbg_syms_reduce(Ofl_desc *ofl, int which, Sym_desc *sdp, int idx,
518     const char *sname)
519 {
520 	static Boolean	sym_reduce_title = TRUE;
521 	static Boolean	sym_retain_title = TRUE;
522 	Boolean		isfromglobal = (which == DBG_SYM_REDUCE_GLOBAL);
523 	Boolean		isfromretain = (which == DBG_SYM_REDUCE_RETAIN);
524 	Lm_list		*lml = ofl->ofl_lml;
525 
526 	if (DBG_NOTCLASS(DBG_C_SYMBOLS | DBG_C_VERSIONS))
527 		return;
528 
529 	if (sym_reduce_title && isfromglobal) {
530 		sym_reduce_title = FALSE;
531 		Dbg_util_nl(lml, DBG_NL_STD);
532 		dbg_print(lml, MSG_INTL(MSG_SYM_REDUCED));
533 	} else if (sym_retain_title && isfromretain) {
534 		sym_retain_title = FALSE;
535 		Dbg_util_nl(lml, DBG_NL_STD);
536 		dbg_print(lml, MSG_INTL(MSG_SYM_RETAINING));
537 	}
538 
539 	if ((sdp->sd_flags & FLG_SY_ELIM) && isfromglobal)
540 		dbg_print(lml, MSG_INTL(MSG_SYM_ELIMINATING),
541 		    Dbg_demangle_name(sdp->sd_name));
542 	else if (isfromglobal)
543 		dbg_print(lml, MSG_INTL(MSG_SYM_REDUCING),
544 		    Dbg_demangle_name(sdp->sd_name));
545 	else
546 		dbg_print(lml, MSG_INTL(MSG_SYM_NOTELIMINATE),
547 		    Dbg_demangle_name(sdp->sd_name), sname, idx);
548 
549 	if (DBG_NOTDETAIL())
550 		return;
551 
552 	Elf_syms_table_entry(ofl->ofl_lml, ELF_DBG_LD, MSG_ORIG(MSG_SYM_LOCAL),
553 	    ofl->ofl_dehdr->e_ident[EI_OSABI], ofl->ofl_dehdr->e_machine,
554 	    sdp->sd_sym, sdp->sd_aux ? sdp->sd_aux->sa_overndx : 0, 0, NULL,
555 	    sdp->sd_file->ifl_name);
556 }
557 
558 void
559 Dbg_syms_dup_sort_addr(Lm_list *lml, const char *secname, const char *symname1,
560     const char *symname2, Addr addr)
561 {
562 	if (DBG_NOTCLASS(DBG_C_SYMBOLS) || DBG_NOTDETAIL())
563 		return;
564 
565 	dbg_print(lml, MSG_INTL(MSG_SYM_DUPSORTADDR), secname,
566 	    symname1, symname2, EC_ADDR(addr));
567 }
568 
569 void
570 Dbg_syminfo_title(Lm_list *lml)
571 {
572 	if (DBG_NOTCLASS(DBG_C_SYMBOLS))
573 		return;
574 	if (DBG_NOTDETAIL())
575 		return;
576 
577 	Dbg_util_nl(lml, DBG_NL_STD);
578 	dbg_print(lml, MSG_INTL(MSG_SYMINFO_INFO));
579 	Elf_syminfo_title(lml);
580 }
581 
582 void
583 Dbg_syminfo_entry(Lm_list *lml, Word ndx, Syminfo *sip, Sym *sym,
584     const char *strtab, Dyn *dyn)
585 {
586 	const char	*needed;
587 
588 	if (DBG_NOTCLASS(DBG_C_SYMBOLS))
589 		return;
590 	if (DBG_NOTDETAIL())
591 		return;
592 
593 	if (sip->si_boundto < SYMINFO_BT_LOWRESERVE)
594 		needed = strtab + dyn[sip->si_boundto].d_un.d_val;
595 	else
596 		needed = 0;
597 
598 	Elf_syminfo_entry(lml, ndx, sip,
599 	    Dbg_demangle_name(strtab + sym->st_name), needed);
600 }
601 
602 /*
603  * Symbol table output can differ slightly depending on the caller.  However,
604  * the final diagnostic is maintained here so hat the various message strings
605  * remain consistent
606  *
607  * elfdump:   index    value       size     type bind oth ver shndx       name
608  * ld:                 value       size     type bind oth ver shndx
609  */
610 void
611 Elf_syms_table_title(Lm_list *lml, int caller)
612 {
613 	if (caller == ELF_DBG_ELFDUMP) {
614 		if (DBG_NOTLONG())
615 			dbg_print(lml, MSG_INTL(MSG_SYM_EFS_TITLE));
616 		else
617 			dbg_print(lml, MSG_INTL(MSG_SYM_EFL_TITLE));
618 		return;
619 	}
620 
621 	if (caller == ELF_DBG_LD) {
622 		if (DBG_NOTLONG())
623 			dbg_print(lml, MSG_INTL(MSG_SYM_LDS_TITLE));
624 		else
625 			dbg_print(lml, MSG_INTL(MSG_SYM_LDL_TITLE));
626 		return;
627 	}
628 }
629 
630 void
631 Elf_syms_table_entry(Lm_list *lml, int caller, const char *prestr,
632     uchar_t osabi, Half mach, Sym *sym, Versym verndx, int gnuver,
633     const char *sec, const char *poststr)
634 {
635 	Conv_inv_buf_t	inv_buf1, inv_buf2, inv_buf3;
636 	Conv_inv_buf_t	inv_buf4, inv_buf5, inv_buf6;
637 	uchar_t		type = ELF_ST_TYPE(sym->st_info);
638 	uchar_t		bind = ELF_ST_BIND(sym->st_info);
639 	const char	*msg;
640 
641 	if ((caller == ELF_DBG_ELFDUMP) ||
642 	    (caller == ELF_DBG_LD)) {
643 		if (DBG_NOTLONG())
644 			msg = MSG_INTL(MSG_SYM_EFS_ENTRY);
645 		else
646 			msg = MSG_INTL(MSG_SYM_EFL_ENTRY);
647 
648 		if (sec == NULL)
649 			sec = conv_sym_shndx(osabi, mach, sym->st_shndx,
650 			    CONV_FMT_DECIMAL, &inv_buf6);
651 
652 		dbg_print(lml, msg, prestr,
653 		    conv_sym_value(mach, type, sym->st_value, &inv_buf1),
654 		    sym->st_size, conv_sym_info_type(mach, type, 0, &inv_buf2),
655 		    conv_sym_info_bind(bind, 0, &inv_buf3),
656 		    conv_sym_other(sym->st_other, &inv_buf4),
657 		    conv_ver_index(verndx, gnuver, &inv_buf5),
658 		    sec, Elf_demangle_name(poststr));
659 	}
660 }
661 
662 void
663 Dbg_syms_cap_title(Ofl_desc *ofl)
664 {
665 	Lm_list	*lml = ofl->ofl_lml;
666 
667 	if (DBG_NOTCLASS(DBG_C_SYMBOLS))
668 		return;
669 	if (DBG_NOTDETAIL())
670 		return;
671 
672 	Dbg_util_nl(lml, DBG_NL_STD);
673 	dbg_print(lml, MSG_INTL(MSG_SYM_CAPABILITIES));
674 	Elf_syms_table_title(lml, ELF_DBG_LD);
675 }
676