1. External functions returning C_DOUBLE are called twice (bug?)
- Posted by ghaberek (admin) Dec 17, 2020
- 1252 views
Forked from Re: Phix+EuGTK
double hello(double x)Can anybody explain why I get two hello's?
LOL.
LOL indeed. It certainly looks like the function is being called twice. Very not good. One call is directly from call_c() and the second is from icall_x86_64(), which is called by call_c().
Here's a stack trace showing the function calls. I'll need to run this against a debug build to get a better stack output and see what's going on. Currently I'm just using the 4.1 beta build.
$ gdb eui GNU gdb (Ubuntu 8.1.1-0ubuntu1) 8.1.1 Reading symbols from eui...(no debugging symbols found)...done. (gdb) break hello Function "hello" not defined. Make breakpoint pending on future shared library load? (y or [n]) y Breakpoint 1 (hello) pending. (gdb) run libmytest.e Starting program: /usr/local/bin/eui libmytest.e [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1". Breakpoint 1, 0x00007ffff701f62e in hello () from ./libmytest.so (gdb) bt #0 0x00007ffff701f62e in hello () from ./libmytest.so #1 0x000000000057b074 in call_c () #2 0x00000000005780e3 in do_exec () #3 0x0000000000578a63 in Execute () #4 0x000000000057d301 in start_backend () #5 0x000000000057def8 in machine () #6 0x00000000004274be in _68BackEnd () #7 0x00000000004fe69c in _2BackEnd () #8 0x00000000004fa93a in _74main () #9 0x000000000041e0bf in main () (gdb) cont Continuing. Hello! Your number was 123.456 Breakpoint 1, 0x00007ffff701f62e in hello () from ./libmytest.so (gdb) bt #0 0x00007ffff701f62e in hello () from ./libmytest.so #1 0x000000000057a590 in icall_x86_64 () #2 0x000000000057b09d in call_c () #3 0x00000000005780e3 in do_exec () #4 0x0000000000578a63 in Execute () #5 0x000000000057d301 in start_backend () #6 0x000000000057def8 in machine () #7 0x00000000004274be in _68BackEnd () #8 0x00000000004fe69c in _2BackEnd () #9 0x00000000004fa93a in _74main () #10 0x000000000041e0bf in main () (gdb) cont Continuing. Hello! Your number was 123.456 Got back: 246.912 warning: Temporarily disabling breakpoints for unloaded shared library "./libmytest.so" [Inferior 1 (process 2575) exited normally] (gdb) quit
-Greg
2. Re: External functions returning C_DOUBLE are called twice (bug?)
- Posted by ghaberek (admin) Dec 17, 2020
- 1219 views
Browsing through be_callc.c, I'm pretty sure the culprit is this call_routine() macro on line 1480.
#define call_routine(type) \ if( is_double ) double_result = dcall_x86_64( long_proc_address, (double*)dbl_op, arg_op SIGNATURE_PARAM);\ if( is_float ) float_result = fcall_x86_64( long_proc_address, (double*)dbl_op, arg_op SIGNATURE_PARAM);\ else int_result = icall_x86_64( long_proc_address, (double*)dbl_op, arg_op, int_args SIGNATURE_PARAM )
For the first if statement, if is_double is TRUE, it will trigger the call to dcall_x86_64(). Then the second if statement triggers its else block because is_float is FALSE.
So really that ought to be...
#define call_routine(type) \ if ( is_double ) double_result = dcall_x86_64( long_proc_address, (double*)dbl_op, arg_op SIGNATURE_PARAM);\ else if( is_float ) float_result = fcall_x86_64( long_proc_address, (double*)dbl_op, arg_op SIGNATURE_PARAM);\ else int_result = icall_x86_64( long_proc_address, (double*)dbl_op, arg_op, int_args SIGNATURE_PARAM )
I'll test this change and see what happens.
-Greg
3. Re: External functions returning C_DOUBLE are called twice (bug?)
- Posted by ghaberek (admin) Dec 17, 2020
- 1213 views
I created a ticket for this: https://openeuphoria.org/ticket/1016.wc
-Greg
4. Re: External functions returning C_DOUBLE are called twice (bug?)
- Posted by ghaberek (admin) Dec 17, 2020
- 1209 views
Stack trace showing the call is coming from inside the house that call_routine() macro as I suspected:
$ gdb /home/greg/Projects/OpenEuphoria/euphoria/source/build/eui GNU gdb (Ubuntu 8.1.1-0ubuntu1) 8.1.1 Reading symbols from /home/greg/Projects/OpenEuphoria/euphoria/source/build/eui...done. (gdb) break hello Function "hello" not defined. Make breakpoint pending on future shared library load? (y or [n]) y Breakpoint 1 (hello) pending. (gdb) run libmytest.e Starting program: /home/greg/Projects/OpenEuphoria/euphoria/source/build/eui libmytest.e [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1". Breakpoint 1, 0x00007ffff701f62e in hello () from ./libmytest.so (gdb) bt #0 0x00007ffff701f62e in hello () from ./libmytest.so #1 0x0000555555952aa3 in dcall_x86_64 (func=func@entry=140737337488938, xmm=xmm@entry=0x7fffffffb2e0, r=r@entry=0x7fffffffb320) at /home/greg/Projects/OpenEuphoria/euphoria/source/be_callc.c:1015 #2 0x0000555555953273 in call_c (func=<optimized out>, proc_ad=<optimized out>, arg_list=-9223360308729739510) at /home/greg/Projects/OpenEuphoria/euphoria/source/be_callc.c:1486 #3 0x000055555594e9a5 in do_exec (start_pc=0x555555d84098) at /home/greg/Projects/OpenEuphoria/euphoria/source/be_execute.c:5179 #4 0x000055555594642f in Execute (start_index=0x555555d84098) at /home/greg/Projects/OpenEuphoria/euphoria/source/be_execute.c:1839 #5 0x0000555555957c29 in start_backend (x=-9223360308729746296) at /home/greg/Projects/OpenEuphoria/euphoria/source/be_machine.c:2911 #6 0x00005555559581ee in machine (opcode=65, x=-9223360308729746296) at /home/greg/Projects/OpenEuphoria/euphoria/source/be_machine.c:3216 #7 0x00005555555cd442 in _69BackEnd (_il_file_68425=0) at /home/greg/Projects/OpenEuphoria/euphoria/source/build/intobj/backend.c:4276 #8 0x0000555555651f51 in _2BackEnd (_x_192=0) at /home/greg/Projects/OpenEuphoria/euphoria/source/build/intobj/mode.c:170 #9 0x00005555555e966e in _75main () at /home/greg/Projects/OpenEuphoria/euphoria/source/build/intobj/main.c:1134 #10 0x00005555557d3c47 in main (argc=2, argv=0x7fffffffe528) at /home/greg/Projects/OpenEuphoria/euphoria/source/build/intobj/main-.c:22331 (gdb) cont Continuing. Hello! Your number was 123.456 Breakpoint 1, 0x00007ffff701f62e in hello () from ./libmytest.so (gdb) bt #0 0x00007ffff701f62e in hello () from ./libmytest.so #1 0x0000555555952a15 in icall_x86_64 (func=func@entry=140737337488938, xmm=xmm@entry=0x7fffffffb2e0, r=r@entry=0x7fffffffb320, args=args@entry=6) at /home/greg/Projects/OpenEuphoria/euphoria/source/be_callc.c:1005 #2 0x000055555595328f in call_c (func=<optimized out>, proc_ad=<optimized out>, arg_list=-9223360308729739510) at /home/greg/Projects/OpenEuphoria/euphoria/source/be_callc.c:1486 #3 0x000055555594e9a5 in do_exec (start_pc=0x555555d84098) at /home/greg/Projects/OpenEuphoria/euphoria/source/be_execute.c:5179 #4 0x000055555594642f in Execute (start_index=0x555555d84098) at /home/greg/Projects/OpenEuphoria/euphoria/source/be_execute.c:1839 #5 0x0000555555957c29 in start_backend (x=-9223360308729746296) at /home/greg/Projects/OpenEuphoria/euphoria/source/be_machine.c:2911 #6 0x00005555559581ee in machine (opcode=65, x=-9223360308729746296) at /home/greg/Projects/OpenEuphoria/euphoria/source/be_machine.c:3216 #7 0x00005555555cd442 in _69BackEnd (_il_file_68425=0) at /home/greg/Projects/OpenEuphoria/euphoria/source/build/intobj/backend.c:4276 #8 0x0000555555651f51 in _2BackEnd (_x_192=0) at /home/greg/Projects/OpenEuphoria/euphoria/source/build/intobj/mode.c:170 #9 0x00005555555e966e in _75main () at /home/greg/Projects/OpenEuphoria/euphoria/source/build/intobj/main.c:1134 #10 0x00005555557d3c47 in main (argc=2, argv=0x7fffffffe528) at /home/greg/Projects/OpenEuphoria/euphoria/source/build/intobj/main-.c:22331 (gdb) cont Continuing. Hello! Your number was 123.456 Got back: 246.912 warning: Temporarily disabling breakpoints for unloaded shared library "./libmytest.so" [Inferior 1 (process 6091) exited normally] (gdb) quit
-Greg
5. Re: External functions returning C_DOUBLE are called twice (bug?)
- Posted by ghaberek (admin) Dec 17, 2020
- 1223 views
Stack trace after correcting the call_routine() macro to use proper if/else if/else.
$ gdb /home/greg/Projects/OpenEuphoria/euphoria/source/build/eui GNU gdb (Ubuntu 8.1.1-0ubuntu1) 8.1.1 Reading symbols from /home/greg/Projects/OpenEuphoria/euphoria/source/build/eui...done. (gdb) break hello Function "hello" not defined. Make breakpoint pending on future shared library load? (y or [n]) y Breakpoint 1 (hello) pending. (gdb) run libmytest.e Starting program: /home/greg/Projects/OpenEuphoria/euphoria/source/build/eui libmytest.e [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1". Breakpoint 1, 0x00007ffff701f62e in hello () from ./libmytest.so (gdb) bt #0 0x00007ffff701f62e in hello () from ./libmytest.so #1 0x0000555555952aa3 in dcall_x86_64 (func=<optimized out>, xmm=<optimized out>, r=<optimized out>) at /home/greg/Projects/OpenEuphoria/euphoria/source/be_callc.c:1015 #2 0x000055555595323f in call_c (func=<optimized out>, proc_ad=<optimized out>, arg_list=<optimized out>) at /home/greg/Projects/OpenEuphoria/euphoria/source/be_callc.c:1486 #3 0x000055555594e9a5 in do_exec (start_pc=0x555555d84098) at /home/greg/Projects/OpenEuphoria/euphoria/source/be_execute.c:5179 #4 0x000055555594642f in Execute (start_index=0x555555d84098) at /home/greg/Projects/OpenEuphoria/euphoria/source/be_execute.c:1839 #5 0x0000555555957bde in start_backend (x=-9223360308729746296) at /home/greg/Projects/OpenEuphoria/euphoria/source/be_machine.c:2911 #6 0x00005555559581a3 in machine (opcode=65, x=-9223360308729746296) at /home/greg/Projects/OpenEuphoria/euphoria/source/be_machine.c:3216 #7 0x0000555555923e6a in _69BackEnd (_il_file_68425=0) at /home/greg/Projects/OpenEuphoria/euphoria/source/build/intobj/backend.c:4276 #8 0x000055555589326f in _2BackEnd (_x_192=0) at /home/greg/Projects/OpenEuphoria/euphoria/source/build/intobj/mode.c:170 #9 0x0000555555618881 in _75main () at /home/greg/Projects/OpenEuphoria/euphoria/source/build/intobj/main.c:1134 #10 0x00005555558178ce in main (argc=2, argv=0x7fffffffe528) at /home/greg/Projects/OpenEuphoria/euphoria/source/build/intobj/main-.c:22331 (gdb) cont Continuing. Hello! Your number was 123.456 Got back: 246.912 warning: Temporarily disabling breakpoints for unloaded shared library "./libmytest.so" [Inferior 1 (process 6402) exited normally] (gdb) quit
-Greg