hi,

i am writing a dynamic plugin,


however, sometimes it run succesfully and sometimes it give following error:

/home/avantika/Downloads/gcc/gccpackage/install/bin/g++ -o result -flto -fplugin=./plugin.so test1.o -O3 -fdump-ipa-all
In function ‘main’:
lto1: internal compiler error: in rebuild_frequencies, at predict.c:2396
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.
lto-wrapper: /home/avantika/Downloads/gcc/gccpackage/install/bin/g++ returned 1 exit status
/usr/bin/ld: lto-wrapper failed
collect2: error: ld returned 1 exit status
make: *** [test] Error 1


code : following are the name of files constraint.cpp, dataflow.cpp , constraint.hpp, dataflow.hpp;

the main file named pointo-callstring.c includes both the hpp files, and is defining some object and class map.

i have attached the files.
#include "constraint.hpp"

using namespace std;
	
namespace con{
// ============constraint=============

	constraint::constraint(int a, type b)
	{
	var=a;
	t=b;
	}

	constraint::constraint(constraint const &ob)
	{
	var=ob.var;
	t=ob.t;
	}

	int constraint::get_var()
	{
	return var;
	}

	type constraint::get_type()
	{
	return t;
	}

	bool operator<(constraint const &ob1, constraint const &ob2)
	{
	if(ob1.var < ob2.var) return true;
	if(ob1.t < ob2.t) return true;
	return false;
	}	
	
	
// ==============constraint_pair===========================

		
			
	constraint_pair::constraint_pair(constraint * a, constraint * b, bool is)
	{
	lhs=a;
	rhs=b;
	is_alias=is;
	livevar=-1;
	}
	
	constraint_pair::constraint_pair(int a, bool is)
	{
	livevar=a;
	is_alias=is;
	lhs=NULL;
	rhs=NULL;
	}
	
	constraint_pair::constraint_pair(constraint_pair const & ob)
	{
	livevar=ob.livevar;
	is_alias=ob.is_alias;
	lhs=ob.lhs;
	rhs=ob.rhs;	
	}
	
	constraint * constraint_pair::get_lhs()
	{
	return lhs;	
	}
	
	constraint * constraint_pair::get_rhs()
	{
	return rhs;	
	}
	
	bool constraint_pair::alias()
	{
	return is_alias;	
	}
	 
	int constraint_pair::get_livevar()
	{
	return livevar;	
	}
	
	int constraint_pair::lhs_var()
	{
	return lhs->var;	
	}
	
	int constraint_pair::rhs_var()
	{
	return rhs->var;	
	}
	
	type constraint_pair::lhs_type()
	{
	return lhs->t;	
	}
	
	type constraint_pair::rhs_type()
	{
	return rhs->t;	
	}
	
	bool operator<(constraint_pair const & ob1, constraint_pair const & ob2)
	{
	if(*(ob1.lhs)<*(ob2.lhs)) return true;
	if(*(ob1.rhs)<*(ob2.rhs)) return true;
	if(ob1.is_alias<ob2.is_alias) return true;
	if(ob1.livevar<ob2.livevar) return true;
	return false;
	}


// ================constraint_list============
	
	bool constraint_list::empty()
		{
		return my.empty();
		}
		
	void constraint_list::push(constraint_pair * a)
		{
		my.push_back(a);
		}
		
	constraint_pair * constraint_list::front()
		{
		return my.front();	
		}
	
	constraint_pair * constraint_list::back()
		{
		return my.back();	
		}
	
	it constraint_list::begin()
		{
		present = my.begin();
		return my.begin();
		}
		
	it constraint_list::end()
		{
		present = my.end();
		return my.end();
		}
	
}

/*int main()
{

con::constraint c(2,con::DEREF);
con::constraint d(3,con::SCALAR);
cout<<c.get_var();
map<con::constraint,con::constraint *> my;
my[c]= &c;
cout<<endl<<my.at(c)->get_var()<<endl;
con::constraint_pair s(&c,&d,1);
cout<<s.lhs_var();
}*/
#ifndef CONSTRAINT_H
#define	CONSTRAINT_H

#include<map>
#include<iostream>
#include<cstring>
#include<list>

using namespace std;

namespace con {

	typedef enum type{	
		SCALAR,DEREF,ADDOF,
		}type;

// =============constraint=================

	class constraint {
		
		int var;
		type t;
		
		public:

			constraint(int a, type b);
			constraint(constraint const &);
			int get_var();
			type get_type();
			void set_var(int a){var =a;}
			friend bool operator<(constraint const &, constraint const &);

