Upon building gdb with -flto I'm getting dozens of errors like: nat/linux-btrace.h:85:8: warning: type ‘struct btrace_target_info’ violates the C++ One Definition Rule [-Wodr] struct btrace_target_info ^ remote.c:13157:8: note: a different type is defined in another translation unit struct btrace_target_info ^ nat/linux-btrace.h:102:5: note: the first difference of corresponding definitions is field ‘variant’ } variant; ^ remote.c:13157:8: note: a type with different number of fields is defined in another translation unit struct btrace_target_info ^ I didn't dig through all of them, but the primary reason seems to be that build-toolchain picks up "g++" as the compiler, whereas the gdb source code does not have .cpp files.
Actually, GDB _is_ a C++ program nowadays [1]. The ODR violations should be fixed. [1] - https://sourceware.org/gdb/wiki/cxx-conversion
The 'compile' component refers to the 'compile' feature, not building gdb.
I got bit debugging an ODR problem in gdb today. I'd accidentally given a struct a name that was already in use. This would be nice to fix.
When using gold as the linker, could try --detect-odr-violations
(In reply to Tom Tromey from comment #3) > I got bit debugging an ODR problem in gdb today. > I'd accidentally given a struct a name that was already in use. > This would be nice to fix. Note that in C, it's valid to have different definitions of structures in different translation units. If GDB isn't coping with that, then I'd say it's a GDB bug. (Not saying we shouldn't fix the ODR violation, of course.)
(In reply to Pedro Alves from comment #5) > (In reply to Tom Tromey from comment #3) > > I got bit debugging an ODR problem in gdb today. > > I'd accidentally given a struct a name that was already in use. > > This would be nice to fix. > > Note that in C, it's valid to have different definitions of structures in > different translation units. If GDB isn't coping with that, then I'd say > it's a GDB bug. > > (Not saying we shouldn't fix the ODR violation, of course.) What happened was that I accidentally introduced a violation into gdb. The code was working for a while, but then I added another field to the structure in question, and I was puzzled because vector.push_back was crashing. It took me a while to figure out why this could possibly be happening. I don't know if -Wodr would really catch this though. (In reply to Christian Biesinger from comment #4) > When using gold as the linker, could try --detect-odr-violations I tried this just now but it didn't report anything. That seems incorrect though.
-Wodr works together with -flto.
*** Bug 28444 has been marked as a duplicate of this bug. ***
The dup points out another ODR violation, not sure if it is platform-specific or not.
More fixes here: https://sourceware.org/pipermail/gdb-patches/2022-May/189194.html
I checked in those fixes, but there are still more ODR violations remaining, so this bug should stay open.
We are still reproducing it in gentoo with 12.1: https://bugs.gentoo.org/853898 ada-exp.c.tmp:576:7: error: type ‘union YYSTYPE’ violates the C++ One Definition Rule [-Werror=odr]
I looked into this a bit, but fixing the YYSTYPE one is a real pain unless perhaps we are willing to require bison so that we can use a bison-specific feature. The usual remapping approach doesn't work because the generated .c file checks: #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED union YYSTYPE { ... I guess maybe we could write out the union by hand but that seems pretty ugly.
(In reply to Hi-Angel from comment #0) > nat/linux-btrace.h:85:8: warning: type ‘struct btrace_target_info’ violates > the C++ One Definition Rule [-Wodr] > struct btrace_target_info > ^ > remote.c:13157:8: note: a different type is defined in another translation > unit > struct btrace_target_info > ^ > nat/linux-btrace.h:102:5: note: the first difference of corresponding > definitions is field ‘variant’ > } variant; > ^ > remote.c:13157:8: note: a type with different number of fields is defined > in another translation unit > struct btrace_target_info > ^ I've filed this particular one as PR30751, and cc-ed the btrace maintainer.
(In reply to Tom Tromey from comment #13) > I looked into this a bit, but fixing the YYSTYPE one is > a real pain unless perhaps we are willing to require bison > so that we can use a bison-specific feature. > > The usual remapping approach doesn't work because > the generated .c file checks: > > #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED > union YYSTYPE > { > ... > > I guess maybe we could write out the union by hand but > that seems pretty ugly. I've proposed a patch for this ( https://sourceware.org/pipermail/gdb-patches/2023-August/201600.html ).
The master branch has been updated by Tom de Vries <vries@sourceware.org>: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=6a93ab8af49be41a44af1b4651e9ab2ebc6d2f77 commit 6a93ab8af49be41a44af1b4651e9ab2ebc6d2f77 Author: Tom de Vries <tdevries@suse.de> Date: Mon Aug 14 18:32:29 2023 +0200 [gdb/build] Fix enum param_types odr violation When building gdb with -O2 -flto, I run into: ... gdb/guile/scm-param.c:121:6: warning: type 'param_types' violates the C++ \ One Definition Rule [-Wodr] enum param_types ^ gdb/python/py-param.c:33:6: note: an enum with different value name is \ defined in another translation unit enum param_types ^ ... Fix this by renaming to enum scm_param_types and py_param_types. Tested on x86_64-linux. Approved-By: Tom Tromey <tom@tromey.com> PR build/22395 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=22395
The master branch has been updated by Tom de Vries <vries@sourceware.org>: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=9972aac27d5d664a29abc88acd3a84c1e72064c4 commit 9972aac27d5d664a29abc88acd3a84c1e72064c4 Author: Tom de Vries <tdevries@suse.de> Date: Mon Aug 14 18:32:29 2023 +0200 [gdb/build] Fix struct token_and_value odr violation When build gdb with -O2 -flto I run into: ... gdb/c-exp.y:3003:8: warning: type 'struct token_and_value' violates the C++ \ One Definition Rule [-Wodr] struct token_and_value ^ gdb/d-exp.y:1310:8: note: a different type is defined in another translation \ unit struct token_and_value ^ ... Fix this by renaming to c_token_and_value and d_token_and_value. Likewise in gdb/go-exp.y, renaming to go_token_and_value. Tested on x86_64-linux. Approved-By: Tom Tromey <tom@tromey.com> PR build/22395 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=22395
The master branch has been updated by Tom de Vries <vries@sourceware.org>: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=e72b937dddaf24d99ec1bf3beda4d8ecf3cd368c commit e72b937dddaf24d99ec1bf3beda4d8ecf3cd368c Author: Tom de Vries <tdevries@suse.de> Date: Mon Aug 14 18:32:29 2023 +0200 [gdb/build] Fix struct token odr violation When building gdb with -O2 -flto I run into: ... /data/vries/gdb/src/gdb/c-exp.y:2450:8: warning: type 'struct token' \ violates the C++ One Definition Rule [-Wodr] struct token ^ /data/vries/gdb/src/gdb/d-exp.y:939:8: note: a different type is defined in \ another translation unit struct token ^ ... Fix this by renaming to c_token and d_token. Likewise in: - fortran-exp.y, renaming to f_token, - go-exp.y, renaming to go_token, and - p-exp.y, renaming to p_token. Tested on x86_64-linux. Approved-By: Tom Tromey <tom@tromey.com> PR build/22395 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=22395
The master branch has been updated by Tom de Vries <vries@sourceware.org>: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=bc6c74b1406cd9f71b432ac61799c1d1bea60a39 commit bc6c74b1406cd9f71b432ac61799c1d1bea60a39 Author: Tom de Vries <tdevries@suse.de> Date: Mon Aug 14 22:52:52 2023 +0200 [gdb/build] Fix YYSTYPE and yyalloc odr violation When building gdb with -O2 -flto I run into: ... ada-exp.c.tmp:576:7: error: type âunion YYSTYPEâ violates the C++ One \ Definition Rule [-Werror=odr] ... Fix this by renaming to ada_exp_YYSTYPE and likewise for other .y files. Likewise for yyalloc. Tested on x86_64-linux. Also tested with byacc rather than bison on suggestion of Tom Tromey. Approved-By: Tom Tromey <tom@tromey.com> PR build/22395 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=22395
The master branch has been updated by Tom de Vries <vries@sourceware.org>: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=0c9546b152f6b01756475ce259c895d3fa446774 commit 0c9546b152f6b01756475ce259c895d3fa446774 Author: Tom de Vries <tdevries@suse.de> Date: Thu Aug 17 17:09:39 2023 +0200 [gdb/build] Fix yysymbol_kind_t odr violation When building gdb with -O2 -flto on openSUSE Tumbleweed (using bison 3.8.2) I run into: ... ada-exp.c.tmp:653: warning: type 'yysymbol_kind_t' violates the C++ One \ Definition Rule [-Wodr] c-exp.c.tmp:398: note: an enum with different value name is defined in \ another translation unit ada-exp.c.tmp:660: note: name 'YYSYMBOL_NULL_PTR' differs from name \ 'YYSYMBOL_COMPLEX_INT' defined in another translation unit c-exp.c.tmp:405: note: mismatching definition ... Fix this by renaming to ada_exp_yysymbol_kind_t and likewise for other .y files. Tested on x86_64-linux. PR build/22395 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=22395
AFAICT, no more ODR warnings, so I'm marking this fixed.