Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DWARF representation of vector extension types #8

Open
hainest opened this issue Aug 28, 2021 · 4 comments
Open

DWARF representation of vector extension types #8

hainest opened this issue Aug 28, 2021 · 4 comments

Comments

@hainest
Copy link

hainest commented Aug 28, 2021

test.c

#include <immintrin.h>

void foo(__m256 a, float b[8]){}

void bar() {
  __m256 a;
  float b[8];
}

Compiled with gcc-11 -std=c11 -mavx -O3 -g -gdwarf-5 -fPIC -shared -o libtest.so test.c. Dumping with readelf gives1

// float
<1><66>: Abbrev Number: 1 (DW_TAG_base_type)
   <67>   DW_AT_byte_size   : 4
   <68>   DW_AT_encoding    : 4  (float)
   <69>   DW_AT_name        : (indirect string, offset: 0x125): float

// __m256 -> typedef float __m256 __attribute__ ((__vector_size__ (32), __may_alias__));
<1><90>: Abbrev Number: 6 (DW_TAG_typedef)
   <91>   DW_AT_name        : (indirect string, offset: 0xea): __m256
   <98>   DW_AT_type        : <0x9c>
<1><9c>: Abbrev Number: 7 (DW_TAG_array_type)
   <9d>   DW_AT_GNU_vector  : 1
   <9d>   DW_AT_type        : <0x66>

// float[8]
<1><d9>: Abbrev Number: 10 (DW_TAG_array_type)
   <da>   DW_AT_type        : <0x66>
   <de>   DW_AT_sibling     : <0xe9>
<2><e2>: Abbrev Number: 11 (DW_TAG_subrange_type)
   <e3>   DW_AT_type        : <0x35>
   <e7>   DW_AT_upper_bound : 7

// void foo(__m256 a, float b[8]){}
<1><e9>: Abbrev Number: 12 (DW_TAG_subprogram)
   <ea>   DW_AT_name        : foo
<2><107>: Abbrev Number: 3 (DW_TAG_formal_parameter)
   <108>   DW_AT_name        : a
   <10b>   DW_AT_type        : <0x90>
   <10f>   DW_AT_location    : 1 byte block: 61  (DW_OP_reg17 (xmm0))
<2><111>: Abbrev Number: 3 (DW_TAG_formal_parameter)
   <112>   DW_AT_name        : b
   <115>   DW_AT_type        : <0x11c>
   <119>   DW_AT_location    : 1 byte block: 55  (DW_OP_reg5 (rdi))
<1><11c>: Abbrev Number: 13 (DW_TAG_pointer_type)
   <11d>   DW_AT_byte_size   : 8
   <11e>   DW_AT_type        : <0x66>

// void bar() {
//   __m256 a;
//   float b[8];
// }
<1><a8>: Abbrev Number: 9 (DW_TAG_subprogram)
   <a9>   DW_AT_name        : bar
<2><c6>: Abbrev Number: 2 (DW_TAG_variable)
   <c7>   DW_AT_name        : a
   <cb>   DW_AT_type        : <0x90>
<2><cf>: Abbrev Number: 2 (DW_TAG_variable)
   <d0>   DW_AT_name        : b
   <d4>   DW_AT_type        : <0xd9>

The key problem is that DWARF treats vector types as arrays. The only indication you get that you are dealing with a vector type is 1) the name string is __m256 and 2) the non-standard DW_AT_GNU_vector. This is problematic for high-level parsers like Dyninst where that information isn't available until after the determination of array-ness has been made. Also, vectors aren't logically arrays, either; the AMD64 ABI treats them differently (not sure about the others). From a language perspective, they aren't the same because vectors don't possess the awful array-to-pointer decay. You can index them when using gcc, but I'm not sure if that's portable.

I see no reason why we can't just have a DW_TAG_vector_type that has a DW_AT_name, DW_AT_type, and a DW_AT_byte_size.


[1] readelf.log

@woodard
Copy link
Collaborator

woodard commented Aug 28, 2021 via email

@woodard
Copy link
Collaborator

woodard commented Aug 30, 2021 via email

@hainest
Copy link
Author

hainest commented Aug 30, 2021

@woodard Ha! I'm not too surprised. gcc hasn't had the greatest history of doing floating-pointer vector transfers correctly. I'm glad to see that gcc-11 is now matching clang-12, if even by accident.

@woodard
Copy link
Collaborator

woodard commented Aug 31, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants