Subject: Re: gethostbyname seg-fault when compiled with cross/i386-linux
To: None <>
From: Alicia da Conceicao <>
List: tech-net
Date: 02/26/2004 08:11:23
Alicia da Conceicao wrote:
> I recently installed "cross/i386-linux" and have used it to successfully
> cross-compile numerous linux binary applications with NetBSD.
> However, wheneven I run any application that calls "gethostbyname", the
> linux binary crashes with a segmentation fault.  Statically linking
> "/usr/pkg/cross/ix86-linux/lib/libresolv.a" does not help and the binary
> still gets the seg-fault.
> But when I compile the exact same code on a SuSE linux machine, the binary
> is able to successfully call gethostbyname, and does not crash.

Just as a follow up.  I copied "/usr/lib" from my SuSE linux machine and
put it "/usr/pkg/cross/i386-linux/lib" onto my Linux machine.  Now I can
successfully compile working linux binaries with gethostbyname, and long
as libc is dynamically linked.  Strange thing though, when I link with
"i386-linux-gcc" or "i386-linux-ld" with the "-static" option, the
resulting Linux binaries always crash with a segmentation fault, even a
simply "hello world" application.

But when I restored "/usr/pkg/cross/i386-linux/lib" back to the original
that was created from pkgsrc, I was able to make static linux binaries
using the "-static" option that work as long as the binaries don't call
gethostbyname.  Statically link Linux binaries built using cross/i386-linux
don't SEG-FAULT when gethostbyname is called like they do when libc is
dynamically linked, but instead gethostbyname just returns a NULL pointer.

> Any suggestions on how to fix or work around this?

My goal is to be able to cross compile, under NetBSD, working statically
linked linux binaries that can successfully call gethostbyname.  Fixes
or work arounds to do this are greatly appreciated.

Thanks in advance.