[OpenBIOS] [PATCH 6/6] libc: Fix build on recent gcc

Segher Boessenkool segher at kernel.crashing.org
Mon Nov 7 00:18:31 CET 2016


On Sun, Nov 06, 2016 at 11:41:40PM +0100, Aurelien Jarno wrote:
> > --- a/libc/string.c
> > +++ b/libc/string.c
> > @@ -349,10 +349,7 @@ int memcmp(const void * cs,const void * ct,size_t count)
> >  char *
> >  strdup( const char *str )
> >  {
> > -	char *p;
> > -	if( !str )
> > -		return NULL;
> > -	p = malloc( strlen(str) + 1 );
> > +	char *p = malloc( strlen(str) + 1 );
> >  	strcpy( p, str );
> >  	return p;
> >  }
> 
> Sorry to react so late, but wouldn't be better to build openbios with
> -ffreestanding instead? That way GCC doesn't try to infer things from
> its knowledge of the GNU libc? After all openbios uses its own libc.

This is required not by glibc but by C, for any hosted environment.  Using
-ffreestanding will work, it probably is best to use that (unless openbios
wants to make sure everything else is also implemented correctly, not a
small task).


Segher



More information about the OpenBIOS mailing list