From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5469 invoked by alias); 15 Feb 2011 09:50:34 -0000 Received: (qmail 5460 invoked by uid 22791); 15 Feb 2011 09:50:33 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,TW_CP,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: sourceware.org Received: from mailout-de.gmx.net (HELO mailout-de.gmx.net) (213.165.64.23) by sourceware.org (qpsmtpd/0.43rc1) with SMTP; Tue, 15 Feb 2011 09:50:28 +0000 Received: (qmail invoked by alias); 15 Feb 2011 09:50:24 -0000 Received: from LN-mac29.grenoble.cnrs.fr (EHLO axel) [147.173.67.29] by mail.gmx.net (mp065) with SMTP; 15 Feb 2011 10:50:24 +0100 Date: Tue, 15 Feb 2011 10:28:00 -0000 From: Axel Freyn To: gcc-help@gcc.gnu.org Subject: Re: -nostdlib option! Message-ID: <20110215095023.GP22738@axel> Mail-Followup-To: gcc-help@gcc.gnu.org References: <4D59BEDC.9000606@yahoo.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.5.18 (2008-05-17) X-IsSubscribed: yes Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org X-SW-Source: 2011-02/txt/msg00212.txt.bz2 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 " does not solve the problem, just removes the warning. Axel > > > On 2/15/11, Patrick Horgan 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 > *(ptr+ctr)=(char)c; > > } > > return s; > > } > > > > > >