aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEd Maste <emaste@FreeBSD.org>2016-05-25 20:49:19 +0000
committerEd Maste <emaste@FreeBSD.org>2016-05-25 20:49:19 +0000
commite2f022b8a2b496795155ba6b175f4c677c91be35 (patch)
tree640acc6fffe677e5ac7ca32870b1301be3f4df8b
parenta7f03fcfe7109df232200b8b5e1f715a18ba7d74 (diff)
downloadsrc-e2f022b8a2b496795155ba6b175f4c677c91be35.tar.gz
src-e2f022b8a2b496795155ba6b175f4c677c91be35.zip
Import ELF Tool Chain snapshot at revision 3477vendor/elftoolchain/elftoolchain-r3477
Notes
Notes: svn path=/vendor/elftoolchain/dist/; revision=300696 svn path=/vendor/elftoolchain/elftoolchain-r3477/; revision=300697; tag=vendor/elftoolchain/elftoolchain-r3477
-rw-r--r--elfcopy/pe.c20
1 files changed, 9 insertions, 11 deletions
diff --git a/elfcopy/pe.c b/elfcopy/pe.c
index 0d075c5c93c2..586b21a74095 100644
--- a/elfcopy/pe.c
+++ b/elfcopy/pe.c
@@ -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, int ofd)
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, int ofd)
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, int ofd)
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, int ofd)
}
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)