tech-toolchain archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: fix to darwin xcompile by including unistd.h in nbcompat getmode.c compile



Alan Barrett wrote:

> On Mon, 09 Jun 2008, Simon Burge wrote:
> > > The issue is that darwin uses tricks to version the setmode symbol
> > > (appending $UNIX2003), while netbsd's compat_defs.h renames that same
> > > token to __nbcompat_setmode.
> > 
> > I think these "tricks" are also the cause of the getopt lossage in
> > 
> >   http://mail-index.netbsd.org/tech-toolchain/2008/02/04/msg000025.html
> > 
> > ?  I never figured out the right fix for this problem.
> 
> I think it's a bug for tools/compat/compat_defs.h to try to do clever
> things with setmode/getmode without first #include <unistd.h>.  Fixing
> that might solve both problems.  Try this patch.
> 
> --apb (Alan Barrett)
> 
> Index: src/tools/compat/compat_defs.h
> ===================================================================
> --- src/tools/compat/compat_defs.h    30 Oct 2007 20:23:35 -0000      1.65
> +++ src/tools/compat/compat_defs.h    11 Jun 2008 07:07:21 -0000
> @@ -44,6 +44,7 @@
>  #include <stdio.h>
>  #include <stdlib.h>
>  #include <string.h>
> +#include <unistd.h>
>  
>  #if HAVE_SYS_CDEFS_H
>  #include <sys/cdefs.h>

For at least the test case in my original email, this doesn't help.  The
GNU binutils has its own getopt.c that doesn't include any of the compat
headers.  Specifically, getopt.c does:

/* This needs to come after some library #include
   to get __GNU_LIBRARY__ defined.  */
#ifdef  __GNU_LIBRARY__
/* Don't include stdlib.h for non-GNU C libraries because some of them
   contain conflicting prototypes for getopt.  */
# include <stdlib.h>
# include <unistd.h>
#endif  /* GNU C library.  */

Always including <unistd.h> works for this test on MacOS, but given the
comment in getopt.c is it always safe to do so?  A quick grep shows that
gcc4, gdb4, gettext, groff and texinfo also have their own getopt.c with
the above construct - not sure how many of these we also need to worry
about.  For me, mdsetimage (which used BFD) was the only obvious failure
on MacOS.

Cheers,
Simon.


Home | Main Index | Thread Index | Old Index