Project

General

Profile

Bug #12898

ctf enum size detection should use DW_AT_byte_size

Added by Robert Mustacchi 4 months ago. Updated 4 months ago.

Status:
Closed
Priority:
Normal
Category:
lib - userland libraries
Start date:
Due date:
% Done:

100%

Estimated time:
Difficulty:
Medium
Tags:
Gerrit CR:

Description

In the implementation of handling packed enums in #12259 the way that the size was determined was by trying to look at a parent type, if it existed. Optionally converting it and looking at its size. While running the test suite against gcc 4.4.4 and then reviving some of the clang efforts, I found that gcc 4.4.4 and clang when using dwarf-2 failed in the same way. If we look at the dwarf from these, using clang-10 for example with -gdwarf-2:

...
0x000000c8:   DW_TAG_enumeration_type
                DW_AT_name    ("ll_enum")
                DW_AT_byte_size    (0x08)
                DW_AT_decl_file    ("/var/tmp/ctf/test-enum.c")
                DW_AT_decl_line    (43)
...

Note how in this case we have an explicit DW_AT_byte_size; however, the code in question is looking for a DW_AT_type. The similar packed struct would look like:

0x000000e5:   DW_TAG_enumeration_type
                DW_AT_type    (0x00000110 "long long unsigned int")
                DW_AT_name    ("ll_enum")
                DW_AT_byte_size    (0x08)
                DW_AT_decl_file    ("/var/tmp/ctf/test-enum.c")
                DW_AT_decl_line    (43)

Note how it has a DW_AT_type. gcc7 and gcc8 always emits this regardless of whether it uses -gdwarf-2 or -gdwarf-4. The same clang differences in dwarf-2 and dwarf-4 are true across clang 8, 9, and 10.

However, all of the considered compilers always emit a DW_AT_byte_size. In this case we should just simplify the implementation and use the DW_AT_byte_size if present and if not just assume it's normal. I was able to verify that gcc 4.4.4, 7, 8, and clang 8, 9, and 10 all honor this. I'll be circling back on gcc 9/10 a bit later with a broader effort.


Related issues

Related to illumos gate - Bug #12259: CTF shouldn't assume enum sizeClosed

Actions
Related to illumos gate - Bug #10854: empty struct array confuses CTFClosed2019-04-25

Actions

History

#1

Updated by Robert Mustacchi 4 months ago

  • Related to Bug #12259: CTF shouldn't assume enum size added
#2

Updated by Electric Monk 4 months ago

  • Gerrit CR set to 755
#3

Updated by Robert Mustacchi 4 months ago

To verify this I also went through and did a diff of the ctf before and after and the only change was in libctf due to the elimination of the ctf_dwarf_get_type_size() function. I also verified that this made these tests pass on gcc 4, gcc7 (dwarf2/4), and clang 8, 9, and 10 (dwarf2 / dwarf4).

#4

Updated by Dan McDonald 4 months ago

  • Related to Bug #10854: empty struct array confuses CTF added
#5

Updated by Electric Monk 4 months ago

  • Status changed from New to Closed
  • % Done changed from 80 to 100

git commit 56f23fa092900d6145428feaadd69e5157186680

commit  56f23fa092900d6145428feaadd69e5157186680
Author: Robert Mustacchi <rm@fingolfin.org>
Date:   2020-07-02T14:54:21.000Z

    12898 ctf enum size detection should use DW_AT_byte_size
    Reviewed by: Rich Lowe <richlowe@richlowe.net>
    Reviewed by: Igor Kozhukhov <igor@dilos.org>
    Reviewed by: Jason King <jason.brian.king@gmail.com>
    Approved by: Dan McDonald <danmcd@joyent.com>

Also available in: Atom PDF