elfcopy: Use elf_getscn() instead of iterating over all sections.

When removing a section, we would loop over all sections looking for
a corresponding relocation section.  With r348652 it is much faster
to just use elf_getscn().

PR:		234949
Reviewed by:	emaste
MFC after:	2 weeks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D20471
This commit is contained in:
Mark Johnston 2019-06-04 18:29:08 +00:00
parent 3c7951c78b
commit dc2282fc8b
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=348654

View File

@ -119,21 +119,19 @@ is_remove_reloc_sec(struct elfcopy *ecp, uint32_t sh_info)
errx(EXIT_FAILURE, "elf_getshstrndx failed: %s",
elf_errmsg(-1));
is = NULL;
while ((is = elf_nextscn(ecp->ein, is)) != NULL) {
if (sh_info == elf_ndxscn(is)) {
if (gelf_getshdr(is, &ish) == NULL)
errx(EXIT_FAILURE, "gelf_getshdr failed: %s",
elf_errmsg(-1));
if ((name = elf_strptr(ecp->ein, indx, ish.sh_name)) ==
NULL)
errx(EXIT_FAILURE, "elf_strptr failed: %s",
elf_errmsg(-1));
if (is_remove_section(ecp, name))
return (1);
else
return (0);
}
is = elf_getscn(ecp->ein, sh_info);
if (is != NULL) {
if (gelf_getshdr(is, &ish) == NULL)
errx(EXIT_FAILURE, "gelf_getshdr failed: %s",
elf_errmsg(-1));
if ((name = elf_strptr(ecp->ein, indx, ish.sh_name)) ==
NULL)
errx(EXIT_FAILURE, "elf_strptr failed: %s",
elf_errmsg(-1));
if (is_remove_section(ecp, name))
return (1);
else
return (0);
}
elferr = elf_errno();
if (elferr != 0)