GCC创建新的通行证

时间:2012-06-11 10:18:45

标签: gcc

我正在尝试在gcc-4.1.2中编写一个新的GCC传递。这是我的第一次尝试,我正在尝试打印gcc正在编译的函数的代码行。所以我添加了以下代码。请注意,如果我在execute_gimple_manipulation方法中删除代码,则不会发生此问题:

gcc/gcc-4.1.2 1223> cat gcc/gimple-manipulation.c
#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "tm.h"
#include "ggc.h"
#include "flags.h"
#include "tree.h"
#include "basic-block.h"
#include "tree-flow.h"
#include "tree-pass.h"
#include "tree-dump.h"
#include "timevar.h"
#include "diagnostic.h"
#include "cfgloop.h"
#include "tree-scalar-evolution.h"
#include "tree-ssa-propagate.h"
#include "tree-chrec.h"


static void execute_gimple_manipulation (void);
static bool gate_gimple_manipulation (void);

/*-------------------------
  The main driver function.
 -------------------------*/
static void execute_gimple_manipulation (void)
{
  basic_block bb = ENTRY_BLOCK_PTR;
  int bbcounter=0, stmtcounter;
  tree stmt;
  block_stmt_iterator si;

  /* traverse each basic block and print all statements  */

  FOR_EACH_BB (bb){ /* in any order */

    bbcounter++;
    printf("\n-> entering bb # %d (internal #: %d)\n", bbcounter, bb->index);

    stmtcounter=0;

    for(si = bsi_start(bb); !bsi_end_p(si); bsi_next(&si)){
      stmtcounter++;
      printf("   encountering statement #%2d: ", stmtcounter);
      stmt = bsi_stmt(si);
      print_generic_stmt (stderr, stmt, 0);
    }
  }
}

/* ------------------------------------------
   Return true if we should execute our pass.
   ------------------------------------------*/
static bool
gate_gimple_manipulation (void)
{
/*    return (flag_unit_at_a_time != 0  && flag_ipa_gimple_manipulation
           Don't bother doing anything if the program has errors.
          && !(errorcount || sorrycount));*/
  return (/*optimize >= 1*/
          /* Don't bother doing anything if the program has errors.  */
          /*&&*/ !(errorcount || sorrycount));
}
struct tree_opt_pass pass_gimple_manipulation =
{
   "gm_pass_simple",             /* name */
   gate_gimple_manipulation,     /* gate */
   execute_gimple_manipulation,  /* execute */
   NULL,                         /* sub */
   NULL,                         /* next */
   0,                            /* static pass number */
   0,                            /* tv_id */
   PROP_cfg | PROP_ssa | PROP_alias,                            /* properties required */
   0,                            /* properties provided */
   0,                            /* properties destroyed */
   0,                            /* todo_flags start */
   TODO_dump_func,                            /* todo_flags finish */
   0                             /* letter */
};

我的新代码编译按照make:

进行
gcc -c   -g -O2 -DIN_GCC   -W -Wall -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes -pedantic -Wno-long-long -Wno-variadic-macros -Wold-style-definition -Wmissing-format-attribute    -DHAVE_CONFIG_H -I. -I. -I../.././gcc -I../.././gcc/. -I../.././gcc/../include -I../.././gcc/../libcpp/include     ../.././gcc/gimple-manipulation.c -o gimple-manipulation.o

但编译过程进一步失败:

gcc/gcc-4.1.2/host-x86_64-unknown-linux-gnu/gcc/xgcc -Bgcc/gcc-4.1.2/host-x86_64-unknown-linux-gnu/gcc/ -B/usr/local/x86_64-unknown-linux-gnu/bin/ -B/usr/local/x86_64-unknown-linux-gnu/lib/ -isystem /usr/local/x86_64-unknown-linux-gnu/include -isystem /usr/local/x86_64-unknown-linux-gnu/sys-include -O2  -O2 -g -O2  -DIN_GCC    -W -Wall -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes -Wold-style-definition  -isystem ./include  -fPIC -g -DHAVE_GTHR_DEFAULT -DIN_LIBGCC2 -D__GCC_FLOAT_NOT_NEEDED  -msse -c \
                ../.././gcc/config/i386/crtfastmath.c \
                -o crtfastmath.o
../.././gcc/config/i386/crtfastmath.c:110: internal compiler error: Segmentation fault
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://gcc.gnu.org/bugs.html> for instructions.
make[2]: *** [crtfastmath.o] Error 1
make[2]: Leaving directory `gcc/gcc-4.1.2/host-x86_64-unknown-linux-gnu/gcc'
make[1]: *** [all-gcc] Error 2
make[1]: Leaving directory `gcc/gcc-4.1.2'
make: *** [all] Error 2
gcc/gcc-4.1.2 1223>

任何帮助 - 问题发生的原因以及如何实现目标?

0 个答案:

没有答案