Debugging a custom GCC Back End
Hi, I'm creating a GCC Back-End for a virtual CPU. I have already created a Machine Description (cpu.md) File and the Target Description Makro Files (cpu.h cpu.c). I have only implemented all the makros, which are needed for compiling the GCC. But not all which are needed for the CPU. The compilation of my custom GCC works, but the binary I get is not working. I always get the "internal compiler error: Segmentation fault" message if I try to Compile a c-file. But the GCC don't tell me, where or why the error occurred. Is there any possibility to debug the gcc-backend? Or how can I find out where the Error occurred? Thank you for your help, Balthasar PS: My English is not so good, but I hope you understand my problem! signature.asc Description: OpenPGP digital signature
Creating own Backend: Segmentation fault in mark_jump_label_1
Hello everybody, I create a gcc-backend. I have already created the *.md, *.h and *.c files and I have compiled the gcc which includes backend. But when I try to compile a simple c-File with my gcc I get a Segmentation fault. I tried to debug it but I don't get the point. The Error occures in mark_jump_label_1. It is called with a null pointer as the rtx x. gdb told me: Program received signal SIGSEGV, Segmentation fault. 0x081c5d48 in mark_jump_label_1 (x=0x0, insn=0xb7b77118, in_mem=0 '\0', is_target=0 '\0') at ../.././gcc/jump.c:987 987 RTX_CODE code = GET_CODE (x); (gdb) where #0 0x081c5d48 in mark_jump_label_1 (x=0x0, insn=0xb7b77118, in_mem=0 '\0', is_target=0 '\0') at ../.././gcc/jump.c:987 #1 0x081c60e0 in mark_jump_label_1 (x=0xb7b70e28, insn=0xb7b77118, in_mem=0 '\0', is_target=0 '\0') at ../.././gcc/jump.c:1108 #2 0x081c5d2f in mark_jump_label (x=0xb7b70e28, insn=0xb7b77118, in_mem=0) at ../.././gcc/jump.c:974 #3 0x081c4af4 in mark_all_labels (f=0xb7bdb120) at ../.././gcc/jump.c:194 #4 0x081c48f7 in rebuild_jump_labels (f=0xb7bdb120) at ../.././gcc/jump.c:86 #5 0x08418fdf in tree_expand_cfg () at ../.././gcc/cfgexpand.c:1935 #6 0x08203198 in execute_one_pass (pass=0x856a640) at ../.././gcc/passes.c:1122 #7 0x082032e4 in execute_pass_list (pass=0x856a640) at ../.././gcc/passes.c:1175 #8 0x082ca0fd in tree_rest_of_compilation (fndecl=0xb7bd7a10) at ../.././gcc/tree-optimize.c:404 #9 0x083db7bd in cgraph_expand_function (node=0xb7b73280) at ../.././gcc/cgraphunit.c:1157 #10 0x083da461 in cgraph_assemble_pending_functions () at ../.././gcc/cgraphunit.c:523 #11 0x083da72d in cgraph_finalize_function (decl=0xb7bd7a10, nested=0 '\0') at ../.././gcc/cgraphunit.c:641 #12 0x0805a470 in finish_function () at ../.././gcc/c-decl.c:6803 #13 0x080a7f9b in c_parser_declaration_or_fndef (parser=0xb7be2b28, fndef_ok=1 '\001', empty_ok=1 '\001', nested=0 '\0', start_attr_ok=1 '\001') at ../.././gcc/c-parser.c:1424 #14 0x080a7920 in c_parser_external_declaration (parser=0xb7be2b28) at ../.././gcc/c-parser.c:1179 #15 0x080a762c in c_parser_translation_unit (parser=0xb7be2b28) at ../.././gcc/c-parser.c:1081 #16 0x080b44c1 in c_parse_file () at ../.././gcc/c-parser.c:8011 #17 0x0809b675 in c_common_parse_file (set_yydebug=0) at ../.././gcc/c-opts.c:1291 #18 0x082861fa in compile_file () at ../.././gcc/toplev.c:1042 #19 0x08287bc4 in do_compile () at ../.././gcc/toplev.c:2247 #20 0x08287c26 in toplev_main (argc=2, argv=0xbfa608c4) at ../.././gcc/toplev.c:2279 #21 0x080bba42 in main (argc=Cannot access memory at address 0x0 ) at ../.././gcc/main.c:35 Which Target Makro or which machine description could create such an error? Thank you for your help! Balthasar signature.asc Description: OpenPGP digital signature
Re: Creating own Backend: Segmentation fault in mark_jump_label_1
Balthasar Biedermann schrieb: > I create a gcc-backend. I have already created the *.md, *.h and *.c > files and I have compiled the gcc which includes backend. > > But when I try to compile a simple c-File with my gcc I get a > Segmentation fault. I tried to debug it but I don't get the point. > > The Error occures in mark_jump_label_1. It is called with a null pointer > as the rtx x. > > Which Target Makro or which machine description could create such an error? > Does nobody have an idea why or where the error occures? I really start to became desperate. I already changed a lot of Makros and analysed the the resulting gcc with gdb but I can't fix the error. I'm really grateful for every help! signature.asc Description: OpenPGP digital signature
Re: Creating own Backend: Segmentation fault in mark_jump_label_1
Ben Elliston schrieb: > Perhaps you could get a stack backtrace and try to understand why you're > getting a NULL_RTX passed in? I already made a stack backtrace and posted it in my first mail: Program received signal SIGSEGV, Segmentation fault. 0x081c5d48 in mark_jump_label_1 (x=0x0, insn=0xb7b77118, in_mem=0 '\0', is_target=0 '\0') at ../.././gcc/jump.c:987 987 RTX_CODE code = GET_CODE (x); (gdb) where #0 0x081c5d48 in mark_jump_label_1 (x=0x0, insn=0xb7b77118, in_mem=0 '\0', is_target=0 '\0') at ../.././gcc/jump.c:987 #1 0x081c60e0 in mark_jump_label_1 (x=0xb7b70e28, insn=0xb7b77118, in_mem=0 '\0', is_target=0 '\0') at ../.././gcc/jump.c:1108 #2 0x081c5d2f in mark_jump_label (x=0xb7b70e28, insn=0xb7b77118, in_mem=0) at ../.././gcc/jump.c:974 #3 0x081c4af4 in mark_all_labels (f=0xb7bdb120) at ../.././gcc/jump.c:194 #4 0x081c48f7 in rebuild_jump_labels (f=0xb7bdb120) at ../.././gcc/jump.c:86 #5 0x08418fdf in tree_expand_cfg () at ../.././gcc/cfgexpand.c:1935 #6 0x08203198 in execute_one_pass (pass=0x856a640) at ../.././gcc/passes.c:1122 #7 0x082032e4 in execute_pass_list (pass=0x856a640) at ../.././gcc/passes.c:1175 #8 0x082ca0fd in tree_rest_of_compilation (fndecl=0xb7bd7a10) at ../.././gcc/tree-optimize.c:404 #9 0x083db7bd in cgraph_expand_function (node=0xb7b73280) at ../.././gcc/cgraphunit.c:1157 #10 0x083da461 in cgraph_assemble_pending_functions () at ../.././gcc/cgraphunit.c:523 #11 0x083da72d in cgraph_finalize_function (decl=0xb7bd7a10, nested=0 '\0') at ../.././gcc/cgraphunit.c:641 #12 0x0805a470 in finish_function () at ../.././gcc/c-decl.c:6803 #13 0x080a7f9b in c_parser_declaration_or_fndef (parser=0xb7be2b28, fndef_ok=1 '\001', empty_ok=1 '\001', nested=0 '\0', start_attr_ok=1 '\001') at ../.././gcc/c-parser.c:1424 #14 0x080a7920 in c_parser_external_declaration (parser=0xb7be2b28) at ../.././gcc/c-parser.c:1179 #15 0x080a762c in c_parser_translation_unit (parser=0xb7be2b28) at ../.././gcc/c-parser.c:1081 #16 0x080b44c1 in c_parse_file () at ../.././gcc/c-parser.c:8011 #17 0x0809b675 in c_common_parse_file (set_yydebug=0) at ../.././gcc/c-opts.c:1291 #18 0x082861fa in compile_file () at ../.././gcc/toplev.c:1042 #19 0x08287bc4 in do_compile () at ../.././gcc/toplev.c:2247 #20 0x08287c26 in toplev_main (argc=2, argv=0xbfa608c4) at ../.././gcc/toplev.c:2279 #21 0x080bba42 in main (argc=Cannot access memory at address 0x0 ) at ../.././gcc/main.c:35 But it doesn't really help me, because I don't know all this functions. Do you know what they do and when they are called? I found out that the RTX which enters mark_jump_label and later causes the error is a "parallel". That is strange, because a don't use parallels in my machine description file(*.md) yet. The parallel RTX is passed to mark_jump_label() and from there to mark_jump_label_1(). In mark_jump_label_1 in line 1108 it takes XVECEXP (x, i, j) from the RTX x and the value of this XVECEXP-expression is null. So I thik the error occures either because the RTX is not valid or because VECEXP dont't work right or because the variables i and j are too big/wrong. The value of i goes from GET_RTX_LENGTH (code), where code is GET_CODE(RTX x), to 0. j goes from XVECLEN (x, i) - 1 to 0. Can I influence one of these things with the Target Makros or the Machine Description? signature.asc Description: OpenPGP digital signature