Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 25 Mar 2005 13:28:13 +1100 (EST)
From:      Bruce Evans <bde@zeta.org.au>
To:        Nick Barnes <Nick.Barnes@pobox.com>
Cc:        freebsd-amd64@freebsd.org
Subject:   Re: undefined reference to `memset' 
Message-ID:  <20050325131358.T215@delplex.bde.org>
In-Reply-To: <90609.1111660565@thrush.ravenbrook.com>
References:  <90609.1111660565@thrush.ravenbrook.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Thu, 24 Mar 2005, Nick Barnes wrote:

> At 2005-03-24 08:31:14+0000, Bruce Evans writes:
>
>> what is gcc to do when -fno-builtin tells it to turn off its
>> builtins and -ffreestanding tells it that the relevant interfaces
>> might not exist in the library?
>
> Plainly, GCC should generate code which fills the array with zeroes.
> It's not obliged to generate code which calls memset (either builtin
> or in a library).  If it knows that it can do so, then fine.
> Otherwise it must do it the Old Fashioned Way.  So this is surely a
> bug in GCC.
>
> Nick B, who used to write compilers for a living

But the compiler can require the Old Fashioned Way to be in the library.

libgcc.a is probably part of gcc even in the freestanding case.  The
current implementation of libgcc.a won't all work in the freestanding
case, since parts of it call stdio, but some parts of it are needed
and work (e.g., __divdi3() on i386's at least).  The kernel doesn't
use libgcc.a, but it knows that __divdi3() and friends are needed and
implements them in its libkern.  Strictly, it should do something
similar for memset().

I think the only bugs in gcc here are that the function it calls is
in the application namespace in the freestanding case, and that the
requirements for freestanding implementations are not all documented.
The requirement for memset() and friends _is_ documented (in gcc.info),
but the requirement for __divdi3() and friends are only documented
indirectly by the presence of these functions in libgcc.a.

Bruce



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20050325131358.T215>