Subject: segfault when dynamic linking of guile/ltdl (NetBSD/alpha 1.5.3-RCish)
To: None <port-alpha@netbsd.org>
From: Greg Troxel <gdt@ir.bbn.com>
List: port-alpha
Date: 05/15/2002 14:13:59
I am currently thinking that ld.elf_so support on Alpha might be not
100% right, or that guile is managing to call dynlinking oddly.
I suspect this is repeatable if anyone is in the mood to chase it -
grab the guile 1.5.6 snapshot from ftp://alpha.gnu.org/pub/gnu/guile/,
make sure GNU readline is not installed, build/install guile, start it
up, and type
(use-modules (ice-9 readline))
This should dynlink in $prefix/lib/libguilereadline.la using libtool's
ltdl library, and call the init function which has no statements due
to the ifdef of having readline not being true.

I am running NetBSD along release-1-5 as of 20020313.  I'm upgrading
to release-1-5 as of 20020510 shortly, but that will take a long time
compiling on an "AlphaStation 200 4/100, 100MHz".


------- Forwarded Message

Delivery-Date: Wed May 15 14:03:50 2002
	by fnord.ir.bbn.com (Postfix) with ESMTP
	id 53F4D3C39; Wed, 15 May 2002 14:03:50 -0400 (EDT)
From: Greg Troxel <gdt@ir.bbn.com>
To: guile-devel@gnu.org
Cc: Greg Troxel <gdt@ir.bbn.com>
Subject: NetBSD/alpha, 1.5.6 and readline
Date: Wed, 15 May 2002 14:03:50 -0400
Sender: gdt@ir.bbn.com
Message-Id: <20020515180350.53F4D3C39@fnord.ir.bbn.com>

I experimented some more with guile 1.5.6, NetBSD/alpha 1.5.2ish and
readline.

Configuring --without-threads, and with GNU readline present,
everything works fine.  I can (use-modules (ice-9 readline)),
(activate-readline), and use history.  I get no unaligned access
warnings.  "gmake check" fails on 3 tests which have nothing to do
with the Alpha (I reported them earlier - putenv and empty regexps).

Configuring/building guile-readline without readline, I get a shlib
that seems to have the single init function with no contens, since it
was all ifdef'd out.

I've spent more time on this than I should, so I should stop.  But the
good news is that guile works unless one tries to use readline and it
isn't present.  I now suspect this is a ltdl bug, not a guile bug.  Or
perhaps a NetBSD bug.  And I don't know alpha asm, so I'm not feeling
productive here...

If I configure --with-threads, I get lots of alignment warnings, but
nothing obviously bad happens.  I'm not sure if I ran make check or
tried to use them, though.

It seems to be dynamic linking of this that is problematic:

guile
guile> (define a (dynamic-link "libguilereadline"))
pid 22536 (guile): unaligned access: va=0x16010433c pc=0x160104398
ra=0x160934918 op=ldq
Segmentation fault (core dumped)

That pc is in rtld_bind_start in NetBSD ld.so code.  It's doing
        ldq     a0, 8(pv)
but gdb doesn't know about pv, so I'm lost.  That also seems to be 't12'.

guile> (use-modules (ice-9 readline))

Breakpoint 2, L100 ()
    at /home/gdt/QUIST-current/netbsd/src/libexec/ld.elf_so/arch/alpha/rtld_start.S:150
150             mov     at_reg, a1              /* offset of reloc entry */
(gdb) bt
#0  L100 ()
    at /home/gdt/QUIST-current/netbsd/src/libexec/ld.elf_so/arch/alpha/rtld_start.S:150
