Bug 21057

Summary: GDB build failure with flex 2.6.3
Product: gdb Reporter: Peter Foley <pefoley2+sourceware>
Component: buildAssignee: Not yet assigned to anyone <unassigned>
Status: NEW ---    
Severity: normal CC: dilyan.palauzov, erik.m.bray+sourceware, HBBroeker, palves, simark, tromey
Priority: P2    
Version: 8.0   
Target Milestone: ---   
Host: Target:
Build: Last reconfirmed: 2017-01-17 00:00:00
Attachments: Patch for bug

Description Peter Foley 2017-01-17 06:38:50 UTC
Created attachment 9756 [details]
Patch for bug

Building gdb at commit f964e51d90 with flex 2.6.3 and bison 3.0.4 fails with the below error.
I've attached a patch that allows the compile to succeed, although I'm unclear whether the compatibility code it removes is still necessary.

g++ -std=gnu++11 -g -O2   -I. -I../../gdb -I../../gdb/common -I../../gdb/config -DLOCALEDIR="\"/usr/local/share/locale\"" -DHAVE_CONFIG_H -I../../gdb/../include/opcode -I../../gdb/../opcodes/.. -I../../gdb/../readline/.. -I../../gdb/../zlib -I../bfd -I../../gdb/../bfd -I../../gdb/../include -I../libdecnumber -I../../gdb/../libdecnumber  -I../../gdb/gnulib/import -Ibuild-gnulib/import   -DTUI=1  -I/usr/include/python2.7 -I/usr/include/python2.7 -Wall -Wpointer-arith -Wno-unused -Wunused-value -Wunused-function -Wno-switch -Wno-char-subscripts -Wempty-body -Wunused-but-set-parameter -Wunused-but-set-variable -Wno-sign-compare -Wno-write-strings -Wno-narrowing -Wformat-nonliteral -Werror `echo " -Wall -Wpointer-arith -Wno-unused -Wunused-value -Wunused-function -Wno-switch -Wno-char-subscripts -Wempty-body -Wunused-but-set-parameter -Wunused-but-set-variable -Wno-sign-compare -Wno-write-strings -Wno-narrowing -Wformat-nonliteral " | sed "s/ -Wold-style-definition / -Wno-old-style-definition /g"` \
	-c -o ada-exp.o -MT ada-exp.o -MMD -MP -MF .deps/ada-exp.Tpo `if test -f ada-exp.c; then echo ada-exp.c; else echo ../../gdb/ada-exp.c; fi`
In file included from ../../gdb/ada-exp.y:731:0:
ada-lex.c:16:0: error: "yy_create_buffer" redefined [-Werror]
 
 ^
../../gdb/ada-exp.y:717:0: note: this is the location of the previous definition
 #define yy_create_buffer ada_yy_create_buffer
 ^
In file included from ../../gdb/ada-exp.y:731:0:
ada-lex.c:18:0: error: "yy_delete_buffer" redefined [-Werror]
 
 ^
../../gdb/ada-exp.y:718:0: note: this is the location of the previous definition
 #define yy_delete_buffer ada_yy_delete_buffer
 ^
In file included from ../../gdb/ada-exp.y:731:0:
ada-lex.c:26:0: error: "yy_init_buffer" redefined [-Werror]
 
 ^
../../gdb/ada-exp.y:719:0: note: this is the location of the previous definition
 #define yy_init_buffer ada_yy_init_buffer
 ^
In file included from ../../gdb/ada-exp.y:731:0:
ada-lex.c:30:0: error: "yy_load_buffer_state" redefined [-Werror]
 
 ^
../../gdb/ada-exp.y:720:0: note: this is the location of the previous definition
 #define yy_load_buffer_state ada_yy_load_buffer_state
 ^
In file included from ../../gdb/ada-exp.y:731:0:
ada-lex.c:32:0: error: "yy_switch_to_buffer" redefined [-Werror]
 
 ^
../../gdb/ada-exp.y:721:0: note: this is the location of the previous definition
 #define yy_switch_to_buffer ada_yy_switch_to_buffer
 ^
In file included from ../../gdb/ada-exp.y:731:0:
ada-lex.c:40:0: error: "yylex" redefined [-Werror]
 
 ^
In file included from ../../gdb/ada-exp.y:56:0:
../../gdb/yy-remap.h:41:0: note: this is the location of the previous definition
 #define yylex  GDB_YY_REMAP (yylex)
 ^
In file included from ../../gdb/ada-exp.y:731:0:
ada-lex.c:42:0: error: "yyrestart" redefined [-Werror]
 
 ^
../../gdb/ada-exp.y:722:0: note: this is the location of the previous definition
 #define yyrestart ada_yyrestart
 ^
In file included from ../../gdb/ada-exp.y:731:0:
ada-lex.c:74:0: error: "yywrap" redefined [-Werror]
 
 ^
../../gdb/ada-exp.y:724:0: note: this is the location of the previous definition
 #define yywrap ada_yywrap
 ^
In file included from ../../gdb/ada-exp.y:731:0:
ada-lex.c:82:0: error: "yytext" redefined [-Werror]
 
 ^
