370 if (cursct->sh_type == SHT_SYMTAB) {
371 // Full symbol table available so use that
372 sym_section = cursct->sh_type;
373 }
374 cursct++;
375 }
376
377 #if defined(ppc64) && !defined(ABI_ELFv2)
378 opd_sect = find_section_by_name(".opd", fd, &ehdr, scn_cache);
379 if (opd_sect != NULL && opd_sect->c_data != NULL && opd_sect->c_shdr != NULL) {
380 // plausibility check
381 opd = opd_sect->c_shdr;
382 }
383 #endif
384
385 for (cnt = 1; cnt < ehdr.e_shnum; cnt++) {
386 ELF_SHDR *shdr = scn_cache[cnt].c_shdr;
387
388 if (shdr->sh_type == sym_section) {
389 ELF_SYM *syms;
390 int j, n, rslt;
391 size_t size;
392
393 // FIXME: there could be multiple data buffers associated with the
394 // same ELF section. Here we can handle only one buffer. See man page
395 // for elf_getdata on Solaris.
396
397 // guarantee(symtab == NULL, "multiple symtab");
398 symtab = (struct symtab*)calloc(1, sizeof(struct symtab));
399 if (symtab == NULL) {
400 goto quit;
401 }
402 // the symbol table
403 syms = (ELF_SYM *)scn_cache[cnt].c_data;
404
405 // number of symbols
406 n = shdr->sh_size / shdr->sh_entsize;
407
408 // create hash table, we use hcreate_r, hsearch_r and hdestroy_r to
409 // manipulate the hash table.
410 symtab->hash_table = (struct hsearch_data*) calloc(1, sizeof(struct hsearch_data));
411 rslt = hcreate_r(n, symtab->hash_table);
412 // guarantee(rslt, "unexpected failure: hcreate_r");
413
414 // shdr->sh_link points to the section that contains the actual strings
415 // for symbol names. the st_name field in ELF_SYM is just the
416 // string table index. we make a copy of the string table so the
417 // strings will not be destroyed by elf_end.
418 size = scn_cache[shdr->sh_link].c_shdr->sh_size;
419 symtab->strs = (char *)malloc(size);
420 memcpy(symtab->strs, scn_cache[shdr->sh_link].c_data, size);
421
422 // allocate memory for storing symbol offset and size;
423 symtab->num_symbols = n;
424 symtab->symbols = (struct elf_symbol *)calloc(n , sizeof(struct elf_symbol));
425
426 // copy symbols info our symtab and enter them info the hash table
427 for (j = 0; j < n; j++, syms++) {
428 ENTRY item, *ret;
429 uintptr_t sym_value;
435 continue;
436 // skip empty strings and undefined symbols
437 if (*sym_name == '\0' || syms->st_shndx == SHN_UNDEF) continue;
438
439 symtab->symbols[j].name = sym_name;
440 symtab->symbols[j].size = syms->st_size;
441 sym_value = syms->st_value;
442
443 #if defined(ppc64) && !defined(ABI_ELFv2)
444 // see hotspot/src/share/vm/utilities/elfFuncDescTable.hpp for a detailed description
445 // of why we have to go this extra way via the '.opd' section on big endian ppc64
446 if (opd != NULL && *sym_name != '.' &&
447 (opd->sh_addr <= sym_value && sym_value <= opd->sh_addr + opd->sh_size)) {
448 sym_value = ((ELF_ADDR*)opd_sect->c_data)[(sym_value - opd->sh_addr) / sizeof(ELF_ADDR*)];
449 }
450 #endif
451
452 symtab->symbols[j].offset = sym_value - baseaddr;
453 item.key = sym_name;
454 item.data = (void *)&(symtab->symbols[j]);
455
456 hsearch_r(item, ENTER, &ret, symtab->hash_table);
457 }
458 }
459 }
460
461 #if defined(ppc64) && !defined(ABI_ELFv2)
462 // On Linux/PPC64 the debuginfo files contain an empty function descriptor
463 // section (i.e. '.opd' section) which makes the resolution of symbols
464 // with the above algorithm impossible (we would need the have both, the
465 // .opd section from the library and the symbol table from the debuginfo
466 // file which doesn't match with the current workflow.)
467 goto quit;
468 #endif
469
470 // Look for a separate debuginfo file.
471 if (try_debuginfo) {
472 // We prefer a debug symtab to an object's own symtab, so look in
473 // the debuginfo file. We stash a copy of the old symtab in case
474 // there is no debuginfo.
475 struct symtab* prev_symtab = symtab;
|
370 if (cursct->sh_type == SHT_SYMTAB) {
371 // Full symbol table available so use that
372 sym_section = cursct->sh_type;
373 }
374 cursct++;
375 }
376
377 #if defined(ppc64) && !defined(ABI_ELFv2)
378 opd_sect = find_section_by_name(".opd", fd, &ehdr, scn_cache);
379 if (opd_sect != NULL && opd_sect->c_data != NULL && opd_sect->c_shdr != NULL) {
380 // plausibility check
381 opd = opd_sect->c_shdr;
382 }
383 #endif
384
385 for (cnt = 1; cnt < ehdr.e_shnum; cnt++) {
386 ELF_SHDR *shdr = scn_cache[cnt].c_shdr;
387
388 if (shdr->sh_type == sym_section) {
389 ELF_SYM *syms;
390 int rslt;
391 size_t size, n, j, htab_sz;
392
393 // FIXME: there could be multiple data buffers associated with the
394 // same ELF section. Here we can handle only one buffer. See man page
395 // for elf_getdata on Solaris.
396
397 // guarantee(symtab == NULL, "multiple symtab");
398 symtab = (struct symtab*)calloc(1, sizeof(struct symtab));
399 if (symtab == NULL) {
400 goto quit;
401 }
402 // the symbol table
403 syms = (ELF_SYM *)scn_cache[cnt].c_data;
404
405 // number of symbols
406 n = shdr->sh_size / shdr->sh_entsize;
407
408 // create hash table, we use hcreate_r, hsearch_r and hdestroy_r to
409 // manipulate the hash table.
410
411 // NOTES section in the man page of hcreate_r says
412 // "Hash table implementations are usually more efficient when
413 // the table contains enough free space to minimize collisions.
414 // Typically, this means that nel should be at least 25% larger
415 // than the maximum number of elements that the caller expects
416 // to store in the table."
417 htab_sz = n*1.25;
418
419 symtab->hash_table = (struct hsearch_data*) calloc(1, sizeof(struct hsearch_data));
420 rslt = hcreate_r(n, symtab->hash_table);
421 // guarantee(rslt, "unexpected failure: hcreate_r");
422
423 // shdr->sh_link points to the section that contains the actual strings
424 // for symbol names. the st_name field in ELF_SYM is just the
425 // string table index. we make a copy of the string table so the
426 // strings will not be destroyed by elf_end.
427 size = scn_cache[shdr->sh_link].c_shdr->sh_size;
428 symtab->strs = (char *)malloc(size);
429 memcpy(symtab->strs, scn_cache[shdr->sh_link].c_data, size);
430
431 // allocate memory for storing symbol offset and size;
432 symtab->num_symbols = n;
433 symtab->symbols = (struct elf_symbol *)calloc(n , sizeof(struct elf_symbol));
434
435 // copy symbols info our symtab and enter them info the hash table
436 for (j = 0; j < n; j++, syms++) {
437 ENTRY item, *ret;
438 uintptr_t sym_value;
444 continue;
445 // skip empty strings and undefined symbols
446 if (*sym_name == '\0' || syms->st_shndx == SHN_UNDEF) continue;
447
448 symtab->symbols[j].name = sym_name;
449 symtab->symbols[j].size = syms->st_size;
450 sym_value = syms->st_value;
451
452 #if defined(ppc64) && !defined(ABI_ELFv2)
453 // see hotspot/src/share/vm/utilities/elfFuncDescTable.hpp for a detailed description
454 // of why we have to go this extra way via the '.opd' section on big endian ppc64
455 if (opd != NULL && *sym_name != '.' &&
456 (opd->sh_addr <= sym_value && sym_value <= opd->sh_addr + opd->sh_size)) {
457 sym_value = ((ELF_ADDR*)opd_sect->c_data)[(sym_value - opd->sh_addr) / sizeof(ELF_ADDR*)];
458 }
459 #endif
460
461 symtab->symbols[j].offset = sym_value - baseaddr;
462 item.key = sym_name;
463 item.data = (void *)&(symtab->symbols[j]);
464 hsearch_r(item, ENTER, &ret, symtab->hash_table);
465 }
466 }
467 }
468
469 #if defined(ppc64) && !defined(ABI_ELFv2)
470 // On Linux/PPC64 the debuginfo files contain an empty function descriptor
471 // section (i.e. '.opd' section) which makes the resolution of symbols
472 // with the above algorithm impossible (we would need the have both, the
473 // .opd section from the library and the symbol table from the debuginfo
474 // file which doesn't match with the current workflow.)
475 goto quit;
476 #endif
477
478 // Look for a separate debuginfo file.
479 if (try_debuginfo) {
480 // We prefer a debug symtab to an object's own symtab, so look in
481 // the debuginfo file. We stash a copy of the old symtab in case
482 // there is no debuginfo.
483 struct symtab* prev_symtab = symtab;
|