Date: Sat, 2 Apr 1994 15:18:33 -0800 From: drupp AT cs DOT washington DOT edu (Douglas Rupp) To: djgpp AT sun DOT soe DOT clarkson DOT edu, gnat-report AT cs DOT nyu DOT edu Subject: Problem with generated assembly code Cc: drupp AT cs DOT washington DOT edu Below is the debugger output from a program generated by the Gnu C back_end via the DOS port of the Gnat Ada compiler. As you can see it blows up at: 000013b4: 0000 add [eax],al eax=00000000 I don't know assembly very well, but it appears that something should be in eax other than all zeroes. Something went wrong somewhere and I need help tracking it down. Below the debugger output is the assembly language version of a trivial Ada program which exhibits the error and a C file containing the binder output. It can be compiled and run without the having the Ada compiler as follows: as -o test2.o test2.s /* the assembly code */ gcc -c b_test2.c /* the C code from the binder */ gcc -o test2 b_test2.o test2.o For those of you interested in the Ada aspect, version 1.74 of Gnat was successfully ported and is available at ftp.cs.washington.edu in file pub/gnat. The above problem is in version 1.76. The (almost) identical assembly code, generated by version 1.76 of Gnat for Sco/Unix, runs fine on SCO Unix, the differences being the .align clauses all designate .align 4 vice .align 2. Conversely, changing the .align clauses to 4 in the DOS version have no effect and the program still crashes. Please help, Doug Rupp drupp AT cs DOT washington DOT edu ----------------------------------------------------------------------------- >> b __ada_test2 dr0 __ada_test2 (0x13aa) dr1 0 (disabled) dr2 0 (disabled) dr3 _main (0x1360) (disabled) >> c eax=00000000 ebx=7ffffc68 ecx=00005010 edx=7ffffc74 esi=00000000 edi=00000000 ebp=7ffffc54 UP IE PL NZ PO NC ds=0048 es=0048 fs=0048 gs=0038 ss:esp=0048:7ffffc50 cs=00d8 breakpoint 0 hit __ada_test2(): 000013aa: 55 push ebp ebp=7ffffc54 >> s 000013ab: 89e5 mov ebp,esp esp=7ffffc4c 000013ad: 83c4fe add esp,-2 esp=7ffffc4c 000013b0: 6668ff00 push 255 000013b4: 0000 add [eax],al eax=00000000 eax=00000000 ebx=7ffffc68 ecx=00005010 edx=7ffffc74 esi=00000000 edi=00000000 ebp=7ffffc4c RF UP IE TF PL NZ AC PO CY ds=0048 es=0048 fs=0048 gs=0038 ss:esp=0048:7ffffc48 cs=00d8 exception 14 (0xe) occurred, error code=0 000013b4: 0000 add [eax],al eax=00000000 ----------------------------------------------------------------------------- test2.s ----------------------------------------------------------------------------- .file "test2.ada" gcc2_compiled.: ___gnu_compiled_ada: .text .align 2 .globl _test2___elabb _test2___elabb: pushl %ebp movl %esp,%ebp L1: leave ret .align 2 .globl _test2___elabs _test2___elabs: pushl %ebp movl %esp,%ebp L2: leave ret .align 2 _set_char_literal_value.0: pushl %ebp movl %esp,%ebp subl $4,%esp movl %ecx,-4(%ebp) jmp L4 .align 2,0x90 L4: leave ret .align 2 .globl __ada_test2 __ada_test2: pushl %ebp movl %esp,%ebp addl $-2,%esp pushw $255 movl %ebp,%ecx call _set_char_literal_value.0 addl $4,%esp jmp L3 .align 2,0x90 L3: leave ret .comm ___gnat_jmpbuf,4 .comm ___gnat_exception,4 ----------------------------------------------------------------------------- b_test2.c ----------------------------------------------------------------------------- #include /* predefined exceptions */ char constraint_error; char numeric_error; char program_error; char storage_error; char tasking_error; static int static_argc; static char * *static_argv; int arg_count () { return static_argc; } int len_arg (arg_num) int arg_num; { return strlen(static_argv[arg_num]); } int fill_arg (a, i) char * a; int i; { strncpy (a, static_argv[i], strlen(static_argv[i])); } void catch_except (ptr, i) void *ptr; int i; { extern char *__gnat_exception; if (!ptr) { if (__gnat_exception == &constraint_error) puts ("\nraised Constraint_Error\n"); else if (__gnat_exception == &numeric_error) puts ("\nraised Numeric_Error\n"); else if (__gnat_exception == &program_error) puts ("\nraised Program_Error\n"); else if (__gnat_exception == &storage_error) puts ("\nraised Storage_Error\n"); else puts ("\nraised unhandled exception\n"); exit (1); } else longjmp (ptr, i); } void __gnat_raise_constraint () { extern char *__gnat_exception; extern void *__gnat_jmpbuf; __gnat_exception = &constraint_error; catch_except (__gnat_jmpbuf, 1); } void main (argc, argv) int argc; char * argv[]; { static_argc = argc; static_argv = argv; test2___elabb (); /* test2.ali */ _ada_test2 (); exit (0); } /* BEGIN Object file list test2.o END Object file list */