public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH v2] [gdb/build] Work around cgen odr violations
@ 2023-08-21  5:47 Tom de Vries
  2023-08-22 15:48 ` Tom Tromey
  0 siblings, 1 reply; 2+ messages in thread
From: Tom de Vries @ 2023-08-21  5:47 UTC (permalink / raw)
  To: gdb-patches

When building gdb with -flto -O2, I run into:
...
opcodes/mep-desc.h:250:14: warning: type 'cgen_operand_type' violates the \
  C++ One Definition Rule [-Wodr]
 typedef enum cgen_operand_type {
              ^
opcodes/or1k-desc.h:624:14: note: an enum with different value name is \
  defined in another translation unit
 typedef enum cgen_operand_type {
              ^
opcodes/mep-desc.h:212:14: warning: type 'cgen_hw_type' violates the C++ One \
  Definition Rule [-Wodr]
 typedef enum cgen_hw_type {
              ^
opcodes/or1k-desc.h:433:14: note: an enum with different value name is \
  defined in another translation unit
 typedef enum cgen_hw_type {
              ^
...

Fix this by making the conflicting type names unique, adding a target-specific
prefix using a define before the include:
...
 #define cgen_operand_type <target-name>_cgen_operand_type
 #define cgen_hw_type  <target-name>_cgen_hw_type
 #include "opcodes/<target-name>-desc.h"
...
and move those defines into a new file cgen-remap.h, similar to how that's
done for yacc in yy-remap.h.

Likewise for targets frv and lm32, the two other targets that include
opcodes/<target-name>-desc.h.

Likewise for more cgen symbols that I got the same warning for when using
-flto-partition=one.

A PR has been filed to take care of this in the opcodes dir instead (PR30758).

Tested on x86_64-linux.

PR build/30757
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30757
---
 gdb/cgen-remap.h | 53 ++++++++++++++++++++++++++++++++++++++++++++++++
 gdb/frv-tdep.c   |  6 +++++-
 gdb/lm32-tdep.c  |  6 +++++-
 gdb/mep-tdep.c   |  5 ++++-
 gdb/or1k-tdep.h  |  3 +++
 5 files changed, 70 insertions(+), 3 deletions(-)
 create mode 100644 gdb/cgen-remap.h

diff --git a/gdb/cgen-remap.h b/gdb/cgen-remap.h
new file mode 100644
index 00000000000..626047e5ac7
--- /dev/null
+++ b/gdb/cgen-remap.h
@@ -0,0 +1,53 @@
+/* Copyright (C) 2023 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 <http://www.gnu.org/licenses/>.  */
+
+#ifndef CGEN_REMAP_H
+#define CGEN_REMAP_H
+
+/* Remap cgen interface names, so we can have multiple cgen generated include
+   files in gdb without violating c++ ODR.  */
+
+/* Define GDB_CGEN_REMAP_PREFIX to the desired remapping prefix before
+   including this file.  */
+#ifndef GDB_CGEN_REMAP_PREFIX
+# error "GDB_CGEN_REMAP_PREFIX not defined"
+#endif
+
+#define GDB_CGEN_REMAP_2(PREFIX, SYM) PREFIX ## _ ## SYM
+#define GDB_CGEN_REMAP_1(PREFIX, SYM) GDB_CGEN_REMAP_2 (PREFIX, SYM)
+#define GDB_CGEN_REMAP(SYM) GDB_CGEN_REMAP_1 (GDB_CGEN_REMAP_PREFIX, SYM)
+
+#define cgen_operand_type	GDB_CGEN_REMAP (cgen_operand_type)
+#define cgen_hw_type		GDB_CGEN_REMAP (cgen_hw_type)
+#define cgen_ifld		GDB_CGEN_REMAP (cgen_ifld)
+#define cgen_insn		GDB_CGEN_REMAP (cgen_insn)
+#define cgen_cpu_desc		GDB_CGEN_REMAP (cgen_cpu_desc)
+#define cgen_fields		GDB_CGEN_REMAP (cgen_fields)
+#define cgen_insn_list		GDB_CGEN_REMAP (cgen_insn_list)
+#define cgen_maybe_multi_ifield	GDB_CGEN_REMAP (cgen_maybe_multi_ifield)
+#define CGEN_OPINST             GDB_CGEN_REMAP (CGEN_OPINST)
+#define CGEN_IFMT_IFLD		GDB_CGEN_REMAP (CGEN_IFMT_IFLD)
+#define CGEN_INSN_ATTR_TYPE	GDB_CGEN_REMAP (CGEN_INSN_ATTR_TYPE)
+#define CGEN_IBASE		GDB_CGEN_REMAP (CGEN_IBASE)
+#define CGEN_HW_ENTRY		GDB_CGEN_REMAP (CGEN_HW_ENTRY)
+#define CGEN_HW_TABLE		GDB_CGEN_REMAP (CGEN_HW_TABLE)
+#define CGEN_INSN_TABLE		GDB_CGEN_REMAP (CGEN_INSN_TABLE)
+#define CGEN_OPERAND_TABLE	GDB_CGEN_REMAP (CGEN_OPERAND_TABLE)
+#define CGEN_OPERAND		GDB_CGEN_REMAP (CGEN_OPERAND)
+#define CGEN_MAYBE_MULTI_IFLD	GDB_CGEN_REMAP (CGEN_MAYBE_MULTI_IFLD)
+
+#endif /* CGEN_REMAP_H */
diff --git a/gdb/frv-tdep.c b/gdb/frv-tdep.c
index 6c6050a919a..273a5bd7180 100644
--- a/gdb/frv-tdep.c
+++ b/gdb/frv-tdep.c
@@ -29,7 +29,6 @@
 #include "dis-asm.h"
 #include "sim-regno.h"
 #include "sim/sim-frv.h"
-#include "opcodes/frv-desc.h"	/* for the H_SPR_... enums */
 #include "symtab.h"
 #include "elf-bfd.h"
 #include "elf/frv.h"
@@ -40,6 +39,11 @@
 #include "objfiles.h"
 #include "gdbarch.h"
 
+/* Make cgen names unique to prevent ODR conflicts with other targets.  */
+#define GDB_CGEN_REMAP_PREFIX frv
+#include "cgen-remap.h"
+#include "opcodes/frv-desc.h"	/* for the H_SPR_... enums */
+
 struct frv_unwind_cache		/* was struct frame_extra_info */
   {
     /* The previous frame's inner-most stack address.  Used as this
diff --git a/gdb/lm32-tdep.c b/gdb/lm32-tdep.c
index 23998f85dd8..0eecdb6ac40 100644
--- a/gdb/lm32-tdep.c
+++ b/gdb/lm32-tdep.c
@@ -32,10 +32,14 @@
 #include "regcache.h"
 #include "trad-frame.h"
 #include "reggroups.h"
-#include "opcodes/lm32-desc.h"
 #include <algorithm>
 #include "gdbarch.h"
 
+/* Make cgen names unique to prevent ODR conflicts with other targets.  */
+#define GDB_CGEN_REMAP_PREFIX lm32
+#include "cgen-remap.h"
+#include "opcodes/lm32-desc.h"
+
 /* Macros to extract fields from an instruction.  */
 #define LM32_OPCODE(insn)       ((insn >> 26) & 0x3f)
 #define LM32_REG0(insn)         ((insn >> 21) & 0x1f)
diff --git a/gdb/mep-tdep.c b/gdb/mep-tdep.c
index fc786f09e44..85c2e229a5c 100644
--- a/gdb/mep-tdep.c
+++ b/gdb/mep-tdep.c
@@ -47,7 +47,10 @@
 #include "gdbarch.h"
 
 /* Get the user's customized MeP coprocessor register names from
-   libopcodes.  */
+   libopcodes.  Make cgen names unique to prevent ODR conflicts with other
+   targets.  */
+#define GDB_CGEN_REMAP_PREFIX mep
+#include "cgen-remap.h"
 #include "opcodes/mep-desc.h"
 #include "opcodes/mep-opc.h"
 
diff --git a/gdb/or1k-tdep.h b/gdb/or1k-tdep.h
index a11950584d7..b2433d15314 100644
--- a/gdb/or1k-tdep.h
+++ b/gdb/or1k-tdep.h
@@ -23,6 +23,9 @@
 #define TARGET_OR1K
 #endif
 
+/* Make cgen names unique to prevent ODR conflicts with other targets.  */
+#define GDB_CGEN_REMAP_PREFIX or1k
+#include "cgen-remap.h"
 #include "opcodes/or1k-desc.h"
 #include "opcodes/or1k-opc.h"
 

base-commit: 069a1561b76532964b1dcc3bdd8f745e927358d6
-- 
2.35.3


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

* Re: [PATCH v2] [gdb/build] Work around cgen odr violations
  2023-08-21  5:47 [PATCH v2] [gdb/build] Work around cgen odr violations Tom de Vries
@ 2023-08-22 15:48 ` Tom Tromey
  0 siblings, 0 replies; 2+ messages in thread
From: Tom Tromey @ 2023-08-22 15:48 UTC (permalink / raw)
  To: Tom de Vries via Gdb-patches; +Cc: Tom de Vries

>>>>> "Tom" == Tom de Vries via Gdb-patches <gdb-patches@sourceware.org> writes:

Tom> Fix this by making the conflicting type names unique, adding a target-specific
Tom> prefix using a define before the include:
Tom> ...
Tom>  #define cgen_operand_type <target-name>_cgen_operand_type
Tom>  #define cgen_hw_type  <target-name>_cgen_hw_type
Tom>  #include "opcodes/<target-name>-desc.h"
Tom> ...
Tom> and move those defines into a new file cgen-remap.h, similar to how that's
Tom> done for yacc in yy-remap.h.

Looks good, thanks.

Approved-By: Tom Tromey <tom@tromey.com>

Tom

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

end of thread, other threads:[~2023-08-22 17:01 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-21  5:47 [PATCH v2] [gdb/build] Work around cgen odr violations Tom de Vries
2023-08-22 15:48 ` Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).