../../gdb/ada-exp.y:723:0: note: this is the location of the previous definition
 #define yytext ada_yytext
 ^
In file included from ../../gdb/ada-exp.y:56:0:
../../gdb/ada-exp.y:55:29: error: ‘int ada_yylex()’ used but never defined [-Werror]
 #define GDB_YY_REMAP_PREFIX ada_
                             ^
../../gdb/yy-remap.h:35:39: note: in definition of macro ‘GDB_YY_REMAP_2’
 #define GDB_YY_REMAP_2(PREFIX, YYSYM) PREFIX ## YYSYM
                                       ^
../../gdb/yy-remap.h:37:29: note: in expansion of macro ‘GDB_YY_REMAP_1’
 #define GDB_YY_REMAP(YYSYM) GDB_YY_REMAP_1 (GDB_YY_REMAP_PREFIX, YYSYM)
                             ^
../../gdb/yy-remap.h:37:45: note: in expansion of macro ‘GDB_YY_REMAP_PREFIX’
 #define GDB_YY_REMAP(YYSYM) GDB_YY_REMAP_1 (GDB_YY_REMAP_PREFIX, YYSYM)
                                             ^
../../gdb/yy-remap.h:41:16: note: in expansion of macro ‘GDB_YY_REMAP’
 #define yylex  GDB_YY_REMAP (yylex)
                ^
../../gdb/ada-exp.y:78:12: note: in expansion of macro ‘yylex’
 static int yylex (void);
            ^
In file included from ../../gdb/ada-exp.y:731:0:
ada-lex.c:40:19: error: ‘int yylex()’ defined but not used [-Werror=unused-function]
../../gdb/ada-lex.l:60:28: note: in expansion of macro ‘yylex’
 #define YY_DECL static int yylex ( void )
                            ^
ada-lex.c:1123:1: note: in expansion of macro ‘YY_DECL’
  */
 ^
cc1plus: all warnings being treated as errors
make[2]: *** [Makefile:2683: ada-exp.o] Error 1
make[2]: Leaving directory '/home/peter/binutils-gdb/work/gdb'
make[1]: *** [Makefile:10456: all-gdb] Error 2
make[1]: Leaving directory '/home/peter/binutils-gdb/work'
make: *** [Makefile:851: all] Error 2
Comment 1 Simon Marchi 2017-01-17 15:19:36 UTC
Here's the commit in flex at which the gdb build starts failing

https://github.com/westes/flex/commit/347652c32b4614995acd4ee0d686499da2070d9e
Comment 2 Simon Marchi 2017-01-17 15:29:33 UTC
Here are the differences between the 2.6.2-generated ada-lex.c and the 2.6.3-generated ada-lex.c:


--- ada-lex.c.2.6.2	2017-01-17 09:40:59.393641771 -0500
+++ ada-lex.c	2017-01-17 09:49:51.425905663 -0500
@@ -9,11 +9,89 @@
 #define FLEX_SCANNER
 #define YY_FLEX_MAJOR_VERSION 2
 #define YY_FLEX_MINOR_VERSION 6
-#define YY_FLEX_SUBMINOR_VERSION 2
+#define YY_FLEX_SUBMINOR_VERSION 3
 #if YY_FLEX_SUBMINOR_VERSION > 0
 #define FLEX_BETA
 #endif
 
+    #define yy_create_buffer yy_create_buffer
+
+    #define yy_delete_buffer yy_delete_buffer
+
+    #define yy_scan_buffer yy_scan_buffer
+
+    #define yy_scan_string yy_scan_string
+
+    #define yy_scan_bytes yy_scan_bytes
+
+    #define yy_init_buffer yy_init_buffer
+
+    #define yy_flush_buffer yy_flush_buffer
+
+    #define yy_load_buffer_state yy_load_buffer_state
+
+    #define yy_switch_to_buffer yy_switch_to_buffer
+
+    #define yypush_buffer_state yypush_buffer_state
+
+    #define yypop_buffer_state yypop_buffer_state
+
+    #define yyensure_buffer_stack yyensure_buffer_stack
+
+    #define yylex yylex
+
+    #define yyrestart yyrestart
+
+    #define yylex_init yylex_init
+
+    #define yylex_init_extra yylex_init_extra
+
+    #define yylex_destroy yylex_destroy
+
+    #define yyget_debug yyget_debug
+
+    #define yyset_debug yyset_debug
+
+    #define yyget_extra yyget_extra
+
+    #define yyset_extra yyset_extra
+
+    #define yyget_in yyget_in
+
+    #define yyset_in yyset_in
+
+    #define yyget_out yyget_out
+
+    #define yyset_out yyset_out
+
+    #define yyget_leng yyget_leng
+
+    #define yyget_text yyget_text
+
+    #define yyget_lineno yyget_lineno
+
+    #define yyset_lineno yyset_lineno
+
+    #define yywrap yywrap
+
+    #define yyalloc yyalloc
+
+    #define yyrealloc yyrealloc
+
+    #define yyfree yyfree
+
+    #define yytext yytext
+
+    #define yyleng yyleng
+
+    #define yyin yyin
+
+    #define yyout yyout
+
+    #define yy_flex_debug yy_flex_debug
+
+    #define yylineno yylineno
+
 /* First, we deal with  platform-specific or compiler-specific issues. */
 
 /* begin standard C headers. */
