From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id GdhiL8Oam2pT4SsAWB0awg (envelope-from ) for ; Sat, 05 Sep 2026 00:29:55 -0400 Authentication-Results: simark.ca; dkim=pass (2048-bit key; unprotected) header.d=polymtl.ca header.i=@polymtl.ca header.a=rsa-sha256 header.s=oct2025 header.b=SfDcM/IZ; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id BBE321E167; Sat, 05 Sep 2026 00:29:55 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-5.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [IPv6:2620:52:6:3111::32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id AE2891E091 for ; Sat, 05 Sep 2026 00:29:53 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E3A784BA2E1B for ; Sat, 5 Sep 2026 04:29:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E3A784BA2E1B Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=polymtl.ca header.i=@polymtl.ca header.a=rsa-sha256 header.s=oct2025 header.b=SfDcM/IZ Received: from smtp.polymtl.ca (smtp.polymtl.ca [132.207.4.11]) by sourceware.org (Postfix) with ESMTPS id 536F24BB58FA for ; Sat, 5 Sep 2026 04:29:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 536F24BB58FA Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=polymtl.ca Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=polymtl.ca ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 536F24BB58FA Authentication-Results: sourceware.org; arc=none smtp.remote-ip=132.207.4.11 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1788582565; cv=none; b=lHeCkvTyXzwjwUDWqIuHE0Ym3WcuBBT4YpHHMWFBpST2FsE/sTyTIiwX4l86VXp4lu1yUqLIYMqIeRWaDsSdvQK5I6lVfKLObJuMJg3crEF8bjGIHmNld/d4TNTkYOnaGZobU74kxeGCYYuD/BaCw8zHE8z9G6L2UemksrMnnns= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1788582565; c=relaxed/simple; bh=xkY36VgybrFjBKWXrqK4a2rR2wefxz2gMX80gu6U8FQ=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=vrrne9XjLX/tN2nPAulVVwKGdNsD8oimYQfoi3brz9ptTYRpmuws2bp8h1ayYuioz9/XJM8Wid12Eot8xSgPAHE4E2ewwa2LkiBG0F/LZO3TpDqYqDegY5hlfmNdP/yYd9OqSJ+ws+herQwNkKraYZ8bHeYlBjZYkbYQGMrHKUA= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=polymtl.ca header.i=@polymtl.ca header.a=rsa-sha256 header.s=oct2025 header.b=SfDcM/IZ DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 536F24BB58FA Received: from simark.ca (simark.ca [158.69.221.121]) (authenticated bits=0) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id 6854TIBR082667 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sat, 5 Sep 2026 00:29:23 -0400 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp.polymtl.ca 6854TIBR082667 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=polymtl.ca; s=oct2025; t=1788582564; bh=zVaGYXHsO2a4Jvq5xRdkATxctFUBwBwSc6kaaeA0DgE=; h=From:To:Cc:Subject:Date:In-Reply-To:From; b=SfDcM/IZeb/6anMPLGyA/StmZxglkwNyw8+CFHZuiHLC+UeT+ZFg9XWz6uEyt0p+m 7Fww/gQYQegzM+XLExrsaMxpxS/f9nwuDWQpZ6kiq6MrNYRWWI8kSlFwxvfl0+z6pu Qvm+K90YhHTfVRWv1QVBnrkqr4wMtGgQCDGupUGztEB2vYfTNFKUFV91GSlGmYSQOq zlegYuH/h7Uc/qPMXSp2/5zyzTqv6TOmIAdEMu2W8eDyRNEJntYDfPThd/kZoGNjYe 8+pqejkRK1FgGy0oj0O+wMGcfysQisYQH+1F3npAIpWv2m+CGMFU6UiXApOGPDGsNL cUvr4sDdinBew== Received: by simark.ca (Postfix) id 44DAB1E171; Sat, 05 Sep 2026 00:23:59 -0400 (EDT) From: simon.marchi@polymtl.ca To: gdb-patches@sourceware.org Cc: Simon Marchi Subject: [PATCH v2 06/19] gdb: let the parser and lexer generators prefix their symbols Date: Sat, 5 Sep 2026 00:23:09 -0400 Message-ID: <20260905042353.1702204-7-simon.marchi@polymtl.ca> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260905042353.1702204-1-simon.marchi@polymtl.ca> References: <20260905042353.1702204-1-simon.marchi@polymtl.ca> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Poly-FromMTA: (simark.ca [158.69.221.121]) at Sat, 5 Sep 2026 04:29:18 +0000 X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org From: Simon Marchi In order for parsers to be able to co-exist and avoid symbol clashes, they all include yy-remap.h to rename their symbols to something unique. Bison and byacc both support doing this natively though, with the `-p` flag. flex also has a similar option `-P`. I think we can get rid of `yy-remap.h` in favor of using these options. It's not totally clear to me if "byacc" is a single program or if there are many variants of "byacc" maintained by various projects, but here are those I found, which support `-p`: - https://invisible-island.net/byacc/manpage/yacc.html - https://man.openbsd.org/yacc - https://man.freebsd.org/cgi/man.cgi?query=byacc&apropos=0&sektion=1&manpath=FreeBSD+15.1-RELEASE&format=html - https://man.netbsd.org/yacc.1 AIX yacc supports it: https://www.ibm.com/docs/en/aix/7.3.0?topic=y-yacc-command Solaris yacc supports it: https://docs.oracle.com/cd/E88353_01/html/E37839/yacc-1.html And in any case, it's always possible to just use GNU bison. For flex, it appears that the various BSDs just use plain flex, so they support `-P`. However, it looks like the AIX and Solaris lex don't support it: - https://www.ibm.com/docs/en/aix/7.3.0?topic=l-lex-command - https://docs.oracle.com/cd/E88353_01/html/E37839/lex-1.html It's not clear to me if we already strictly required flex or not. We don't use AC_PROG_LEX, and gdb/Makefile.in hardcodes: FLEX = flex It's possible to override it with $ make FLEX=lex but I don't know if that is really a supported use case. I would like feedback from the AIX and Solaris maintainers to know whether using flex to build GDB is ok or not (you might already do it). Remember that it's only necessary when building from git, as generated parser/lexer files are distributed in tarballs. So, this patch removes yy-remap.h, and then updates gdb/Makefile.in to pass a unique `-p` value to all processed .y files. This is done by defining variables based on the files base names: ... YY_PREFIX_c-exp = c_yy YY_PREFIX_cp-name-parser = cpnameyy YY_PREFIX_d-exp = d_yy ... and then accessing them like this: -p $(YY_PREFIX_$*) And likewise for flex. yy-remap.h did one more thing besides the renaming: it defaulted YYDEBUG to 1, to enable the parsers' tracing support. Pass `-t` to $(YACC), which should have the same effect. Note that the `-t` passed to lex means something else (output to stdout). I had Claude check the symbols in the generated objects before and after the patch, for both bison and byacc (the Arch Linux package), and this is the result: Verified by comparing the symbols exported by each generated parser's .o file before and after this patch, with nm --defined-only --extern-only, using both bison (3.8.2) and byacc (20260126): - For the seven pure parsers (c, cp-name, d, f, go, m2, p), the exported symbols are identical before and after, with both generators. Replacing the yy-remap.h #defines with the generator's -p flag changes nothing in the emitted interface. - ada-exp is the only one that differs, and only in the lexer symbols: 25 flex symbols that used to be exported as bare globals (yyin, yyout, yyleng, yylineno, yy_flex_debug, yyalloc, yyfree, yyxrealloc, yy_scan_*, yyget_*/yyset_*, yy_flush_buffer, yy{push,pop}_buffer_state, yylex_destroy) are now prefixed with ada_. The old hand-written block only remapped seven flex symbols; -P covers them all. Same result with both generators. No exported symbol with a bare "yy" prefix remains in any parser. byacc additionally exports yyval and yyerrflag, but prefixed (e.g. c_yyval), so they still cannot collide. Change-Id: Ib46ff232722c686072ece4fdbf4f70737e10d8c1 --- gdb/Makefile.in | 18 +++++++-- gdb/ada-exp.y | 19 --------- gdb/c-exp.y | 5 --- gdb/cp-name-parser.y | 3 -- gdb/d-exp.y | 5 --- gdb/f-exp.y | 5 --- gdb/go-exp.y | 5 --- gdb/m2-exp.y | 5 --- gdb/p-exp.y | 5 --- gdb/yy-remap.h | 96 -------------------------------------------- 10 files changed, 15 insertions(+), 151 deletions(-) delete mode 100644 gdb/yy-remap.h diff --git a/gdb/Makefile.in b/gdb/Makefile.in index 80b2f8573294..fdfefbff1f6c 100644 --- a/gdb/Makefile.in +++ b/gdb/Makefile.in @@ -1741,7 +1741,6 @@ HFILES_NO_SRCDIR = \ xml-syscall.h \ xml-tdesc.h \ xtensa-tdep.h \ - yy-remap.h \ z80-tdep.h # Header files that already have srcdir in them, or which are in objdir. @@ -2698,14 +2697,27 @@ po/$(PACKAGE).pot: force POST_PROCESS_PARSER_OUTPUT_SH = $(srcdir)/post-process-parser-output.sh POST_PROCESS_PARSER_OUTPUT = $(SHELL) $(POST_PROCESS_PARSER_OUTPUT_SH) +# The prefix to give to the symbols each parser or lexer generator +# produces, so that they can coexist in the same program. There is no +# rule tying it to the file name, so spell it out for each one. +YY_PREFIX_ada-exp = ada_yy +YY_PREFIX_ada-lex = ada_yy +YY_PREFIX_c-exp = c_yy +YY_PREFIX_cp-name-parser = cpnameyy +YY_PREFIX_d-exp = d_yy +YY_PREFIX_f-exp = f_yy +YY_PREFIX_go-exp = go_yy +YY_PREFIX_m2-exp = m2_yy +YY_PREFIX_p-exp = pascal_yy + %-gen.c: %.y $(POST_PROCESS_PARSER_OUTPUT_SH) $(ECHO_YACC) $(SHELL) $(YLWRAP) $< y.tab.c $@.tmp -- \ - $(YACC) $(YFLAGS) || (rm -f $@.tmp; false) + $(YACC) $(YFLAGS) -p $(YY_PREFIX_$*) -t || (rm -f $@.tmp; false) @$(POST_PROCESS_PARSER_OUTPUT) bison $* < $@.tmp > $@.new && \ rm -f $@.tmp && \ mv $@.new $@ %-gen.c: %.l $(POST_PROCESS_PARSER_OUTPUT_SH) - $(ECHO_LEX) $(FLEX) -t $< > $@.tmp || (rm -f $@.tmp; false) + $(ECHO_LEX) $(FLEX) -t -P $(YY_PREFIX_$*) $< > $@.tmp || (rm -f $@.tmp; false) @$(POST_PROCESS_PARSER_OUTPUT) flex $* < $@.tmp > $@.new && \ rm -f $@.tmp && \ mv $@.new $@ diff --git a/gdb/ada-exp.y b/gdb/ada-exp.y index bffe94a8de9b..433293d22ad9 100644 --- a/gdb/ada-exp.y +++ b/gdb/ada-exp.y @@ -46,11 +46,6 @@ #include "ada-exp.h" #include "cli/cli-style.h" -/* Remap normal yacc parser interface names (yyparse, yylex, yyerror, - etc). */ -#define GDB_YY_REMAP_PREFIX ada_ -#include "yy-remap.h" - /* The state of the parser, used internally when we are parsing the expression. */ @@ -1237,20 +1232,6 @@ primary : '*' primary %prec '.' /* yylex defined in ada-lex-gen.c: Reads one token, getting characters */ /* through lexptr. */ -/* Remap normal flex interface names (yylex) as well as gratuitously */ -/* global symbol names, so we can have multiple flex-generated parsers */ -/* in gdb. */ - -/* (See note above on previous definitions for YACC.) */ - -#define yy_create_buffer ada_yy_create_buffer -#define yy_delete_buffer ada_yy_delete_buffer -#define yy_init_buffer ada_yy_init_buffer -#define yy_load_buffer_state ada_yy_load_buffer_state -#define yy_switch_to_buffer ada_yy_switch_to_buffer -#define yyrestart ada_yyrestart -#define yytext ada_yytext - /* The following kludge was found necessary to prevent conflicts between */ /* defs.h and non-standard stdlib.h files. */ #define qsort __qsort__dummy diff --git a/gdb/c-exp.y b/gdb/c-exp.y index d58bce833551..9a1ecb3e6d3a 100644 --- a/gdb/c-exp.y +++ b/gdb/c-exp.y @@ -54,11 +54,6 @@ #include "macroexp.h" #include "cli/cli-style.h" -/* Remap normal yacc parser interface names (yyparse, yylex, yyerror, - etc). */ -#define GDB_YY_REMAP_PREFIX c_ -#include "yy-remap.h" - /* The state of the parser, used internally when we are parsing the expression. */ diff --git a/gdb/cp-name-parser.y b/gdb/cp-name-parser.y index 1fd4a17db06a..44ef1a41eb39 100644 --- a/gdb/cp-name-parser.y +++ b/gdb/cp-name-parser.y @@ -45,9 +45,6 @@ #include "parser-defs.h" #include "gdbsupport/selftest.h" -#define GDB_YY_REMAP_PREFIX cpname -#include "yy-remap.h" - %} %union diff --git a/gdb/d-exp.y b/gdb/d-exp.y index d3263ba4fd72..3b3a212cd741 100644 --- a/gdb/d-exp.y +++ b/gdb/d-exp.y @@ -50,11 +50,6 @@ #include "expop.h" #include "cli/cli-style.h" -/* Remap normal yacc parser interface names (yyparse, yylex, yyerror, - etc). */ -#define GDB_YY_REMAP_PREFIX d_ -#include "yy-remap.h" - /* The state of the parser, used internally when we are parsing the expression. */ diff --git a/gdb/f-exp.y b/gdb/f-exp.y index 4cdfcc973923..ad1a9253d7f9 100644 --- a/gdb/f-exp.y +++ b/gdb/f-exp.y @@ -52,11 +52,6 @@ #include "type-stack.h" #include "f-exp.h" -/* Remap normal yacc parser interface names (yyparse, yylex, yyerror, - etc). */ -#define GDB_YY_REMAP_PREFIX f_ -#include "yy-remap.h" - /* The state of the parser, used internally when we are parsing the expression. */ diff --git a/gdb/go-exp.y b/gdb/go-exp.y index 199da6dc5c37..1384c3ebeeec 100644 --- a/gdb/go-exp.y +++ b/gdb/go-exp.y @@ -61,11 +61,6 @@ #include "block.h" #include "expop.h" -/* Remap normal yacc parser interface names (yyparse, yylex, yyerror, - etc). */ -#define GDB_YY_REMAP_PREFIX go_ -#include "yy-remap.h" - /* The state of the parser, used internally when we are parsing the expression. */ diff --git a/gdb/m2-exp.y b/gdb/m2-exp.y index 0889054f1f37..fae0f86ffdae 100644 --- a/gdb/m2-exp.y +++ b/gdb/m2-exp.y @@ -45,11 +45,6 @@ #include "block.h" #include "m2-exp.h" -/* Remap normal yacc parser interface names (yyparse, yylex, yyerror, - etc). */ -#define GDB_YY_REMAP_PREFIX m2_ -#include "yy-remap.h" - /* The state of the parser, used internally when we are parsing the expression. */ diff --git a/gdb/p-exp.y b/gdb/p-exp.y index 70c74beae438..dd4ae2cb209b 100644 --- a/gdb/p-exp.y +++ b/gdb/p-exp.y @@ -51,11 +51,6 @@ #include "block.h" #include "expop.h" -/* Remap normal yacc parser interface names (yyparse, yylex, yyerror, - etc). */ -#define GDB_YY_REMAP_PREFIX pascal_ -#include "yy-remap.h" - /* The state of the parser, used internally when we are parsing the expression. */ diff --git a/gdb/yy-remap.h b/gdb/yy-remap.h deleted file mode 100644 index 0cadf6082fd5..000000000000 --- a/gdb/yy-remap.h +++ /dev/null @@ -1,96 +0,0 @@ -/* Copyright (C) 1986-2026 Free Software Foundation, Inc. - - This file is part of GDB. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . */ - -#ifndef GDB_YY_REMAP_H -#define GDB_YY_REMAP_H - -/* Remap normal yacc parser interface names (yyparse, yylex, yyerror, - etc), as well as gratuitously global symbol names, so we can have - multiple yacc generated parsers in gdb. Note that these are only - the variables produced by yacc. If other parser generators (bison, - byacc, etc) produce additional global names that conflict at link - time, then those parser generators need to be fixed instead of - adding those names to this list. */ - -/* NOTE: This is clumsy since BISON and FLEX provide --prefix options. - We are maintaining it to accommodate systems without BISON. */ - -/* Define GDB_YY_REMAP_PREFIX to the desired remapping prefix before - including this file. */ -#ifndef GDB_YY_REMAP_PREFIX -# error "GDB_YY_REMAP_PREFIX not defined" -#endif - -#define GDB_YY_REMAP_2(PREFIX, YYSYM) PREFIX ## YYSYM -#define GDB_YY_REMAP_1(PREFIX, YYSYM) GDB_YY_REMAP_2 (PREFIX, YYSYM) -#define GDB_YY_REMAP(YYSYM) GDB_YY_REMAP_1 (GDB_YY_REMAP_PREFIX, YYSYM) - -#define yymaxdepth GDB_YY_REMAP (yymaxdepth) -#define yyparse GDB_YY_REMAP (yyparse) -#define yylex GDB_YY_REMAP (yylex) -#define yyerror GDB_YY_REMAP (yyerror) -#define yylval GDB_YY_REMAP (yylval) -#define yychar GDB_YY_REMAP (yychar) -#define yydebug GDB_YY_REMAP (yydebug) -#define yypact GDB_YY_REMAP (yypact) -#define yyr1 GDB_YY_REMAP (yyr1) -#define yyr2 GDB_YY_REMAP (yyr2) -#define yydef GDB_YY_REMAP (yydef) -#define yychk GDB_YY_REMAP (yychk) -#define yypgo GDB_YY_REMAP (yypgo) -#define yyact GDB_YY_REMAP (yyact) -#define yyexca GDB_YY_REMAP (yyexca) -#define yyerrflag GDB_YY_REMAP (yyerrflag) -#define yynerrs GDB_YY_REMAP (yynerrs) -#define yyps GDB_YY_REMAP (yyps) -#define yypv GDB_YY_REMAP (yypv) -#define yys GDB_YY_REMAP (yys) -#define yy_yys GDB_YY_REMAP (yy_yys) -#define yystate GDB_YY_REMAP (yystate) -#define yytmp GDB_YY_REMAP (yytmp) -#define yyv GDB_YY_REMAP (yyv) -#define yy_yyv GDB_YY_REMAP (yy_yyv) -#define yyval GDB_YY_REMAP (yyval) -#define yylloc GDB_YY_REMAP (yylloc) -#define yyreds GDB_YY_REMAP (yyreds) /* With YYDEBUG defined */ -#define yytoks GDB_YY_REMAP (yytoks) /* With YYDEBUG defined */ -#define yyname GDB_YY_REMAP (yyname) /* With YYDEBUG defined */ -#define yyrule GDB_YY_REMAP (yyrule) /* With YYDEBUG defined */ -#define yylhs GDB_YY_REMAP (yylhs) -#define yylen GDB_YY_REMAP (yylen) -#define yydefred GDB_YY_REMAP (yydefred) -#define yydgoto GDB_YY_REMAP (yydgoto) -#define yysindex GDB_YY_REMAP (yysindex) -#define yyrindex GDB_YY_REMAP (yyrindex) -#define yygindex GDB_YY_REMAP (yygindex) -#define yytable GDB_YY_REMAP (yytable) -#define yycheck GDB_YY_REMAP (yycheck) -#define yyss GDB_YY_REMAP (yyss) -#define yysslim GDB_YY_REMAP (yysslim) -#define yyssp GDB_YY_REMAP (yyssp) -#define yystacksize GDB_YY_REMAP (yystacksize) -#define yyvs GDB_YY_REMAP (yyvs) -#define yyvsp GDB_YY_REMAP (yyvsp) -#define YYSTACKDATA GDB_YY_REMAP (YYSTACKDATA) - -/* The following are common to all parsers. */ - -#ifndef YYDEBUG -# define YYDEBUG 1 /* Default to yydebug support */ -#endif - -#endif /* GDB_YY_REMAP_H */ -- 2.55.0