summaryrefslogtreecommitdiffstats
path: root/contrib/elftoolchain/elfcopy
diff options
context:
space:
mode:
authoremaste <emaste@FreeBSD.org>2015-12-07 20:21:12 +0000
committeremaste <emaste@FreeBSD.org>2015-12-07 20:21:12 +0000
commitb4974472b45031a77d86cdefbe75d580ede653fb (patch)
treee5a3e3ac64e422dc86165abfd2a1e93245916907 /contrib/elftoolchain/elfcopy
parent8ec073a10b301b8fa209d6e81d78c9b512a9b811 (diff)
downloadFreeBSD-src-b4974472b45031a77d86cdefbe75d580ede653fb.zip
FreeBSD-src-b4974472b45031a77d86cdefbe75d580ede653fb.tar.gz
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
Diffstat (limited to 'contrib/elftoolchain/elfcopy')
-rw-r--r--contrib/elftoolchain/elfcopy/binary.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/contrib/elftoolchain/elfcopy/binary.c b/contrib/elftoolchain/elfcopy/binary.c
index 23e46e7..6213623 100644
--- a/contrib/elftoolchain/elfcopy/binary.c
+++ b/contrib/elftoolchain/elfcopy/binary.c
@@ -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)
/*
OpenPOWER on IntegriCloud