Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH] gdb: rename YYSTACKDATA in generated parsers
@ 2026-10-07 13:55 simon.marchi
  2026-10-08 14:00 ` Simon Marchi
  0 siblings, 1 reply; 2+ messages in thread
From: simon.marchi @ 2026-10-07 13:55 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Marchi

From: Simon Marchi <simon.marchi@polymtl.ca>

When building with byacc and -flto -Werror=odr, we get:

    ada-exp-parser-gen.c.tmp:1552:3: error: type 'struct YYSTACKDATA' violates the C++ One Definition Rule [-Werror=odr]
    c-exp-parser-gen.c.tmp:3732:3: note: a different type is defined in another translation unit
    ada-exp-parser-gen.c.tmp:1546:30: note: the first difference of corresponding definitions is field 'l_base'
    c-exp-parser-gen.c.tmp:3726:28: note: a field of same name but different type is defined in another translation unit
    ada-exp-parser-gen.c.tmp:1552:3: note: type name 'ada_exp_parser_YYSTYPE' should match type name 'c_exp_parser_YYSTYPE'

The byacc generated parsers define this type:

    typedef struct {
        unsigned stacksize;
        YYINT    *s_base;
        YYINT    *s_mark;
        YYINT    *s_last;
        YYSTYPE  *l_base;
        YYSTYPE  *l_mark;
        ...
    } YYSTACKDATA;

Since YYSTYPE represents a different type in each parser (it is renamed
to {prefix}_YYSTYPE by post-process-parser-output.sh), then YYSTACKDATA
is also a different type in each parser, which leads to ODR violations.

This is a regression from my patch that removed yy-remap.h (d3d68d798e0c
"gdb: let the parser and lexer generators prefix their symbols").
yy-remap.h remapped YYSTACKDATA, since commit df940f8bb348 ("gdb: Fix an
ODR warning with byacc with GDB_YY_REMAP") which fixed this exact
problem.

Fix it by adding YYSTACKDATA to the renames done in
post-process-parser-output.sh, alongside YYSTYPE and friends.

This is a master-only bug, no need to cherry-pick to gdb-18-branch.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=34712
Change-Id: I6332bd0edc6619434f67cccef463cd21e96e3251
---
 gdb/post-process-parser-output.sh | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/gdb/post-process-parser-output.sh b/gdb/post-process-parser-output.sh
index a0cf6b464c4b..ca5f0ba302fb 100755
--- a/gdb/post-process-parser-output.sh
+++ b/gdb/post-process-parser-output.sh
@@ -53,7 +53,8 @@ case "$generator" in
 	    -e '/^#line.*y.tab.c/d' \
 	    -e "s/YYSTYPE/${name}_YYSTYPE/g" \
 	    -e "s/yyalloc/${name}_yyalloc/g" \
-	    -e "s/yysymbol_kind_t/${name}_yysymbol_kind_t/g"
+	    -e "s/yysymbol_kind_t/${name}_yysymbol_kind_t/g" \
+	    -e "s/YYSTACKDATA/${name}_YYSTACKDATA/g"
 	;;
     flex)
 	sed -e "$common" \

base-commit: ca0665335ff67af94f9ded026d7ef2405a68c453
-- 
2.55.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] gdb: rename YYSTACKDATA in generated parsers
  2026-10-07 13:55 [PATCH] gdb: rename YYSTACKDATA in generated parsers simon.marchi
@ 2026-10-08 14:00 ` Simon Marchi
  0 siblings, 0 replies; 2+ messages in thread
From: Simon Marchi @ 2026-10-08 14:00 UTC (permalink / raw)
  To: gdb-patches

On 10/7/26 9:55 AM, simon.marchi@polymtl.ca wrote:
> From: Simon Marchi <simon.marchi@polymtl.ca>
> 
> When building with byacc and -flto -Werror=odr, we get:
> 
>     ada-exp-parser-gen.c.tmp:1552:3: error: type 'struct YYSTACKDATA' violates the C++ One Definition Rule [-Werror=odr]
>     c-exp-parser-gen.c.tmp:3732:3: note: a different type is defined in another translation unit
>     ada-exp-parser-gen.c.tmp:1546:30: note: the first difference of corresponding definitions is field 'l_base'
>     c-exp-parser-gen.c.tmp:3726:28: note: a field of same name but different type is defined in another translation unit
>     ada-exp-parser-gen.c.tmp:1552:3: note: type name 'ada_exp_parser_YYSTYPE' should match type name 'c_exp_parser_YYSTYPE'
> 
> The byacc generated parsers define this type:
> 
>     typedef struct {
>         unsigned stacksize;
>         YYINT    *s_base;
>         YYINT    *s_mark;
>         YYINT    *s_last;
>         YYSTYPE  *l_base;
>         YYSTYPE  *l_mark;
>         ...
>     } YYSTACKDATA;
> 
> Since YYSTYPE represents a different type in each parser (it is renamed
> to {prefix}_YYSTYPE by post-process-parser-output.sh), then YYSTACKDATA
> is also a different type in each parser, which leads to ODR violations.
> 
> This is a regression from my patch that removed yy-remap.h (d3d68d798e0c
> "gdb: let the parser and lexer generators prefix their symbols").
> yy-remap.h remapped YYSTACKDATA, since commit df940f8bb348 ("gdb: Fix an
> ODR warning with byacc with GDB_YY_REMAP") which fixed this exact
> problem.
> 
> Fix it by adding YYSTACKDATA to the renames done in
> post-process-parser-output.sh, alongside YYSTYPE and friends.
> 
> This is a master-only bug, no need to cherry-pick to gdb-18-branch.
> 
> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=34712
> Change-Id: I6332bd0edc6619434f67cccef463cd21e96e3251

Sam confirmed on Bugzilla that the patch fixes the problem, so I went
ahead and pushed it.

Simon

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-10-08 14:01 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-07 13:55 [PATCH] gdb: rename YYSTACKDATA in generated parsers simon.marchi
2026-10-08 14:00 ` Simon Marchi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox