From 68ccf4d3245e78c869f25ffc5078f267eb22a9ee Mon Sep 17 00:00:00 2001 From: Kartik Agaram Date: Thu, 25 Jul 2019 17:15:20 -0700 Subject: 5478 - disallow programs without 'data' segments Now all known discrepancies between C++ and SubX translators are fixed. If a SubX program builds with C++, it should also build fine with just SubX. (If it doesn't build with C++, all bets are off. The self-hosted SubX translator has negligible error-detection or handling.) --- subx/028translate.cc | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'subx/028translate.cc') diff --git a/subx/028translate.cc b/subx/028translate.cc index 46f4f219..d3a6a8ac 100644 --- a/subx/028translate.cc +++ b/subx/028translate.cc @@ -80,10 +80,16 @@ void save_elf(const program& p, const string& filename) { } void save_elf(const program& p, ostream& out) { + // validation: stay consistent with the self-hosted translator if (p.entry == 0) { raise << "no 'Entry' label found\n" << end(); return; } + if (find(p, "data") == NULL) { + raise << "must include a 'data' segment\n" << end(); + return; + } + // processing write_elf_header(out, p); for (size_t i = 0; i < p.segments.size(); ++i) write_segment(p.segments.at(i), out); -- cgit 1.4.1-2-gfad0