Add --asm option to elf2e32, so that GCCE builds can use --asm=gas with --dump=a and get a usable .s file (Bug 1405)
authorMike Kinghan <mikek@symbian.org>
Mon, 21 Jun 2010 17:57:23 +0100
changeset 589 851206cea67b
parent 586 bfc226f3f18c
child 597 35d98d69ca78
Add --asm option to elf2e32, so that GCCE builds can use --asm=gas with --dump=a and get a usable .s file (Bug 1405)
e32tools/elf2e32/source/filedump.cpp
e32tools/elf2e32/source/filedump.h
e32tools/elf2e32/source/parameterlistinterface.h
e32tools/elf2e32/source/parametermanager.cpp
e32tools/elf2e32/source/parametermanager.h
--- a/e32tools/elf2e32/source/filedump.cpp	Fri Jun 18 12:51:41 2010 +0100
+++ b/e32tools/elf2e32/source/filedump.cpp	Mon Jun 21 17:57:23 2010 +0100
@@ -9,6 +9,7 @@
 // Nokia Corporation - initial contribution.
 //
 // Contributors:
+// Mike Kinghan, mikek@symbian.org, for Symbian Foundation, 2010 
 //
 // Description:
 // FileDump Operations of elf2e32 tool to dump E32Image and generate ASM File.
@@ -23,7 +24,9 @@
 #include "h_utl.h"
 #include "deffile.h"
 #include "errorhandler.h"
-#include <stdio.h>
+#include <cstdio>
+#include <cassert>
+
 /**
 Constructor for class FileDump
 @param aParameterListInterface - Instance of class ParameterListInterface
@@ -63,7 +66,7 @@
 		if(!iParameterListInterface->DefInput())
 			throw ParameterParserError(NOREQUIREDOPTIONERROR,"--definput");
 
-		GenerateAsmFile(iParameterListInterface->E32ImageOutput());
+		GenerateAsmFile();
 	}
 	else
 	{
@@ -71,7 +74,7 @@
 			throw ParameterParserError(NOREQUIREDOPTIONERROR,"--e32input");
 		if(iParameterListInterface->DumpOptions() & EDumpAsm )
 			throw InvalidArgumentError(INVALIDARGUMENTERROR,iParameterListInterface->FileDumpSubOptions() ,"--dump");
-		DumpE32Image(iParameterListInterface->E32Input());
+		DumpE32Image();
 	}
 	return 0;
 }
@@ -83,11 +86,34 @@
 @internalComponent
 @released
 */
-int FileDump::GenerateAsmFile(const char* afileName)//DumpAsm
+int FileDump::GenerateAsmFile() //DumpAsm
+{
+	EAsmDialect asmDialect = iParameterListInterface->AsmDialect();
+	switch(asmDialect)
+	{
+	case EGas:
+		return GenerateGasAsmFile();
+	case EArmas:
+		return GenerateArmasAsmFile();
+	default:
+		assert(false);
+	}
+	return 0;
+}
+
+/**
+Function to generate an RVCT armas ASM File.
+@param afileName - ASM File name
+@return 0 on success, otherwise throw error 
+@internalComponent
+@released
+*/
+int FileDump::GenerateArmasAsmFile()
 {
 	DefFile *iDefFile = new DefFile();
 	SymbolList *aSymList;
 	aSymList = iDefFile->ReadDefFile(iParameterListInterface->DefInput());
+	char const *afileName = iParameterListInterface->E32ImageOutput(); 
 
 	FILE *fptr;
 
@@ -155,14 +181,89 @@
 }
 
 /**
+Function to generate a GNU as ASM File.
+@param afileName - ASM File name
+@return 0 on success, otherwise throw error 
+@internalComponent
+@released
+*/
+int FileDump::GenerateGasAsmFile()
+{
+	DefFile *iDefFile = new DefFile();
+	SymbolList *aSymList;
+	aSymList = iDefFile->ReadDefFile(iParameterListInterface->DefInput());
+	char const *afileName = iParameterListInterface->E32ImageOutput(); 
+
+	FILE *fptr;
+
+	if((fptr=fopen(afileName,"w"))==NULL)
+	{
+		throw FileError(FILEOPENERROR,(char*)afileName);
+	}
+	else
+	{
+		SymbolList::iterator aItr = aSymList->begin();
+		SymbolList::iterator last = aSymList->end();
+		Symbol *aSym;
+
+		while( aItr != last)
+		{
+			aSym = *aItr;
+
+			if(aSym->Absent())
+			{
+				aItr++;
+				continue;
+			}
+
+			fputs("\t.extern ",fptr);
+			fputs(aSym->SymbolName(),fptr);
+			fputs("\n",fptr);
+			aItr++;
+		}
+
+        // Create a directive section that instructs the linker to make all listed
+        // symbols visible.
+
+        fputs("\t.text\n\n",fptr);
+
+        fputs("\t.ascii \"#<SYMEDIT>#\\n\"\n", fptr);
+
+		aItr = aSymList->begin();
+		while (aItr != last)
+		{
+			aSym = *aItr;
+
+			if ( aSym->Absent() )
+			{
+				aItr++;
+				continue;
+			}
+
+            // Example:
+            //  DCB "EXPORT __ARM_ll_mlass\n"
+			fputs("\t.ascii \"EXPORT ",fptr);
+			fputs(aSym->SymbolName(),fptr);
+			fputs("\\n\"\n", fptr);
+
+			aItr++;
+		}
+		fclose(fptr);
+	}
+	return 0;
+}
+
+
+/**
 Function to Dump E32 Image.
 @param afileName - E32 Image File name
 @return 1 on success, otherwise throw error 
 @internalComponent
 @released
 */
