[racket-dev] Building Racket with the Android NDK

From: Jan Wedekind (jan at wedesoft.de)
Date: Wed Sep 5 07:59:39 EDT 2012

On Thu, 30 Aug 2012, Matthew Flatt wrote:
> At Thu, 30 Aug 2012 13:39:52 +0100 (BST), Jan Wedekind wrote:
>> On Sat, 25 Aug 2012, Matthew Flatt wrote:
>>> At Sat, 25 Aug 2012 20:04:45 +0100 (BST), Jan Wedekind wrote:
>>>> I tried to debug
>>>> However then the
>>>> program reports the following segmentation fault instead:
>>>>
>>>>      Program received signal SIGSEGV, Segmentation fault.
>>>>      0x00282540 in scheme_gmp_tls_unload (s=0x4031cedc, data=0x0) at
>>>> ./gmp/gmp.c:5813
>>>>      5813      s[0] = 0;
>>>>      (gdb) l
>>>>      5808    void scheme_gmp_tls_unload(intptr_t *s, void *data)
>>>> [...]
>>>>
>>>> According to [2] this is a GC write barrier and one needs to ignore
>>>> semgentation faults as follows
>>>>
>>>>      (gdb) handle SIGSEGV nostop noprint
>>>
>>> Yes.
>>>
>>>> But in that case it is not possible to debug the initial segmentation fault
>>>> though.
>>>
>>> Does it work to set a breakpoint on abort()?
>>>
>>> (gdb) br abort
>>>
>>>
>>    Thanks. That seems to ignore the GC write barrier related signals.
>> Unfortunately there is no debug information for the stack frame
>> (0xffff050c) of the current crash:
>>
>> Breakpoint 1, 0x00022658 in abort ()
>> (gdb) up
>> #1  0x0028ce30 in fault_handler (sn=11, si=0x3437a8, ctx=0x343828) at
>> ./sighand.c:99
>> 99          abort();
>> (gdb)
>> #2  0xffff050c in ?? ()
>> (gdb)
>> #3  0xffff050c in ?? ()
>> (gdb)
>> Initial frame selected; you cannot go up.
>> (gdb) cont
>> Continuing.
>
> Here's something different to try:
>
> In "src/racket/gc2/sighand.c", change to initialize_signal_handler() to
> set `gc->generations_available = 0' and return install of installing
> signal handlers. That should disable generational GC and the associated
> write barrier.

Ok, I tried that. The program now fails in 
'scheme_extend_module_rename_with_shared'. The stack trace has a couple of 
hundred entries, so I am only posting part of it here. I hope the 
backtrace makes any sense.

jan at wedemob:~/build/cross/racket-5.3.0/src$ $NDK/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-gdb racket/racket3m 
GNU gdb (GDB) 7.3.1-gg2
Copyright (C) 2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "--host=x86_64-linux-gnu --target=arm-linux-android".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/jan/build/cross/racket-5.3.0/src/racket/racket3m...done.
(gdb) target remote 192.168.2.11:1234
Remote debugging using 192.168.2.11:1234
warning: Unable to find dynamic linker breakpoint function.
GDB will be unable to debug shared library initializers
and track explicitly loaded dynamic code.
0xb0001000 in ?? ()
(gdb) cont
Continuing.
Cannot access memory at address 0x0

Program received signal SIGSEGV, Segmentation fault.
0x00282540 in scheme_gmp_tls_snapshot (s=0x4031cedc, save=0x0) at ./gmp/gmp.c:5818
5818    {
(gdb) up
#1  0xbec2d7e4 in ?? ()
(gdb) 
Cannot access memory at address 0xb
#2  0xbec2d7e4 in ?? ()
(gdb) 
Cannot access memory at address 0xb
Initial frame selected; you cannot go up.
(gdb) cont
Continuing.

Program received signal SIGSEGV, Segmentation fault.
0x00212870 in scheme_extend_module_rename_with_shared (rn=0x403ba6c0, modidx=0x4031c378,
     pt=0x40336688, unmarshal_phase_index=0x1, src_phase_index=0x3, marks=0x323b2c,
     bdg=0x323a84, save_unmarshal=1) at xsrc/syntax.c:1520
1520        pr = (__funcarg56 = (__funcarg57 = FUNCCALL(SETUP_XfOrM204(_), scheme_make_pair (unmarshal_phase_index , index_plus_marks ) ), FUNCCALL_AGAIN(scheme_make_pair (modidx , __funcarg57 ) )) , FUNCCALL_AGAIN(scheme_make_pair (__funcarg56 , mrn -> unmarshal_info ) )) ; 
(gdb) up
#1  0x000e1288 in add_single_require (me=0x403e6030, only_phase=0x0, src_phase_index=0x3,
     idx=0x4031c378, orig_env=0x403ac340, rn_set=0x4031d9d0, post_ex_rn_set=0x4031d7b8,
     single_rn=0x0, exns=0x0, onlys=0x0, prefix=0x0, iname=0x0, orig_ename=0x0,
     mark_src=0x402040c8, unpack_kern=0, copy_vars=0, for_unmarshal=0, can_save_marshal=1,
     all_simple=0x40351d48, ck=0xcdff8 <check_require_name+64>, data=0x4031db50,
     form=0x40204018, err_src=0x402040c8, cki=0x402040c8) at xsrc/module.c:12556
12556         exets = pt -> provide_src_phases ; 
(gdb) 
#2  0x000e4d74 in parse_requires (form=0x40204018, at_phase=0, base_modidx=0x4031d988,
     main_env=0x4031dd38, for_m=0x4031dbf0, rn_set=0x4031d9d0, post_ex_rn_set=0x4031d7b8,
     ck=0xcdff8 <check_require_name+64>, data=0x4031db50, redef_modname=0x0, unpack_kern=0,
     copy_vars=0, can_save_marshal=1, eval_exp=1, eval_run=0, all_simple=0x40351d48,
     modidx_cache=0x4031db28, submodule_names=0x0) at xsrc/module.c:13316
13316             if (onlys -> vals [k ] )
(gdb) 
#3  0x000d48e0 in do_module_begin_at_phase (form=0x4031da60, env=0x4031d8d0, rec=0xbec2e3e8,
     drec=0, erec=0x0, derec=0, phase=0, body_lists=0x323b2c, bxs=0x40319f48)
     at xsrc/module.c:9632
9632                FUNCCALL(SETUP_XfOrM1896(_), scheme_call_expand_observe (observer , 7 , e ) ); 
(gdb) 
#4  0x000d04f4 in do_module_begin (orig_form=0x4031dae0, env=0x4031d8d0, rec=0xbec2e3e8,
     drec=0) at xsrc/module.c:8643
8643        expanded_l = (((Scheme_Simple_Object * ) (body_lists ) ) -> u . pair_val . car ) ; 
(gdb) 
#5  0x000d7ec8 in module_begin_expand (form=0x2f874c, env=0xbec2dea4, erec=0x0,
     drec=-1094525320) at xsrc/module.c:10516
10516     PREPARE_VAR_STACK_ONCE(3);
(gdb) up
#6  0x002c4e08 in scheme_compile_expand_expr (form=0x4031dae0, env=0x4031d8d0, rec=0xbec2e3e8,
     drec=0, app_position=0) at xsrc/compile.c:5630
5630                  FUNCCALL(SETUP_XfOrM850(_), scheme_call_expand_observe (rec [drec ] . observer , 2 , form ) ); 
(gdb) up
#7  0x002c9518 in scheme_pair_lifted (_ip=0xd7e98, _ids=0xbec2df8c, expr=0xbec2dfb0,
     env=0x4031dba0) at xsrc/compile.c:6568
6568        FUNCCALL(SETUP_XfOrM1002(_), scheme_add_compilation_binding (-- pos , id , naya ) ); 
(gdb) backtrace
#0  0x00212870 in scheme_extend_module_rename_with_shared (rn=0x403ba6c0, modidx=0x4031c378,
     pt=0x40336688, unmarshal_phase_index=0x1, src_phase_index=0x3, marks=0x323b2c,
     bdg=0x323a84, save_unmarshal=1) at xsrc/syntax.c:1520
#1  0x000e1288 in add_single_require (me=0x403e6030, only_phase=0x0, src_phase_index=0x3,
     idx=0x4031c378, orig_env=0x403ac340, rn_set=0x4031d9d0, post_ex_rn_set=0x4031d7b8,
     single_rn=0x0, exns=0x0, onlys=0x0, prefix=0x0, iname=0x0, orig_ename=0x0,
     mark_src=0x402040c8, unpack_kern=0, copy_vars=0, for_unmarshal=0, can_save_marshal=1,
     all_simple=0x40351d48, ck=0xcdff8 <check_require_name+64>, data=0x4031db50,
     form=0x40204018, err_src=0x402040c8, cki=0x402040c8) at xsrc/module.c:12556
#2  0x000e4d74 in parse_requires (form=0x40204018, at_phase=0, base_modidx=0x4031d988,
     main_env=0x4031dd38, for_m=0x4031dbf0, rn_set=0x4031d9d0, post_ex_rn_set=0x4031d7b8,
     ck=0xcdff8 <check_require_name+64>, data=0x4031db50, redef_modname=0x0, unpack_kern=0,
     copy_vars=0, can_save_marshal=1, eval_exp=1, eval_run=0, all_simple=0x40351d48,
     modidx_cache=0x4031db28, submodule_names=0x0) at xsrc/module.c:13316

...

#255 0x00076e54 in scheme_top_level_do_worker (k=0x77598 <apply_k+64>, eb=1, new_thread=0,
     dyn_state=0x0) at xsrc/fun.c:888
#256 0x000769e4 in scheme_top_level_do_worker (k=0xbec3a5b8, eb=-1094474220, new_thread=12,
     dyn_state=0xbec3a7bc) at xsrc/fun.c:796
#257 0x0007775c in scheme_apply (rator=0x40242028, num_rands=1075888768, rands=0x34d478)
     at xsrc/fun.c:1109
#258 0x000777ac in scheme_apply_multi (rator=0x34d478, num_rands=2, rands=0xbec3a7f4)
     at xsrc/fun.c:1113
#259 0x00022efc in configure_environment (mod=0x4031f690) at xsrc/main.c:1276
#260 0x00023448 in finish_cmd_line_run (fa=0x4031a000, repl=0x26bfc <do_scheme_rep+64>)
     at xsrc/main.c:1385
#261 0x00026be8 in do_scheme_rep (env=0x0, fa=0x0) at xsrc/main.c:2353
#262 0x000268b0 in run_from_cmd_line (argc=0, _argv=0xbec3aca4,
     mk_basic_env=0x2d01c <scheme_basic_env+64>, cont_run=0x26bc4 <do_scheme_rep+8>)
     at xsrc/main.c:2276
#263 0x00026b64 in main_after_stack (data=0xbec3ac68) at xsrc/main.c:2345
#264 0x00027004 in do_main_stack_setup (no_auto_statics=1,
     _main=0x26a8c <main_after_stack+64>, data=0xbec3ac68) at xsrc/salloc.c:81
#265 0x00027088 in scheme_set_stack_bounds (base=0xbec3ac68, deepest=0x4000000c,
     no_auto_statics=159880) at xsrc/salloc.c:91
#266 0x00026a78 in main_after_stack (data=0x27088) at xsrc/main.c:2324
#267 0x00026a2c in main_after_dlls (argc=158252, argv=0xbec3ac84) at xsrc/main.c:2318
#268 0xafd1546c in ?? ()
#269 0xafd1546c in ?? ()


Posted on the dev mailing list.