ctf enum size detection should use DW_AT_byte_size
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.
Updated by Robert Mustacchi about 1 year 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).
Updated by Electric Monk about 1 year ago
- Status changed from New to Closed
- % Done changed from 80 to 100
commit 56f23fa092900d6145428feaadd69e5157186680 Author: Robert Mustacchi <firstname.lastname@example.org> Date: 2020-07-02T14:54:21.000Z 12898 ctf enum size detection should use DW_AT_byte_size Reviewed by: Rich Lowe <email@example.com> Reviewed by: Igor Kozhukhov <firstname.lastname@example.org> Reviewed by: Jason King <email@example.com> Approved by: Dan McDonald <firstname.lastname@example.org>