Subject: bug#11645: Unable to cross compile guile 2.0.5 for MIPS/PPC on x86_64

From: "Marinescu, Bogdan A" <[email-masked]>
Date: Thu, 7 Jun 2012 14:00:19 +0300

Compiling guile 2.0.5 for MIPS and PowerPC (both in big endian mode)
fails with a segmentation fault. guile 2.0.5 is built first for x86_64
and this version is used to cross-compile guile for MIPS. The
compilation stops with this error:

GUILE_AUTO_COMPILE=0      \
  ../meta/uninstalled-env     \
  guild compile --target="mips-poky-linux-gnu" -Wunbound-variable
-Warity-mismatch -Wformat \
    -L "/ssd/build/tmp/work/mips32-poky-linux/guile-2.0.5-r0/guile-2.0.5/module"
-L "/ssd/build/tmp/work/mips32-poky-linux/guile-2.0.5-r0/guile-2.0.5/module"
  \
    -L "/ssd/build/tmp/work/mips32-poky-linux/guile-2.0.5-r0/guile-2.0.5/guile-readline"
     \
    -o "ice-9/occam-channel.go" "ice-9/occam-channel.scm"
make[2]: *** [ice-9/occam-channel.go] Segmentation fault (core dumped)

This is the stack trace:

Core was generated by
`/ssd/build/tmp/sysroots/x86_64-linux/usr/bin/x86_64-linux-guile.real
-e (@@ (gu'.
Program terminated with signal 11, Segmentation fault.
#0  0x00007f76a81450fd in vm_regular_engine (vm=0x26b76c0,
program=0x2d0a8e0, argv=0x0, nargs=0) at vm-i-loader.c:80
80    NEXT;
(gdb) bt
#0  0x00007f76a81450fd in vm_regular_engine (vm=0x26b76c0,
program=0x2d0a8e0, argv=0x0, nargs=0) at vm-i-loader.c:80
#1  0x00007f76a8160e09 in scm_c_vm_run (vm=0x26b76c0,
program=0x2b8dc60, argv=0x0, nargs=0) at vm.c:567
#2  0x00007f76a8161ae5 in scm_load_compiled_with_vm (file=0x2b8dca0) at vm.c:878
#3  0x00007f76a8096a86 in scm_primitive_load_path (args=0x2aec5d0) at load.c:913
#4  0x00007f76a8136555 in vm_regular_engine (vm=0x26b76c0,
program=0x7f76a83e36a0, argv=0x7fff60d8d860, nargs=1) at
vm-i-system.c:892
#5  0x00007f76a8160e09 in scm_c_vm_run (vm=0x26b76c0,
program=0x26c69c0, argv=0x7fff60d8d858, nargs=1) at vm.c:567
#6  0x00007f76a800010c in scm_primitive_eval (exp=0x28907c0) at eval.c:685
#7  0x00007f76a80001d2 in scm_eval (exp=0x28907c0,
module_or_state=0x2871d80) at eval.c:719
#8  0x00007f76a80f6fd4 in scm_shell (argc=19, argv=0x7fff60d8eb68) at
script.c:441
#9  0x0000000000400bc8 in inner_main (closure=0x0, argc=19,
argv=0x7fff60d8eb68) at guile.c:62
#10 0x00007f76a808ad8b in invoke_main_func (body_data=0x7fff60d8ea30)
at init.c:336
#11 0x00007f76a7ff25f2 in c_body (d=0x7fff60d8e910) at continuations.c:512
#12 0x00007f76a812a2e4 in apply_catch_closure (clo=0x2870b40,
args=0x304) at throw.c:146
#13 0x00007f76a8136d10 in vm_regular_engine (vm=0x26b76c0,
program=0x2870a00, argv=0x7fff60d8e7d0, nargs=1) at vm-i-system.c:960
#14 0x00007f76a8160e09 in scm_c_vm_run (vm=0x26b76c0,
program=0x279ea50, argv=0x7fff60d8e7b0, nargs=4) at vm.c:567
#15 0x00007f76a7fff7d3 in scm_call_4 (proc=0x279ea50, arg1=0x404,
arg2=0x2870b40, arg3=0x2870b20, arg4=0x2870b00) at eval.c:507
#16 0x00007f76a8129f67 in scm_catch_with_pre_unwind_handler
(key=0x404, thunk=0x2870b40, handler=0x2870b20,
pre_unwind_handler=0x2870b00) at throw.c:86
#17 0x00007f76a812a3cc in scm_c_catch (tag=0x404, body=0x7f76a7ff25ca
<c_body>, body_data=0x7fff60d8e910, handler=0x7f76a7ff2601
<c_handler>, handler_data=0x7fff60d8e910,
pre_unwind_handler=0x7f76a7ff2655 <pre_unwind_handler>,
    pre_unwind_handler_data=0x26b75f0) at throw.c:213
#18 0x00007f76a7ff2466 in scm_i_with_continuation_barrier
(body=0x7f76a7ff25ca <c_body>, body_data=0x7fff60d8e910,
handler=0x7f76a7ff2601 <c_handler>, handler_data=0x7fff60d8e910,
pre_unwind_handler=0x7f76a7ff2655 <pre_unwind_handler>,
    pre_unwind_handler_data=0x26b75f0) at continuations.c:450
#19 0x00007f76a7ff26ec in scm_c_with_continuation_barrier
(func=0x7f76a808ad38 <invoke_main_func>, data=0x7fff60d8ea30) at
continuations.c:546
#20 0x00007f76a8126b82 in with_guile_and_parent (base=0x7fff60d8e980,
data=0x7fff60d8e9c0) at threads.c:902
#21 0x00007f76a7d28d75 in GC_call_with_stack_base () from
/ssd/build/tmp/sysroots/x86_64-linux/usr/bin/../../usr/lib/libgc.so.1
#22 0x00007f76a8126c62 in scm_i_with_guile_and_parent
(func=0x7f76a808ad38 <invoke_main_func>, data=0x7fff60d8ea30,
parent=0x0) at threads.c:945
#23 0x00007f76a8126c8e in scm_with_guile (func=0x7f76a808ad38
<invoke_main_func>, data=0x7fff60d8ea30) at threads.c:951
#24 0x00007f76a808ad19 in scm_boot_guile (argc=19,
argv=0x7fff60d8eb68, main_func=0x400ba4 <inner_main>, closure=0x0) at
init.c:319
#25 0x0000000000400c20 in main (argc=19, argv=0x7fff60d8eb68) at guile.c:79
(gdb)

While debugging this issue, I modified the "NEXT" macro in vm-engine.h
to output information about the current IP and the next instruction:

#define NEXT          \
{           \
  NEXT_HOOK ();         \
  CHECK_STACK_LEAK ();                          \
  if(getenv("GUILELOGS")) fprintf(stderr,"->NEXT:%d IP=%p\n", (*ip) &
SCM_VM_INSTRUCTION_MASK, ip); \
  NEXT_JUMP ();         \
}

Below are the last lines of the output that I get with this
modification (the complete output is too large to attach):

->NEXT:11 IP=0x260df6d
->NEXT:1 IP=0x260df6e
->NEXT:52 IP=0x7f76a85e2d0a
->NEXT:21 IP=0x7f76a85e2d0b
->NEXT:62 IP=0x7f76a85e2d0d
->NEXT:93 IP=0x7f76a84e3548
->NEXT:52 IP=0x7f76a84e354a
->NEXT:27 IP=0x7f76a84e354b
->NEXT:76 IP=0x7f76a84e354d
->NEXT:62 IP=0x7f76a84e354f
->NEXT:44 IP=0x7f76a8187c50
->NEXT:19 IP=0x7f76a8187c53
->NEXT:55 IP=0x7f76a8187c55
->NEXT:2 IP=0x7f76a84e3554
->NEXT:34 IP=0x7f76a84e3555
->NEXT:52 IP=0x7f76a84e355c
->NEXT:76 IP=0x7f76a84e355d
->NEXT:53 IP=0x7f76a84e355f
->NEXT:93 IP=0x28acaa0
->NEXT:6 IP=0x28acaa2
->NEXT:6 IP=0x28acaa3
->NEXT:18 IP=0x28acaa4
->NEXT:29 IP=0x28acaa7
->NEXT:52 IP=0x28acaa9
->NEXT:21 IP=0x28acaaa
->NEXT:0 IP=0x28acaac
->NEXT:0 IP=0x28acaad
->NEXT:0 IP=0x28acaae
->NEXT:104 IP=0x28acaaf
Segmentation fault (core dumped)