Changeset View
Changeset View
Standalone View
Standalone View
head/contrib/elftoolchain/elfcopy/sections.c
Show First 20 Lines • Show All 1,397 Lines • ▼ Show 20 Lines | |||||
void | void | ||||
init_shstrtab(struct elfcopy *ecp) | init_shstrtab(struct elfcopy *ecp) | ||||
{ | { | ||||
Elf_Scn *shstrtab; | Elf_Scn *shstrtab; | ||||
GElf_Shdr shdr; | GElf_Shdr shdr; | ||||
struct section *s; | struct section *s; | ||||
size_t indx, sizehint; | size_t indx, sizehint; | ||||
if (elf_getshstrndx(ecp->ein, &indx) != 0) { | if (elf_getshdrstrndx(ecp->ein, &indx) == 0) { | ||||
shstrtab = elf_getscn(ecp->ein, indx); | shstrtab = elf_getscn(ecp->ein, indx); | ||||
if (shstrtab == NULL) | if (shstrtab == NULL) | ||||
errx(EXIT_FAILURE, "elf_getscn failed: %s", | errx(EXIT_FAILURE, "elf_getscn failed: %s", | ||||
elf_errmsg(-1)); | elf_errmsg(-1)); | ||||
if (gelf_getshdr(shstrtab, &shdr) != &shdr) | if (gelf_getshdr(shstrtab, &shdr) != &shdr) | ||||
errx(EXIT_FAILURE, "gelf_getshdr failed: %s", | errx(EXIT_FAILURE, "gelf_getshdr failed: %s", | ||||
elf_errmsg(-1)); | elf_errmsg(-1)); | ||||
sizehint = shdr.sh_size; | sizehint = shdr.sh_size; | ||||
} else { | } else { | ||||
/* Clear the error from elf_getshdrstrndx(3). */ | |||||
(void)elf_errno(); | |||||
sizehint = 0; | 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; | ||||
▲ Show 20 Lines • Show All 272 Lines • Show Last 20 Lines |