* -nostdlib option! @ 2011-02-07 11:18 ali hagigat 2011-02-07 11:21 ` Drasko DRASKOVIC 2011-02-07 12:44 ` Manuel Coutinho 0 siblings, 2 replies; 14+ messages in thread From: ali hagigat @ 2011-02-07 11:18 UTC (permalink / raw) To: gcc-help I have copied part of gcc manual: ------------------------------------ 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 "memcmp", "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. ------------------------------------ What is some other mechanism? How can i use -nostdlib? ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: -nostdlib option! 2011-02-07 11:18 -nostdlib option! ali hagigat @ 2011-02-07 11:21 ` Drasko DRASKOVIC 2011-02-07 12:44 ` Manuel Coutinho 1 sibling, 0 replies; 14+ messages in thread From: Drasko DRASKOVIC @ 2011-02-07 11:21 UTC (permalink / raw) To: ali hagigat; +Cc: gcc-help On Mon, Feb 7, 2011 at 12:03 PM, ali hagigat <hagigatali@gmail.com> wrote: > I have copied part of gcc manual: > ------------------------------------ > 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 "memcmp", > "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. > ------------------------------------ > What is some other mechanism? How can i use -nostdlib? You posted the answer to your question already. BR, Drasko ^ permalink raw reply [flat|nested] 14+ messages in thread
* RE: -nostdlib option! 2011-02-07 11:18 -nostdlib option! ali hagigat 2011-02-07 11:21 ` Drasko DRASKOVIC @ 2011-02-07 12:44 ` Manuel Coutinho 2011-02-07 14:43 ` ali hagigat 1 sibling, 1 reply; 14+ messages in thread From: Manuel Coutinho @ 2011-02-07 12:44 UTC (permalink / raw) To: 'ali hagigat', gcc-help 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 -----Original Message----- From: gcc-help-owner@gcc.gnu.org [mailto:gcc-help-owner@gcc.gnu.org] On Behalf Of ali hagigat Sent: 07 February 2011 11:04 To: gcc-help@gcc.gnu.org Subject: -nostdlib option! I have copied part of gcc manual: ------------------------------------ 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 "memcmp", "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. ------------------------------------ What is some other mechanism? How can i use -nostdlib? ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: -nostdlib option! 2011-02-07 12:44 ` Manuel Coutinho @ 2011-02-07 14:43 ` ali hagigat 2011-02-07 15:22 ` Kai Ruottu [not found] ` <4D59BEDC.9000606@yahoo.com> 0 siblings, 2 replies; 14+ messages in thread From: ali hagigat @ 2011-02-07 14:43 UTC (permalink / raw) To: Manuel Coutinho, gcc-help, drasko.draskovic 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 > ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: -nostdlib option! 2011-02-07 14:43 ` ali hagigat @ 2011-02-07 15:22 ` Kai Ruottu 2011-02-07 16:20 ` Manuel Coutinho [not found] ` <4D59BEDC.9000606@yahoo.com> 1 sibling, 1 reply; 14+ messages in thread From: Kai Ruottu @ 2011-02-07 15:22 UTC (permalink / raw) To: gcc-help; +Cc: ali hagigat 7.2.2011 14:44, ali hagigat kirjoitti: > 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. Most probably these functions are standalone and don't call other functions... Does your program really call them? What does 'nm' say anout undefined symbols in the compiled object(s)? > Are those functions available stand alone some where? For instance in : newlib-1.18.0/newlib/libc/machine/i386 in the current newlib sources. ^ permalink raw reply [flat|nested] 14+ messages in thread
* RE: -nostdlib option! 2011-02-07 15:22 ` Kai Ruottu @ 2011-02-07 16:20 ` Manuel Coutinho 2011-02-07 16:48 ` Drasko DRASKOVIC 0 siblings, 1 reply; 14+ messages in thread From: Manuel Coutinho @ 2011-02-07 16:20 UTC (permalink / raw) To: 'Kai Ruottu', gcc-help; +Cc: 'ali hagigat' Yes. Memset and memcpy are standalone functions. My team (at Edisoft) has a version for these files. For memcpy we have the file: /** * @brief check if either of the addresses are aligned * * Nonzero if either X or Y is not aligned on a "long" boundary. */ #define UNALIGNED(X, Y) \ (((uint32)X & (sizeof (uint32) - 1U)) | ((uint32)Y & (sizeof (uint32) - 1U))) /** * @brief determine how many bytes are copied each iteration of the 4X unrolled * loop */ #define BIGBLOCKSIZE ((uint32)sizeof (sint32) << 2U) /** * @brief determine how many bytes are copied each iteration of the word copy * loop */ #define LITTLEBLOCKSIZE ((uint32)sizeof (sint32)) /** * @brief Threshhold for punting to the byte copier */ #define TOO_SMALL(LEN) ((LEN) < BIGBLOCKSIZE) void *memcpy(void *dst0 , const void *src0 , rtems_size len0) { #if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__) /* get destination address as a byte pointer */ sint8 *dst = (sint8 *) dst0; /* get source address as a byte pointer */ sint8 *src = (const sint8 *) src0; /* save the destination address */ void * save = dst0; /* copy the source vector to destination for len0 bytes*/ while(len0--) { /* copy the source to the destination */ *dst++ = *src++; } /* return the saved destination address */ return save; #else /* get destination address as a byte pointer */ sint8 *dst = (sint8 *) dst0; /* get source address as a byte pointer */ const sint8 *src = src0; /* alligned destination pointer */ sint32 *aligned_dst; /* aligned source pointer */ const sint32 *aligned_src; /* lenght in integer */ uint32 len = (uint32) len0; /* If the size is small, or either SRC or DST is unaligned, * then punt into the byte copy loop. This should be rare. */ if(( ( TOO_SMALL(len) ) == 0U ) && ( ( UNALIGNED((uint32) src0 , (uint32) dst0) ) == FALSE )) { /* get the destination */ aligned_dst = (sint32*) dst; /* get the source */ aligned_src = (sint32*) src; /* Copy 4X long words at a time if possible. */ while(len >= BIGBLOCKSIZE) { /* copy the first 4 bytes */ *aligned_dst = *aligned_src; aligned_dst++; aligned_src++; /* copy the second 4 bytes */ *aligned_dst = *aligned_src; aligned_dst++; aligned_src++; /* copy the third 4 bytes */ *aligned_dst = *aligned_src; aligned_dst++; aligned_src++; /* copy the fourth 4 bytes */ *aligned_dst = *aligned_src; aligned_dst++; aligned_src++; /* decrement the number of bytes left to copy */ len -= BIGBLOCKSIZE; } /* Copy one long word at a time if possible. */ while(len >= LITTLEBLOCKSIZE) { /* copy 4 bytes */ *aligned_dst = *aligned_src; aligned_dst++; aligned_src++; /* decrement the number of bytes left to copy */ len -= LITTLEBLOCKSIZE; } /* Pick up any residual with a byte copier. */ dst = (sint8*) aligned_dst; src = (sint8*) aligned_src; } /* copy residual bytes (maximum of 3) */ while(len > 0U) { /* copy each byte */ *dst = *src; /* increment the pointer */ dst++; src++; /* decrement number of bytes */ len--; } /* return the destination address */ return dst0; #endif /* not PREFER_SIZE_OVER_SPEED */ } For the file memset.c we have the file: /** * @brief size of a block */ #define LBLOCKSIZE ((uint32) sizeof(uintptr)) /** * @brief check if the address is alligned */ #define UNALIGNED(X) ((uintptr)X & (LBLOCKSIZE - 1)) /** * @brief check if the size is too small */ #define TOO_SMALL(LEN) ((LEN) < LBLOCKSIZE) void *memset(void *m , sint32 c , rtems_size n) { #if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__) /* copy the destination address to another variable */ sint8 *s = (sint8 *) m; /* while there are bytes left to copy */ while(n != 0) { /* copy the byte */ *s = (sint8) c; /* increment index on array */ s++; /* decrement number of remaining bytes to copy */ n--; } /* return the destination address */ return m; #else /* pointer to address where to write */ sint8 *s = (sint8 *) m; /* iterator */ uint32 i; /* buffer where to place small array */ uint32 buffer; /* pointer to address aligned */ uintptr *aligned_addr; /* To avoid sign extension, copy c to an unsigned variable. */ uint32 d = (uint32) c & 0xffU; /* check if the size is too small or the destination address in not aligned */ if(( TOO_SMALL(n) == 0U ) && ( UNALIGNED(m) == 0U )) { /* If we get this far, we know that n is large and m is word-aligned. */ aligned_addr = (uint32*) m; /* Store D into each char sized location in BUFFER so that we can set large blocks quickly. */ if(LBLOCKSIZE == 4U) { /* copy to the buffer */ buffer = (uint32) ( ( d << 8U ) | d ); buffer = buffer | ( buffer << 16U ); } else { /* reset the buffer */ buffer = 0U; /* copy to the buffer the char */ for(i = 0U; i < LBLOCKSIZE; i++) { buffer = ( buffer << 8U ) | d; } } /* copy the aligned bytes */ while(n >= LBLOCKSIZE * 4U) { /* copy the first four byte word */ *aligned_addr = buffer; aligned_addr++; /* copy the second four byte word */ *aligned_addr = buffer; aligned_addr++; /* copy the third four byte word */ *aligned_addr = buffer; aligned_addr++; /* copy the fourth four byte word */ *aligned_addr = buffer; aligned_addr++; /* decrement the number of bytes copied */ n -= (rtems_size) ( 4U * LBLOCKSIZE ); } /* copy the remaining bytes */ while(n >= LBLOCKSIZE) { /* copy the first four byte word */ *aligned_addr = buffer; aligned_addr++; /* decrement the number of bytes copied */ n -= LBLOCKSIZE; } /* Pick up the remainder with a bytewise loop. */ s = (sint8*) aligned_addr; } /* copy the remaining bytes */ while(n > 0U) { /* copy the byte */ *s = (sint8) d; s++; /* decrement size */ n--; } /* return the destination address */ return m; #endif /* not PREFER_SIZE_OVER_SPEED */ } Hope this help ;) Manuel Coutinho -----Original Message----- From: gcc-help-owner@gcc.gnu.org [mailto:gcc-help-owner@gcc.gnu.org] On Behalf Of Kai Ruottu Sent: 07 February 2011 14:43 To: gcc-help@gcc.gnu.org Cc: ali hagigat Subject: Re: -nostdlib option! 7.2.2011 14:44, ali hagigat kirjoitti: > 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. Most probably these functions are standalone and don't call other functions... Does your program really call them? What does 'nm' say anout undefined symbols in the compiled object(s)? > Are those functions available stand alone some where? For instance in : newlib-1.18.0/newlib/libc/machine/i386 in the current newlib sources. ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: -nostdlib option! 2011-02-07 16:20 ` Manuel Coutinho @ 2011-02-07 16:48 ` Drasko DRASKOVIC 2011-02-07 17:57 ` Manuel Coutinho 0 siblings, 1 reply; 14+ messages in thread From: Drasko DRASKOVIC @ 2011-02-07 16:48 UTC (permalink / raw) To: Manuel Coutinho; +Cc: Kai Ruottu, gcc-help, ali hagigat I hope that you are not pasting NDA covered SW to this list. BR, Drasko On Mon, Feb 7, 2011 at 5:10 PM, Manuel Coutinho <manuel.coutinho@edisoft.pt> wrote: > Yes. > > Memset and memcpy are standalone functions. My team (at Edisoft) has a > version for these files. > > For memcpy we have the file: > > /** > * @brief check if either of the addresses are aligned > * > * Nonzero if either X or Y is not aligned on a "long" boundary. > */ > #define UNALIGNED(X, Y) \ > (((uint32)X & (sizeof (uint32) - 1U)) | ((uint32)Y & (sizeof (uint32) - > 1U))) > > /** > * @brief determine how many bytes are copied each iteration of the 4X > unrolled > * loop > */ > #define BIGBLOCKSIZE ((uint32)sizeof (sint32) << 2U) > > /** > * @brief determine how many bytes are copied each iteration of the word > copy > * loop > */ > #define LITTLEBLOCKSIZE ((uint32)sizeof (sint32)) > > /** > * @brief Threshhold for punting to the byte copier */ #define > TOO_SMALL(LEN) ((LEN) < BIGBLOCKSIZE) > > > void *memcpy(void *dst0 , const void *src0 , rtems_size len0) { > > #if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__) > > /* get destination address as a byte pointer */ > sint8 *dst = (sint8 *) dst0; > > /* get source address as a byte pointer */ > sint8 *src = (const sint8 *) src0; > > > /* save the destination address */ > void * save = dst0; > > /* copy the source vector to destination for len0 bytes*/ > while(len0--) > { > /* copy the source to the destination */ > *dst++ = *src++; > } > > /* return the saved destination address */ > return save; > > #else > > /* get destination address as a byte pointer */ > sint8 *dst = (sint8 *) dst0; > > /* get source address as a byte pointer */ > const sint8 *src = src0; > > /* alligned destination pointer */ > sint32 *aligned_dst; > > /* aligned source pointer */ > const sint32 *aligned_src; > > /* lenght in integer */ > uint32 len = (uint32) len0; > > > /* If the size is small, or either SRC or DST is unaligned, > * then punt into the byte copy loop. This should be rare. */ > if(( ( TOO_SMALL(len) ) == 0U ) && > ( ( UNALIGNED((uint32) src0 , (uint32) dst0) ) == FALSE )) > { > /* get the destination */ > aligned_dst = (sint32*) dst; > > /* get the source */ > aligned_src = (sint32*) src; > > /* Copy 4X long words at a time if possible. */ > while(len >= BIGBLOCKSIZE) > { > /* copy the first 4 bytes */ > *aligned_dst = *aligned_src; > aligned_dst++; > aligned_src++; > > /* copy the second 4 bytes */ > *aligned_dst = *aligned_src; > aligned_dst++; > aligned_src++; > > /* copy the third 4 bytes */ > *aligned_dst = *aligned_src; > aligned_dst++; > aligned_src++; > > /* copy the fourth 4 bytes */ > *aligned_dst = *aligned_src; > aligned_dst++; > aligned_src++; > > /* decrement the number of bytes left to copy */ > len -= BIGBLOCKSIZE; > } > > /* Copy one long word at a time if possible. */ > while(len >= LITTLEBLOCKSIZE) > { > /* copy 4 bytes */ > *aligned_dst = *aligned_src; > aligned_dst++; > aligned_src++; > > /* decrement the number of bytes left to copy */ > len -= LITTLEBLOCKSIZE; > } > > /* Pick up any residual with a byte copier. */ > dst = (sint8*) aligned_dst; > src = (sint8*) aligned_src; > } > > /* copy residual bytes (maximum of 3) */ > while(len > 0U) > { > /* copy each byte */ > *dst = *src; > > /* increment the pointer */ > dst++; > src++; > > /* decrement number of bytes */ > len--; > } > > /* return the destination address */ > return dst0; > > #endif /* not PREFER_SIZE_OVER_SPEED */ > } > > > > > For the file memset.c we have the file: > > > /** > * @brief size of a block > */ > #define LBLOCKSIZE ((uint32) sizeof(uintptr)) > > /** > * @brief check if the address is alligned */ #define UNALIGNED(X) > ((uintptr)X & (LBLOCKSIZE - 1)) > > /** > * @brief check if the size is too small */ #define TOO_SMALL(LEN) ((LEN) < > LBLOCKSIZE) > > > void *memset(void *m , sint32 c , rtems_size n) { > > #if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__) > > /* copy the destination address to another variable */ > sint8 *s = (sint8 *) m; > > > /* while there are bytes left to copy */ > while(n != 0) > { > /* copy the byte */ > *s = (sint8) c; > > /* increment index on array */ > s++; > > /* decrement number of remaining bytes to copy */ > n--; > } > > /* return the destination address */ > return m; > > #else > > /* pointer to address where to write */ > sint8 *s = (sint8 *) m; > > /* iterator */ > uint32 i; > > /* buffer where to place small array */ > uint32 buffer; > > /* pointer to address aligned */ > uintptr *aligned_addr; > > /* To avoid sign extension, copy c to an unsigned variable. */ > uint32 d = (uint32) c & 0xffU; > > > /* check if the size is too small or the destination address in not > aligned */ > if(( TOO_SMALL(n) == 0U ) && ( UNALIGNED(m) == 0U )) > { > /* If we get this far, we know that n is large and m is > word-aligned. */ > aligned_addr = (uint32*) m; > > /* Store D into each char sized location in BUFFER so that > we can set large blocks quickly. */ > if(LBLOCKSIZE == 4U) > { > /* copy to the buffer */ > buffer = (uint32) ( ( d << 8U ) | d ); > buffer = buffer | ( buffer << 16U ); > } > else > { > /* reset the buffer */ > buffer = 0U; > > /* copy to the buffer the char */ > for(i = 0U; i < LBLOCKSIZE; i++) > { > buffer = ( buffer << 8U ) | d; > } > } > > /* copy the aligned bytes */ > while(n >= LBLOCKSIZE * 4U) > { > /* copy the first four byte word */ > *aligned_addr = buffer; > aligned_addr++; > > /* copy the second four byte word */ > *aligned_addr = buffer; > aligned_addr++; > > /* copy the third four byte word */ > *aligned_addr = buffer; > aligned_addr++; > > /* copy the fourth four byte word */ > *aligned_addr = buffer; > aligned_addr++; > > /* decrement the number of bytes copied */ > n -= (rtems_size) ( 4U * LBLOCKSIZE ); > } > > /* copy the remaining bytes */ > while(n >= LBLOCKSIZE) > { > /* copy the first four byte word */ > *aligned_addr = buffer; > aligned_addr++; > > /* decrement the number of bytes copied */ > n -= LBLOCKSIZE; > } > /* Pick up the remainder with a bytewise loop. */ > s = (sint8*) aligned_addr; > } > > /* copy the remaining bytes */ > while(n > 0U) > { > /* copy the byte */ > *s = (sint8) d; > s++; > /* decrement size */ > n--; > } > > /* return the destination address */ > return m; > > #endif /* not PREFER_SIZE_OVER_SPEED */ > } > > > > > > Hope this help ;) > Manuel Coutinho > > -----Original Message----- > From: gcc-help-owner@gcc.gnu.org [mailto:gcc-help-owner@gcc.gnu.org] On > Behalf Of Kai Ruottu > Sent: 07 February 2011 14:43 > To: gcc-help@gcc.gnu.org > Cc: ali hagigat > Subject: Re: -nostdlib option! > > 7.2.2011 14:44, ali hagigat kirjoitti: > >> 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. > > Most probably these functions are standalone and don't > call other functions... Does your program really call > them? What does 'nm' say anout undefined symbols in the > compiled object(s)? > >> Are those functions available stand alone some where? > > For instance in : > newlib-1.18.0/newlib/libc/machine/i386 > in the current newlib sources. > > > ^ permalink raw reply [flat|nested] 14+ messages in thread
* RE: -nostdlib option! 2011-02-07 16:48 ` Drasko DRASKOVIC @ 2011-02-07 17:57 ` Manuel Coutinho 0 siblings, 0 replies; 14+ messages in thread From: Manuel Coutinho @ 2011-02-07 17:57 UTC (permalink / raw) To: 'Drasko DRASKOVIC' Cc: 'Kai Ruottu', gcc-help, 'ali hagigat' Nope ;) -----Original Message----- From: Drasko DRASKOVIC [mailto:drasko.draskovic@gmail.com] Sent: 07 February 2011 16:21 To: Manuel Coutinho Cc: Kai Ruottu; gcc-help@gcc.gnu.org; ali hagigat Subject: Re: -nostdlib option! I hope that you are not pasting NDA covered SW to this list. BR, Drasko On Mon, Feb 7, 2011 at 5:10 PM, Manuel Coutinho <manuel.coutinho@edisoft.pt> wrote: > Yes. > > Memset and memcpy are standalone functions. My team (at Edisoft) has a > version for these files. > > For memcpy we have the file: > > /** > * @brief check if either of the addresses are aligned > * > * Nonzero if either X or Y is not aligned on a "long" boundary. > */ > #define UNALIGNED(X, Y) \ > (((uint32)X & (sizeof (uint32) - 1U)) | ((uint32)Y & (sizeof (uint32) - > 1U))) > > /** > * @brief determine how many bytes are copied each iteration of the 4X > unrolled > * loop > */ > #define BIGBLOCKSIZE ((uint32)sizeof (sint32) << 2U) > > /** > * @brief determine how many bytes are copied each iteration of the word > copy > * loop > */ > #define LITTLEBLOCKSIZE ((uint32)sizeof (sint32)) > > /** > * @brief Threshhold for punting to the byte copier */ #define > TOO_SMALL(LEN) ((LEN) < BIGBLOCKSIZE) > > > void *memcpy(void *dst0 , const void *src0 , rtems_size len0) { > > #if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__) > > /* get destination address as a byte pointer */ > sint8 *dst = (sint8 *) dst0; > > /* get source address as a byte pointer */ > sint8 *src = (const sint8 *) src0; > > > /* save the destination address */ > void * save = dst0; > > /* copy the source vector to destination for len0 bytes*/ > while(len0--) > { > /* copy the source to the destination */ > *dst++ = *src++; > } > > /* return the saved destination address */ > return save; > > #else > > /* get destination address as a byte pointer */ > sint8 *dst = (sint8 *) dst0; > > /* get source address as a byte pointer */ > const sint8 *src = src0; > > /* alligned destination pointer */ > sint32 *aligned_dst; > > /* aligned source pointer */ > const sint32 *aligned_src; > > /* lenght in integer */ > uint32 len = (uint32) len0; > > > /* If the size is small, or either SRC or DST is unaligned, > * then punt into the byte copy loop. This should be rare. */ > if(( ( TOO_SMALL(len) ) == 0U ) && > ( ( UNALIGNED((uint32) src0 , (uint32) dst0) ) == FALSE )) > { > /* get the destination */ > aligned_dst = (sint32*) dst; > > /* get the source */ > aligned_src = (sint32*) src; > > /* Copy 4X long words at a time if possible. */ > while(len >= BIGBLOCKSIZE) > { > /* copy the first 4 bytes */ > *aligned_dst = *aligned_src; > aligned_dst++; > aligned_src++; > > /* copy the second 4 bytes */ > *aligned_dst = *aligned_src; > aligned_dst++; > aligned_src++; > > /* copy the third 4 bytes */ > *aligned_dst = *aligned_src; > aligned_dst++; > aligned_src++; > > /* copy the fourth 4 bytes */ > *aligned_dst = *aligned_src; > aligned_dst++; > aligned_src++; > > /* decrement the number of bytes left to copy */ > len -= BIGBLOCKSIZE; > } > > /* Copy one long word at a time if possible. */ > while(len >= LITTLEBLOCKSIZE) > { > /* copy 4 bytes */ > *aligned_dst = *aligned_src; > aligned_dst++; > aligned_src++; > > /* decrement the number of bytes left to copy */ > len -= LITTLEBLOCKSIZE; > } > > /* Pick up any residual with a byte copier. */ > dst = (sint8*) aligned_dst; > src = (sint8*) aligned_src; > } > > /* copy residual bytes (maximum of 3) */ > while(len > 0U) > { > /* copy each byte */ > *dst = *src; > > /* increment the pointer */ > dst++; > src++; > > /* decrement number of bytes */ > len--; > } > > /* return the destination address */ > return dst0; > > #endif /* not PREFER_SIZE_OVER_SPEED */ > } > > > > > For the file memset.c we have the file: > > > /** > * @brief size of a block > */ > #define LBLOCKSIZE ((uint32) sizeof(uintptr)) > > /** > * @brief check if the address is alligned */ #define UNALIGNED(X) > ((uintptr)X & (LBLOCKSIZE - 1)) > > /** > * @brief check if the size is too small */ #define TOO_SMALL(LEN) ((LEN) < > LBLOCKSIZE) > > > void *memset(void *m , sint32 c , rtems_size n) { > > #if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__) > > /* copy the destination address to another variable */ > sint8 *s = (sint8 *) m; > > > /* while there are bytes left to copy */ > while(n != 0) > { > /* copy the byte */ > *s = (sint8) c; > > /* increment index on array */ > s++; > > /* decrement number of remaining bytes to copy */ > n--; > } > > /* return the destination address */ > return m; > > #else > > /* pointer to address where to write */ > sint8 *s = (sint8 *) m; > > /* iterator */ > uint32 i; > > /* buffer where to place small array */ > uint32 buffer; > > /* pointer to address aligned */ > uintptr *aligned_addr; > > /* To avoid sign extension, copy c to an unsigned variable. */ > uint32 d = (uint32) c & 0xffU; > > > /* check if the size is too small or the destination address in not > aligned */ > if(( TOO_SMALL(n) == 0U ) && ( UNALIGNED(m) == 0U )) > { > /* If we get this far, we know that n is large and m is > word-aligned. */ > aligned_addr = (uint32*) m; > > /* Store D into each char sized location in BUFFER so that > we can set large blocks quickly. */ > if(LBLOCKSIZE == 4U) > { > /* copy to the buffer */ > buffer = (uint32) ( ( d << 8U ) | d ); > buffer = buffer | ( buffer << 16U ); > } > else > { > /* reset the buffer */ > buffer = 0U; > > /* copy to the buffer the char */ > for(i = 0U; i < LBLOCKSIZE; i++) > { > buffer = ( buffer << 8U ) | d; > } > } > > /* copy the aligned bytes */ > while(n >= LBLOCKSIZE * 4U) > { > /* copy the first four byte word */ > *aligned_addr = buffer; > aligned_addr++; > > /* copy the second four byte word */ > *aligned_addr = buffer; > aligned_addr++; > > /* copy the third four byte word */ > *aligned_addr = buffer; > aligned_addr++; > > /* copy the fourth four byte word */ > *aligned_addr = buffer; > aligned_addr++; > > /* decrement the number of bytes copied */ > n -= (rtems_size) ( 4U * LBLOCKSIZE ); > } > > /* copy the remaining bytes */ > while(n >= LBLOCKSIZE) > { > /* copy the first four byte word */ > *aligned_addr = buffer; > aligned_addr++; > > /* decrement the number of bytes copied */ > n -= LBLOCKSIZE; > } > /* Pick up the remainder with a bytewise loop. */ > s = (sint8*) aligned_addr; > } > > /* copy the remaining bytes */ > while(n > 0U) > { > /* copy the byte */ > *s = (sint8) d; > s++; > /* decrement size */ > n--; > } > > /* return the destination address */ > return m; > > #endif /* not PREFER_SIZE_OVER_SPEED */ > } > > > > > > Hope this help ;) > Manuel Coutinho > > -----Original Message----- > From: gcc-help-owner@gcc.gnu.org [mailto:gcc-help-owner@gcc.gnu.org] On > Behalf Of Kai Ruottu > Sent: 07 February 2011 14:43 > To: gcc-help@gcc.gnu.org > Cc: ali hagigat > Subject: Re: -nostdlib option! > > 7.2.2011 14:44, ali hagigat kirjoitti: > >> 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. > > Most probably these functions are standalone and don't > call other functions... Does your program really call > them? What does 'nm' say anout undefined symbols in the > compiled object(s)? > >> Are those functions available stand alone some where? > > For instance in : > newlib-1.18.0/newlib/libc/machine/i386 > in the current newlib sources. > > > ^ permalink raw reply [flat|nested] 14+ messages in thread
[parent not found: <4D59BEDC.9000606@yahoo.com>]
* Re: -nostdlib option! [not found] ` <4D59BEDC.9000606@yahoo.com> @ 2011-02-15 9:50 ` ali hagigat 2011-02-15 10:28 ` Axel Freyn ` (2 more replies) 0 siblings, 3 replies; 14+ messages in thread From: ali hagigat @ 2011-02-15 9:50 UTC (permalink / raw) To: phorgan1, gcc-help 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. 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; > } > > > ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: -nostdlib option! 2011-02-15 9:50 ` ali hagigat @ 2011-02-15 10:28 ` Axel Freyn 2011-02-15 12:13 ` Jonathan Wakely 2011-02-15 14:56 ` Thomas Martitz 2011-02-15 15:52 ` Ian Lance Taylor 2 siblings, 1 reply; 14+ messages in thread From: Axel Freyn @ 2011-02-15 10:28 UTC (permalink / raw) To: gcc-help 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; > > } > > > > > > ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: -nostdlib option! 2011-02-15 10:28 ` Axel Freyn @ 2011-02-15 12:13 ` Jonathan Wakely 2011-02-16 10:05 ` Axel Freyn 0 siblings, 1 reply; 14+ messages in thread From: Jonathan Wakely @ 2011-02-15 12:13 UTC (permalink / raw) To: gcc-help 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. ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: -nostdlib option! 2011-02-15 12:13 ` Jonathan Wakely @ 2011-02-16 10:05 ` Axel Freyn 0 siblings, 0 replies; 14+ messages in thread From: Axel Freyn @ 2011-02-16 10:05 UTC (permalink / raw) To: Jonathan Wakely; +Cc: gcc-help On Tue, Feb 15, 2011 at 10:28:30AM +0000, Jonathan Wakely wrote: > On 15 February 2011 09:50, Axel Freyn wrote: > > 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. I see -- sorry for the noise :-) Axel ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: -nostdlib option! 2011-02-15 9:50 ` ali hagigat 2011-02-15 10:28 ` Axel Freyn @ 2011-02-15 14:56 ` Thomas Martitz 2011-02-15 15:52 ` Ian Lance Taylor 2 siblings, 0 replies; 14+ messages in thread From: Thomas Martitz @ 2011-02-15 14:56 UTC (permalink / raw) To: gcc-help Am 15.02.2011 08:36, schrieb ali hagigat: > 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 struct assigments (e.g. struct foo bar = baz). Perhaps if they're big enough gcc doesn't inline the implicit memcpy anymore. Best regards. ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: -nostdlib option! 2011-02-15 9:50 ` ali hagigat 2011-02-15 10:28 ` Axel Freyn 2011-02-15 14:56 ` Thomas Martitz @ 2011-02-15 15:52 ` Ian Lance Taylor 2 siblings, 0 replies; 14+ messages in thread From: Ian Lance Taylor @ 2011-02-15 15:52 UTC (permalink / raw) To: ali hagigat; +Cc: phorgan1, gcc-help ali hagigat <hagigatali@gmail.com> writes: > 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. If I compile this file: struct s { char a[100000]; }; struct s v; void f(struct s *p) { v = *p; } for the x86_64 with no optimization, I get a call to memcpy. Ian ^ permalink raw reply [flat|nested] 14+ messages in thread
end of thread, other threads:[~2011-02-16 8:53 UTC | newest] Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2011-02-07 11:18 -nostdlib option! 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 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
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).