Date: Fri, 25 Mar 2005 09:46:02 +1100 From: Peter Jeremy <PeterJeremy@optushome.com.au> To: Vinod Kashyap <vkashyap@amcc.com> Cc: freebsd-amd64@freebsd.org Subject: Re: undefined reference to `memset' Message-ID: <20050324224602.GC43123@cirb503493.alcatel.com.au> In-Reply-To: <IDVH3802.ESF@hadar.amcc.com> References: <IDVH3802.ESF@hadar.amcc.com>
next in thread | previous in thread | raw e-mail | index | archive | help
On Thu, 2005-Mar-24 12:03:19 -0800, Vinod Kashyap wrote: [ char x[100] = { 0 }; ] >A statement like this (auto and not static) I'd point out that this is the first time that you've mentioned that the variable is auto. Leaving out critical information will not encourage people to help you. > is necessary if you >are dealing with re-entrancy. This isn't completely true. The preferred approach is: char *x; x = malloc(100, MEM_POOL_xxx, M_ZERO | M_WAITOK); (with a matching free() later). > Whatever the issues with wastage or >bad performance, a programmer should definitely be able to do it, >if he so desires. Again, untrue. The FreeBSD kernel is not a standard C environment. Kernel stack is a relatively small, fixed size and using excessive kernel stack will lead to panics. Increasing the kernel stack size is undesirable because it's expensive in RAM consumption. >How is it then, that an explicit call to memset (like in my example) works? The code auto char x[100] = {0}; is equivalent to auto char x[100]; memset(x, 0, sizeof(x)); but memset only exists as a static inline function (defined in libkern.h). If an explicit call to memset works then the problem would appear to be that the compiler's implicit expansion is failing to detect the static inline definition, and generating an external reference which can't be satisfied. This would seem to be a gcc bug. >2. I should have mentioned that I don't see the problem if I am > building only the kernel module. It happens only when I am building > the kernel integrating the module containing the example code. This is the opposite of what you implied previously. There are some differences in how kernel modules are built so this How about posting a (short) compilable piece of C code that shows the problem. I would expect that an "nm" of the resultant object would show "U memset" when the code was compiled for linking into the kernel and "<some_address> t memset" or not reference memset at all when compiled as a module. -- Peter Jeremy
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20050324224602.GC43123>