From owner-svn-src-all@freebsd.org Wed May 25 20:56:31 2016 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 5D234B4A838; Wed, 25 May 2016 20:56:31 +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 202581B83; Wed, 25 May 2016 20:56:31 +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 u4PKuUl2085347; Wed, 25 May 2016 20:56:30 GMT (envelope-from emaste@FreeBSD.org) Received: (from emaste@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u4PKuUX3085345; Wed, 25 May 2016 20:56:30 GMT (envelope-from emaste@FreeBSD.org) Message-Id: <201605252056.u4PKuUX3085345@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: emaste set sender to emaste@FreeBSD.org using -f From: Ed Maste Date: Wed, 25 May 2016 20:56:30 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r300698 - in head: contrib/elftoolchain/elfcopy lib/libelftc 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.22 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: Wed, 25 May 2016 20:56:31 -0000 Author: emaste Date: Wed May 25 20:56:30 2016 New Revision: 300698 URL: https://svnweb.freebsd.org/changeset/base/300698 Log: Update to ELF Tool Chain r3477 This fixes a EFI/PE header issue that prevented elfcopy-produced .efi files from working with Secure Boot: Make sure section raw size is always padded to multiple of FileAlignment from the optional header, as requested by the PE specification. This change should reduce the diff between PE image generated by Binutils objcopy and elftoolchain elfcopy. Submitted by: kaiw Reported by: ambrisko Modified: head/contrib/elftoolchain/elfcopy/pe.c head/lib/libelftc/elftc_version.c Directory Properties: head/contrib/elftoolchain/ (props changed) Modified: head/contrib/elftoolchain/elfcopy/pe.c ============================================================================== --- head/contrib/elftoolchain/elfcopy/pe.c Wed May 25 20:50:05 2016 (r300697) +++ head/contrib/elftoolchain/elfcopy/pe.c Wed May 25 20:56:30 2016 (r300698) @@ -34,7 +34,7 @@ #include "elfcopy.h" -ELFTC_VCSID("$Id: pe.c 3312 2016-01-10 09:23:51Z kaiwang27 $"); +ELFTC_VCSID("$Id: pe.c 3477 2016-05-25 20:00:42Z kaiwang27 $"); /* Convert ELF object to Portable Executable (PE). */ void @@ -54,7 +54,7 @@ create_pe(struct elfcopy *ecp, int ifd, PE_Buffer *pb; const char *name; size_t indx; - int elferr, i; + int elferr; if (ecp->otf == ETF_EFI || ecp->oem == EM_X86_64) po = PE_O_PE32P; @@ -175,7 +175,7 @@ create_pe(struct elfcopy *ecp, int ifd, psh.sh_addr = sh.sh_addr; psh.sh_virtsize = sh.sh_size; if (sh.sh_type != SHT_NOBITS) - psh.sh_rawsize = sh.sh_size; + psh.sh_rawsize = roundup(sh.sh_size, poh.oh_filealign); else psh.sh_char |= IMAGE_SCN_CNT_UNINITIALIZED_DATA; @@ -190,12 +190,6 @@ create_pe(struct elfcopy *ecp, int ifd, IMAGE_SCN_CNT_CODE; if ((sh.sh_flags & SHF_ALLOC) && (psh.sh_char & 0xF0) == 0) psh.sh_char |= IMAGE_SCN_CNT_INITIALIZED_DATA; - for (i = 0xE; i > 0; i--) { - if (sh.sh_addralign & (1U << (i - 1))) { - psh.sh_char |= i << 20; - break; - } - } /* Mark relocation section "discardable". */ if (strcmp(name, ".reloc") == 0) @@ -213,8 +207,12 @@ create_pe(struct elfcopy *ecp, int ifd, } pb->pb_align = 1; pb->pb_off = 0; - pb->pb_size = sh.sh_size; - pb->pb_buf = d->d_buf; + pb->pb_size = roundup(sh.sh_size, poh.oh_filealign); + if ((pb->pb_buf = calloc(1, pb->pb_size)) == NULL) { + warn("calloc failed"); + continue; + } + memcpy(pb->pb_buf, d->d_buf, sh.sh_size); } elferr = elf_errno(); if (elferr != 0) Modified: head/lib/libelftc/elftc_version.c ============================================================================== --- head/lib/libelftc/elftc_version.c Wed May 25 20:50:05 2016 (r300697) +++ head/lib/libelftc/elftc_version.c Wed May 25 20:56:30 2016 (r300698) @@ -6,5 +6,5 @@ const char * elftc_version(void) { - return "elftoolchain r3475M"; + return "elftoolchain r3477M"; }