> From: [email protected] (=?utf-8?Q?J=C3=A9r=C3=A9mie_Courr=C3=A8ges-Anglas?=)
> Date: Mon, 18 May 2015 18:47:34 +0200
>
> Mark Kettenis <[email protected]> writes:
>
> >> From: [email protected] (=?utf-8?Q?J=C3=A9r=C3=A9mie_Courr=C3=A8ges-Anglas?=)
> >> Date: Mon, 18 May 2015 13:26:08 +0200
> >>
> >> Mark Kettenis <[email protected]> writes:
> >>
> >> > This one is tricky. The bison skeleton code uses malloc(3) and
> >> > free(3), and tries to make sure a prototype for those functions is in
> >> > scope. It attempts to detect if <stdlib.h> has been included, and if
> >> > not, provides its own prototypes. The detection code checks if
> >> > _STDLIB_H has been defined. However, the BSD stdlib.h uses _STDLIB_H_
> >> > (note the trailing underscore). So the check fails and a typically
> >> > redundant prototype will be provided. Usually this only produces a
> >> > compiler warning. However...
> >> >
> >> > The multimedia/libaacs port has a
> >> >
> >> > #pragma GCC visibility push(hidden)
> >> >
> >> > in its parser code. Since the malloc and free prototypes appear after
> >> > that pragma, it means they get marked as hidden symbols. This makes
> >> > the compiler generate R_X86_64_PC32 relocations that binutils 2.17
> >> > doesn't like.
> >> >
> >> > Here is a simple fix that simply replaces _STDLIB_H with _STDLIB_H_ in
> >> > the skeleton code. Newer bison versions take a slightly different
> >> > approach and check whether EXIT_SUCCESS has been defined.
> >>
> >> Maybe I'm nitpicking here, but that would mean that parsers generated by
> >> the OpenBSD bison package may now misbehave on systems where _STDLIB_H
> >> is provided. I know that our bison package is old, people should
> >> probably not use it, but maybe there's another way to deal with this?
> >>
> >> I think that this #ifdef _STDLIB_H maze would be enough with the
> >> following tweak. I see no reason for C++ to be a special case here.
> >> The resulting libaacs parser *still depends on stdlib.h being included
> >> earlier in the .y*, but at least the _STDLIB_H guards are working and
> >> prevent the local decls.
> >>
> >> Thoughts?
> >
> > My guess is that it was done this way for a reason.
>
> Looking at the git log, I'm not sure
> (fc3f467ff12133962ef69f58e60cb24fc29cc929). Forward decls were provided
> for both C and C++ before they switched to including stdlib.h
>
> > If you really
> > think that redistributing OpenBSD generated parsers to non-BSD systems
> > is something that needs to be addressed, I'd rather take the
> > EXIT_SUCCESS approach.
>
> I'd be fine with this approach.
>
> Here's the diff. ok jca@ (if you haven't changed your mind of course).
Yes that looks good. Committed.
> Index: Makefile
> ===================================================================
> RCS file: /cvs/ports/devel/bison/Makefile,v
> retrieving revision 1.50
> diff -u -p -r1.50 Makefile
> --- Makefile 9 Nov 2013 23:19:02 -0000 1.50
> +++ Makefile 18 May 2015 16:16:39 -0000
> @@ -3,7 +3,7 @@
> COMMENT= GNU parser generator
>
> DISTNAME= bison-2.3
> -REVISION= 1
> +REVISION= 2
> CATEGORIES= devel
> MASTER_SITES= ${MASTER_SITE_GNU:=bison/}
>
> Index: patches/patch-data_yacc_c
> ===================================================================
> RCS file: patches/patch-data_yacc_c
> diff -N patches/patch-data_yacc_c
> --- /dev/null 1 Jan 1970 00:00:00 -0000
> +++ patches/patch-data_yacc_c 18 May 2015 16:16:39 -0000
> @@ -0,0 +1,46 @@
> +$OpenBSD$
> +--- data/yacc.c.orig Mon May 18 18:07:15 2015
> ++++ data/yacc.c Mon May 18 18:08:26 2015
> +@@ -307,10 +307,10 @@ typedef short int yytype_int16;
> + # define alloca _alloca
> + # else
> + # define YYSTACK_ALLOC alloca
> +-# if ! defined _ALLOCA_H && ! defined _STDLIB_H && ]b4_c_modern[
> ++# if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS && ]b4_c_modern[
> + # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
> +-# ifndef _STDLIB_H
> +-# define _STDLIB_H 1
> ++# ifndef EXIT_SUCCESS
> ++# define EXIT_SUCCESS 0
> + # endif
> + # endif
> + # endif
> +@@ -333,23 +333,23 @@ typedef short int yytype_int16;
> + # ifndef YYSTACK_ALLOC_MAXIMUM
> + # define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
> + # endif
> +-# if (defined __cplusplus && ! defined _STDLIB_H \
> ++# if (defined __cplusplus && ! defined EXIT_SUCCESS \
> + && ! ((defined YYMALLOC || defined malloc) \
> + && (defined YYFREE || defined free)))
> + # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
> +-# ifndef _STDLIB_H
> +-# define _STDLIB_H 1
> ++# ifndef EXIT_SUCCESS
> ++# define EXIT_SUCCESS 0
> + # endif
> + # endif
> + # ifndef YYMALLOC
> + # define YYMALLOC malloc
> +-# if ! defined malloc && ! defined _STDLIB_H && ]b4_c_modern[
> ++# if ! defined malloc && ! defined EXIT_SUCCESS && ]b4_c_modern[
> + void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
> + # endif
> + # endif
> + # ifndef YYFREE
> + # define YYFREE free
> +-# if ! defined free && ! defined _STDLIB_H && ]b4_c_modern[
> ++# if ! defined free && ! defined EXIT_SUCCESS && ]b4_c_modern[
> + void free (void *); /* INFRINGES ON USER NAME SPACE */
> + # endif
> + # endif
>
>
> --
> jca | PGP : 0x1524E7EE / 5135 92C1 AD36 5293 2BDF DDCC 0DFA 74AE 1524 E7EE
>