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 2007 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 #pragma ident "%Z%%M% %I% %E% SMI" 27 28 #include <stdio.h> 29 #include <dlfcn.h> 30 #include "msg.h" 31 #include "_debug.h" 32 #include "libld.h" 33 34 #if !(defined(_ELF64)) 35 36 void 37 Dbg_syms_lookup_aout(Lm_list *lml, const char *name) 38 { 39 if (DBG_NOTCLASS(DBG_C_SYMBOLS)) 40 return; 41 42 dbg_print(lml, MSG_INTL(MSG_SYM_AOUT), Dbg_demangle_name(name)); 43 } 44 45 #endif 46 47 void 48 Dbg_syms_lookup(Rt_map *lmp, const char *name, const char *type) 49 { 50 Lm_list *lml = LIST(lmp); 51 52 if (DBG_NOTCLASS(DBG_C_SYMBOLS)) 53 return; 54 55 dbg_print(lml, MSG_INTL(MSG_SYM_LOOKUP), Dbg_demangle_name(name), 56 NAME(lmp), type); 57 } 58 59 void 60 Dbg_syms_ignore_gnuver(Rt_map *lmp, const char *name, Word symndx, 61 Versym verndx) 62 { 63 Lm_list *lml = LIST(lmp); 64 65 if (DBG_NOTCLASS(DBG_C_SYMBOLS)) 66 return; 67 68 dbg_print(lml, MSG_INTL(MSG_SYM_IGNGNUVER), Dbg_demangle_name(name), 69 EC_WORD(symndx), EC_HALF(verndx), NAME(lmp)); 70 } 71 72 void 73 Dbg_syms_dlsym(Rt_map *clmp, const char *sym, const char *next, int flag) 74 { 75 const char *str, *from = NAME(clmp); 76 Lm_list *lml = LIST(clmp); 77 78 if (DBG_NOTCLASS(DBG_C_SYMBOLS)) 79 return; 80 81 switch (flag) { 82 case DBG_DLSYM_NEXT: 83 str = MSG_ORIG(MSG_SYM_NEXT); 84 break; 85 case DBG_DLSYM_DEFAULT: 86 str = MSG_ORIG(MSG_SYM_DEFAULT); 87 break; 88 case DBG_DLSYM_SELF: 89 str = MSG_ORIG(MSG_SYM_SELF); 90 break; 91 case DBG_DLSYM_PROBE: 92 str = MSG_ORIG(MSG_SYM_PROBE); 93 break; 94 case DBG_DLSYM_SINGLETON: 95 str = MSG_ORIG(MSG_SYM_SINGLETON); 96 break; 97 default: 98 str = MSG_ORIG(MSG_STR_EMPTY); 99 } 100 101 Dbg_util_nl(lml, DBG_NL_STD); 102 if (next == 0) 103 dbg_print(lml, MSG_INTL(MSG_SYM_DLSYM_1), 104 Dbg_demangle_name(sym), from, str); 105 else 106 dbg_print(lml, MSG_INTL(MSG_SYM_DLSYM_2), 107 Dbg_demangle_name(sym), from, next, str); 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, int again) 122 { 123 if (DBG_NOTCLASS(DBG_C_SYMBOLS)) 124 return; 125 126 Dbg_util_nl(lml, DBG_NL_STD); 127 dbg_print(lml, MSG_INTL(MSG_SYM_AR_FILE), file, 128 again ? MSG_INTL(MSG_STR_AGAIN) : MSG_ORIG(MSG_STR_EMPTY)); 129 } 130 131 void 132 Dbg_syms_ar_entry(Lm_list *lml, Xword ndx, Elf_Arsym *arsym) 133 { 134 if (DBG_NOTCLASS(DBG_C_SYMBOLS)) 135 return; 136 137 dbg_print(lml, MSG_INTL(MSG_SYM_AR_ENTRY), EC_XWORD(ndx), 138 Dbg_demangle_name(arsym->as_name)); 139 } 140 141 void 142 Dbg_syms_ar_checking(Lm_list *lml, Xword ndx, Elf_Arsym *arsym, 143 const char *name) 144 { 145 if (DBG_NOTCLASS(DBG_C_SYMBOLS)) 146 return; 147 148 dbg_print(lml, MSG_INTL(MSG_SYM_AR_CHECK), EC_XWORD(ndx), 149 Dbg_demangle_name(arsym->as_name), name); 150 } 151 152 void 153 Dbg_syms_ar_resolve(Lm_list *lml, Xword ndx, Elf_Arsym *arsym, 154 const char *fname, int flag) 155 { 156 const char *fmt; 157 158 if (DBG_NOTCLASS(DBG_C_SYMBOLS)) 159 return; 160 161 if (flag) 162 fmt = MSG_INTL(MSG_SYM_AR_FORCEDEXRT); 163 else 164 fmt = MSG_INTL(MSG_SYM_AR_RESOLVE); 165 166 dbg_print(lml, fmt, EC_XWORD(ndx), Dbg_demangle_name(arsym->as_name), 167 fname); 168 } 169 170 void 171 Dbg_syms_spec_title(Lm_list *lml) 172 { 173 if (DBG_NOTCLASS(DBG_C_SYMBOLS)) 174 return; 175 176 Dbg_util_nl(lml, DBG_NL_STD); 177 dbg_print(lml, MSG_INTL(MSG_SYM_SPECIAL)); 178 } 179 180 void 181 Dbg_syms_discarded(Lm_list *lml, Sym_desc *sdp, Is_desc *disp) 182 { 183 const char *sectname; 184 185 if (DBG_NOTCLASS(DBG_C_SYMBOLS)) 186 return; 187 if (DBG_NOTDETAIL()) 188 return; 189 190 if ((sectname = disp->is_basename) == 0) 191 sectname = disp->is_name; 192 193 dbg_print(lml, MSG_INTL(MSG_SYM_DISCARDED), 194 Dbg_demangle_name(sdp->sd_name), sectname, disp->is_file->ifl_name); 195 } 196 197 void 198 Dbg_syms_entered(Ofl_desc *ofl, Sym *sym, Sym_desc *sdp) 199 { 200 Conv_inv_buf_t inv_buf; 201 Lm_list *lml = ofl->ofl_lml; 202 203 if (DBG_NOTCLASS(DBG_C_SYMBOLS)) 204 return; 205 if (DBG_NOTDETAIL()) 206 return; 207 208 Elf_syms_table_entry(lml, ELF_DBG_LD, MSG_INTL(MSG_STR_ENTERED), 209 ofl->ofl_dehdr->e_machine, sym, 210 sdp->sd_aux ? sdp->sd_aux->sa_overndx : 0, 0, NULL, 211 conv_def_tag(sdp->sd_ref, &inv_buf)); 212 } 213 214 void 215 Dbg_syms_process(Lm_list *lml, Ifl_desc *ifl) 216 { 217 Conv_inv_buf_t inv_buf; 218 219 if (DBG_NOTCLASS(DBG_C_SYMBOLS)) 220 return; 221 222 Dbg_util_nl(lml, DBG_NL_STD); 223 dbg_print(lml, MSG_INTL(MSG_SYM_PROCESS), ifl->ifl_name, 224 conv_ehdr_type(ifl->ifl_ehdr->e_type, 0, &inv_buf)); 225 } 226 227 void 228 Dbg_syms_entry(Lm_list *lml, Word ndx, Sym_desc *sdp) 229 { 230 if (DBG_NOTCLASS(DBG_C_SYMBOLS)) 231 return; 232 233 dbg_print(lml, MSG_INTL(MSG_SYM_BASIC), EC_WORD(ndx), 234 Dbg_demangle_name(sdp->sd_name)); 235 } 236 237 void 238 Dbg_syms_global(Lm_list *lml, Word ndx, const char *name) 239 { 240 if (DBG_NOTCLASS(DBG_C_SYMBOLS)) 241 return; 242 243 dbg_print(lml, MSG_INTL(MSG_SYM_ADDING), EC_WORD(ndx), 244 Dbg_demangle_name(name)); 245 } 246 247 void 248 Dbg_syms_sec_title(Lm_list *lml) 249 { 250 if (DBG_NOTCLASS(DBG_C_SYMBOLS)) 251 return; 252 if (DBG_NOTDETAIL()) 253 return; 254 255 Dbg_util_nl(lml, DBG_NL_STD); 256 dbg_print(lml, MSG_INTL(MSG_SYM_INDEX)); 257 } 258 259 void 260 Dbg_syms_sec_entry(Lm_list *lml, Word ndx, Sg_desc *sgp, Os_desc *osp) 261 { 262 if (DBG_NOTCLASS(DBG_C_SYMBOLS)) 263 return; 264 if (DBG_NOTDETAIL()) 265 return; 266 267 dbg_print(lml, MSG_INTL(MSG_SYM_SECTION), EC_WORD(ndx), osp->os_name, 268 (*sgp->sg_name ? sgp->sg_name : MSG_INTL(MSG_STR_NULL))); 269 } 270 271 void 272 Dbg_syms_up_title(Lm_list *lml) 273 { 274 if (DBG_NOTCLASS(DBG_C_SYMBOLS)) 275 return; 276 if (DBG_NOTDETAIL()) 277 return; 278 279 Dbg_util_nl(lml, DBG_NL_STD); 280 dbg_print(lml, MSG_INTL(MSG_SYM_FINAL)); 281 Elf_syms_table_title(lml, ELF_DBG_LD); 282 } 283 284 void 285 Dbg_syms_ignore(Ofl_desc *ofl, Sym_desc *sdp) 286 { 287 if (DBG_NOTCLASS(DBG_C_SYMBOLS)) 288 return; 289 if (DBG_NOTDETAIL()) 290 return; 291 292 Elf_syms_table_entry(ofl->ofl_lml, ELF_DBG_LD, MSG_INTL(MSG_STR_IGNORE), 293 ofl->ofl_dehdr->e_machine, sdp->sd_sym, 0, 0, NULL, 294 MSG_INTL(MSG_STR_UNUSED)); 295 } 296 297 void 298 Dbg_syms_old(Ofl_desc *ofl, Sym_desc *sdp) 299 { 300 if (DBG_NOTCLASS(DBG_C_SYMBOLS)) 301 return; 302 if (DBG_NOTDETAIL()) 303 return; 304 305 Elf_syms_table_entry(ofl->ofl_lml, ELF_DBG_LD, MSG_INTL(MSG_STR_OLD), 306 ofl->ofl_dehdr->e_machine, sdp->sd_sym, 307 sdp->sd_aux ? sdp->sd_aux->sa_overndx : 0, 0, NULL, sdp->sd_name); 308 } 309 310 void 311 Dbg_syms_new(Ofl_desc *ofl, Sym *sym, Sym_desc *sdp) 312 { 313 Conv_inv_buf_t inv_buf; 314 315 if (DBG_NOTCLASS(DBG_C_SYMBOLS)) 316 return; 317 if (DBG_NOTDETAIL()) 318 return; 319 320 Elf_syms_table_entry(ofl->ofl_lml, ELF_DBG_LD, MSG_INTL(MSG_STR_NEW), 321 ofl->ofl_dehdr->e_machine, sym, 322 sdp->sd_aux ? sdp->sd_aux->sa_overndx : 0, 0, NULL, 323 conv_def_tag(sdp->sd_ref, &inv_buf)); 324 } 325 326 void 327 Dbg_syms_updated(Ofl_desc *ofl, Sym_desc *sdp, const char *name) 328 { 329 Conv_inv_buf_t inv_buf; 330 Lm_list *lml = ofl->ofl_lml; 331 332 if (DBG_NOTCLASS(DBG_C_SYMBOLS)) 333 return; 334 335 dbg_print(lml, MSG_INTL(MSG_SYM_UPDATE), name); 336 337 if (DBG_NOTDETAIL()) 338 return; 339 340 Elf_syms_table_entry(ofl->ofl_lml, ELF_DBG_LD, MSG_ORIG(MSG_STR_EMPTY), 341 ofl->ofl_dehdr->e_machine, sdp->sd_sym, 342 sdp->sd_aux ? sdp->sd_aux->sa_overndx : 0, 0, NULL, 343 conv_def_tag(sdp->sd_ref, &inv_buf)); 344 } 345 346 void 347 Dbg_syms_created(Lm_list *lml, const char *name) 348 { 349 if (DBG_NOTCLASS(DBG_C_SYMBOLS)) 350 return; 351 352 dbg_print(lml, MSG_INTL(MSG_SYM_CREATE), Dbg_demangle_name(name)); 353 } 354 355 void 356 Dbg_syms_resolving(Ofl_desc *ofl, Word ndx, const char *name, int row, 357 int col, Sym *osym, Sym *nsym, Sym_desc *sdp, Ifl_desc *ifl) 358 { 359 Lm_list *lml = ofl->ofl_lml; 360 Half mach = ofl->ofl_dehdr->e_machine; 361 362 if (DBG_NOTCLASS(DBG_C_SYMBOLS)) 363 return; 364 365 dbg_print(lml, MSG_INTL(MSG_SYM_RESOLVING), EC_WORD(ndx), 366 Dbg_demangle_name(name), row, col); 367 368 if (DBG_NOTDETAIL()) 369 return; 370 371 Elf_syms_table_entry(ofl->ofl_lml, ELF_DBG_LD, MSG_INTL(MSG_STR_OLD), 372 mach, osym, sdp->sd_aux ? sdp->sd_aux->sa_overndx : 0, 0, NULL, 373 sdp->sd_file->ifl_name); 374 375 Elf_syms_table_entry(ofl->ofl_lml, ELF_DBG_LD, MSG_INTL(MSG_STR_NEW), 376 mach, nsym, 0, 0, NULL, ifl->ifl_name); 377 } 378 379 void 380 Dbg_syms_resolved(Ofl_desc *ofl, Sym_desc *sdp) 381 { 382 Conv_inv_buf_t inv_buf; 383 384 if (DBG_NOTCLASS(DBG_C_SYMBOLS)) 385 return; 386 if (DBG_NOTDETAIL()) 387 return; 388 389 Elf_syms_table_entry(ofl->ofl_lml, ELF_DBG_LD, 390 MSG_INTL(MSG_STR_RESOLVED), ofl->ofl_dehdr->e_machine, sdp->sd_sym, 391 sdp->sd_aux ? sdp->sd_aux->sa_overndx : 0, 0, NULL, 392 conv_def_tag(sdp->sd_ref, &inv_buf)); 393 } 394 395 void 396 Dbg_syms_reloc(Ofl_desc *ofl, Sym_desc *sdp) 397 { 398 static Boolean symbol_title = TRUE; 399 Conv_inv_buf_t inv_buf; 400 Lm_list *lml = ofl->ofl_lml; 401 402 if (DBG_NOTCLASS(DBG_C_SYMBOLS)) 403 return; 404 405 if (symbol_title) { 406 Dbg_util_nl(lml, DBG_NL_STD); 407 dbg_print(lml, MSG_INTL(MSG_SYM_BSS)); 408 409 symbol_title = FALSE; 410 } 411 dbg_print(lml, MSG_INTL(MSG_SYM_UPDATE), 412 Dbg_demangle_name(sdp->sd_name)); 413 414 if (DBG_NOTDETAIL()) 415 return; 416 417 Elf_syms_table_entry(lml, ELF_DBG_LD, MSG_ORIG(MSG_SYM_COPY), 418 ofl->ofl_dehdr->e_machine, sdp->sd_sym, 419 sdp->sd_aux ? sdp->sd_aux->sa_overndx : 0, 0, NULL, 420 conv_def_tag(sdp->sd_ref, &inv_buf)); 421 } 422 423 void 424 Dbg_syms_reduce(Ofl_desc *ofl, int which, Sym_desc *sdp, int idx, 425 const char *sname) 426 { 427 static Boolean sym_reduce_title = TRUE; 428 static Boolean sym_retain_title = TRUE; 429 Boolean isfromglobal = (which == DBG_SYM_REDUCE_GLOBAL); 430 Boolean isfromretain = (which == DBG_SYM_REDUCE_RETAIN); 431 Lm_list *lml = ofl->ofl_lml; 432 433 if (DBG_NOTCLASS(DBG_C_SYMBOLS | DBG_C_VERSIONS)) 434 return; 435 436 if (sym_reduce_title && isfromglobal) { 437 sym_reduce_title = FALSE; 438 Dbg_util_nl(lml, DBG_NL_STD); 439 dbg_print(lml, MSG_INTL(MSG_SYM_REDUCED)); 440 } else if (sym_retain_title && isfromretain) { 441 sym_retain_title = FALSE; 442 Dbg_util_nl(lml, DBG_NL_STD); 443 dbg_print(lml, MSG_INTL(MSG_SYM_RETAINING)); 444 } 445 446 if ((sdp->sd_flags1 & FLG_SY1_ELIM) && isfromglobal) 447 dbg_print(lml, MSG_INTL(MSG_SYM_ELIMINATING), 448 Dbg_demangle_name(sdp->sd_name)); 449 else if (isfromglobal) 450 dbg_print(lml, MSG_INTL(MSG_SYM_REDUCING), 451 Dbg_demangle_name(sdp->sd_name)); 452 else 453 dbg_print(lml, MSG_INTL(MSG_SYM_NOTELIMINATE), 454 Dbg_demangle_name(sdp->sd_name), sname, idx); 455 456 if (DBG_NOTDETAIL()) 457 return; 458 459 Elf_syms_table_entry(ofl->ofl_lml, ELF_DBG_LD, MSG_ORIG(MSG_SYM_LOCAL), 460 ofl->ofl_dehdr->e_machine, sdp->sd_sym, 461 sdp->sd_aux ? sdp->sd_aux->sa_overndx : 0, 0, NULL, 462 sdp->sd_file->ifl_name); 463 } 464 465 void 466 Dbg_syms_dup_sort_addr(Lm_list *lml, const char *secname, const char *symname1, 467 const char *symname2, Addr addr) 468 { 469 if (DBG_NOTCLASS(DBG_C_SYMBOLS) || DBG_NOTDETAIL()) 470 return; 471 472 dbg_print(lml, MSG_INTL(MSG_SYM_DUPSORTADDR), secname, 473 symname1, symname2, EC_ADDR(addr)); 474 } 475 476 void 477 Dbg_syminfo_title(Lm_list *lml) 478 { 479 if (DBG_NOTCLASS(DBG_C_SYMBOLS)) 480 return; 481 if (DBG_NOTDETAIL()) 482 return; 483 484 Dbg_util_nl(lml, DBG_NL_STD); 485 dbg_print(lml, MSG_INTL(MSG_SYMINFO_INFO)); 486 Elf_syminfo_title(lml); 487 } 488 489 void 490 Dbg_syminfo_entry(Lm_list *lml, Word ndx, Syminfo *sip, Sym *sym, 491 const char *strtab, Dyn *dyn) 492 { 493 const char *needed; 494 495 if (DBG_NOTCLASS(DBG_C_SYMBOLS)) 496 return; 497 if (DBG_NOTDETAIL()) 498 return; 499 500 if (sip->si_boundto < SYMINFO_BT_LOWRESERVE) 501 needed = strtab + dyn[sip->si_boundto].d_un.d_val; 502 else 503 needed = 0; 504 505 Elf_syminfo_entry(lml, ndx, sip, 506 Dbg_demangle_name(strtab + sym->st_name), needed); 507 } 508 509 /* 510 * Symbol table output can differ slightly depending on the caller. However, 511 * the final diagnostic is maintained here so hat the various message strings 512 * remain consistent 513 * 514 * elfdump: index value size type bind oth ver shndx name 515 * ld: value size type bind oth ver shndx 516 */ 517 void 518 Elf_syms_table_title(Lm_list *lml, int caller) 519 { 520 if (caller == ELF_DBG_ELFDUMP) { 521 if (DBG_NOTLONG()) 522 dbg_print(lml, MSG_INTL(MSG_SYM_EFS_TITLE)); 523 else 524 dbg_print(lml, MSG_INTL(MSG_SYM_EFL_TITLE)); 525 return; 526 } 527 528 if (caller == ELF_DBG_LD) { 529 if (DBG_NOTLONG()) 530 dbg_print(lml, MSG_INTL(MSG_SYM_LDS_TITLE)); 531 else 532 dbg_print(lml, MSG_INTL(MSG_SYM_LDL_TITLE)); 533 return; 534 } 535 } 536 537 void 538 Elf_syms_table_entry(Lm_list *lml, int caller, const char *prestr, Half mach, 539 Sym *sym, Versym verndx, int gnuver, const char *sec, const char *poststr) 540 { 541 Conv_inv_buf_t inv_buf1, inv_buf2, inv_buf3; 542 Conv_inv_buf_t inv_buf4, inv_buf5, inv_buf6; 543 uchar_t type = ELF_ST_TYPE(sym->st_info); 544 uchar_t bind = ELF_ST_BIND(sym->st_info); 545 const char *msg; 546 547 if ((caller == ELF_DBG_ELFDUMP) || 548 (caller == ELF_DBG_LD)) { 549 if (DBG_NOTLONG()) 550 msg = MSG_INTL(MSG_SYM_EFS_ENTRY); 551 else 552 msg = MSG_INTL(MSG_SYM_EFL_ENTRY); 553 554 dbg_print(lml, msg, prestr, 555 conv_sym_value(mach, type, sym->st_value, &inv_buf1), 556 sym->st_size, conv_sym_info_type(mach, type, 0, &inv_buf2), 557 conv_sym_info_bind(bind, 0, &inv_buf3), 558 conv_sym_other(sym->st_other, &inv_buf4), 559 conv_ver_index(verndx, gnuver, &inv_buf5), 560 sec ? sec : conv_sym_shndx(sym->st_shndx, &inv_buf6), 561 Elf_demangle_name(poststr)); 562 } 563 } 564