1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-10-19 02:29:40 +00:00

elfcopy: Provide a size hint when creating the section string table.

Use the input file's .shstrtab size as the hint if it exists.  This
gives a small performance improvement when processing files with
many sections.

Reviewed by:	emaste
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D20544
This commit is contained in:
Mark Johnston 2019-06-26 16:35:37 +00:00
parent 9810827a3a
commit c8b057f4a7
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=349423

View File

@ -1398,7 +1398,23 @@ update_shdr(struct elfcopy *ecp, int update_link)
void
init_shstrtab(struct elfcopy *ecp)
{
Elf_Scn *shstrtab;
GElf_Shdr shdr;
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)
err(EXIT_FAILURE, "calloc failed");
@ -1410,7 +1426,7 @@ init_shstrtab(struct elfcopy *ecp)
s->loadable = 0;
s->type = SHT_STRTAB;
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, ".symtab");