summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2019-07-28 20:23:18 -0700
committerH. Peter Anvin <hpa@zytor.com>2019-07-28 20:23:18 -0700
commit059695c799d4080a9ca8112c79712e93667f9229 (patch)
tree6dbf7483422adb2df51378dfa9ac198e4f305335
parentcea7355743f1fd8f4fa77a766311ffa6634bfcc9 (diff)
downloadsamples-059695c799d4080a9ca8112c79712e93667f9229.tar.gz
samples-059695c799d4080a9ca8112c79712e93667f9229.tar.xz
samples-059695c799d4080a9ca8112c79712e93667f9229.zip
elf2exe: fix computation of bssmem
-rw-r--r--elf2exe/elf2exe.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/elf2exe/elf2exe.c b/elf2exe/elf2exe.c
index e7808d2..985a37d 100644
--- a/elf2exe/elf2exe.c
+++ b/elf2exe/elf2exe.c
@@ -302,7 +302,7 @@ static int process_file(const char *infile, const char *outfile)
size_t nrelocs;
uint32_t *exerelocs = NULL;
struct mzhdr *mzhdr;
- size_t hdrsize, filesize, bssmem;
+ size_t hdrsize, filesize, datasize, bssmem;
in = map_file(infile, READ_FILE);
if (!in) {
@@ -362,10 +362,14 @@ static int process_file(const char *infile, const char *outfile)
* if it turns out to be necessary... just in case.
*/
filesize = (hdrsize + di.e2e_filesize + 15) & ~15;
- if (di.e2e_memsize < filesize)
- bssmem = 0;
- else
- bssmem = di.e2e_memsize - filesize;
+
+ /*
+ * This is how much loaded data is actually present in the file;
+ * this may be larger than e2e_filesize/e2e_memsize due to padding
+ * or added stubs.
+ */
+ datasize = filesize - hdrsize;
+ bssmem = (di.e2e_memsize < datasize) ? 0 : di.e2e_memsize - datasize;
/* Open output file */
out = map_file(outfile, filesize);