diff options
author | Kartik Agaram <vc@akkartik.com> | 2018-07-16 16:16:06 -0700 |
---|---|---|
committer | Kartik Agaram <vc@akkartik.com> | 2018-07-16 16:16:06 -0700 |
commit | bcf92ad220b8702c8af5cd6a8b66b7d8e467b1ba (patch) | |
tree | 54da6a8e95b061b246e5a3db7361f59d5998ead4 /subx | |
parent | ff46e6a5e1f53b711653004f3bef349941ce7114 (diff) | |
download | mu-bcf92ad220b8702c8af5cd6a8b66b7d8e467b1ba.tar.gz |
4358 - verify alignment of generated ELF binary
Diffstat (limited to 'subx')
-rw-r--r-- | subx/020elf.cc | 1 | ||||
-rw-r--r-- | subx/021translate.cc | 6 |
2 files changed, 6 insertions, 1 deletions
diff --git a/subx/020elf.cc b/subx/020elf.cc index e61212b1..7121f933 100644 --- a/subx/020elf.cc +++ b/subx/020elf.cc @@ -137,7 +137,6 @@ ostream& operator<<(unused ostream& os, unused die) { #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> -#include <unistd.h> #include <stdarg.h> #include <errno.h> diff --git a/subx/021translate.cc b/subx/021translate.cc index 94cebc04..636ce607 100644 --- a/subx/021translate.cc +++ b/subx/021translate.cc @@ -21,6 +21,7 @@ if (is_equal(argv[1], "translate")) { transform(p); if (trace_contains_errors()) return 1; dump_elf(p, argv[3]); + if (trace_contains_errors()) unlink(argv[3]); } :(code) @@ -106,6 +107,11 @@ void dump_elf_header(ostream& out, const program& p) { uint32_t p_align = 0x1000; emit(p_align); + if (p_offset % p_align != p.segments.at(i).start % p_align) { + raise << "segment starting at 0x" << HEXWORD << p.segments.at(i).start << " is improperly aligned; alignment for p_offset " << p_offset << " should be " << (p_offset % p_align) << " but is " << (p.segments.at(i).start % p_align) << '\n' << end(); + return; + } + // prepare for next segment p_offset += size; } |