From: Axel Freyn <axel-freyn@gmx.de>
To: gcc-help@gcc.gnu.org
Subject: Re: -nostdlib option!
Date: Tue, 15 Feb 2011 10:28:00 -0000 [thread overview]
Message-ID: <20110215095023.GP22738@axel> (raw)
In-Reply-To: <AANLkTik1WwZ7WnCesfvz9y06+4kOo153J1OnvMxuwhz=@mail.gmail.com>
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:
~> gcc -nostdlib nostdlib.c
nano-th2 ~ $ gcc -nostdlib nostdlib.c
nostdlib.c: In function âmainâ:
nostdlib.c:2: warning: incompatible implicit declaration of built-in function âmallocâ
nostdlib.c:3: warning: incompatible implicit declaration of built-in function âfreeâ
/usr/bin/ld: warning: cannot find entry symbol _start; defaulting to 00000000004000e8
/tmp/cckDrpxw.o: In function `main':
nostdlib.c:(.text+0xe): undefined reference to `malloc'
nostdlib.c:(.text+0x1b): undefined reference to `free'
collect2: ld returned 1 exit status
Adding "#include <stdlib.h>" does not solve the problem, just removes
the warning.
Axel
>
>
> On 2/15/11, Patrick Horgan <phorgan1@yahoo.com> wrote:
> > On 02/07/2011 04:44 AM, ali hagigat wrote:
> >> Thank you Manuel.
> >> How will be memset, memcpy, etc. Can i copy them from the source code
> >> of gcc? But they are dependent to other functions in other libraries
> >> probably and some headers.
> >> Are those functions available stand alone some where?
> >>
> >>
> >> On Mon, Feb 7, 2011 at 2:51 PM, Manuel Coutinho
> >>> Hi
> >>>
> >>> Other mechanism: supply your own memset, memcpy, etc.
> >>> If you do this, the linker will know which memset, memcpy, etc to use and
> >>> will not complaint about not using libc.
> >>>
> >>> Regards
> >>> Manuel Coutinho
> >>>
> > you would just write your own copies of these methods. These are very
> > simple functions any beginning computer science student could write in a
> > few minutes. For example:
> >
> > void *memset(void *s, int c, size_t n)
> > {
> > size_t ctr;
> > char *ptr=s;
> > for(ctr=0;ctr<n;ctr++){
> > *(ptr+ctr)=(char)c;
> > }
> > return s;
> > }
> >
> >
> >
next prev parent reply other threads:[~2011-02-15 9:50 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-02-07 11:18 ali hagigat
2011-02-07 11:21 ` Drasko DRASKOVIC
2011-02-07 12:44 ` Manuel Coutinho
2011-02-07 14:43 ` ali hagigat
2011-02-07 15:22 ` Kai Ruottu
2011-02-07 16:20 ` Manuel Coutinho
2011-02-07 16:48 ` Drasko DRASKOVIC
2011-02-07 17:57 ` Manuel Coutinho
[not found] ` <4D59BEDC.9000606@yahoo.com>
2011-02-15 9:50 ` ali hagigat
2011-02-15 10:28 ` Axel Freyn [this message]
2011-02-15 12:13 ` Jonathan Wakely
2011-02-16 10:05 ` Axel Freyn
2011-02-15 14:56 ` Thomas Martitz
2011-02-15 15:52 ` Ian Lance Taylor
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20110215095023.GP22738@axel \
--to=axel-freyn@gmx.de \
--cc=gcc-help@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).