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