From 46e445017ec8cccd0e99c92488c553f6e611a3d5 Mon Sep 17 00:00:00 2001 From: Joshua Warner Date: Tue, 9 Dec 2014 14:53:12 -0700 Subject: [PATCH] make sure binary-to-object doesn't generate empty objects for invalid format/architecture combinations --- src/tools/binary-to-object/main.cpp | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/tools/binary-to-object/main.cpp b/src/tools/binary-to-object/main.cpp index 1636d46dfd..ed984b12f5 100644 --- a/src/tools/binary-to-object/main.cpp +++ b/src/tools/binary-to-object/main.cpp @@ -50,20 +50,11 @@ bool writeObject(uint8_t* data, OutputStream* out, const char* startName, const char* endName, - const char* format, - const char* architecture, + Platform* platform, unsigned alignment, bool writable, bool executable) { - Platform* platform = Platform::getPlatform( - PlatformInfo(PlatformInfo::formatFromString(format), - PlatformInfo::archFromString(architecture))); - - if (!platform) { - fprintf(stderr, "unsupported platform: %s/%s\n", format, architecture); - return false; - } SymbolInfo symbols[] = {SymbolInfo(0, startName), SymbolInfo(size, endName)}; @@ -113,6 +104,19 @@ int main(int argc, const char** argv) } } + const char* format = argv[5]; + const char* architecture = argv[6]; + + Platform* platform = Platform::getPlatform( + PlatformInfo(PlatformInfo::formatFromString(format), + PlatformInfo::archFromString(architecture))); + + if (!platform) { + fprintf(stderr, "unsupported platform: %s/%s\n", format, architecture); + return 1; + } + + uint8_t* data = 0; unsigned size; int fd = open(argv[1], O_RDONLY); @@ -148,8 +152,7 @@ int main(int argc, const char** argv) &out, argv[3], argv[4], - argv[5], - argv[6], + platform, alignment, writable, executable);