From ded8781f7aa9e2eed96a898c817f03e3de075319 Mon Sep 17 00:00:00 2001
From: jdh8d <jdh8d@git.zephyr-software.com>
Date: Thu, 21 Aug 2014 19:17:48 +0000
Subject: [PATCH] Lots of updates to compile on solaris.  some of these changes
 were for non-gnu portabliity, others for just building with CC vrs g++.

Former-commit-id: 7eefd712cbe60859d242fdce1e9b24daebabc7f8
---
 build.sh                               |  5 ++-
 include/i686/config.h                  | 22 ++++++-----
 libIRDB/Makefile                       |  8 +++-
 libIRDB/include/core/variantid.hpp     |  5 ++-
 libIRDB/src/cfg/Makefile               |  2 +-
 libIRDB/src/core/Makefile              |  2 +-
 libIRDB/src/core/fileir.cpp            |  7 +++-
 libIRDB/test/Makefile                  | 14 ++++---
 libIRDB/test/calc_conflicts.cpp        |  3 ++
 libIRDB/test/fill_in_cfg.cpp           |  3 +-
 libIRDB/test/fill_in_indtargs.cpp      |  2 +-
 libIRDB/test/find_strings.cpp          | 18 +++++----
 libIRDB/test/read_ehframe.cpp          |  8 ++--
 libMEDSannotation/Makefile             |  6 ++-
 libMEDSannotation/src/Makefile         |  2 +-
 libtransform/src/Makefile              |  2 +-
 libtransform/src/integertransform.cpp  | 53 +++++++++++++++++++-------
 libtransform/src/transform.cpp         | 33 +++++++++++++---
 tools/cover/Makefile                   |  5 +--
 tools/cover/coverage.cpp               | 14 ++++---
 tools/meds2pdb/Makefile                |  5 +--
 tools/memcover/Makefile                | 10 ++---
 tools/spasm/Makefile                   |  8 ++--
 tools/transforms/General_Utility.cpp   | 14 +++----
 tools/transforms/General_Utility.hpp   |  2 +-
 tools/transforms/Makefile              | 12 +++---
 tools/transforms/OffsetInference.cpp   | 11 +++---
 tools/transforms/PNIrdbManager.hpp     |  4 +-
 tools/transforms/PNTransformDriver.cpp | 47 +++++++++++++++++------
 tools/transforms/nulltransform.cpp     |  6 +++
 xform/Makefile                         |  2 +-
 xform/elfreader.cpp                    |  5 +++
 xform/null_transform.cpp               |  7 ++++
 xform/rewriter.cpp                     | 12 +++++-
 xform/rewriter.h                       |  4 ++
 35 files changed, 247 insertions(+), 116 deletions(-)

diff --git a/build.sh b/build.sh
index 00d62e817..457cd72eb 100755
--- a/build.sh
+++ b/build.sh
@@ -1,4 +1,7 @@
-#!/bin/sh
+#!/bin/bash
+
+export CC="cc -I/opt/csw/include -L /opt/csw/lib/"
+export CXX="CC -I/opt/csw/include -L /opt/csw/lib/"
 
 #sanity check
 if [ $SECURITY_TRANSFORMS_HOME"X" = "X" ]; then
diff --git a/include/i686/config.h b/include/i686/config.h
index 220142079..294979ee8 100644
--- a/include/i686/config.h
+++ b/include/i686/config.h
@@ -58,17 +58,19 @@ typedef s_uint64_t 	   counter_t;
 #define NULL 0
 #endif
 
+namespace std {
 #include <elf.h>
-
-typedef Elf32_Ehdr  IRDB_Elf_Ehdr;
-typedef Elf32_Shdr  IRDB_Elf_Shdr;
-typedef Elf32_Off   IRDB_Elf_Off;
-typedef Elf32_Half  IRDB_Elf_Half;
-typedef Elf32_Word  IRDB_Elf_Word;
-typedef Elf32_Addr  IRDB_Elf_Addr;
-typedef Elf32_Sym  IRDB_Elf_Sym;
-typedef Elf32_Rel  IRDB_Elf_Rel;
-typedef Elf32_Rela  IRDB_Elf_Rela;
+}
+
+typedef std::Elf32_Ehdr  IRDB_Elf_Ehdr;
+typedef std::Elf32_Shdr  IRDB_Elf_Shdr;
+typedef std::Elf32_Off   IRDB_Elf_Off;
+typedef std::Elf32_Half  IRDB_Elf_Half;
+typedef std::Elf32_Word  IRDB_Elf_Word;
+typedef std::Elf32_Addr  IRDB_Elf_Addr;
+typedef std::Elf32_Sym  IRDB_Elf_Sym;
+typedef std::Elf32_Rel  IRDB_Elf_Rel;
+typedef std::Elf32_Rela  IRDB_Elf_Rela;
 #define IRDB_ELF_ST_TYPE ELF32_ST_TYPE
 
 
diff --git a/libIRDB/Makefile b/libIRDB/Makefile
index 88b2807c8..35d2b89b4 100644
--- a/libIRDB/Makefile
+++ b/libIRDB/Makefile
@@ -1,8 +1,12 @@
 
+CC="cc -I/opt/csw/include"
+CXX="CC -I/opt/csw/include"
+
 all:
-	cd src;make
+	cd src;make CC=$(CC) CXX=$(CXX)
 	./install_libs.sh
-	cd test;make 
+	cd test;make CC=$(CC) CXX=$(CXX)
+
 
 clean:
 	cd src;make clean
diff --git a/libIRDB/include/core/variantid.hpp b/libIRDB/include/core/variantid.hpp
index 1117855b2..fa75931e8 100644
--- a/libIRDB/include/core/variantid.hpp
+++ b/libIRDB/include/core/variantid.hpp
@@ -1,6 +1,10 @@
 
 #define CURRENT_SCHEMA 2
 
+class VariantID_t;
+
+std::ostream& operator<<(std::ostream& out, const libIRDB::VariantID_t& pid);
+
 class VariantID_t : public BaseObj_t
 {
     public:
@@ -52,4 +56,3 @@ class VariantID_t : public BaseObj_t
 
 };
 
-std::ostream& operator<<(std::ostream& out, const VariantID_t& pid);
diff --git a/libIRDB/src/cfg/Makefile b/libIRDB/src/cfg/Makefile
index 6058b7ec3..e411ee347 100644
--- a/libIRDB/src/cfg/Makefile
+++ b/libIRDB/src/cfg/Makefile
@@ -11,5 +11,5 @@ clean:
 	rm -f $(OBJS)
 
 .cpp.o:
-	g++ -g -c -I. -I../../include -I../../../beaengine/include $<
+	$(CXX) -g -c -I. -I../../include -I../../../beaengine/include $<
 	ar rc $(LIB) $@
diff --git a/libIRDB/src/core/Makefile b/libIRDB/src/core/Makefile
index f9a80e8d7..a8939e924 100644
--- a/libIRDB/src/core/Makefile
+++ b/libIRDB/src/core/Makefile
@@ -12,5 +12,5 @@ clean:
 	rm -f $(OBJS)
 
 .cpp.o:
-	g++ -g -c -I. -I../../include -I../../../beaengine/include $<
+	$(CXX) -g -c -I. -I../../include -I../../../beaengine/include $<
 	ar rc $(LIB) $@
diff --git a/libIRDB/src/core/fileir.cpp b/libIRDB/src/core/fileir.cpp
index bae0778d1..65a50cafd 100644
--- a/libIRDB/src/core/fileir.cpp
+++ b/libIRDB/src/core/fileir.cpp
@@ -5,6 +5,9 @@
 #include <map>
 #include <fstream>
 #include <elf.h>
+#include <stdlib.h>
+#include <sys/wait.h>
+
 using namespace libIRDB;
 using namespace std;
 
@@ -506,8 +509,8 @@ void FileIR_t::WriteToDB()
 		}
 
 		string r="";
