This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: A pass that worked in gcc-4.6.2 fails in gcc-4.7.2


Hello,

Now I am trying to convert the same pass into a dynamic plugin. Since
I was having trouble doing so, I tried adding a simple dynamic plugin
which would just dump the cfg using gimple_dump_cfg. But even in this
simple plugin I faced the same problem, as explained below.

When I build my plugin using ../install/bin/g++ it would not give any
errors. But when I used gcc instead of g++, it gave the following
error during runtime :

cc1: error: cannot load plugin ./plugin.so
./plugin.so: undefined symbol: decl_assembler_name
make: *** [test] Error 1

However, this symbol decl_assembler_name (a function) and is not
present anywhere in my plugin. It is declared in tree.c so and is not
static, so I even tried including tree.h and declaring the function as
extern.

I don't know what else to do!!

Sudakshina




On Sat, Jan 26, 2013 at 1:16 AM, Sudakshina Das
<sudakshina1990@gmail.com> wrote:
>
> On Fri, Jan 25, 2013 at 9:27 PM, Richard Biener
> <richard.guenther@gmail.com> wrote:
> > On Fri, Jan 25, 2013 at 3:57 PM, Sudakshina Das
> > <sudakshina1990@gmail.com> wrote:
> >> On Fri, Jan 25, 2013 at 8:02 PM, Richard Biener
> >> <richard.guenther@gmail.com> wrote:
> >>> On Fri, Jan 25, 2013 at 3:05 PM, Sudakshina Das
> >>> <sudakshina1990@gmail.com> wrote:
> >>>> On Fri, Jan 25, 2013 at 9:46 AM, Sudakshina Das
> >>>> <sudakshina1990@gmail.com> wrote:
> >>>>>
> >>>>> On Thu, Jan 24, 2013 at 5:15 PM, Richard Biener
> >>>>> <richard.guenther@gmail.com> wrote:
> >>>>> >
> >>>>> > On Thu, Jan 24, 2013 at 7:06 AM, Sudakshina Das
> >>>>> > <sudakshina1990@gmail.com> wrote:
> >>>>> > > Dear all,
> >>>>> > >
> >>>>> > > I am currently updating a pass that was made for gcc-4.6.*, so
> >>>>> > > that it
> >>>>> > > works for gcc.4.7.2.
> >>>>> > >
> >>>>> > > In the pass for gcc-4.6.*, a code fragment from
> >>>>> > > tree-ssa-structalias.c
> >>>>> > > was picked up and used.
> >>>>> > > Given below is the fragment taken form create_function_info_for
> >>>>> > > () .
> >>>>> > > This fragment was used to create variable information for the
> >>>>> > > function
> >>>>> > > and it was picked up to perform a similar operation in the added
> >>>>> > > pass
> >>>>> > > as well.
> >>>>> > >
> >>>>> > > But in gcc-4.7.2 some changes are introduced in the fragment.
> >>>>> > > The code
> >>>>> > > given below shows the changes that have been introduced in
> >>>>> > > create_function_info_for () of tree-ssa-structalias.c in
> >>>>> > > gcc-4.7.2
> >>>>> > > along with the original code in the comments.
> >>>>> > >
> >>>>> > >   /* Add one representative for all further args.  */
> >>>>> > >   if (is_varargs)
> >>>>> > >     {
> >>>>> > >       varinfo_t argvi;
> >>>>> > >       const char *newname;
> >>>>> > >       char *tempname;
> >>>>> > >       tree decl;
> >>>>> > >
> >>>>> > >       asprintf (&tempname, "%s.varargs", name);
> >>>>> > >       newname = ggc_strdup (tempname);
> >>>>> > >       free (tempname);
> >>>>> > >
> >>>>> > >       /* We need sth that can be pointed to for va_start.  */
> >>>>> > >
> >>>>> > > /**************** CHANGED CODE in GCC-4.7.2 ***************/
> >>>>> > >       decl = build_fake_var_decl (ptr_type_node);
> >>>>> > >
> >>>>> > > /************ ORIGINAL CODE in GCC-4.6.2 *******************
> >>>>> > > /*      decl = create_tmp_var_raw (ptr_type_node, name);
> >>>>> > >         get_var_ann (decl);
> >>>>> > > */
> >>>>> > >
> >>>>> > >       argvi = new_var_info (decl, newname);
> >>>>> > >       argvi->offset = fi_parm_base + num_args;
> >>>>> > >       argvi->size = ~0;
> >>>>> > >       argvi->is_full_var = true;
> >>>>> > >       argvi->is_heap_var = true;
> >>>>> > >       argvi->fullsize = vi->fullsize;
> >>>>> > >       gcc_assert (prev_vi->offset < argvi->offset);
> >>>>> > >       prev_vi->next = argvi;
> >>>>> > >       prev_vi = argvi;
> >>>>> > >     }
> >>>>> > >
> >>>>> > >   return vi;
> >>>>> > >
> >>>>> > >
> >>>>> > > So I made the same changes in the pass where this fragment was
> >>>>> > > used.
> >>>>> > > But after making the changes the pass is now giving an "internal
> >>>>> > > compiler error" and a "segmentation fault" at runtime.
> >>>>> > >
> >>>>> > > After debugging I could narrow it down to the function
> >>>>> > > build_fake_var_decl() and to be specific at the memory
> >>>>> > > allocation
> >>>>> > > statement highlighted below.
> >>>>> > >
> >>>>> > >
> >>>>> > > tree
> >>>>> > > build_fake_var_decl (tree type)
> >>>>> > > {
> >>>>> > > /************************ My debugging showed that the control
> >>>>> > > came
> >>>>> > > here *********************/
> >>>>> > >   tree decl = (tree) XOBNEW (&fake_var_decl_obstack, struct
> >>>>> > > tree_var_decl);
> >>>>> > > /************************ But did not come here
> >>>>> > > **********************************************************/
> >>>>> > >   memset (decl, 0, sizeof (struct tree_var_decl));
> >>>>> > >   TREE_SET_CODE (decl, VAR_DECL);
> >>>>> > >   TREE_TYPE (decl) = type;
> >>>>> > >   DECL_UID (decl) = allocate_decl_uid ();
> >>>>> > >   SET_DECL_PT_UID (decl, -1);
> >>>>> > >   layout_decl (decl, 0);
> >>>>> > >   return decl;
> >>>>> > > }
> >>>>> > >
> >>>>> > > The builf_fake_var_decl() function is a gcc function defined in
> >>>>> > > tree-ssa-structalias.c. To be able to use it in my pass, I
> >>>>> > > removed the
> >>>>> > > keyword static in its definition.
> >>>>> > >
> >>>>> > > I cannot figure out what can possibly cause this error in the
> >>>>> > > XOBNEW function.
> >>>>> > >
> >>>>> > > Please help!!!
> >>>>> >
> >>>>> > Don't use build_fake_var_decl, use what 4.6 did,
> >>>>> > create_tmp_var_raw.
> >>>>> >
> >>>>> > Richard.
> >>>>> >
> >>>>> >
> >>>>>
> >>>>> But 4.6 used get_var_ann() also along with create_tmp_var_raw()
> >>>>> which
> >>>>> has been removed from 4.7.
> >>>>
> >>>>
> >>>> I would like to clarify my above statement by saying that 4.6 used 2
> >>>> functions [ie. create_tmp_var_raw() and get_var_ann()] whereas 4.7
> >>>> used only one function [build_fake_var_decl()] for the same purpose.
> >>>> Now in 4.7 get_var_ann() is unavailable. So is it safe to use only
> >>>> create_tmp_var_raw(). In other words, was get_var_ann() a redundant
> >>>> function in 4.6?
> >>>
> >>> The whole function is very special for tree-ssa-structalias.c.  I have
> >>> no idea
> >>> what your pass does, but unless it closely resembles
> >>> tree-ssa-structalias.c
> >>> and shares its internal data structures you shouldn't blindly copy
> >>> over what
> >>> tree-ssa-structalias.c does (well, at least not without understanding
> >>> what you
> >>> are doing).
> >>>
> >>> What do you think you are doing with the copy of that code?
> >>>
> >>> Richard.
> >>>
> >>>>
> >>>>>
> >>
> >>
> >> The copy of the above code is from function create_function_info_for()
> >> in tree-ssa-structalias.c which is used to create variables for a
> >> function in its tree. In the pass there is a similar function named
> >> cs_create_func_info_for() used for the same purpose, except it does
> >> not create variables for all the cases. In other words some portions
> >> from the original function is omitted. Also the data structure
> >> varinfo_t is modified a bit to suite the pass and renamed as
> >> csvarinfo_t. I have copied the function from my pass below,
> >> highlighting the difference from the original function using comments.
> >
> > Well, then you can literally copy the original function.  Just make sure
> > to also copy and initialize and free the obstack it uses.
> >
>
>
> Thank you!!!!! The initializing and freeing obstack was the problem.
> So with that and after removing a few more glitches the pass is now
> running!!!
>
>
> >> /* Creation function node for DECL, using NAME, and return the index
> >>    of the variable we've created for the function.  */
> >> static csvarinfo_t
> >> cs_create_func_info_for (tree decl, const char *name)
> >> {
> >>    csvarinfo_t vi, prev_vi;
> >>    tree arg;
> >>    unsigned int i;
> >>    bool is_varargs = false;
> >>    unsigned int num_args = count_num_arguments (decl, &is_varargs);
> >>
> >>    /* Create the variable info.  */
> >>    vi = cs_new_var_info (decl, name);
> >>    vi->offset = 0;
> >>    vi->size = 1;
> >>    vi->fullsize = num_args + 1;
> >>    vi->may_have_pointers = false;
> >>    if (is_varargs)
> >>        vi->fullsize = ~0;
> >>    cs_insert_vi_for_tree (vi->decl, vi);
> >>
> >>    prev_vi = vi
> >>
> >>   /************ There were portions in original code with the
> >> following comments: **************
> >>
> >>        1. Create a variable for things the function clobbers and one
> >> for things the function uses.
> >>
> >>        2. And one for the static chain.
> >>
> >>        3. Create a variable for the return var.
> >>
> >>
> >> *******************************************************************************************************/
> >>
> >>    /* Set up variables for each argument.  */
> >>    arg = DECL_ARGUMENTS (decl);
> >>    for (i = 1; i < num_args + 1; i++) {
> >>        csvarinfo_t argvi;
> >>        tree argdecl = decl;
> >>
> >>        if (arg)
> >>            argdecl = arg;
> >>
> >>        argvi = cs_new_var_info (argdecl, alias_get_name (argdecl));
> >>        argvi->offset = i;
> >>        argvi->size = 1;
> >>        argvi->is_full_var = true;
> >>        argvi->fullsize = vi->fullsize;
> >>        if (arg)
> >>            argvi->may_have_pointers = true;
> >>        gcc_assert (prev_vi->offset < argvi->offset);
> >>        prev_vi->next = argvi;
> >>        prev_vi = argvi;
> >>        if (arg) {
> >>            cs_insert_vi_for_tree (arg, argvi);
> >>            arg = DECL_CHAIN (arg);
> >>        }
> >>    }
> >>
> >>    /* Add one representative for all further args.  */
> >>    if (is_varargs) {
> >>        csvarinfo_t argvi;
> >>        const char *newname;
> >>        char *tempname;
> >>        tree decl;
> >>
> >>        asprintf (&tempname, "%s.varargs", name);
> >>        newname = ggc_strdup (tempname);
> >>        free (tempname);
> >>
> >>        /* We need sth that can be pointed to for va_start.  */
> >>        decl = create_tmp_var_raw (ptr_type_node, name);
> >>        get_var_ann (decl);
> >>
> >>        argvi = cs_new_var_info (decl, newname);
> >>        argvi->offset = 1 + num_args;
> >>        argvi->size = ~0;
> >>        argvi->is_full_var = true;
> >>        argvi->is_heap_var = true;
> >>        argvi->fullsize = vi->fullsize;
> >>        gcc_assert (prev_vi->offset < argvi->offset);
> >>        prev_vi->next = argvi;
> >>        prev_vi = argvi;
> >>    }
> >>
> >>    return vi;
> >> }
> >>
> >>
> >> Sudakshina Das


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]