439 * than this value.
440 */
441 tdata_label_newmax(td, iiburst->iib_maxtypeid);
442
443 return (iiburst);
444 }
445
446 static void
447 write_file(Elf *src, const char *srcname, Elf *dst, const char *dstname,
448 caddr_t ctfdata, size_t ctfsize, int flags)
449 {
450 GElf_Ehdr sehdr, dehdr;
451 Elf_Scn *sscn, *dscn;
452 Elf_Data *sdata, *ddata;
453 GElf_Shdr shdr;
454 GElf_Word symtab_type;
455 int symtab_idx = -1;
456 off_t new_offset = 0;
457 off_t ctfnameoff = 0;
458 int dynsym = (flags & CTF_USE_DYNSYM);
459 int keep_stabs = (flags & CTF_KEEP_STABS);
460 int *secxlate;
461 int srcidx, dstidx;
462 int curnmoff = 0;
463 int changing = 0;
464 int pad;
465 int i;
466
467 if (gelf_newehdr(dst, gelf_getclass(src)) == 0)
468 elfterminate(dstname, "Cannot copy ehdr to temp file");
469 gelf_getehdr(src, &sehdr);
470 memcpy(&dehdr, &sehdr, sizeof (GElf_Ehdr));
471 gelf_update_ehdr(dst, &dehdr);
472
473 symtab_type = dynsym ? SHT_DYNSYM : SHT_SYMTAB;
474
475 /*
476 * Neither the existing stab sections nor the SUNW_ctf sections (new or
477 * existing) are SHF_ALLOC'd, so they won't be in areas referenced by
478 * program headers. As such, we can just blindly copy the program
479 * headers from the existing file to the new file.
489 gelf_getphdr(src, i, &phdr);
490 gelf_update_phdr(dst, i, &phdr);
491 }
492 }
493
494 secxlate = xmalloc(sizeof (int) * sehdr.e_shnum);
495 for (srcidx = dstidx = 0; srcidx < sehdr.e_shnum; srcidx++) {
496 Elf_Scn *scn = elf_getscn(src, srcidx);
497 GElf_Shdr shdr;
498 char *sname;
499
500 gelf_getshdr(scn, &shdr);
501 sname = elf_strptr(src, sehdr.e_shstrndx, shdr.sh_name);
502 if (sname == NULL) {
503 elfterminate(srcname, "Can't find string at %u",
504 shdr.sh_name);
505 }
506
507 if (strcmp(sname, CTF_ELF_SCN_NAME) == 0) {
508 secxlate[srcidx] = -1;
509 } else if (!keep_stabs &&
510 (strncmp(sname, ".stab", 5) == 0 ||
511 strncmp(sname, ".debug", 6) == 0 ||
512 strncmp(sname, ".rel.debug", 10) == 0 ||
513 strncmp(sname, ".rela.debug", 11) == 0)) {
514 secxlate[srcidx] = -1;
515 } else if (dynsym && shdr.sh_type == SHT_SYMTAB) {
516 /*
517 * If we're building CTF against the dynsym,
518 * we'll rip out the symtab so debuggers aren't
519 * confused.
520 */
521 secxlate[srcidx] = -1;
522 } else {
523 secxlate[srcidx] = dstidx++;
524 curnmoff += strlen(sname) + 1;
525 }
526
527 new_offset = (off_t)dehdr.e_phoff;
528 }
529
530 for (srcidx = 1; srcidx < sehdr.e_shnum; srcidx++) {
531 char *sname;
532
533 sscn = elf_getscn(src, srcidx);
534 gelf_getshdr(sscn, &shdr);
|
439 * than this value.
440 */
441 tdata_label_newmax(td, iiburst->iib_maxtypeid);
442
443 return (iiburst);
444 }
445
446 static void
447 write_file(Elf *src, const char *srcname, Elf *dst, const char *dstname,
448 caddr_t ctfdata, size_t ctfsize, int flags)
449 {
450 GElf_Ehdr sehdr, dehdr;
451 Elf_Scn *sscn, *dscn;
452 Elf_Data *sdata, *ddata;
453 GElf_Shdr shdr;
454 GElf_Word symtab_type;
455 int symtab_idx = -1;
456 off_t new_offset = 0;
457 off_t ctfnameoff = 0;
458 int dynsym = (flags & CTF_USE_DYNSYM);
459 int *secxlate;
460 int srcidx, dstidx;
461 int curnmoff = 0;
462 int changing = 0;
463 int pad;
464 int i;
465
466 if (gelf_newehdr(dst, gelf_getclass(src)) == 0)
467 elfterminate(dstname, "Cannot copy ehdr to temp file");
468 gelf_getehdr(src, &sehdr);
469 memcpy(&dehdr, &sehdr, sizeof (GElf_Ehdr));
470 gelf_update_ehdr(dst, &dehdr);
471
472 symtab_type = dynsym ? SHT_DYNSYM : SHT_SYMTAB;
473
474 /*
475 * Neither the existing stab sections nor the SUNW_ctf sections (new or
476 * existing) are SHF_ALLOC'd, so they won't be in areas referenced by
477 * program headers. As such, we can just blindly copy the program
478 * headers from the existing file to the new file.
488 gelf_getphdr(src, i, &phdr);
489 gelf_update_phdr(dst, i, &phdr);
490 }
491 }
492
493 secxlate = xmalloc(sizeof (int) * sehdr.e_shnum);
494 for (srcidx = dstidx = 0; srcidx < sehdr.e_shnum; srcidx++) {
495 Elf_Scn *scn = elf_getscn(src, srcidx);
496 GElf_Shdr shdr;
497 char *sname;
498
499 gelf_getshdr(scn, &shdr);
500 sname = elf_strptr(src, sehdr.e_shstrndx, shdr.sh_name);
501 if (sname == NULL) {
502 elfterminate(srcname, "Can't find string at %u",
503 shdr.sh_name);
504 }
505
506 if (strcmp(sname, CTF_ELF_SCN_NAME) == 0) {
507 secxlate[srcidx] = -1;
508 } else if (dynsym && shdr.sh_type == SHT_SYMTAB) {
509 /*
510 * If we're building CTF against the dynsym,
511 * we'll rip out the symtab so debuggers aren't
512 * confused.
513 */
514 secxlate[srcidx] = -1;
515 } else {
516 secxlate[srcidx] = dstidx++;
517 curnmoff += strlen(sname) + 1;
518 }
519
520 new_offset = (off_t)dehdr.e_phoff;
521 }
522
523 for (srcidx = 1; srcidx < sehdr.e_shnum; srcidx++) {
524 char *sname;
525
526 sscn = elf_getscn(src, srcidx);
527 gelf_getshdr(sscn, &shdr);
|