@@ -215,7 +293,7 @@
 
     int yy_bs_lineno; /**< The line count. */
     int yy_bs_column; /**< The column count. */
-    
+
 	/* Whether to try to fill the input buffer when we reach the
 	 * end of it.
 	 */
@@ -856,9 +934,9 @@
 
 static int find_dot_all (const char *);
 
-#line 859 "ada-lex.c"
+#line 937 "ada-lex.c"
 
-#line 861 "ada-lex.c"
+#line 939 "ada-lex.c"
 
 #define INITIAL 0
 #define BEFORE_QUAL_QUOTE 1
@@ -1079,7 +1157,7 @@
 #line 85 "/home/simark/src/binutils-gdb/gdb/ada-lex.l"
 
 
-#line 1082 "ada-lex.c"
+#line 1160 "ada-lex.c"
 
 	while ( /*CONSTCOND*/1 )		/* loops until end-of-file is reached */
 		{
@@ -1524,7 +1602,7 @@
 #line 291 "/home/simark/src/binutils-gdb/gdb/ada-lex.l"
 YY_FATAL_ERROR( "flex scanner jammed" );
 	YY_BREAK
-#line 1527 "ada-lex.c"
+#line 1605 "ada-lex.c"
 case YY_STATE_EOF(INITIAL):
 case YY_STATE_EOF(BEFORE_QUAL_QUOTE):
 	yyterminate();
@@ -2206,9 +2284,9 @@
 								);
 		if ( ! (yy_buffer_stack) )
 			YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" );
-								  
+
 		memset((yy_buffer_stack), 0, num_to_alloc * sizeof(struct yy_buffer_state*));
-				
+
 		(yy_buffer_stack_max) = num_to_alloc;
 		(yy_buffer_stack_top) = 0;
 		return;
@@ -2237,7 +2315,7 @@
  * @param base the character buffer
  * @param size the size in bytes of the character buffer
  * 
- * @return the newly allocated buffer state object. 
+ * @return the newly allocated buffer state object.
  */
 YY_BUFFER_STATE yy_scan_buffer  (char * base, yy_size_t  size )
 {
@@ -2353,7 +2431,7 @@
  */
 int yyget_lineno  (void)
 {
-        
+    
     return yylineno;
 }
Comment 3 HBBroeker 2017-01-21 13:52:48 UTC
(In reply to Peter Foley from comment #0)

> Building gdb at commit f964e51d90 with flex 2.6.3 and bison 3.0.4 fails with
> the below error.
> I've attached a patch that allows the compile to succeed, although I'm
> unclear whether the compatibility code it removes is still necessary.

That patch relies on $(YACC) being bison, for otherwise the %name-prefix option would not be available.  I fear a more generally applicable solution will be needed (maybe use the -p command-line option instead, which is required by POSIX).   The same issue could apply to the lex file change, but the gdb source already insists on using flex, anyway.
Comment 4 Erik Bray 2017-04-13 11:30:24 UTC
For what it's worth, one small merge conflict aside, this patch solved the issue for me as well, bison-specificity aside.
Comment 5 Pedro Alves 2017-04-13 17:20:41 UTC
I couldn't reproduce this with current flex master:

 $ flex --version
 flex 2.6.4

Looking at the git log, it sound like it was fixed with this:

commit 078b46c69d063aef1715b11348a2871d6036f253
Author:     Christos Zoulas <christos@zoulas.com>
AuthorDate: Sun Jan 22 18:34:30 2017 +0100
Commit:     Will Estes <westes575@gmail.com>
CommitDate: Mon Jan 23 13:39:49 2017 -0500

    Add more defines in the non-reentrant part.
    
    Fix the reentrant part; don't "#define yyfoo yyfoo" because it breaks
    code that does #ifndef yywrap ..
Comment 6 Pedro Alves 2017-04-13 17:34:17 UTC
Confirmed, that commit fixes it.  AFAICS, there's no official 2.6.4 yet, so looks like the simplest for now is to just avoid 2.6.3.  (Maybe get distros to backport that flex patch.)
Comment 7 Pedro Alves 2017-04-13 17:36:33 UTC
For GDB, switching to -p sounds like a viable option going forward.  Also, we probably need to switch to C++ mode, to avoid ODR violations around the parsers...  Need volunteers.  :-)
Comment 8 Tom Tromey 2017-04-22 01:49:13 UTC
(In reply to Pedro Alves from comment #7)
> For GDB, switching to -p sounds like a viable option going forward.  Also,
> we probably need to switch to C++ mode, to avoid ODR violations around the
> parsers...  Need volunteers.  :-)

I tried yacc -p once, and it was trickier than it seemed like it ought
to have been.

C++ mode is a bison extension AFAIK.  I think using it would be very
nice, but I wonder whether it's acceptable.
Comment 9 Mike Frysinger 2018-02-05 18:15:01 UTC
*** Bug 20993 has been marked as a duplicate of this bug. ***