			friend class constraint_pair;
			friend class constraint_list;

		};

// ===============constraint pair========================

	class constraint_pair {
		
		constraint *lhs;
		constraint *rhs;
		bool is_alias;
		int livevar;

		public:
			constraint_pair(constraint *, constraint *, bool);
			constraint_pair(int,bool);
			constraint_pair(constraint_pair const &);
			constraint * get_lhs();
			constraint * get_rhs();
			bool alias();
			int get_livevar();
			int lhs_var();
			int rhs_var();
			type lhs_type();
			type rhs_type();
			friend bool operator<(constraint const & , constraint const &);
			friend bool operator<(constraint_pair const &, constraint_pair const &);
			
		friend class constraint_list;
	};
	
	
	typedef list<constraint_pair *>::iterator it;
	
// ================constraint_list============
	
	class constraint_list{
	
		list<constraint_pair *> my;
		list<constraint_pair *>::iterator present;
	
			public:
				constraint_list() {}
				bool empty();
				void push(constraint_pair *);
				constraint_pair * front();
				constraint_pair * back();	
				it begin();
				it end();
	};
	
}

#endif
#ifndef DATAFLOW_H
#define DATAFLOW_H

#include<map>
#include<utility>
#include<iostream>

using namespace std;

namespace data{
	
//=======liveness============
	
	class liveness{
	
	string *live;
	
	public:
		liveness(int);
		string get_live();
		friend bool operator<(liveness const &, liveness const &);
		bool is_live(int);
		void make_live(int); 
		void kill_live(int); 
		
	};
	
//=======pointsto============

	/*typedef enum pointinfo {
		NOTPOINTS=0,POINTS=1,UNDEF=2,NOINFO=3
	}type;*/
	
	class pointsto{
		
		int lhs;
		int size;
		string *rhs;
		
		public:
			pointsto(int,int);
			int get_lhs();
			string get_rhs();
			bool is_must();
			bool is_may();
			bool is_noinfo();
			bool is_undef();
			void set(int);
			void unset(int);
			void set_undef();
			void set_noinfo();
			bool is_pointsto(int); // if this integer in pointsto set of lhs
			friend bool operator<(pointsto const &, pointsto const &);
			
			
	};

	
}

#endif

#include"dataflow.hpp"

using namespace std;

namespace data{
        
//=======liveness============

        liveness::liveness(int s)
        {
        live= new string(s,'0');
        }
        
        string  liveness::get_live()
        {
        return *live;   
        }
        
        bool operator<(liveness const & ob1, liveness const & ob2)
        {
         if(((*(ob1.live)).compare(*(ob2.live)))<0) return true;                
        return false;
        }
        
        bool liveness::is_live(int a)
        {
        if(((*live)[a])=='0') return false;
        return true;
        }
        
        void liveness::make_live(int a)
        {
        (*live)[a]='1'; 
        }
        
        void liveness::kill_live(int a)
        {
        (*live)[a]='0'; 
        }
                
                
//=======pointsto============

        pointsto::pointsto(int l,int s)
        {
        lhs=l;
        size=s;
        rhs = new string(s,'3');
        }
        
        int pointsto::get_lhs()
        {
        return lhs;
        }
        
        string  pointsto::get_rhs()
        {
        return *rhs;
        }
        
        bool pointsto::is_must()
        {
        if(!is_noinfo() && !is_undef())
                {
                if(!is_may()) return true;
                }
        return false;
        }
        
        bool pointsto::is_may()
        {
        if(!is_noinfo() && !is_undef())
                {
                int count=0;
                for(int i=0;i<size;i++)
                        {
                        if((*rhs)[i] == '1') count++;
                        if(count>1) return true;
                        }
                }
                return false;
        }
        
        bool pointsto::is_noinfo()
        {
        string n(size,'3');
        if((*rhs).compare(n)==0) return true;
        return false;  //compare returns 0 when equal
        }
        
        bool pointsto::is_undef()
        {
        string n(size,'2');
        if((*rhs).compare(n)==0) return true;
        return false;   
        }
        
        void pointsto::set(int a)
        {
        (*rhs)[a]='1';
        }
        
        void pointsto::unset(int a)
        {
        (*rhs)[a]='0';  
        }
        
        void pointsto::set_undef()
        {
        rhs= new string(size,'2');
        }
        
        void pointsto::set_noinfo()
        {
        rhs= new string(size,'3');      
        }
        
        bool pointsto::is_pointsto(int a)
        {
        return ((*rhs)[a]==1);  
        }
        
