binutils-gdb/gdb/cgen-remap.h
Tom de Vries 883d90a0ff [gdb/build] Work around cgen odr violations
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.

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

PR build/30757
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30757
2023-08-22 19:35:52 +02:00

54 lines
2.3 KiB
C

/* 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 */