#1  0x16024bcac in sysdep_dynl_link ()
#2  0x16024c190 in scm_dynamic_link ()
#3  0x16026a36c in scm_deval ()
#4  0x16026aaf8 in scm_deval ()
#5  0x160263a80 in scm_i_eval_x ()
#6  0x160263c40 in scm_primitive_eval_x ()
#7  0x1602956c8 in load ()
#8  0x16024cd34 in scm_internal_dynamic_wind ()
#9  0x16029585c in scm_primitive_load ()
#10 0x16026a36c in scm_deval ()
#11 0x16026cd4c in scm_dapply ()
#12 0x1602618c8 in scm_apply ()
#13 0x1602612b0 in scm_call_0 ()
#14 0x16024caf8 in scm_dynamic_wind ()
#15 0x16026b758 in scm_deval ()
#16 0x160265478 in scm_deval ()
#17 0x16026cd4c in scm_dapply ()
#18 0x1602618c8 in scm_apply ()
#19 0x1602612b0 in scm_call_0 ()
#20 0x16024caf8 in scm_dynamic_wind ()
#21 0x16026b758 in scm_deval ()
#22 0x160265478 in scm_deval ()
#23 0x160266b28 in scm_deval ()
#24 0x160265478 in scm_deval ()
#25 0x16026698c in scm_deval ()
#26 0x16026698c in scm_deval ()
#27 0x16026cd4c in scm_dapply ()
#28 0x1602618c8 in scm_apply ()
#29 0x160263054 in scm_for_each ()
#30 0x16026afc8 in scm_deval ()
#31 0x160263b5c in scm_i_eval ()
#32 0x160263d20 in scm_primitive_eval ()
#33 0x16026a36c in scm_deval ()
#34 0x160263b5c in scm_i_eval ()
#35 0x16024ab08 in scm_start_stack ()
#36 0x16024ace8 in scm_m_start_stack ()
#37 0x16026c2d4 in scm_dapply ()
#38 0x16026937c in scm_deval ()
#39 0x16026698c in scm_deval ()
#40 0x16026cd4c in scm_dapply ()
#41 0x160269094 in scm_deval ()
#42 0x160269ed8 in scm_deval ()
#43 0x16026cc1c in scm_dapply ()
- ---Type <return> to continue, or q <return> to quit---
#44 0x1602618c8 in scm_apply ()
#45 0x1602612b0 in scm_call_0 ()
#46 0x160249bd0 in with_traps_inner ()
#47 0x16024cd34 in scm_internal_dynamic_wind ()
#48 0x160249c84 in scm_with_traps ()
#49 0x16026a36c in scm_deval ()
#50 0x16026cd4c in scm_dapply ()
#51 0x1602618c8 in scm_apply ()
#52 0x1602612b0 in scm_call_0 ()
#53 0x16024caf8 in scm_dynamic_wind ()
#54 0x16026b758 in scm_deval ()
#55 0x16026cd4c in scm_dapply ()
#56 0x1602618c8 in scm_apply ()
#57 0x1602612b0 in scm_call_0 ()
#58 0x1602dfbd4 in scm_body_thunk ()
#59 0x1602df914 in scm_internal_lazy_catch ()
#60 0x1602e03a8 in scm_lazy_catch ()
#61 0x16026b758 in scm_deval ()
#62 0x16026cd4c in scm_dapply ()
#63 0x1602618c8 in scm_apply ()
#64 0x1602612b0 in scm_call_0 ()
#65 0x1602dfbd4 in scm_body_thunk ()
#66 0x1602df5f8 in scm_internal_catch ()
#67 0x1602e02c8 in scm_catch ()
#68 0x16026b758 in scm_deval ()
#69 0x16026698c in scm_deval ()
#70 0x16026698c in scm_deval ()
#71 0x16026698c in scm_deval ()
#72 0x16026cd4c in scm_dapply ()
#73 0x1602618c8 in scm_apply ()
#74 0x1602612b0 in scm_call_0 ()
#75 0x16024caf8 in scm_dynamic_wind ()
#76 0x160260b24 in scm_ceval ()
#77 0x160263a80 in scm_i_eval_x ()
#78 0x160263c40 in scm_primitive_eval_x ()
#79 0x160263e88 in inner_eval_x ()
#80 0x16024cd34 in scm_internal_dynamic_wind ()
#81 0x160263f68 in scm_eval_x ()
#82 0x1602c9d7c in scm_shell ()
#83 0x12000123c in inner_main ()
#84 0x160290cd0 in invoke_main_func ()
#85 0x160290c20 in scm_boot_guile_1 ()
#86 0x1602904a0 in scm_boot_guile ()
#87 0x1200012b8 in main ()

(continue over lots of calls)
pid 22548 (guile): unaligned access: va=0x16010433c pc=0x160104398 ra=0x1609348f8 op=ldq

