undefined reference to `memset'

Bruce Evans bde at zeta.org.au
Thu Mar 24 18:28:27 PST 2005


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


More information about the freebsd-stable mailing list