From 9937072395cfa1b3caad8edafff915535215096e Mon Sep 17 00:00:00 2001 From: jdh8d <jdh8d@git.zephyr-software.com> Date: Tue, 3 Jul 2012 19:57:53 +0000 Subject: [PATCH] fixes for spasm with libstrata.so Former-commit-id: 90112870110ff883249b93c94c25bb2944db4643 --- tools/spasm/spasm.cpp | 17 +++++++++++++++-- tools/spasm/spasm_main.cpp | 32 ++++++++++++++++++++++++++++++-- 2 files changed, 45 insertions(+), 4 deletions(-) diff --git a/tools/spasm/spasm.cpp b/tools/spasm/spasm.cpp index e53430877..e440d9f64 100755 --- a/tools/spasm/spasm.cpp +++ b/tools/spasm/spasm.cpp @@ -51,18 +51,31 @@ static void resolveSymbols(const string &mapFile); static vector<bin_instruction_t> parseBin(const string &binFile); static vector<string> getSPRI(const vector<bin_instruction_t> &bin, const vector<spasmline_t> &spasmlines, const string &symbolFilename); static void printVector(const string &outputFile, const vector<string> &lines); +static int getSymbolAddress(const string &symbolFilename, const string &symbol) throw(exception); // // @todo: need to cache results // static string getCallbackAddress(const string &symbolFilename, const string &symbol) throw(exception) { + char buf[30]; + int diff=getSymbolAddress(symbolFilename, symbol) + - getSymbolAddress(symbolFilename, "strata_init"); + sprintf(buf,"%x", diff); + string s(buf); + return s; +} + + +static int getSymbolAddress(const string &symbolFilename, const string &symbol) throw(exception) +{ + string symbolFullName = symbolFilename + "+" + symbol; map<string,string>::iterator callbackMapIterator; if(callbackMap.find(symbolFullName) != callbackMap.end()) { - return callbackMap[symbolFullName]; + return strtol(callbackMap[symbolFullName].c_str(),NULL,16); } // nm -a stratafier.o.exe | egrep " integer_overflow_detector$" | cut -f1 -d' ' @@ -79,7 +92,7 @@ static string getCallbackAddress(const string &symbolFilename, const string &sym callbackMap[symbolFullName] = addressString; - return addressString; + return strtol(addressString.c_str(),NULL,16); } void a2bspri(const string &input, const string &output, const string &symbolFilename) throw(exception) diff --git a/tools/spasm/spasm_main.cpp b/tools/spasm/spasm_main.cpp index b8de81e41..5e17810e1 100644 --- a/tools/spasm/spasm_main.cpp +++ b/tools/spasm/spasm_main.cpp @@ -1,20 +1,48 @@ #include "spasm.h" #include <iostream> +#include <fstream> #include <string> #include <cstdlib> using namespace std; +bool fexists(string filename) +{ + ifstream ifile(filename.c_str()); + return ifile; +} + ///Utility SPASM's main int main(int argc, char *argv[]) { - if(argc != 4) + string input, output, elf; + + if(argc == 4) + { + elf = string(argv[3]); + if(!fexists(elf)) + { + cerr<<"Symbol file "<<elf<<" does not exist. SPASM will not be able to process callbacks properly."<<endl; + } + } + else if(argc == 5) + { + elf = string(argv[3]); + if(!fexists(elf)) + { + elf = string(argv[4]); + if(!fexists(elf)) + cerr<<"Symbol files ("<<argv[3] << " and " << argv[4] << + ") do not exist. SPASM will not be able to process callbacks properly."<<endl; + } + + } + else { cerr<<"SPASM Usage:\n<input file> <output file> <symbol file> \n"<<endl; exit(1); } - string input, output, elf; input = string(argv[1]); output = string(argv[2]); -- GitLab