-nostdlib option!
Jonathan Wakely
jwakely.gcc@gmail.com
Tue Feb 15 12:13:00 GMT 2011
On 15 February 2011 09:50, Axel Freyn wrote:
> Hi Ali,
> On Tue, Feb 15, 2011 at 11:06:08AM +0330, ali hagigat wrote:
>> I am compiling my C programs with -nostdlib option without providing
>> mem functions like memcpy and GNU tool chain has not complained so
>> far(gcc 4.4.2, Fedora 12). Is that natural? I have defined char
>> pointers, nested functions and no error so far. I wonder if anybody
>> can write a simple C program and compile it with -nostdlib so that the
>> compiler needs one of mem functions and the compiler stops with an
>> error.
> try the program:
> int main(){
> char *c = (char*) malloc(10*sizeof(char));
> free(c);
> }
> On my machine (gcc-4.3.2), this compiles fine without the switch (just
> warning about the missing header file):
> ~> gcc nostdlib.c
> nostdlib.c: In function ‘main’:
> nostdlib.c:2: warning: incompatible implicit declaration of built-in function ‘malloc’
>
> and with "-nostdlib", it gives the link error as expected:
I think you've missed the point - obviously if you call a stdlib
function it will be required.
Ali is asking about the case where the compiler generates calls to
stdlib functions which do not appear explicitly in the code. See the
docs for -nostdlib in the manual.
-nostdlib
Do not use the standard system startup files or libraries when
linking. No startup files and only the libraries you specify will
be passed to the linker. The compiler may generate calls to "mem-
cmp", "memset", "memcpy" and "memmove". These entries are usually
resolved by entries in libc. These entry points should be supplied
through some other mechanism when this option is specified.
More information about the Gcc-help
mailing list