-		std::set<Relocation_t*> relocs = (*i)->GetRelocations();
-		for(set<Relocation_t*>::iterator it=relocs.begin(); it!=relocs.end(); ++it)
+		std::set<Relocation_t*> irelocs = (*i)->GetRelocations();
+		for(set<Relocation_t*>::iterator it=irelocs.begin(); it!=irelocs.end(); ++it)
 		{
 			Relocation_t* reloc=*it;
 			r+=reloc->WriteToDB(fileptr,*i);
diff --git a/libIRDB/test/Makefile b/libIRDB/test/Makefile
index 303e622b3..92d5ca265 100644
--- a/libIRDB/test/Makefile
+++ b/libIRDB/test/Makefile
@@ -7,7 +7,11 @@ OPT=-g
 
 PROGS=print_variant.exe list_programs.exe create_variant.exe create_variantir.exe read_variantir.exe clone.exe ilr.exe \
 	drop_variant.exe generate_spri.exe fill_in_cfg.exe fix_calls.exe fill_in_indtargs.exe unfix_calls.exe \
-	calc_conflicts.exe find_strings.exe
+	find_strings.exe
+
+
+#	calc_conflicts.exe   -- doesn't build on solaris and isn't necessary for anything.
+
 
 all: $(PROGS)
 
@@ -15,18 +19,18 @@ $(PROGS): ../../lib/*
 
 
 fill_in_indtargs.exe: read_ehframe.o fill_in_indtargs.o check_thunks.o
-	g++ fill_in_indtargs.o read_ehframe.o check_thunks.o  $(INCLUDES) $(LIBS) $(OPT) -o $@
+	$(CXX) fill_in_indtargs.o read_ehframe.o check_thunks.o  $(INCLUDES) $(LIBS) $(OPT) -o $@
 
 
 .o.exe:  $< ../lib/libIRDB-core.a ../lib/libIRDB-cfg.a
-	g++ $< $(INCLUDES) $(LIBS) $(OPT)  -o $@
+	$(CXX) $< $(INCLUDES) $(LIBS) $(OPT)  -o $@
 
 .cpp.o:  $< 
-	g++ $< $(INCLUDES) $(LIBS) $(OPT) -o $@ -c
+	$(CXX) $< $(INCLUDES) $(LIBS) $(OPT) -o $@ -c
 
 # shouldn't be needed anymore
 #read_ehframe.o: read_ehframe.cpp
-#	g++ -w -fpermissive $(INCLUDES) $(LIBS)  $(OPT) $^ -o $@ -c
+#	$(CXX) -w -fpermissive $(INCLUDES) $(LIBS)  $(OPT) $^ -o $@ -c
 
 clean:
 	rm -f $(PROGS) *.o
diff --git a/libIRDB/test/calc_conflicts.cpp b/libIRDB/test/calc_conflicts.cpp
index 0f597f34e..63dcf0a18 100644
--- a/libIRDB/test/calc_conflicts.cpp
+++ b/libIRDB/test/calc_conflicts.cpp
@@ -10,6 +10,9 @@
 #include <sys/mman.h>
 #include <ctype.h>
 #include "targ-config.h"
+#include "elfio/elfio.hpp"
+#include "elfio/elfio_dump.hpp"
+
 
 
 #include "beaengine/BeaEngine.h"
diff --git a/libIRDB/test/fill_in_cfg.cpp b/libIRDB/test/fill_in_cfg.cpp
index 96ed98360..1c72f1674 100644
--- a/libIRDB/test/fill_in_cfg.cpp
+++ b/libIRDB/test/fill_in_cfg.cpp
@@ -9,10 +9,11 @@
 #include <sys/mman.h>
 #include <ctype.h>
 
+#include "targ-config.h"
+
 #include "elfio/elfio.hpp"
 #include "elfio/elfio_dump.hpp"
 
-#include "targ-config.h"
 
 
 #include "beaengine/BeaEngine.h"
diff --git a/libIRDB/test/fill_in_indtargs.cpp b/libIRDB/test/fill_in_indtargs.cpp
index 73878ceae..45e12dfb8 100644
--- a/libIRDB/test/fill_in_indtargs.cpp
+++ b/libIRDB/test/fill_in_indtargs.cpp
@@ -10,9 +10,9 @@
 // #include <elf.h>
 #include <ctype.h>
 
+#include "targ-config.h"
 #include "elfio/elfio.hpp"
 #include "elfio/elfio_dump.hpp"
-#include "targ-config.h"
 #include "beaengine/BeaEngine.h"
 #include "check_thunks.hpp"
 
diff --git a/libIRDB/test/find_strings.cpp b/libIRDB/test/find_strings.cpp
index 5b58de045..9c4dad39d 100644
--- a/libIRDB/test/find_strings.cpp
+++ b/libIRDB/test/find_strings.cpp
@@ -6,11 +6,13 @@
 #include <stdlib.h>
 #include <cctype>
 #include <assert.h>
+#include <stdlib.h>
+
 
+#include "targ-config.h"
 #include "elfio/elfio.hpp"
 #include "elfio/elfio_dump.hpp"
 
-#include "targ-config.h"
 
 
 using namespace libIRDB;
@@ -38,7 +40,7 @@ typedef struct elf_info {
 
 void found_string(string s, void* addr)
 {
-	char buff[s.length()+2];
+	char *buff=(char*)malloc(s.length()+2);
 	char *old_p=buff, *p;
 	// use .data() instead of c_str(); can find multiple C-strings in one string
 	memcpy(buff,s.data(),s.length());
@@ -402,27 +404,27 @@ void find_strings_in_data(FileIR_t* firp, elf_info_t& ei)
 		{
 		case SHT_REL:
 			if(arch_ptr_bytes()==4)
-				step = sizeof(::Elf32_Rel);
+				step = sizeof(std::Elf32_Rel);
 			else
-				step = sizeof(::Elf64_Rel);
+				step = sizeof(std::Elf64_Rel);
 			break;
 		case SHT_RELA:
 			if(arch_ptr_bytes()==4)
-				step = sizeof(::Elf32_Rela);
+				step = sizeof(std::Elf32_Rela);
 			else
-				step = sizeof(::Elf64_Rela);
+				step = sizeof(std::Elf64_Rela);
 			break;
 		case SHT_SYMTAB:
 		case SHT_DYNSYM:
 			if(arch_ptr_bytes()==4)
 			{
 				offset = sizeof(::Elf32_Word);
-				step = sizeof(::Elf32_Sym);
+				step = sizeof(std::Elf32_Sym);
 			}
 			else
 			{
 				offset = sizeof(::Elf64_Word);
-				step = sizeof(::Elf64_Sym);
+				step = sizeof(std::Elf64_Sym);
 			}
 			break;
 		default:
diff --git a/libIRDB/test/read_ehframe.cpp b/libIRDB/test/read_ehframe.cpp
index 73b5324f3..fc9cb0b45 100644
--- a/libIRDB/test/read_ehframe.cpp
+++ b/libIRDB/test/read_ehframe.cpp
@@ -9,9 +9,9 @@
 #include <assert.h>
 #include <string.h>
 
+#include "targ-config.h"
 #include "elfio/elfio.hpp"
 #include "elfio/elfio_dump.hpp"
-#include "targ-config.h"
 
 using namespace libIRDB;
 using namespace std;
@@ -82,7 +82,7 @@ struct dwarf_cie
   uword length;
   sword CIE_id;
   ubyte version;
-  unsigned char augmentation[];
+  unsigned char augmentation[1];
 } __attribute__ ((packed, aligned (__alignof__ (void *))));
 
 
@@ -91,7 +91,7 @@ struct dwarf_fde
 {
   uword length;
   sword CIE_delta;
-  unsigned char pc_begin[];
+  unsigned char pc_begin[1];
 } __attribute__ ((packed, aligned (__alignof__ (void *))));
 
 
@@ -99,7 +99,7 @@ struct fde_vector
 {
   void *orig_data;
   size_t count;
-  struct dwarf_fde *array[];
+  struct dwarf_fde *array[1];
 };
 
 struct object
diff --git a/libMEDSannotation/Makefile b/libMEDSannotation/Makefile
index 8eeb9bea0..3efff213e 100644
--- a/libMEDSannotation/Makefile
+++ b/libMEDSannotation/Makefile
@@ -1,5 +1,9 @@
+
+CC="cc -I/opt/csw/include"
+CXX="CC -I/opt/csw/include"
+
 all:
-	cd src; make
+	cd src;make CC=$(CC) CXX=$(CXX)
 
 clean:
 	cd src; make clean
diff --git a/libMEDSannotation/src/Makefile b/libMEDSannotation/src/Makefile
index bfeb0b826..0202d40fc 100644
--- a/libMEDSannotation/src/Makefile
+++ b/libMEDSannotation/src/Makefile
@@ -11,6 +11,6 @@ clean:
 	rm -f $(OBJS)
 
 .cpp.o:
-	g++ -g -c -I. -I../include $<
+	$(CXX) -g -c -I. -I../include $<
 	ar rc $(LIB) $@
 	cp $(LIB) ../../lib
diff --git a/libtransform/src/Makefile b/libtransform/src/Makefile
index 42a516afd..43464bf65 100644
--- a/libtransform/src/Makefile
+++ b/libtransform/src/Makefile
@@ -10,6 +10,6 @@ clean:
 	rm -f $(OBJS)
 
 .cpp.o:
-	g++ -g -c -I. -I../include -I../../libIRDB/include -I../../libMEDSannotation/include -I../../beaengine/include $<
+	$(CXX) -g -c -I. -I../include -I../../libIRDB/include -I../../libMEDSannotation/include -I../../beaengine/include $<
 	ar rc $(LIB) $@
 	cp $(LIB) ../../lib/
diff --git a/libtransform/src/integertransform.cpp b/libtransform/src/integertransform.cpp
index 4328f4a9c..6e1ab44d9 100644
--- a/libtransform/src/integertransform.cpp
+++ b/libtransform/src/integertransform.cpp
@@ -2,6 +2,31 @@
 #include "integertransform.hpp"
 #include "leapattern.hpp"
 
+
+/*
+ * Find the first occurrence of find in s, ignore case.
+ */
+static char *
+my_strcasestr(const char* s, char *find)
+{
+        char c, sc;
+        size_t len;
+
+        if ((c = *find++) != 0) {
+                c = tolower((unsigned char)c);
+                len = strlen(find);
+                do {
+                        do {
+                                if ((sc = *s++) == 0)
+                                        return (NULL);
+                        } while ((char)tolower((unsigned char)sc) != c);
+                } while (strncasecmp(s, find, len) != 0);
+                s--;
+        }
+        return ((char *)s);
+}
+
+
 // 
 // For list of blacklisted functions, see: isBlacklisted()
 //
@@ -2065,23 +2090,23 @@ bool IntegerTransform::isBlacklisted(Function_t *func)
 	if (!func) return false;
 
 	const char *funcName = func->GetName().c_str();
-	if (/*strcasestr(funcName, "hash") ||
-		strcasestr(funcName, "compress") ||
-		strcasestr(funcName, "encode") ||
-		strcasestr(funcName, "decode") ||
-		strcasestr(funcName, "crypt") ||
+	if (/*my_strcasestr(funcName, "hash") ||
+		my_strcasestr(funcName, "compress") ||
+		my_strcasestr(funcName, "encode") ||
+		my_strcasestr(funcName, "decode") ||
+		my_strcasestr(funcName, "crypt") ||
 		*/
 		//          haystack, needle
-		strcasestr(funcName, "yyparse") ||
-		strcasestr(funcName, "yyerror") ||
-		strcasestr(funcName, "yydestruct") ||
-		strcasestr(funcName, "yyrestart") ||
-		strcasestr(funcName, "yylex") ||
-		strcasestr(funcName, "yy_")
+		my_strcasestr(funcName, "yyparse") ||
+		my_strcasestr(funcName, "yyerror") ||
+		my_strcasestr(funcName, "yydestruct") ||
+		my_strcasestr(funcName, "yyrestart") ||
+		my_strcasestr(funcName, "yylex") ||
+		my_strcasestr(funcName, "yy_")
 		/* ||
-		strcasestr(funcName, "sub_17810") ||
-		strcasestr(funcName, "process_active_connection") 
-		strcasestr(funcName, "random")
+		my_strcasestr(funcName, "sub_17810") ||
+		my_strcasestr(funcName, "process_active_connection") 
+		my_strcasestr(funcName, "random")
 		*/
 		)
 	{
diff --git a/libtransform/src/transform.cpp b/libtransform/src/transform.cpp
index f00cda0de..da724652e 100644
--- a/libtransform/src/transform.cpp
+++ b/libtransform/src/transform.cpp
@@ -1,5 +1,28 @@
 #include "transform.hpp"
 
+/*
+ * Find the first occurrence of find in s, ignore case.
+ */
+static char *
+my_strcasestr(const char* s, char *find)
+{
+	char c, sc;
+	size_t len;
+
+	if ((c = *find++) != 0) {
+		c = tolower((unsigned char)c);
+		len = strlen(find);
+		do {
+			do {
+				if ((sc = *s++) == 0)
+					return (NULL);
+			} while ((char)tolower((unsigned char)sc) != c);
+		} while (strncasecmp(s, find, len) != 0);
+		s--;
+	}
+	return ((char *)s);
+}
+
 #define OPTIMIZE_ASSEMBLY
 
 using namespace libTransform;
@@ -467,14 +490,14 @@ bool Transform::isMultiplyInstruction(Instruction_t *p_instruction)
 	std::string assembly = m_fileIR->LookupAssembly(p_instruction);
 	if (assembly.length() > 0)
 	{
-		return strcasestr(assembly.c_str(), "MUL") != NULL;
+		return my_strcasestr(assembly.c_str(), "MUL") != NULL;
 	}
 
 	DISASM disasm;
 	p_instruction->Disassemble(disasm);
 
 	// beaengine adds space at the end of the mnemonic string
-	return strcasestr(disasm.Instruction.Mnemonic, "MUL ") != NULL;
+	return my_strcasestr(disasm.Instruction.Mnemonic, "MUL ") != NULL;
 }
 
 //
@@ -490,13 +513,13 @@ bool Transform::isAddSubNonEspInstruction(Instruction_t *p_instruction)
 	p_instruction->Disassemble(disasm);
 
 	// beaengine adds space at the end of the mnemonic string
-	if (strcasestr(disasm.Instruction.Mnemonic, "ADD "))
+	if (my_strcasestr(disasm.Instruction.Mnemonic, "ADD "))
 	{
 		return true;
 	}
-	else if (strcasestr(disasm.Instruction.Mnemonic, "SUB ")) 
+	else if (my_strcasestr(disasm.Instruction.Mnemonic, "SUB ")) 
 	{
-		if (strcasestr(disasm.Argument1.ArgMnemonic,"esp") &&
+		if (my_strcasestr(disasm.Argument1.ArgMnemonic,"esp") &&
 			(disasm.Argument2.ArgType & 0xFFFF0000 & (CONSTANT_TYPE | ABSOLUTE_)))
 		{
 			// optimization: filter out "sub esp, K"
diff --git a/tools/cover/Makefile b/tools/cover/Makefile
index 794d5866f..ed824c84c 100644
--- a/tools/cover/Makefile
+++ b/tools/cover/Makefile
@@ -15,7 +15,6 @@
 #
 
 
-CC=g++
 CFLAGS= -g
 INCLUDE=-I. -I../../include -I../../xform -I../../beaengine/include -I../../libIRDB/include/
 LIBS=-L../../lib -L../../xform -lxform -lIRDB-core -lBeaEngine_s_d -lpqxx 
@@ -24,7 +23,7 @@ OBJS=coverage.o
 .SUFFIXES: .o .c .cpp
 
 .cpp.o .c.o:
-	$(CC) $(CFLAGS) $(INCLUDE) -c $<
+	$(CXX) $(CFLAGS) $(INCLUDE) -c $<
 
 
 all: cover 
@@ -34,5 +33,5 @@ clean:
 	rm -f *.o core cover
 
 cover: $(OBJS) cover.cpp ../../lib/*
-	$(CC) $(CFLAGS) -o cover $(INCLUDE) cover.cpp $(OBJS) $(LIBS)
+	$(CXX) $(CFLAGS) -o cover $(INCLUDE) cover.cpp $(OBJS) $(LIBS)
 
diff --git a/tools/cover/coverage.cpp b/tools/cover/coverage.cpp
index d11ceba55..31981e5a2 100644
--- a/tools/cover/coverage.cpp
+++ b/tools/cover/coverage.cpp
@@ -5,6 +5,8 @@
 #include <limits.h>
 #include <string>
 #include <fstream>
+#include <libgen.h>
+
 
 using namespace std;
 using namespace libIRDB;
@@ -20,7 +22,7 @@ void trim(string& str)
   else str.erase(str.begin(), str.end());
 }
 
-enum STR2NUM_ERROR { SUCCESS, OVERFLOW, UNDERFLOW, INCONVERTIBLE };
+enum STR2NUM_ERROR { STR2_SUCCESS, STR2_OVERFLOW, STR2_UNDERFLOW, STR2_INCONVERTIBLE };
 
 //TODO: what if the string represents a negative number? Currently
 //the number will be translated into an unsigned int. I could make this
@@ -32,14 +34,14 @@ STR2NUM_ERROR str2uint (unsigned int &i, char const *s, int base=0)
 	errno = 0;
 	l = strtoul(s, &end, base);
 	if ((errno == ERANGE && l == ULONG_MAX) || l > UINT_MAX) {
-		return OVERFLOW;
+		return STR2_OVERFLOW;
 	}
 	if (*s == '\0' || *end != '\0') {
-		return INCONVERTIBLE;
+		return STR2_INCONVERTIBLE;
 	}
 	i = l;
 
-	return SUCCESS;
+	return STR2_SUCCESS;
 }
 
 
@@ -80,7 +82,7 @@ void coverage::parse_coverage_file(ifstream &coverage_file)
 
 		
 		unsigned int uint_addr;
-		assert(str2uint(uint_addr,addr.c_str())==SUCCESS);
+		assert(str2uint(uint_addr,addr.c_str())==STR2_SUCCESS);
 
 		coverage_map[file].coverage[uint_addr]=uint_addr;
 	}
@@ -97,7 +99,7 @@ file_coverage* coverage::find_file_coverage(string url)
 		//the shared objects are registered, but this might cause
 		//issues if shared objects have the same name. 
 
-		key=string(basename(key.c_str()));
+		key=string(basename((char*)key.c_str()));
 
 		if(key.empty())
 			continue;
diff --git a/tools/meds2pdb/Makefile b/tools/meds2pdb/Makefile
index 9638d39d5..832fd0b6e 100644
--- a/tools/meds2pdb/Makefile
+++ b/tools/meds2pdb/Makefile
@@ -15,7 +15,6 @@
 #
 
 
-CC=g++
 CFLAGS= -g
 INCLUDE=-I. -I../../include -I../../xform -I../../beaengine/include
 LIBS=-L../../lib -lxform -lBeaEngine_s_d -lpq -lpqxx
@@ -23,7 +22,7 @@ LIBS=-L../../lib -lxform -lBeaEngine_s_d -lpq -lpqxx
 .SUFFIXES: .o .c .cpp
 
 .cpp.o .c.o:
-	$(CC) $(CFLAGS) $(INCLUDE) -c $<
+	$(CXX) $(CFLAGS) $(INCLUDE) -c $<
 
 
 all: meds2pdb  
@@ -33,5 +32,5 @@ clean:
 	rm -f *.o core meds2pdb
 
 meds2pdb: $(OBJS) meds2pdb.cpp ../../lib/*.a
-	$(CC) $(CFLAGS) -o meds2pdb $(INCLUDE) meds2pdb.cpp $(OBJS) $(LIBS)
+	$(CXX) $(CFLAGS) -o meds2pdb $(INCLUDE) meds2pdb.cpp $(OBJS) $(LIBS)
 
diff --git a/tools/memcover/Makefile b/tools/memcover/Makefile
index bdce8147b..2786ca172 100644
--- a/tools/memcover/Makefile
+++ b/tools/memcover/Makefile
@@ -17,8 +17,8 @@
 
 PROGS=memcover.exe
 
-CC=g++
-CFLAGS= -g -O3 -Wall
+CFLAGS= -g 
+# -O3 -Wall
 INCLUDE=-I. -I../../include -I../../xform -I../../beaengine/include -I../../libIRDB/include/ -I../../libMEDSannotation/include/ -I../../libtransform/include/
 LIBS=-L../../lib -L../../xform -lxform -lELFIO -L../../libIRDB/lib/ -lIRDB-core -lIRDB-cfg -L../../beaengine/lib/Linux.gnu.Debug -lBeaEngine_s_d -lpqxx  -L../../libMEDSannotation/lib -lMEDSannotation -L../../libtransform/lib -ltransform
 OBJS=transformutils.o
@@ -29,14 +29,14 @@ all: memcover $(OBJS) $(PROGS)
 	echo memcover build complete
 
 .o: $<
-	$(CC) -g -c $@
+	$(CXX) -g -c $@
 
 .cpp.exe:  $<
-	$(CC) -g $< $(INCLUDE) $(LIBS) $(OBJS) -o $@
+	$(CXX) -g $< $(INCLUDE) $(LIBS) $(OBJS) -o $@
 
 clean:
 	rm -f *.o core $(PROGS)
 
 
 memcover: 
-	$(CC) $(CFLAGS) memcover.cpp General_Utility.cpp Rewrite_Utility.cpp $(INCLUDE) $(LIBS) -o memcover.exe
+	$(CXX) $(CFLAGS) memcover.cpp General_Utility.cpp Rewrite_Utility.cpp $(INCLUDE) $(LIBS) -o memcover.exe
diff --git a/tools/spasm/Makefile b/tools/spasm/Makefile
index 32ecc91d6..5a1115c4f 100644
--- a/tools/spasm/Makefile
+++ b/tools/spasm/Makefile
@@ -16,14 +16,14 @@
 #
 #
 
-CC=g++
-CFLAGS= -Wall -g# -DUBUNTU -Wall -O3
+CFLAGS=  -g 
+# -DUBUNTU -Wall -O3
 
 INCLUDE=-I. -I../../include -I../../xform 
 LIBS=-L../../xform -lxform 
 
 .cpp.o .c.o:
-	$(CC) $(CFLAGS) $(INCLUDE) -c $<
+	$(CXX) $(CFLAGS) $(INCLUDE) -c $<
 
 all: spasm
 	echo spasm build complete
@@ -32,4 +32,4 @@ clean:
 	rm -f *.o core spasm *.map *.bspri *.asm *.bin
 
 spasm: $(OBJS) spasm.cpp Makefile spasm.h spasm_main.cpp ben_lib.cpp ben_lib.h ../../xform/libxform.a 
-	$(CC) -o spasm $(INCLUDE) $(CFLAGS) spasm_main.cpp  spasm.cpp ben_lib.cpp $(OBJS) $(LIBS)
+	$(CXX) -o spasm $(INCLUDE) $(CFLAGS) spasm_main.cpp  spasm.cpp ben_lib.cpp $(OBJS) $(LIBS)
diff --git a/tools/transforms/General_Utility.cpp b/tools/transforms/General_Utility.cpp
index 70b27ed4b..e2eb56658 100644
--- a/tools/transforms/General_Utility.cpp
+++ b/tools/transforms/General_Utility.cpp
@@ -12,16 +12,16 @@ STR2NUM_ERROR str2int (int &i, char const *s, int base)
 	errno = 0;
 	l = strtol(s, &end, base);
 	if ((errno == ERANGE && l == LONG_MAX) || l > INT_MAX) {
-		return OVERFLOW;
+		return STR2_OVERFLOW;
 	}
 	if ((errno == ERANGE && l == LONG_MIN) || l < INT_MIN) {
-		return UNDERFLOW;
+		return STR2_UNDERFLOW;
 	}
 	if (*s == '\0' || *end != '\0') {
-		return INCONVERTIBLE;
+		return STR2_INCONVERTIBLE;
 	}
 	i = l;
-	return SUCCESS;
+	return STR2_SUCCESS;
 }
 
 //TODO: what if the string represents a negative number? Currently
@@ -34,11 +34,11 @@ STR2NUM_ERROR str2uint (unsigned int &i, char const *s, int base)
 	errno = 0;
 	l = strtoul(s, &end, base);
 	if ((errno == ERANGE && l == ULONG_MAX) || l > UINT_MAX) {
-		return OVERFLOW;
+		return STR2_OVERFLOW;
 	}
 	if (*s == '\0' || *end != '\0') {
-		return INCONVERTIBLE;
+		return STR2_INCONVERTIBLE;
 	}
 	i = l;
-	return SUCCESS;
+	return STR2_SUCCESS;
 }
diff --git a/tools/transforms/General_Utility.hpp b/tools/transforms/General_Utility.hpp
index a40ffb985..437ebf75b 100644
--- a/tools/transforms/General_Utility.hpp
+++ b/tools/transforms/General_Utility.hpp
@@ -1,7 +1,7 @@
 #ifndef _GENERAL_UTILITY
 #define _GENERAL_UTILITY
 
-enum STR2NUM_ERROR { SUCCESS, OVERFLOW, UNDERFLOW, INCONVERTIBLE };
+enum STR2NUM_ERROR { STR2_SUCCESS, STR2_OVERFLOW, STR2_UNDERFLOW, STR2_INCONVERTIBLE };
 STR2NUM_ERROR str2int (int &i, char const *s, int base = 0);
 STR2NUM_ERROR str2uint (unsigned int &i, char const *s, int base = 0);
 
diff --git a/tools/transforms/Makefile b/tools/transforms/Makefile
index e5b38f5ae..9c02ee78a 100644
--- a/tools/transforms/Makefile
+++ b/tools/transforms/Makefile
@@ -17,10 +17,10 @@
 
 PROGS=p1transform.exe nulltransform.exe integertransformdriver.exe
 
-CC=g++
-CFLAGS= -g -Wall
+CFLAGS= -g 
+# -Wall
 INCLUDE=-I. -I../../include -I../../xform -I../../beaengine/include -I../../libIRDB/include/ -I../../libMEDSannotation/include/ -I../../libtransform/include/
-LIBS=-L../../lib -lxform -lIRDB-core -lIRDB-cfg -lBeaEngine_s_d -lpqxx  -lMEDSannotation -ltransform
+LIBS=-L../../lib -lxform -lIRDB-core -lIRDB-cfg -lBeaEngine_s_d -L /opt/csw/lib/ -lpqxx  -lMEDSannotation -ltransform
 
 OBJS=transformutils.o
 
@@ -36,17 +36,17 @@ all: p1transform.exe pntransform.exe $(OBJS) $(PROGS)
 $(all_objs): *hpp
 
 .cpp.o: PNStackLayoutInference.hpp  *.hpp
-	$(CC) $(INCLUDE) $(CFLAGS)  -g -c $< 
+	$(CXX) $(INCLUDE) $(CFLAGS)  -g -c $< 
 
 .cpp.exe:   
-	$(CC) -g $< $(INCLUDE) $(LIBS) $(OBJS) -o $@
+	$(CXX) -g $< $(INCLUDE) $(LIBS) $(OBJS) -o $@
 
 clean:
 	rm -f *.o core $(PROGS)
 
 
 pntransform.exe:  $(all_objs) ../../lib/*.a 
-	$(CC) $(CFLAGS) $(all_objs) $(INCLUDE) $(LIBS) -o pntransform.exe
+	$(CXX) $(CFLAGS) $(all_objs) $(INCLUDE) $(LIBS) -o pntransform.exe
 
 
 p1transform.exe:  pntransform.exe
diff --git a/tools/transforms/OffsetInference.cpp b/tools/transforms/OffsetInference.cpp
index 220d44376..347cfc2d4 100644
--- a/tools/transforms/OffsetInference.cpp
+++ b/tools/transforms/OffsetInference.cpp
@@ -100,7 +100,7 @@ StackLayout* OffsetInference::SetupLayout(Function_t *func)
 	//	 bool has_frame_pointer = false;
 
 	int max = PNRegularExpressions::MAX_MATCHES;
-	regmatch_t pmatch[max];
+	regmatch_t *pmatch=(regmatch_t*)malloc(max*sizeof(pmatch));
 	memset(pmatch, 0,sizeof(regmatch_t) * max);	 
 
 	assert(out_args_size >=0);
@@ -219,7 +219,7 @@ StackLayout* OffsetInference::SetupLayout(Function_t *func)
 						//find the indirect branch target instruction, and reset entry to this instruction, then continue execution of the loop. 
 
 						int target_addr_offset;
-						assert(str2int(target_addr_offset, matched.c_str())==SUCCESS);
+						assert(str2int(target_addr_offset, matched.c_str())==STR2_SUCCESS);
 
 						//TODO: it is better to make a map of ind branch targets, but this efficient enough for now. 
 						
@@ -281,7 +281,7 @@ StackLayout* OffsetInference::SetupLayout(Function_t *func)
 				matched = disasm_str.substr(pmatch[1].rm_so,mlen);
 				//extract K 
 				//stack_frame_size = strtol(matched.c_str(),NULL,0);
-				if(str2uint(stack_frame_size, matched.c_str())!= SUCCESS)
+				if(str2uint(stack_frame_size, matched.c_str())!= STR2_SUCCESS)
 				{
 					//If this occurs, then the found stack size is not a 
 					//constant integer, so it must be a register. 
@@ -337,7 +337,8 @@ void OffsetInference::FindAllOffsets(Function_t *func)
 	//int out_args_size;
 
 	int max = PNRegularExpressions::MAX_MATCHES;
-	regmatch_t pmatch[max];
+	//regmatch_t pmatch[max];
+	regmatch_t *pmatch=(regmatch_t*)malloc(max*sizeof(pmatch));
 	memset(pmatch, 0,sizeof(regmatch_t) * max);	 
 	unsigned int stack_frame_size = 0;
 	unsigned int saved_regs_size = 0;
@@ -538,7 +539,7 @@ else
 			matched = disasm_str.substr(pmatch[1].rm_so,mlen);
 			//extract K 
 			unsigned int scheck;
-			if(str2uint(scheck, matched.c_str()) != SUCCESS)
+			if(str2uint(scheck, matched.c_str()) != STR2_SUCCESS)
 			{
 				//If this occurs, then the found stack size is not a 
 				//constant integer, so it must be a register.
diff --git a/tools/transforms/PNIrdbManager.hpp b/tools/transforms/PNIrdbManager.hpp
index 34b494866..66cd5dda5 100644
--- a/tools/transforms/PNIrdbManager.hpp
+++ b/tools/transforms/PNIrdbManager.hpp
@@ -9,8 +9,8 @@ class PNIrdbManager
 public:
 
     enum IRSource {
-        PEASOUP,
-        DWARF,
+        IRS_PEASOUP,
+        IRS_DWARF
     };
 
     PNIrdbManager(libIRDB::db_id_t variant_db_id);
diff --git a/tools/transforms/PNTransformDriver.cpp b/tools/transforms/PNTransformDriver.cpp
index 80b297fe6..e3844c906 100644
--- a/tools/transforms/PNTransformDriver.cpp
+++ b/tools/transforms/PNTransformDriver.cpp
@@ -10,9 +10,30 @@
 #include "globals.h"
 #include <libIRDB-cfg.hpp>
 
+#include <fcntl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <libgen.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+
+
 using namespace std;
 using namespace libIRDB;
 
+char* get_current_dir_name(void) 
+{
+  char* pwd = getenv("PWD");
+  char tmp[PATH_MAX];
+  struct stat a,b;
+  if (pwd && !stat(".",&a) && !stat(pwd,&b) &&
+      a.st_dev==b.st_dev && a.st_ino==b.st_ino)
+    return strdup(pwd);
+  if (getcwd(tmp,sizeof(tmp)))
+    return strdup(tmp);
+  return 0;
+}
+
 //TODO: this var is a hack for TNE
 extern map<Function_t*, set<Instruction_t*> > inserted_instr;
 extern map<Function_t*, set<AddressID_t*> > inserted_addr;
@@ -600,7 +621,7 @@ ELFIO::dump::section_headers(cout,*elfiop);
 				//TODO: basename is only used as a hack
 				//because of the way the url is stored in the db.
 				//The url should be fixed to be the absolute path. 
-				key=string(basename(key.c_str()));
+				key=string(basename((char*)key.c_str()));
 
 				if(key.empty())
 					continue;
@@ -755,12 +776,12 @@ bool	check_for_push_pop_coherence(Function_t *func)
 	// stack first.  Also handy as this allows "fixed" calls to be ignored.
 	// but, since exits with 0 pops aren't in the map, we don't need an explicit check for them.
 	for(
-		map<Instruction_t*,int>::const_iterator it=pop_count_per_exit.begin();
+		map<Instruction_t* ,int>::iterator it=pop_count_per_exit.begin();
 		it!=pop_count_per_exit.end();
 		++it
 	   )
 	{
-		pair<Instruction_t*,int> map_pair=*it;
+		pair<Instruction_t*const,int> map_pair=*it;
 		Instruction_t* insn=map_pair.first;
 		assert(insn);
 		DISASM d;
@@ -1200,7 +1221,7 @@ void PNTransformDriver::GenerateTransformsHidden(map<string,double> &file_covera
 	cerr<<"Functions to shuffle validate: "<<shuffle_validate_funcs.size()<<endl;
 	ShuffleValidation(shuffle_validate_funcs);
 
-	if(!Validate(NULL,string(basename(orig_virp->GetFile()->GetURL().c_str()))+"_accum"))
+	if(!Validate(NULL,string(basename((char*)orig_virp->GetFile()->GetURL().c_str()))+"_accum"))
 	{
 		cerr<<"TEST ERROR: File: "<<orig_virp->GetFile()->GetURL()<<" does not pass accumulation validation, ignoring the file for now."<<endl;
 
@@ -1871,7 +1892,7 @@ bool PNTransformDriver::Canary_Rewrite(PNStackLayout *orig_layout, Function_t *f
 	
 	//bool stack_alloc = false;
 	int max = PNRegularExpressions::MAX_MATCHES;
-	regmatch_t pmatch[max];
+	regmatch_t *pmatch=(regmatch_t*)malloc(max*sizeof(regmatch_t));
 	memset(pmatch, 0,sizeof(regmatch_t) * max);
 
 	for(
@@ -1908,7 +1929,7 @@ bool PNTransformDriver::Canary_Rewrite(PNStackLayout *orig_layout, Function_t *f
 				matched = disasm_str.substr(pmatch[1].rm_so,mlen);
 				//extract K 
 				unsigned int ssize;
-				if(str2uint(ssize, matched.c_str()) != SUCCESS)
+				if(str2uint(ssize, matched.c_str()) != STR2_SUCCESS)
 				{
 					//If this occurs, then the found stack size is not a 
 					//constant integer, so it must be a register. 
@@ -2097,7 +2118,8 @@ int PNTransformDriver::prologue_offset_to_actual_offset(ControlFlowGraph_t* cfg,
 			return offset;
 	
 		int max = PNRegularExpressions::MAX_MATCHES;
-		regmatch_t pmatch[max];
+		//regmatch_t pmatch[max];
+		regmatch_t *pmatch=(regmatch_t*)malloc(max*sizeof(regmatch_t));
 
 		/* check for a stack alloc */
                 if(regexec(&(pn_regex->regex_stack_alloc), d.CompleteInstr, 5, pmatch, 0)==0)
@@ -2110,7 +2132,7 @@ int PNTransformDriver::prologue_offset_to_actual_offset(ControlFlowGraph_t* cfg,
                                 matched = disasm_str.substr(pmatch[1].rm_so,mlen);
                                 //extract K
                                 unsigned int ssize;
-                                if(str2uint(ssize, matched.c_str()) != SUCCESS)
+                                if(str2uint(ssize, matched.c_str()) != STR2_SUCCESS)
                                 {
 					return offset;
                                 }
@@ -2149,7 +2171,8 @@ inline bool PNTransformDriver::Instruction_Rewrite(PNStackLayout *layout, Instru
 		esp_reg="rsp";
 
 	int max = PNRegularExpressions::MAX_MATCHES;
-	regmatch_t pmatch[max];
+	//regmatch_t pmatch[max];
+	regmatch_t *pmatch=(regmatch_t*)malloc(max*sizeof(regmatch_t));
 	memset(pmatch, 0,sizeof(regmatch_t) * max);
 
 	string matched="";
@@ -2197,7 +2220,7 @@ inline bool PNTransformDriver::Instruction_Rewrite(PNStackLayout *layout, Instru
 			matched = disasm_str.substr(pmatch[1].rm_so,mlen);
 			//extract K 
 			unsigned int ssize;
-			if(str2uint(ssize, matched.c_str()) != SUCCESS)
+			if(str2uint(ssize, matched.c_str()) != STR2_SUCCESS)
 			{
 				//If this occurs, then the found stack size is not a 
 				//constant integer, so it must be a register. 
@@ -2684,7 +2707,7 @@ bool PNTransformDriver::WriteStackIRToDB()
     }
     else
     {
-        irdb_manager.DeleteSource(PNIrdbManager::PEASOUP);
+        irdb_manager.DeleteSource(PNIrdbManager::IRS_PEASOUP);
     }
 
     std::map< std::string,std::vector<PNStackLayout*> >::const_iterator it =
@@ -2704,7 +2727,7 @@ bool PNTransformDriver::WriteStackIRToDB()
                     layouts[laynum]->GetFunctionName(),
                     mem_objects[j]->GetOffset(),
                     mem_objects[j]->GetSize(),
-                    PNIrdbManager::PEASOUP);
+                    PNIrdbManager::IRS_PEASOUP);
 
                 // DEBUG
                 cerr<< "\tOffset = " << mem_objects[j]->GetOffset() << " Size = "<<mem_objects[j]->GetSize() << endl;
diff --git a/tools/transforms/nulltransform.cpp b/tools/transforms/nulltransform.cpp
index 06026a4ef..4ede4869b 100644
--- a/tools/transforms/nulltransform.cpp
+++ b/tools/transforms/nulltransform.cpp
@@ -1,6 +1,12 @@
 #include <iostream>
+#include "targ-config.h"
+
+#include "elfio/elfio.hpp"
+#include "elfio/elfio_dump.hpp"
+
 #include "null_transform.h"
 
+
 int main(int argc, char **argv)
 {
   if (argc < 3)
diff --git a/xform/Makefile b/xform/Makefile
index b5185c621..1f5261645 100644
--- a/xform/Makefile
+++ b/xform/Makefile
@@ -13,7 +13,7 @@
 # MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 #
 
-CC=g++
+CC=$(CXX)
 CFLAGS= -DUBUNTU -g
 DIR=..
 INCLUDEDIR=${DIR}/include
diff --git a/xform/elfreader.cpp b/xform/elfreader.cpp
index 686da4a71..c2e2ccd18 100644
--- a/xform/elfreader.cpp
+++ b/xform/elfreader.cpp
@@ -1,5 +1,10 @@
 #include <iostream>
 #include <string.h>
+#include "targ-config.h"
+
+#include "elfio/elfio.hpp"
+#include "elfio/elfio_dump.hpp"
+
 #include "elfreader.h"
 
 using namespace std;
diff --git a/xform/null_transform.cpp b/xform/null_transform.cpp
index 5207b0b0b..49c8f2469 100644
--- a/xform/null_transform.cpp
+++ b/xform/null_transform.cpp
@@ -1,8 +1,15 @@
 #include <iostream>
 
+#include "targ-config.h"
+
+#include "elfio/elfio.hpp"
+#include "elfio/elfio_dump.hpp"
+
 #include "null_transform.h"
 #include "stackref_hash.h"
 
+
+
 using namespace wahoo;
 
 //
diff --git a/xform/rewriter.cpp b/xform/rewriter.cpp
index fcc486c74..b5cba15c0 100644
--- a/xform/rewriter.cpp
+++ b/xform/rewriter.cpp
@@ -3,10 +3,18 @@
 #include <set>
 #include <stdlib.h>
 
+
+
 #include "beaengine/BeaEngine.h"
 
-#include "rewriter.h"
 #include "all.h"
+#include "targ-config.h"
+#include "elfio/elfio.hpp"
+#include "elfio/elfio_dump.hpp"
+
+
+#include "rewriter.h"
+
 
 using namespace std;
 
@@ -629,7 +637,7 @@ void Rewriter::readXrefsFile(char p_filename[])
 void Rewriter::readElfFile(char p_filename[])
 {
 	char buf[1000];
-	sprintf(buf, "objdump -d --prefix-addresses %s | grep \"^[0-9]\"", p_filename);
+	sprintf(buf, "gobjdump -d --prefix-addresses %s | grep \"^[0-9]\"", p_filename);
 	FILE* pin=popen(buf, "r");
 	int addr;
 
diff --git a/xform/rewriter.h b/xform/rewriter.h
index 9f8715f7c..d2726b6fb 100644
--- a/xform/rewriter.h
+++ b/xform/rewriter.h
@@ -1,4 +1,8 @@
 #include <map>
+#include "targ-config.h"
+#include "elfio/elfio.hpp"
+#include "elfio/elfio_dump.hpp"
+
 #include "elfreader.h"
 #include "function_descriptor.h"
 
-- 
GitLab