-int FileDump::DumpE32Image(const char* afileName)
+int FileDump::DumpE32Image()
 {
+	char const *afileName = iParameterListInterface->E32Input(); 
 	E32ImageFile *aE32Imagefile=new E32ImageFile();
 	TInt result = aE32Imagefile->Open(afileName);
 	
--- a/e32tools/elf2e32/source/filedump.h	Fri Jun 18 12:51:41 2010 +0100
+++ b/e32tools/elf2e32/source/filedump.h	Mon Jun 21 17:57:23 2010 +0100
@@ -9,6 +9,7 @@
 // Nokia Corporation - initial contribution.
 //
 // Contributors:
+// Mike Kinghan, mikek@symbian.org, for Symbian Foundation, 2010
 //
 // Description:
 // FileDump Class for elf2e32 tool
@@ -35,8 +36,10 @@
 		~FileDump();
 		int Execute();
 	private:
-		int DumpE32Image(const char * fileName);
-		int GenerateAsmFile(const char* afileName);//DumpAsm
+		int DumpE32Image();
+		int GenerateAsmFile();//DumpAsm
+		int GenerateArmasAsmFile();
+		int GenerateGasAsmFile();
 };
 
 #endif
--- a/e32tools/elf2e32/source/parameterlistinterface.h	Fri Jun 18 12:51:41 2010 +0100
+++ b/e32tools/elf2e32/source/parameterlistinterface.h	Mon Jun 21 17:57:23 2010 +0100
@@ -9,6 +9,7 @@
 // Nokia Corporation - initial contribution.
 //
 // Contributors:
+// Mike Kinghan, mikek@symbian.org, for Symbian Foundation, 2010
 //
 // Description:
 // Implementation of the Header file for the ParameterListInterface of the elf2e32 tool
@@ -43,6 +44,12 @@
 	EStdExe
 };
 
+enum EAsmDialect // Which dialect of arm assembly to write for the --dump option
+{
+	EArmas, // RVCT armas
+	EGas	// GNU as
+};
+
 typedef unsigned int UINT;
 
 using std::vector;
@@ -278,6 +285,7 @@
 	virtual bool SymNamedLookup() = 0;
 	virtual bool IsDebuggable() = 0;
 	virtual bool IsSmpSafe() = 0;
+	virtual EAsmDialect AsmDialect() = 0;
 };
 
 
--- a/e32tools/elf2e32/source/parametermanager.cpp	Fri Jun 18 12:51:41 2010 +0100
+++ b/e32tools/elf2e32/source/parametermanager.cpp	Mon Jun 21 17:57:23 2010 +0100
@@ -9,6 +9,7 @@
 // Nokia Corporation - initial contribution.
 //
 // Contributors:
+// Mike Kinghan, mikek@symbian.org, for Symbian Foundation, 2010
 //
 // Description:
 // Implementation of the Class ParameterManager for the elf2e32 tool
@@ -25,6 +26,7 @@
 #include "parametermanager.h"
 #include "errorhandler.h"
 #include <iostream>
+#include <cstdlib>
 
 #include "h_utl.h"
 #include "h_ver.h"
@@ -110,7 +112,8 @@
 	iCustomDllTarget(false),
 	iSymNamedLookup(false),
 	iDebuggable(false),
-	iSmpSafe(false)
+	iSmpSafe(false),
+	iAsmDialect(EArmas)
 {
 	iArgumentCount = aArgc;
 	ParamList temp(aArgv, aArgv+aArgc);
@@ -429,6 +432,12 @@
 		(void*)ParameterManager::ParseSmpSafe,
 		"SMP Safe",
 	},
+	{
+		"asm",
+		(void*)ParameterManager::ParseAsmDialect,
+		"Dialect of arm assembly to write for the --dump option. "
+		"Either \"gas\" (GNU as) or \"armas\" (RVCT as: default)",
+	},
 	{ 
 		"help", 
 		(void *)ParameterManager::ParamHelp,
@@ -647,7 +656,7 @@
 			parser(this, "help", 0, 0);
 		}
 