(gdb) i fr
warning: Hit heuristic-fence-post without finding
warning: enclosing function for address 0x1609348f8
This warning occurs if you are debugging a function without any symbols
(for example, in a stripped executable).  In that case, you may wish to
increase the size of the search with the `set heuristic-fence-post' command.

Otherwise, you told GDB there was a function where there isn't one, or
(more likely) you have encountered a bug in GDB.
Stack level 0, frame at 0x1ffffc338:
 pc = 0x16010439c in _rtld_bind_start
    (/home/gdt/QUIST-current/netbsd/src/libexec/ld.elf_so/arch/alpha/rtld_start.S:150); saved pc 0x1609348f8
 source language asm.
 Arglist at 0x1ffffc308, args: 
 Locals at 0x1ffffc338, Previous frame's sp is 0x1ffffc338
(gdb) step

Program received signal SIGSEGV, Segmentation fault.
0x16010616c in _rtld_bind ()
Current language:  auto; currently c

Dump of assembler code for function _rtld_bind:
0x160106160 <_rtld_bind>:       ldah    gp,17(t12)
0x160106164 <_rtld_bind+4>:     lda     gp,-1888(gp)
0x160106168 <_rtld_bind+8>:     subq    sp,0x30,sp
0x16010616c <_rtld_bind+12>:    stq     ra,0(sp)
0x160106170 <_rtld_bind+16>:    ldq     t0,144(a0)
0x160106174 <_rtld_bind+20>:    beq     t0,0x160106194 <_rtld_bind+52>
0x160106178 <_rtld_bind+24>:    addq    t0,a1,t0
0x16010617c <_rtld_bind+28>:    addq    sp,0x10,a1
0x160106180 <_rtld_bind+32>:    ldq     t1,8(t0)
0x160106184 <_rtld_bind+36>:    stq     t1,24(sp)
0x160106188 <_rtld_bind+40>:    ldq     t2,0(t0)
0x16010618c <_rtld_bind+44>:    stq     t2,16(sp)
0x160106190 <_rtld_bind+48>:    br      0x16010619c <_rtld_bind+60>
0x160106194 <_rtld_bind+52>:    ldq     t0,160(a0)
0x160106198 <_rtld_bind+56>:    addq    t0,a1,a1
0x16010619c <_rtld_bind+60>:    addq    sp,0x28,a2
0x1601061a0 <_rtld_bind+64>:    mov     0x1,a3
0x1601061a4 <_rtld_bind+68>:    mov     0x1,a4
0x1601061a8 <_rtld_bind+72>:    ldq     t12,-32448(gp)
0x1601061ac <_rtld_bind+76>:    
    jsr ra,(t12),0x160106040 <_rtld_relocate_plt_object>
0x1601061b0 <_rtld_bind+80>:    ldah    gp,17(ra)

(gdb) i reg
v0             0x0      0
t0             0x160104390      5906645904
t1             0xffffffffffffffff       -1
t2             0x160b4f2b0      5917438640
t3             0x1601053e0      5906650080
t4             0x160105340      5906649920
t5             0x1601057c0      5906651072
t6             0x160105400      5906650112
t7             0x160b50960      5917444448
s0             0x160112c00      5906705408
s1             0xffffffffffffffff       -1
s2             0x101    257
s3             0x160112a08      5906704904
s4             0x16020e9a0      5907736992
s5             0x0      0
fp             0x1ffffc4f0      8589919472
a0             0xb43e0010b41e0008       -5458925626585120760
a1             0x18     24
a2             0x0      0
a3             0x0      0
a4             0x1      1
a5             0x0      0
t8             0x10     16
- ---Type <return> to continue, or q <return> to quit--- 
t9             0x160106744      5906655044
t10            0x51f    1311
t11            0x107    263
ra             0x1601043a8      5906645928
t12            0x160106160      5906653536
at             0x18     24
gp             0x160215a00      5907765760
sp             0x1ffffc308      8589918984
zero           0x0      0
pc             0x16010616c      5906653548
vfp            0x1ffffc338      8589919032



The .la file is appended.

# libguilereadline.la - a libtool library file
# Generated by ltmain.sh - GNU libtool 1.4.2a (1.922.2.79 2001/11/28 21:50:31)
#
# Please DO NOT delete this file!
# It is necessary for linking the library.

# The name that we can dlopen(3).
dlname='libguilereadline.so.15'

# Names of this library.
library_names='libguilereadline.so.15.0 libguilereadline.so.15 libguilereadline.so libguilereadline.so'

# The name of the static archive.
old_library='libguilereadline.a'

# Libraries that this one depends upon.
dependency_libs=' -L/usr/pkg/lib /home/gdt/QUIST-current/guile/libguile/libguile.la /usr/pkg/lib/libltdl.la -lcrypt -lm -lcurses '

# Version information for libguilereadline.
current=15
age=1
revision=0

# Is this an already installed library?
installed=no

# Files to dlopen/dlpreopen
dlopen=''
dlpreopen=''

# Directory that this library needs to be installed in:
libdir='/usr/quist/lib'
relink_command="(cd /home/gdt/QUIST-current/guile/guile-readline; /bin/sh ./libtool --mode=relink gcc -I/usr/pkg/include -L/usr/pkg/lib -o libguilereadline.la -rpath /usr/quist/lib -version-info 15:0:1 -export-dynamic -no-undefined readline.lo ../libguile/libguile.la -lcurses)"

------- End of Forwarded Message