        bool operator<(pointsto const & ob1, pointsto const & ob2)
        {
        if(ob1.lhs < ob2.lhs) return true;
        if(ob1.size < ob2.size) return true;
        if(((*(ob1.rhs)).compare(*(ob2.rhs)))<0) return true;
        return false;
        }
        
}

int main()
{
data::liveness l(4);
cout<<(l.get_live())<<endl;
l.make_live(2);
cout<<(l.get_live());
cout<<l.is_live(2);
map<data::liveness,data::liveness *> my;
my[l]=&l;
}
#include "gcc-plugin.h"
#include "config.h"
#include "system.h"
#include "cgraph.h"
#include "coretypes.h"
#include "tm.h"
#include "tree.h"
#include "tree-flow.h"
#include "diagnostic.h"
#include "tree-pass.h"
#include "timevar.h"
#include "alloc-pool.h"
#include "params.h"
#include "ggc.h"
#include "vec.h"
#include "gimple-pretty-print.h"

#include"constraint.hpp"
#include"dataflow.hpp"

//#define alloc_mem ggc_alloc_cleared_atomic 
using namespace std;
/*-----------------------------------------------------------------------------
 *  Each plugin MUST define this global int to assert compatibility with GPL; 
 *  else the compiler throws a fatal error 
 *-----------------------------------------------------------------------------*/
int plugin_is_GPL_compatible;  
//using namespace std;

/* -----------------------------------------
   Return: true if we should execute IPA PTA.
   ----------------------------------------*/
/*static bool
gate_ipacs (void)
{
   return (flag_ipacs && !(errorcount || sorrycount));
}*/

/* -------------------------------
   The callstrings pointsto pass. 
   ------------------------------*/

static unsigned int
execute_ipacs (void)
{
con::constraint c(2,con::DEREF);
cout<<c.get_var();
map<con::constraint, con::constraint *> my;
my[c]= &c;
fprintf(dump_file,"\njhgiocsud==========\n");
//struct cgraph_node *cnode;
}

struct simple_ipa_opt_pass pass_ipacs =
{
  {
    SIMPLE_IPA_PASS,
    "lfcpa",                                /* name */
    NULL,	                            /* gate */
    execute_ipacs,		            /* execute */
    NULL,                                   /* sub */
    NULL,                                   /* next */
    0,                                      /* static_pass_number */
    TV_INTEGRATION,                         /* tv_id */
    0,                                      /* properties_required */
    0,                                      /* properties_provided */
    0,                                      /* properties_destroyed */
    0,                                      /* todo_flags_start */
    0                                       /* todo_flags_finish */
  }
};
struct register_pass_info pass_info = 
{
	&(pass_ipacs.pass),
	"pta",
	0,
	PASS_POS_INSERT_AFTER
};
int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
{
	register_callback(
		plugin_info->base_name,
		PLUGIN_PASS_MANAGER_SETUP,
		NULL,
		&pass_info);
	return 0;
}

#------ MAKE CHANGES TO BASE_DIR : Please put the path to base directory of 
your pristine gcc-4.7.2 build -----------#
BASE_DIR = /home/avantika/Downloads/gcc/gccpackage

INSTALL = $(BASE_DIR)/install
CC = $(INSTALL)/bin/g++
NEW_PATH = $(BASE_DIR)/gcc-4.7.2/gcc

#----- MAKE CHANGES TO OBJS : Add the name of your test file with extension .o 
(say test as test.o) --------#
#------------------------------- Multiple dependent files maybe also be added 
------------------------------#
OBJS = test1.o

GCCPLUGINS_DIR:= $(shell $(CC) -print-file-name=plugin)
INCLUDE= -I$(GCCPLUGINS_DIR)/include -I$(NEW_PATH)

FLAGS= -fPIC -O0 -flto -flto-partition=none


%.o : %.c
        $(CC) $(FLAGS) $(INCLUDE) -c $< 

%.o : %.cpp
        $(CC) $(FLAGS) $(INCLUDE) -c $< 

plugin.so: pointsto-callstrings.o constraint.o dataflow.o
        $(CC) $(INCLUDE) $(FLAGS) -shared $^ -o $@

test:  $(OBJS) plugin.so
        $(CC) -o result -flto  -fplugin=./plugin.so $(OBJS) -O3 -fdump-ipa-all 
#test:   plugin.so
#       $(CC) -c -flto -flto-partition=none -fplugin=./plugin.so 
function-pointer.c -O0 -fdump-ipa-all 

clean:
        \rm -f plugin.so *~ *.o a.out result* *.cpp.*


Reply via email to