-		parser(this, const_cast<char*>(aName.c_str()), optval, aDesc);
+		parser(this, aName.c_str(), optval, aDesc);
 	}
 }
 
@@ -1508,6 +1517,21 @@
 }
 
 /**
+This function indicates the asm assembly dialect that will be written for the
+--dump option, as determined by the specified or default value of the --asm
+option.
+
+@internalComponent
+@released
+
+@return EArmas if --asm=armas was passed, else EGas
+*/
+EAsmDialect ParameterManager::AsmDialect()
+{
+	return iAsmDialect;
+}
+
+/**
 This function extracts the filename from the absolute path that is given as input.
 
 @internalComponent
@@ -2247,7 +2271,7 @@
 		{
 			int len = nq;
 			symbol = new char[len+1];
-			memcpy(symbol, p, len);
+			memcpy(symbol, &*p, len);
 			symbol[len] = 0;
 			q = nq+1;
 
@@ -2387,7 +2411,7 @@
 			if (*e == '-' || *e == '+') break;
 		}
 		if (e != b)
-			ParseCapability1(b, e, aCapabilities, invert);
+			ParseCapability1(&*b, &*e, aCapabilities, invert);
 
 		b = e;
 		
@@ -2846,6 +2870,23 @@
 	aPM->SetSmpSafe(true); 
 }
 
+DEFINE_PARAM_PARSER(ParameterManager::ParseAsmDialect)
+{
+	INITIALISE_PARAM_PARSER;
+	if (!strcmp(aValue,"gas"))
+	{
+		aPM->SetAsmDialect(EGas); 
+	}
+	else if (!strcmp(aValue,"armas"))
+	{
+		aPM->SetSmpSafe(EArmas); 
+	}
+	else
+	{
+		throw InvalidArgumentError(INVALIDARGUMENTERROR, aValue, "--asm");
+	} 
+}
+
 static const ParameterManager::TargetTypeDesc DefaultTargetTypes[] =
 {
 	{ "DLL", EDll },
@@ -3728,3 +3769,18 @@
 {
 	iSmpSafe = aVal;
 }
+
+/**
+This function sets iAsmDialect if --asm is passed in.
+
+@internalComponent
+@released
+
+@param aVal
+A member of enum EAsmDialect
+*/
+void ParameterManager::SetAsmDialect(EAsmDialect aAsmDialect)
+{
+	iAsmDialect = aAsmDialect;
+}
+
--- a/e32tools/elf2e32/source/parametermanager.h	Fri Jun 18 12:51:41 2010 +0100
+++ b/e32tools/elf2e32/source/parametermanager.h	Mon Jun 21 17:57:23 2010 +0100
@@ -9,6 +9,7 @@
 // Nokia Corporation - initial contribution.
 //
 // Contributors:
+// Mike Kinghan, mikek@symbian.org, for Symbian Foundation, 2010
 //
 // Description:
 // Implementation of the Header file for Class ParameterManager of the elf2e32 tool
@@ -81,7 +82,7 @@
 	typedef std::map<string, const OptionDesc *, OptionCompare> OptionMap;
 	typedef vector<char *> LibSearchPaths;
 
-	typedef void (*ParserFn)(ParameterManager *, char *, char *, const OptionDesc *);
+	typedef void (*ParserFn)(ParameterManager *, char const *, char const *, const OptionDesc *);
 
 
 	#define DECLARE_PARAM_PARSER(name) \
@@ -144,6 +145,7 @@
 	DECLARE_PARAM_PARSER(ParseSymNamedLookup);
 	DECLARE_PARAM_PARSER(ParseDebuggable);
 	DECLARE_PARAM_PARSER(ParseSmpSafe);
+	DECLARE_PARAM_PARSER(ParseAsmDialect);
 
 	ParameterManager(int aArgc, char** aArgv);
 	virtual ~ParameterManager();
@@ -195,6 +197,7 @@
 	void SetSymNamedLookup(bool aVal);
 	void SetDebuggable(bool aVal);
 	void SetSmpSafe(bool aVal);
+	void SetAsmDialect(EAsmDialect aAsmDialect);
 
 	int NumOptions();
 	int NumShortOptions();
@@ -279,6 +282,7 @@
 	bool SymNamedLookup();
 	bool IsDebuggable();
 	bool IsSmpSafe();
+	EAsmDialect AsmDialect();
 
 private:
 	/** The number of command line arguments passed into the program */
@@ -445,6 +449,7 @@
 	bool iSymNamedLookup;
 	bool iDebuggable;
 	bool iSmpSafe;
+	EAsmDialect iAsmDialect;
 };