summaryrefslogtreecommitdiffstats
path: root/contrib/elftoolchain
diff options
context:
space:
mode:
authoremaste <emaste@FreeBSD.org>2015-12-11 18:47:41 +0000
committeremaste <emaste@FreeBSD.org>2015-12-11 18:47:41 +0000
commitc90cc6d115c12678a931b143898ab908559b0223 (patch)
tree7a8cc372b3153b25b257da1ae15c8fda5a5603c8 /contrib/elftoolchain
parent69e096c120ec1d9cd28d6d3e328d0e0bc5b5a968 (diff)
downloadFreeBSD-src-c90cc6d115c12678a931b143898ab908559b0223.zip
FreeBSD-src-c90cc6d115c12678a931b143898ab908559b0223.tar.gz
elfcopy: include extension but replace . when converting from binary
The change in r291958 was not consistent with GNU objcopy. The start, end and size symbols created for ELF objects converted from binary need to include the full filename including the extension, but with the periods replaced with underscores. Reviewed by: imp Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D4474
Diffstat (limited to 'contrib/elftoolchain')
-rw-r--r--contrib/elftoolchain/elfcopy/binary.c20
1 files changed, 8 insertions, 12 deletions
diff --git a/contrib/elftoolchain/elfcopy/binary.c b/contrib/elftoolchain/elfcopy/binary.c
index 6213623..bc5f9fd 100644
--- a/contrib/elftoolchain/elfcopy/binary.c
+++ b/contrib/elftoolchain/elfcopy/binary.c
@@ -37,16 +37,6 @@
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
@@ -150,6 +140,7 @@ create_elf_from_binary(struct elfcopy *ecp, int ifd, const char *ifn)
GElf_Shdr sh;
void *content;
uint64_t off, data_start, data_end, data_size;
+ char *sym_basename, *p;
/* Reset internal section list. */
if (!TAILQ_EMPTY(&ecp->v_sec))
@@ -220,9 +211,13 @@ create_elf_from_binary(struct elfcopy *ecp, int ifd, const char *ifn)
/* Count in .symtab and .strtab section headers. */
shtab->sz += gelf_fsize(ecp->eout, ELF_T_SHDR, 2, EV_CURRENT);
+ if ((sym_basename = strdup(ifn)) == NULL)
+ err(1, "strdup");
+ p = sym_basename;
+ while ((p = strchr(p, '.')) != NULL)
+ *p++ = '_';
#define _GEN_SYMNAME(S) do { \
- snprintf(name, sizeof(name), "%s%.*s%s", "_binary_", \
- basename_length(ifn), ifn, S); \
+ snprintf(name, sizeof(name), "%s%s%s", "_binary_", sym_basename, S); \
} while (0)
/*
@@ -244,6 +239,7 @@ create_elf_from_binary(struct elfcopy *ecp, int ifd, const char *ifn)
finalize_external_symtab(ecp);
create_symtab_data(ecp);
#undef _GEN_SYMNAME
+ free(sym_basename);
/*
* Write the underlying ehdr. Note that it should be called
OpenPOWER on IntegriCloud