[1/2] Output CodeView type information for references

Message ID 20240720193120.19722-1-mark@harmstone.com
State Committed
Commit 7341607544e01a4a155613470b2ef099b051b881
Headers
Series [1/2] Output CodeView type information for references |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gcc_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_gcc_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_gcc_check--master-aarch64 success Test passed
linaro-tcwg-bot/tcwg_gcc_check--master-arm success Test passed

Commit Message

Mark Harmstone July 20, 2024, 7:31 p.m. UTC
  Translates DW_TAG_reference_type DIEs into LF_POINTER types.

gcc/
	* dwarf2codeview.cc (get_type_num_reference_type): New function.
	(get_type_num_array_type): Add DW_TAG_reference_type to switch.
	(get_type_num): Handle DW_TAG_reference_type DIEs.
	* dwarf2codeview.h (CV_PTR_MODE_LVREF): Define.
---
 gcc/dwarf2codeview.cc | 44 +++++++++++++++++++++++++++++++++++++++++++
 gcc/dwarf2codeview.h  |  1 +
 2 files changed, 45 insertions(+)
  

Comments

Jeff Law July 23, 2024, 10:06 p.m. UTC | #1
On 7/20/24 1:31 PM, Mark Harmstone wrote:
> Translates DW_TAG_reference_type DIEs into LF_POINTER types.
> 
> gcc/
> 	* dwarf2codeview.cc (get_type_num_reference_type): New function.
> 	(get_type_num_array_type): Add DW_TAG_reference_type to switch.
> 	(get_type_num): Handle DW_TAG_reference_type DIEs.
> 	* dwarf2codeview.h (CV_PTR_MODE_LVREF): Define.
Both patches in this series are fine.

Thanks!
jeff
  

Patch

diff --git a/gcc/dwarf2codeview.cc b/gcc/dwarf2codeview.cc
index c174f320480..23175204acd 100644
--- a/gcc/dwarf2codeview.cc
+++ b/gcc/dwarf2codeview.cc
@@ -2293,6 +2293,45 @@  get_type_num_pointer_type (dw_die_ref type, bool in_struct)
   return ct->num;
 }
 
+/* Process a DW_TAG_reference_type DIE, add a new LF_POINTER type, and return
+   its number.  */
+
+static uint32_t
+get_type_num_reference_type (dw_die_ref type, bool in_struct)
+{
+  uint32_t base_type_num, byte_size;
+  dw_die_ref base_type;
+  codeview_custom_type *ct;
+
+  byte_size = get_AT_unsigned (type, DW_AT_byte_size);
+  if (byte_size != 4 && byte_size != 8)
+    return 0;
+
+  base_type = get_AT_ref (type, DW_AT_type);
+
+  base_type_num = get_type_num (base_type, in_struct, false);
+  if (base_type_num == 0)
+    return 0;
+
+  ct = (codeview_custom_type *) xmalloc (sizeof (codeview_custom_type));
+
+  ct->next = NULL;
+  ct->kind = LF_POINTER;
+  ct->lf_pointer.base_type = base_type_num;
+  ct->lf_pointer.attributes = CV_PTR_MODE_LVREF;
+
+  if (byte_size == 4)
+    ct->lf_pointer.attributes |= CV_PTR_NEAR32;
+  else
+    ct->lf_pointer.attributes |= CV_PTR_64;
+
+  ct->lf_pointer.attributes |= byte_size << 13;
+
+  add_custom_type (ct);
+
+  return ct->num;
+}
+
 /* Process a DW_TAG_const_type DIE, adding an LF_MODIFIER type and returning
    its number.  */
 
@@ -3024,6 +3063,7 @@  get_type_num_array_type (dw_die_ref type, bool in_struct)
 	case DW_TAG_class_type:
 	case DW_TAG_union_type:
 	case DW_TAG_pointer_type:
+	case DW_TAG_reference_type:
 	  size = get_AT_unsigned (t, DW_AT_byte_size);
 	  break;
 
@@ -3151,6 +3191,10 @@  get_type_num (dw_die_ref type, bool in_struct, bool no_fwd_ref)
       num = get_type_num_pointer_type (type, in_struct);
       break;
 
+    case DW_TAG_reference_type:
+      num = get_type_num_reference_type (type, in_struct);
+      break;
+
     case DW_TAG_const_type:
       num = get_type_num_const_type (type, in_struct);
       break;
diff --git a/gcc/dwarf2codeview.h b/gcc/dwarf2codeview.h
index 8fd3632e524..7d4e3ab1db4 100644
--- a/gcc/dwarf2codeview.h
+++ b/gcc/dwarf2codeview.h
@@ -55,6 +55,7 @@  along with GCC; see the file COPYING3.  If not see
 /* LF_POINTER attributes.  */
 #define CV_PTR_NEAR32		0x0a
 #define CV_PTR_64		0x0c
+#define CV_PTR_MODE_LVREF	0x20
 
 /* LF_MODIFIER values.  */
 #define MOD_const		0x1