public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug debug/105089] New: CTF for a defined extern variable is ambiguous
@ 2022-03-28 18:41 ibhagat at gcc dot gnu.org
  2022-03-29  7:39 ` [Bug debug/105089] " rguenth at gcc dot gnu.org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: ibhagat at gcc dot gnu.org @ 2022-03-28 18:41 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105089

            Bug ID: 105089
           Summary: CTF for a defined extern variable is ambiguous
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: debug
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ibhagat at gcc dot gnu.org
  Target Milestone: ---

$ cat extern.c
extern const char a[];
const char a[] = "testme";

$ gcc -gctf -dA -S extern.c

excerpt from extern.s:

        .long   0x5     # objtinfo_var_type
        .long   0x8     # objtinfo_var_type
        .long   0xb     # objtinfo_name
        .long   0x1f    # objtinfo_name
        .long   0xb     # ctv_name
        .long   0x5     # ctv_typeidx
        .long   0x1f    # ctv_name
        .long   0x8     # ctv_typeidx

There are TWO CTF variable records (two ctv_name, each with a ctv_typeidx). 
Further, two CTF objects records as well.

$ gcc -gctf -c extern.c
$ objdump --ctf=.ctf extern.o
shows:

  Variables:
    a ->  8: const const char [7] (size 0x7) -> 7: const char [7] (size 0x7)
    a ->  5: const const char [0] (size 0x0) -> 4: const char [0] (size 0x0)

  Types:
     1: char (size 0x1)
        [0x0] (ID 0x1) (kind 1) char  (aligned at 0x1, format 0x3, offset:bits
0x0:0x8)
     2: const char (size 0x1) -> 1: char (size 0x1)
        [0x0] (ID 0x2) (kind 12) const char  (aligned at 0x1)
     3: void (size 0x0)
        [0x0] (ID 0x3) (kind 1) void  (aligned at 0x0, format 0x1, offset:bits
0x0:0x0)
     4: const char [0] (size 0x0)
        [0x0] (ID 0x4) (kind 4) const char [0]  (aligned at 0x1)
     5: const const char [0] (size 0x0) -> 4: const char [0] (size 0x0)
        [0x0] (ID 0x5) (kind 12) const const char [0]  (aligned at 0x1)
     6: long unsigned int (size 0x8)
        [0x0] (ID 0x6) (kind 1) long unsigned int  (aligned at 0x8, format 0x0,
offset:bits 0x0:0x40)
     7: const char [7] (size 0x7)
        [0x0] (ID 0x7) (kind 4) const char [7]  (aligned at 0x1)
     8: const const char [7] (size 0x7) -> 7: const char [7] (size 0x7)
        [0x0] (ID 0x8) (kind 12) const const char [7]  (aligned at 0x1)

  Strings:
    0: 
    1: char
    6: void
    b: a
    d: long unsigned int
    1f: a
    ...

Note, two entries in the "Variables:" sub-section, and two strings "a" for the
variable name in the "Strings:" sub-section.

In the above case, the compiler must emit only one entry for the variable a
with type specified as const char [7].

Note that, CTF format cannot differentiate between a non-defining extern
variable declaration vs. a defining variable declaration (unlike DWARF). So,
emitting two CTF variable records, one for the non-defining decl and another
for the defining decl will create ambiguity for the linker/CTF reader.

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

end of thread, other threads:[~2023-03-16 21:41 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-28 18:41 [Bug debug/105089] New: CTF for a defined extern variable is ambiguous ibhagat at gcc dot gnu.org
2022-03-29  7:39 ` [Bug debug/105089] " rguenth at gcc dot gnu.org
2022-03-29 15:58 ` ibhagat at gcc dot gnu.org
2022-03-29 16:00 ` ibhagat at gcc dot gnu.org
2022-03-29 16:11 ` pinskia at gcc dot gnu.org
2022-03-29 17:12 ` ibhagat at gcc dot gnu.org
2022-04-14 17:37 ` cvs-commit at gcc dot gnu.org
2022-04-14 17:37 ` cvs-commit at gcc dot gnu.org
2023-03-16 21:41 ` ibhagat 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).