Changeset View
Changeset View
Standalone View
Standalone View
head/contrib/elftoolchain/elfcopy/sections.c
Show First 20 Lines • Show All 1,392 Lines • ▼ Show 20 Lines | update_shdr(struct elfcopy *ecp, int update_link) | ||||
if (elferr != 0) | if (elferr != 0) | ||||
errx(EXIT_FAILURE, "elf_nextscn failed: %s", | errx(EXIT_FAILURE, "elf_nextscn failed: %s", | ||||
elf_errmsg(elferr)); | elf_errmsg(elferr)); | ||||
} | } | ||||
void | void | ||||
init_shstrtab(struct elfcopy *ecp) | init_shstrtab(struct elfcopy *ecp) | ||||
{ | { | ||||
Elf_Scn *shstrtab; | |||||
GElf_Shdr shdr; | |||||
struct section *s; | struct section *s; | ||||
size_t indx, sizehint; | |||||
if (elf_getshstrndx(ecp->ein, &indx) != 0) { | |||||
shstrtab = elf_getscn(ecp->ein, indx); | |||||
if (shstrtab == NULL) | |||||
errx(EXIT_FAILURE, "elf_getscn failed: %s", | |||||
elf_errmsg(-1)); | |||||
if (gelf_getshdr(shstrtab, &shdr) != &shdr) | |||||
errx(EXIT_FAILURE, "gelf_getshdr failed: %s", | |||||
elf_errmsg(-1)); | |||||
sizehint = shdr.sh_size; | |||||
} else { | |||||
sizehint = 0; | |||||
} | |||||
if ((ecp->shstrtab = calloc(1, sizeof(*ecp->shstrtab))) == NULL) | if ((ecp->shstrtab = calloc(1, sizeof(*ecp->shstrtab))) == NULL) | ||||
err(EXIT_FAILURE, "calloc failed"); | err(EXIT_FAILURE, "calloc failed"); | ||||
s = ecp->shstrtab; | s = ecp->shstrtab; | ||||
s->name = ".shstrtab"; | s->name = ".shstrtab"; | ||||
s->is = NULL; | s->is = NULL; | ||||
s->sz = 0; | s->sz = 0; | ||||
s->align = 1; | s->align = 1; | ||||
s->loadable = 0; | s->loadable = 0; | ||||
s->type = SHT_STRTAB; | s->type = SHT_STRTAB; | ||||
s->vma = 0; | s->vma = 0; | ||||
s->strtab = elftc_string_table_create(0); | s->strtab = elftc_string_table_create(sizehint); | ||||
add_to_shstrtab(ecp, ""); | add_to_shstrtab(ecp, ""); | ||||
add_to_shstrtab(ecp, ".symtab"); | add_to_shstrtab(ecp, ".symtab"); | ||||
add_to_shstrtab(ecp, ".strtab"); | add_to_shstrtab(ecp, ".strtab"); | ||||
add_to_shstrtab(ecp, ".shstrtab"); | add_to_shstrtab(ecp, ".shstrtab"); | ||||
} | } | ||||
static void | static void | ||||
▲ Show 20 Lines • Show All 258 Lines • Show Last 20 Lines |