From owner-svn-src-all@freebsd.org Fri Dec 11 18:47:42 2015 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id DC95A9D7BFE; Fri, 11 Dec 2015 18:47:42 +0000 (UTC) (envelope-from emaste@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 8EC181F71; Fri, 11 Dec 2015 18:47:42 +0000 (UTC) (envelope-from emaste@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id tBBIlf5q062989; Fri, 11 Dec 2015 18:47:41 GMT (envelope-from emaste@FreeBSD.org) Received: (from emaste@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id tBBIlfuF062988; Fri, 11 Dec 2015 18:47:41 GMT (envelope-from emaste@FreeBSD.org) Message-Id: <201512111847.tBBIlfuF062988@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: emaste set sender to emaste@FreeBSD.org using -f From: Ed Maste Date: Fri, 11 Dec 2015 18:47:41 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r292116 - head/contrib/elftoolchain/elfcopy X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 11 Dec 2015 18:47:43 -0000 Author: emaste Date: Fri Dec 11 18:47:41 2015 New Revision: 292116 URL: https://svnweb.freebsd.org/changeset/base/292116 Log: 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 Modified: head/contrib/elftoolchain/elfcopy/binary.c Modified: head/contrib/elftoolchain/elfcopy/binary.c ============================================================================== --- head/contrib/elftoolchain/elfcopy/binary.c Fri Dec 11 18:28:20 2015 (r292115) +++ head/contrib/elftoolchain/elfcopy/binary.c Fri Dec 11 18:47:41 2015 (r292116) @@ -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 *e 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 *e /* 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 *e finalize_external_symtab(ecp); create_symtab_data(ecp); #undef _GEN_SYMNAME + free(sym_basename); /* * Write the underlying ehdr. Note that it should be called