elfcopy: exclude extension when converting from binary

When converting from binary to ELF, elfcopy creates symbols
_binary_<filename>_start_, _binary_<filename>_end, and
_binary_<filename>_size. For compatibility with GNU objcopy (and to
produce sensible symbol names) the extension must be stripped off.

Reviewed by:	imp
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D4238
This commit is contained in:
Ed Maste 2015-12-07 20:21:12 +00:00
parent 645babfa8f
commit fc7284da06
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=291958

View File

@ -37,6 +37,16 @@
ELFTC_VCSID("$Id: binary.c 3174 2015-03-27 17:13:41Z emaste $");
static int
basename_length(const char *filename)
{
char *p;
if ((p = strchr(filename, '.')) != NULL)
return (p - filename);
return (strlen(filename));
}
/*
* Convert ELF object to `binary'. Sections with SHF_ALLOC flag set
* are copied to the result binary. The relative offsets for each section
@ -211,7 +221,8 @@ create_elf_from_binary(struct elfcopy *ecp, int ifd, const char *ifn)
shtab->sz += gelf_fsize(ecp->eout, ELF_T_SHDR, 2, EV_CURRENT);
#define _GEN_SYMNAME(S) do { \
snprintf(name, sizeof(name), "%s%s%s", "_binary_", ifn, S); \
snprintf(name, sizeof(name), "%s%.*s%s", "_binary_", \
basename_length(ifn), ifn, S); \
} while (0)
/*