Subject: lib/5731: User application gets SEGV when linked with libc
To: None <>
From: The Terminator rAT <>
List: netbsd-bugs
Date: 07/09/1998 15:21:12
>Number:         5731
>Category:       lib
>Synopsis:       User application gets SEGV when linked with libc
>Confidential:   yes
>Severity:       serious
>Priority:       medium
>Responsible:    lib-bug-people (Library Bug People)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Jul  9 15:35:01 1998
>Originator:     The Terminator rAT
NAS Facility, NASA Ames Research Center
>Release:        <NetBSD-current source date> NetBSD-1.3.2/i386 from CD
System: NetBSD nosferatu 1.3.2 NetBSD 1.3.2 (NOSFERATU) #2: Thu Jun 25 16:58:32 PDT 1998 root@nosferatu:/usr/src/sys/arch/i386/compile/NOSFERATU i386

Machine was installed from NetBSD-1.3.2 CD, only kernel custom.


Helping port an application which  dumps core on NetBSD-1.3.2/i386 (in 
gethostbyname2()) when linked with libc ctype's, but works when linked 
statically against a .o generated from the library sources.

Linked against /usr/lib/ 

    rat@nosferatu ~/work/pbsdedtime 1098% gcc  -o pbsdedtime misc.o net_utils.o pbsdedtime.o

    rat@nosferatu ~/work/pbsdedtime 1099% ./pbsdedtime hopper
    Segmentation fault (core dumped)

    rat@nosferatu ~/work/pbsdedtime 1100% gdb ./pbsdedtime ./pbsdedtime.core
    GDB is free software and you are welcome to distribute copies of it
     under certain conditions; type "show copying" to see the conditions.
    There is absolutely no warranty for GDB; type "show warranty" for details.
    GDB 4.16 (i386-netbsd), Copyright 1996 Free Software Foundation, Inc...
    Core was generated by `pbsdedtime'.
    Program terminated with signal 11, Segmentation fault.
    Reading symbols from /usr/libexec/
    Reading symbols from /usr/lib/
    #0  0x4003059b in gethostbyname2 ()
    (gdb) where
    #0  0x4003059b in gethostbyname2 ()
    #1  0x400304a7 in gethostbyname ()
    #2  0x1b87 in getHostAddress (HostName=0xefbfd1b4 "",
        buffer=0xefbfcf78 "") at net_utils.c:100
    #3  0x1cd2 in openTcpClientSocket (HostName=0xefbfd1b4 "",
        ServiceName=0xefbfd194 "schedule", SockOptions=0x0) at net_utils.c:131
    #4  0x24e1 in main (argc=1, argv=0xefbfd4ec) at pbsdedtime.c:203
    (gdb) quit 

    rat@nosferatu ~/work/pbsdedtime 1101% ldd pbsdedtime
            -lc.12 => /usr/lib/ (0x4001d000)

But, if one links it with ctype built from the library sources, it works:

    rat@nosferatu ~/work/pbsdedtime 1102% gcc -g -Wall -I/usr/src/lib/libc/include  -c /usr/src/lib/libc/gen/ctype_.c
    rat@nosferatu ~/work/pbsdedtime 1105% gcc  -o pbsdedtime misc.o net_utils.o pbsdedtime.o ctype_.o

    rat@nosferatu ~/work/pbsdedtime 1106% ./pbsdedtime hopper
	HOPPER       07/09/1998 16:00-19:00 07/09/1998  PBS Scheduler dev/test.
    rat@nosferatu ~/work/pbsdedtime 1107%


    I don't know.  The code which exhibits the error is available at :


    Short-term, explicitly link with the ctype_.o created from the library
    sources (/usr/src/lib/libc/gen/ctype_.c).
Application catches SEGV in gethostbyname2() if linked with libc ctype object.