public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug debug/113977] New: debug info for alignment of structure is unspecified
@ 2024-02-18 2:06 tsqurt at outlook dot com
2024-02-18 2:29 ` [Bug debug/113977] " pinskia at gcc dot gnu.org
` (13 more replies)
0 siblings, 14 replies; 15+ messages in thread
From: tsqurt at outlook dot com @ 2024-02-18 2:06 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113977
Bug ID: 113977
Summary: debug info for alignment of structure is unspecified
Product: gcc
Version: 13.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: debug
Assignee: unassigned at gcc dot gnu.org
Reporter: tsqurt at outlook dot com
Target Milestone: ---
Created attachment 57454
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=57454&action=edit
src.c
GCC does not generate complete debug information for my C code when generating
debug information. The alignment requirement for my structures is 1, but the
debugger believes their alignment requirement is 8 (which is likely inherited
from the default structure alignment requirement on the platform).
I'm using the AMD64 instruction set, and the operating system is Ubuntu 20.04.6
LTS on Windows Subsystem for Linux.
To reproduce this issue, follow these steps with the attached code:
gcc src.c -gdwarf-5 -o a.out && gdb a.out
(gdb) b 13
Breakpoint 1 at 0x1170: file src.c, line 13.
(gdb) run
Starting program: a.out
Breakpoint 1, main () at src.c:13
13 return 0;
(gdb) expr z[0]._[0] = 1
(gdb) expr y[0]._[0] = 1
(gdb) expr x[0]._[0] = 1
gdb command line:1:1: error: alignment of array elements is greater than
element size
Compilation failed.
(gdb)
GDB reports that the alignment requirement for these structures is 8, but it is
1.
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug debug/113977] debug info for alignment of structure is unspecified
2024-02-18 2:06 [Bug debug/113977] New: debug info for alignment of structure is unspecified tsqurt at outlook dot com
@ 2024-02-18 2:29 ` pinskia at gcc dot gnu.org
2024-02-18 2:32 ` [Bug libcc1/113977] " pinskia at gcc dot gnu.org
` (12 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-02-18 2:29 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113977
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
This seems like a bug in gdb really.
GCC produces:
```
.uleb128 0x3 # (DIE (0x2e) DW_TAG_structure_type)
.ascii "s7\0" # DW_AT_name
.byte 0x7 # DW_AT_byte_size
# DW_AT_decl_file (1, /app/example.cpp)
.byte 0x1 # DW_AT_decl_line
# DW_AT_decl_column (0x8)
.long 0x41 # DW_AT_sibling
.uleb128 0x4 # (DIE (0x38) DW_TAG_member)
.ascii "_\0" # DW_AT_name
# DW_AT_decl_file (1, /app/example.cpp)
.byte 0x1 # DW_AT_decl_line
# DW_AT_decl_column (0x12)
.long 0x41 # DW_AT_type
# DW_AT_data_member_location (0)
.byte 0 # end of children of DIE 0x2e
.uleb128 0x2 # (DIE (0x41) DW_TAG_array_type)
.long 0x58 # DW_AT_type
.long 0x51 # DW_AT_sibling
```
```
.ascii "x\0" # DW_AT_name
# DW_AT_decl_file (1, /app/example.cpp)
.byte 0x7 # DW_AT_decl_line
# DW_AT_decl_column (0xd)
.long 0xf1 # DW_AT_type
.uleb128 0x2 # DW_AT_location
.byte 0x91 # DW_OP_fbreg
.sleb128 -30
```
```
.uleb128 0x2 # (DIE (0xf1) DW_TAG_array_type)
.long 0x2e # DW_AT_type
.long 0x101 # DW_AT_sibling
.uleb128 0x1 # (DIE (0xfa) DW_TAG_subrange_type)
.long 0x51 # DW_AT_type
.byte 0x1 # DW_AT_upper_bound
.byte 0 # end of children of DIE 0xf1
```
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug libcc1/113977] debug info for alignment of structure is unspecified
2024-02-18 2:06 [Bug debug/113977] New: debug info for alignment of structure is unspecified tsqurt at outlook dot com
2024-02-18 2:29 ` [Bug debug/113977] " pinskia at gcc dot gnu.org
@ 2024-02-18 2:32 ` pinskia at gcc dot gnu.org
2024-02-18 2:35 ` pinskia at gcc dot gnu.org
` (11 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-02-18 2:32 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113977
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Component|debug |libcc1
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Or is it is a bug in libcc1.
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug libcc1/113977] debug info for alignment of structure is unspecified
2024-02-18 2:06 [Bug debug/113977] New: debug info for alignment of structure is unspecified tsqurt at outlook dot com
2024-02-18 2:29 ` [Bug debug/113977] " pinskia at gcc dot gnu.org
2024-02-18 2:32 ` [Bug libcc1/113977] " pinskia at gcc dot gnu.org
@ 2024-02-18 2:35 ` pinskia at gcc dot gnu.org
2024-02-18 2:41 ` tsqurt at outlook dot com
` (10 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-02-18 2:35 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113977
--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
For me with the trunk GCC we get:
```
(gdb) expr z[0]._[0] = 1
gdb command line:1:1: error: size of array element is not a multiple of its
alignment
Compilation failed.
(gdb) expr y[0]._[0] = 1
(gdb) expr x[0]._[0] = 1
gdb command line:1:1: error: alignment of array elements is greater than
element size
Compilation failed.
```
I am starting to think this is a gdb issue ...
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug libcc1/113977] debug info for alignment of structure is unspecified
2024-02-18 2:06 [Bug debug/113977] New: debug info for alignment of structure is unspecified tsqurt at outlook dot com
` (2 preceding siblings ...)
2024-02-18 2:35 ` pinskia at gcc dot gnu.org
@ 2024-02-18 2:41 ` tsqurt at outlook dot com
2024-02-18 2:47 ` pinskia at gcc dot gnu.org
` (9 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: tsqurt at outlook dot com @ 2024-02-18 2:41 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113977
--- Comment #4 from Tan Senqi <tsqurt at outlook dot com> ---
(In reply to Andrew Pinski from comment #3)
> For me with the trunk GCC we get:
> ```
> (gdb) expr z[0]._[0] = 1
> gdb command line:1:1: error: size of array element is not a multiple of its
> alignment
> Compilation failed.
> (gdb) expr y[0]._[0] = 1
> (gdb) expr x[0]._[0] = 1
> gdb command line:1:1: error: alignment of array elements is greater than
> element size
> Compilation failed.
>
> ```
>
> I am starting to think this is a gdb issue ...
I think gcc can generate a DW_AT_alignment for my struct to solve this problem.
But why the alignment is considered as 8, I am not sure about this. If it is
inherited from the default structure alignment requirement on the platform,
then gcc should specify alignment for those whose alignment is not 8. Or 8 is
not the default value by DWARF5(i.e. undefined), then it is surely a bug in
gdb.
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug libcc1/113977] debug info for alignment of structure is unspecified
2024-02-18 2:06 [Bug debug/113977] New: debug info for alignment of structure is unspecified tsqurt at outlook dot com
` (3 preceding siblings ...)
2024-02-18 2:41 ` tsqurt at outlook dot com
@ 2024-02-18 2:47 ` pinskia at gcc dot gnu.org
2024-02-18 2:48 ` pinskia at gcc dot gnu.org
` (8 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-02-18 2:47 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113977
--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Tan Senqi from comment #4)
> (In reply to Andrew Pinski from comment #3)
> I think gcc can generate a DW_AT_alignment for my struct to solve this
> problem. But why the alignment is considered as 8, I am not sure about this.
> If it is inherited from the default structure alignment requirement on the
> platform, then gcc should specify alignment for those whose alignment is not
> 8. Or 8 is not the default value by DWARF5(i.e. undefined), then it is
> surely a bug in gdb.
So reading the definition of DW_AT_alignment, it is if the alignment is not the
default for that type. In this case it should be 1 as char arrays have
alignment of 1 inside structs.
See https://dwarfstd.org/issues/140528.1.html for the definition.
in this case the ABI specifies the alignment and GCC does not need to emit
DW_AT_alignment since it is not different from the ABI. This would mean the bug
is in gdb's gcc_convert_symbol, eg.:
```
gcc_convert_symbol "z": local symbol
gdb command line:1:1: error: size of array element is not a multiple of its
alignment
```
I am testing the trunk gdb right now to see if it was fixed.
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug libcc1/113977] debug info for alignment of structure is unspecified
2024-02-18 2:06 [Bug debug/113977] New: debug info for alignment of structure is unspecified tsqurt at outlook dot com
` (4 preceding siblings ...)
2024-02-18 2:47 ` pinskia at gcc dot gnu.org
@ 2024-02-18 2:48 ` pinskia at gcc dot gnu.org
2024-02-18 2:58 ` pinskia at gcc dot gnu.org
` (7 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-02-18 2:48 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113977
--- Comment #6 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
trunk gdb fails too.
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug libcc1/113977] debug info for alignment of structure is unspecified
2024-02-18 2:06 [Bug debug/113977] New: debug info for alignment of structure is unspecified tsqurt at outlook dot com
` (5 preceding siblings ...)
2024-02-18 2:48 ` pinskia at gcc dot gnu.org
@ 2024-02-18 2:58 ` pinskia at gcc dot gnu.org
2024-02-18 3:06 ` pinskia at gcc dot gnu.org
` (6 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-02-18 2:58 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113977
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution|--- |MOVED
See Also| |https://sourceware.org/bugz
| |illa/show_bug.cgi?id=31397
--- Comment #7 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Moved to https://sourceware.org/bugzilla/show_bug.cgi?id=31397 since this is
almost definitely a bug in gdb's gcc_convert_symbol or gdb's understanding of
the struct.
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug libcc1/113977] debug info for alignment of structure is unspecified
2024-02-18 2:06 [Bug debug/113977] New: debug info for alignment of structure is unspecified tsqurt at outlook dot com
` (6 preceding siblings ...)
2024-02-18 2:58 ` pinskia at gcc dot gnu.org
@ 2024-02-18 3:06 ` pinskia at gcc dot gnu.org
2024-02-20 18:27 ` tromey at gcc dot gnu.org
` (5 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-02-18 3:06 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113977
--- Comment #8 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
>(which is likely inherited from the default structure alignment requirement on the platform)
That is wrong assumption really. Since the ABI (the platform) says the
alignment is type depedent and in this case the types are arrays of 7,8,9 in
size of type char which definition has an alignment of 1 for the ABI.
Anyways this is definitely a gdb bug in "mis"understanding the ABI.
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug libcc1/113977] debug info for alignment of structure is unspecified
2024-02-18 2:06 [Bug debug/113977] New: debug info for alignment of structure is unspecified tsqurt at outlook dot com
` (7 preceding siblings ...)
2024-02-18 3:06 ` pinskia at gcc dot gnu.org
@ 2024-02-20 18:27 ` tromey at gcc dot gnu.org
2024-02-20 18:32 ` pinskia at gcc dot gnu.org
` (4 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: tromey at gcc dot gnu.org @ 2024-02-20 18:27 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113977
Tom Tromey <tromey at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |tromey at gcc dot gnu.org
--- Comment #9 from Tom Tromey <tromey at gcc dot gnu.org> ---
I think this should be reopened -- some of the fix has
to happen in libcc1.
When this code was written, there was no way to find
the alignment in DWARF. That's since been fixed but
the protocol wasn't updated. There are some comments
about this, see libcc1/libcc1plugin.cc:
// FIXME there's no way to get this from DWARF,
// or even, it seems, a particularly good way to deduce it.
SET_TYPE_ALIGN (record_or_union_type,
TYPE_PRECISION (pointer_sized_int_node));
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug libcc1/113977] debug info for alignment of structure is unspecified
2024-02-18 2:06 [Bug debug/113977] New: debug info for alignment of structure is unspecified tsqurt at outlook dot com
` (8 preceding siblings ...)
2024-02-20 18:27 ` tromey at gcc dot gnu.org
@ 2024-02-20 18:32 ` pinskia at gcc dot gnu.org
2024-02-22 1:46 ` tromey at gcc dot gnu.org
` (3 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-02-20 18:32 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113977
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Ever confirmed|0 |1
Resolution|MOVED |---
Last reconfirmed| |2024-02-20
Status|RESOLVED |NEW
--- Comment #10 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed for the libcc1 part that needs to be improved.
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug libcc1/113977] debug info for alignment of structure is unspecified
2024-02-18 2:06 [Bug debug/113977] New: debug info for alignment of structure is unspecified tsqurt at outlook dot com
` (9 preceding siblings ...)
2024-02-20 18:32 ` pinskia at gcc dot gnu.org
@ 2024-02-22 1:46 ` tromey at gcc dot gnu.org
2024-02-29 16:08 ` cvs-commit at gcc dot gnu.org
` (2 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: tromey at gcc dot gnu.org @ 2024-02-22 1:46 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113977
Tom Tromey <tromey at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Assignee|unassigned at gcc dot gnu.org |tromey at gcc dot gnu.org
--- Comment #11 from Tom Tromey <tromey at gcc dot gnu.org> ---
I have a patch.
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug libcc1/113977] debug info for alignment of structure is unspecified
2024-02-18 2:06 [Bug debug/113977] New: debug info for alignment of structure is unspecified tsqurt at outlook dot com
` (10 preceding siblings ...)
2024-02-22 1:46 ` tromey at gcc dot gnu.org
@ 2024-02-29 16:08 ` cvs-commit at gcc dot gnu.org
2024-02-29 16:34 ` tromey at gcc dot gnu.org
2024-03-07 8:20 ` pinskia at gcc dot gnu.org
13 siblings, 0 replies; 15+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-02-29 16:08 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113977
--- Comment #12 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Tom Tromey <tromey@gcc.gnu.org>:
https://gcc.gnu.org/g:bc0e18a960f9dff3e740f4d0cb5b25b3f68d920a
commit r14-9239-gbc0e18a960f9dff3e740f4d0cb5b25b3f68d920a
Author: Tom Tromey <tom@tromey.com>
Date: Mon Feb 26 18:21:03 2024 -0700
Fix PR libcc1/113977
PR libcc1/113977 points out a case where a simple expression is
rejected with a compiler error message. The bug here is that gdb does
not inform the plugin of the correct alignment -- in fact, there is no
way to do that.
This patch adds a new method to allow the alignment to be set, and
bumps the C front end protocol version.
It also includes some updates to various comments in 'include', done
here to simplify the merge to binutils-gdb.
include
* gcc-cp-interface.h (gcc_cp_fe_context_function): Update
comment.
* gcc-c-interface.h (enum gcc_c_api_version) <GCC_C_FE_VERSION_2>:
New constant.
(gcc_c_fe_context_function): Update comment.
* gcc-c-fe.def (finish_record_with_alignment): New method.
Update documentation.
libcc1
PR libcc1/113977
* libcc1plugin.cc (plugin_finish_record_or_union): New function.
(plugin_finish_record_or_union): Rewrite.
(plugin_init): Use GCC_C_FE_VERSION_2.
* libcc1.cc (c_vtable): Use GCC_C_FE_VERSION_2.
(gcc_c_fe_context): Check for GCC_C_FE_VERSION_2.
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug libcc1/113977] debug info for alignment of structure is unspecified
2024-02-18 2:06 [Bug debug/113977] New: debug info for alignment of structure is unspecified tsqurt at outlook dot com
` (11 preceding siblings ...)
2024-02-29 16:08 ` cvs-commit at gcc dot gnu.org
@ 2024-02-29 16:34 ` tromey at gcc dot gnu.org
2024-03-07 8:20 ` pinskia at gcc dot gnu.org
13 siblings, 0 replies; 15+ messages in thread
From: tromey at gcc dot gnu.org @ 2024-02-29 16:34 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113977
--- Comment #13 from Tom Tromey <tromey at gcc dot gnu.org> ---
This is fixed on trunk now.
I think that means it'll be in GCC 14... ?
Which maybe I shouldn't have done according to the current status.
Anyway, I'm not sure any more how gcc manages bugs, so I don't
know if I should close this or what.
gdb fix still not in, will do that soon.
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug libcc1/113977] debug info for alignment of structure is unspecified
2024-02-18 2:06 [Bug debug/113977] New: debug info for alignment of structure is unspecified tsqurt at outlook dot com
` (12 preceding siblings ...)
2024-02-29 16:34 ` tromey at gcc dot gnu.org
@ 2024-03-07 8:20 ` pinskia at gcc dot gnu.org
13 siblings, 0 replies; 15+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-03-07 8:20 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113977
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Target Milestone|--- |14.0
Resolution|--- |FIXED
--- Comment #14 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
So fixed for GCC 14.
^ permalink raw reply [flat|nested] 15+ messages in thread
end of thread, other threads:[~2024-03-07 8:20 UTC | newest]
Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-18 2:06 [Bug debug/113977] New: debug info for alignment of structure is unspecified tsqurt at outlook dot com
2024-02-18 2:29 ` [Bug debug/113977] " pinskia at gcc dot gnu.org
2024-02-18 2:32 ` [Bug libcc1/113977] " pinskia at gcc dot gnu.org
2024-02-18 2:35 ` pinskia at gcc dot gnu.org
2024-02-18 2:41 ` tsqurt at outlook dot com
2024-02-18 2:47 ` pinskia at gcc dot gnu.org
2024-02-18 2:48 ` pinskia at gcc dot gnu.org
2024-02-18 2:58 ` pinskia at gcc dot gnu.org
2024-02-18 3:06 ` pinskia at gcc dot gnu.org
2024-02-20 18:27 ` tromey at gcc dot gnu.org
2024-02-20 18:32 ` pinskia at gcc dot gnu.org
2024-02-22 1:46 ` tromey at gcc dot gnu.org
2024-02-29 16:08 ` cvs-commit at gcc dot gnu.org
2024-02-29 16:34 ` tromey at gcc dot gnu.org
2024-03-07 8:20 ` pinskia at gcc dot gnu.org
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).