summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2019-07-29 00:55:17 -0700
committerH. Peter Anvin <hpa@zytor.com>2019-07-29 00:55:17 -0700
commitff315b229c216788e4220a8a90134b3a391d9c78 (patch)
treec6cfe7cb05b3d9d2094fa05b8839e7224ff558d2
parent05fb0f23df26a1630294273188f740c3e064bf49 (diff)
downloadsamples-ff315b229c216788e4220a8a90134b3a391d9c78.tar.gz
samples-ff315b229c216788e4220a8a90134b3a391d9c78.tar.xz
samples-ff315b229c216788e4220a8a90134b3a391d9c78.zip
Fix the computation optional memory requested
-rw-r--r--elf2exe/elf2exe.c7
-rw-r--r--exe.ld5
2 files changed, 8 insertions, 4 deletions
diff --git a/elf2exe/elf2exe.c b/elf2exe/elf2exe.c
index 358836a..efa37c9 100644
--- a/elf2exe/elf2exe.c
+++ b/elf2exe/elf2exe.c
@@ -321,7 +321,7 @@ static int process_file(const char *infile, const char *outfile)
Elf32_Half e_machine;
struct dyninfo di;
struct mzhdr *mzhdr;
- size_t hdrsize, filesize, datasize, bssmem;
+ size_t hdrsize, filesize, datasize, bssmem, reqmem;
struct exe_relocs er[3];
size_t i;
@@ -409,6 +409,9 @@ static int process_file(const char *infile, const char *outfile)
*/
datasize = filesize - hdrsize;
bssmem = (di.e2e_memsize < datasize) ? 0 : di.e2e_memsize - datasize;
+ reqmem = di.e2e_optmem + bssmem;
+ if (reqmem > 0xffff0)
+ reqmem = 0xffff0; /* Can't ask for more than this... */
/* Open output file */
out = map_file(outfile, filesize);
@@ -423,7 +426,7 @@ static int process_file(const char *infile, const char *outfile)
putle(&mzhdr->nrelocs, er[0].nrelocs);
putle(&mzhdr->hdrparas, hdrsize >> 4);
putle(&mzhdr->bssparas, (bssmem + 15) >> 4);
- putle(&mzhdr->maxparas, (bssmem + di.e2e_optmem + 15) >> 4);
+ putle(&mzhdr->maxparas, (reqmem + 15) >> 4);
putle(&mzhdr->ss, di.e2e_stkseg >> 4);
putle(&mzhdr->sp, di.e2e_stkbase + di.e2e_stksize - di.e2e_stkseg);
putle(&mzhdr->ip, getle(eh->e_entry) - di.e2e_entseg);
diff --git a/exe.ld b/exe.ld
index 085c5b9..90e76da 100644
--- a/exe.ld
+++ b/exe.ld
@@ -89,9 +89,10 @@ SECTIONS
* Optional memory section. Allocations requested here are
* not necessarily satisfied; the program needs to verify.
*/
- _OPTIONAL ALIGN(16) : {
+ _OPTIONAL : {
*(SORT_BY_NAME(SORT_BY_ALIGNMENT(*_OPTIONAL*)))
}
+ HIDDEN(___.optend = .);
/*
* Anything beyond this point is used by elf2exe and are not
@@ -127,7 +128,7 @@ SECTIONS
LONG(0x6bb31706); LONG(___stack_size);
/* Requested additional memory */
- LONG(0x6bb31707); LONG(SIZEOF(_OPTIONAL));
+ LONG(0x6bb31707); LONG(___.optend - ___.end);
KEEP(*(.dynamic))