break;
case BTF_KIND_ENUM:
- vlen_bytes += vlen * sizeof (struct btf_enum);
+ vlen_bytes += (dtd->dtd_data.ctti_size == 0x8)
+ ? vlen * sizeof (struct btf_enum64)
+ : vlen * sizeof (struct btf_enum);
break;
case BTF_KIND_FUNC_PROTO:
btf_size_type = 0;
}
+ if (btf_kind == BTF_KIND_ENUM)
+ {
+ btf_kflag = dtd->dtd_enum_unsigned
+ ? BTF_KF_ENUM_UNSIGNED
+ : BTF_KF_ENUM_SIGNED;
+ if (dtd->dtd_data.ctti_size == 0x8)
+ btf_kind = BTF_KIND_ENUM64;
+ }
+
dw2_asm_output_data (4, dtd->dtd_data.ctti_name, "btt_name");
dw2_asm_output_data (4, BTF_TYPE_INFO (btf_kind, btf_kflag, btf_vlen),
"btt_info: kind=%u, kflag=%u, vlen=%u",
case BTF_KIND_UNION:
case BTF_KIND_ENUM:
case BTF_KIND_DATASEC:
+ case BTF_KIND_ENUM64:
dw2_asm_output_data (4, dtd->dtd_data.ctti_size, "btt_size: %uB",
dtd->dtd_data.ctti_size);
return;
}
}
-/* Asm'out an enum constant following a BTF_KIND_ENUM. */
+/* Asm'out an enum constant following a BTF_KIND_ENUM{,64}. */
static void
-btf_asm_enum_const (ctf_dmdef_t * dmd)
+btf_asm_enum_const (unsigned int size, ctf_dmdef_t * dmd)
{
dw2_asm_output_data (4, dmd->dmd_name_offset, "bte_name");
- dw2_asm_output_data (4, dmd->dmd_value, "bte_value");
+ if (size == 4)
+ dw2_asm_output_data (size, dmd->dmd_value, "bte_value");
+ else
+ {
+ dw2_asm_output_data (4, dmd->dmd_value & 0xffffffff, "bte_value_lo32");
+ dw2_asm_output_data (4, (dmd->dmd_value >> 32) & 0xffffffff, "bte_value_hi32");
+ }
}
/* Asm'out a function parameter description following a BTF_KIND_FUNC_PROTO. */
btf_asm_sou_member (ctfc, dmd);
}
-/* Output all enumerator constants following a BTF_KIND_ENUM. */
+/* Output all enumerator constants following a BTF_KIND_ENUM{,64}. */
static void
output_asm_btf_enum_list (ctf_container_ref ARG_UNUSED (ctfc),
for (dmd = dtd->dtd_u.dtu_members;
dmd != NULL; dmd = (ctf_dmdef_t *) ctf_dmd_list_next (dmd))
- btf_asm_enum_const (dmd);
+ btf_asm_enum_const (dtd->dtd_data.ctti_size, dmd);
}
/* Output all function arguments following a BTF_KIND_FUNC_PROTO. */
ctf_id_t
ctf_add_enum (ctf_container_ref ctfc, uint32_t flag, const char * name,
- HOST_WIDE_INT size, dw_die_ref die)
+ HOST_WIDE_INT size, bool eunsigned, dw_die_ref die)
{
ctf_dtdef_ref dtd;
ctf_id_t type;
gcc_assert (size <= CTF_MAX_SIZE);
dtd->dtd_data.ctti_size = size;
+ dtd->dtd_enum_unsigned = eunsigned;
ctfc->ctfc_num_stypes++;
gcc_assert (kind == CTF_K_ENUM && vlen < CTF_MAX_VLEN);
- /* Enum value is of type HOST_WIDE_INT in the compiler, dmd_value is int32_t
- on the other hand. Check bounds and skip adding this enum value if out of
- bounds. */
- if ((value > INT_MAX) || (value < INT_MIN))
+ /* Enum value is of type HOST_WIDE_INT in the compiler, CTF enumerators
+ values in ctf_enum_t is limited to int32_t, BTF supports signed and
+ unsigned enumerators values of 32 and 64 bits, for both debug formats
+ we use ctf_dmdef_t.dmd_value entry of HOST_WIDE_INT type. So check
+ CTF bounds and skip adding this enum value if out of bounds. */
+ if (!btf_debuginfo_p() && ((value > INT_MAX) || (value < INT_MIN)))
{
/* FIXME - Note this TBD_CTF_REPRESENTATION_LIMIT. */
return (1);
ctf_id_t dmd_type; /* Type of this member (for sou). */
uint32_t dmd_name_offset; /* Offset of the name in str table. */
uint64_t dmd_offset; /* Offset of this member in bits (for sou). */
- int dmd_value; /* Value of this member (for enum). */
+ HOST_WIDE_INT dmd_value; /* Value of this member (for enum). */
struct ctf_dmdef * dmd_next; /* A list node. */
} ctf_dmdef_t;
bool from_global_func; /* Whether this type was added from a global
function. */
uint32_t linkage; /* Used in function types. 0=local, 1=global. */
+ bool dtd_enum_unsigned; /* Enum signedness. */
union GTY ((desc ("ctf_dtu_d_union_selector (&%1)")))
{
/* struct, union, or enum. */
extern ctf_id_t ctf_add_reftype (ctf_container_ref, uint32_t, ctf_id_t,
uint32_t, dw_die_ref);
extern ctf_id_t ctf_add_enum (ctf_container_ref, uint32_t, const char *,
- HOST_WIDE_INT, dw_die_ref);
+ HOST_WIDE_INT, bool, dw_die_ref);
extern ctf_id_t ctf_add_slice (ctf_container_ref, uint32_t, ctf_id_t,
uint32_t, uint32_t, dw_die_ref);
extern ctf_id_t ctf_add_float (ctf_container_ref, uint32_t, const char *,
{
const char *enum_name = get_AT_string (enumeration, DW_AT_name);
unsigned int bit_size = ctf_die_bitsize (enumeration);
+ unsigned int signedness = get_AT_unsigned (enumeration, DW_AT_encoding);
int declaration_p = get_AT_flag (enumeration, DW_AT_declaration);
ctf_id_t enumeration_type_id;
/* Generate a CTF type for the enumeration. */
enumeration_type_id = ctf_add_enum (ctfc, CTF_ADD_ROOT,
- enum_name, bit_size / 8, enumeration);
+ enum_name, bit_size / 8,
+ (signedness == DW_ATE_unsigned),
+ enumeration);
/* Process the enumerators. */
{
/* { dg-options "-O0 -gbtf -dA" } */
/* { dg-final { scan-assembler-times "\[\t \]0x6000004\[\t \]+\[^\n\]*btt_info" 1 } } */
-/* { dg-final { scan-assembler-times "\[\t \]0x6000003\[\t \]+\[^\n\]*btt_info" 1 } } */
+/* { dg-final { scan-assembler-times "\[\t \]0x86000003\[\t \]+\[^\n\]*btt_info" 1 } } */
/* { dg-final { scan-assembler-times "ascii \"QAD.0\"\[\t \]+\[^\n\]*btf_string" 1 } } */
/* { dg-final { scan-assembler-times "ascii \"QED.0\"\[\t \]+\[^\n\]*btf_string" 1 } } */
/* { dg-final { scan-assembler-times "ascii \"QOD.0\"\[\t \]+\[^\n\]*btf_string" 1 } } */
--- /dev/null
+/* Test BTF generation for 64 bits enums. */
+
+/* { dg-do compile } */
+/* { dg-options "-O0 -gbtf -dA" } */
+
+/* { dg-final { scan-assembler-times "\[\t \].size\[\t \]myenum1,\[\t \]8" 1 } } */
+/* { dg-final { scan-assembler-times "\[\t \].size\[\t \]myenum2,\[\t \]8" 1 } } */
+/* { dg-final { scan-assembler-times "\[\t \].size\[\t \]myenum3,\[\t \]8" 1 } } */
+/* { dg-final { scan-assembler-times "\[\t \]0x13000003\[\t \]+\[^\n\]*btt_info" 2 } } */
+/* { dg-final { scan-assembler-times "\[\t \]0x93000003\[\t \]+\[^\n\]*btt_info" 1 } } */
+/* { dg-final { scan-assembler-times "\[\t \]0xffffffaa\[\t \]+\[^\n\]*bte_value_lo32" 2 } } */
+/* { dg-final { scan-assembler-times "\[\t \]0xff\[\t \]+\[^\n\]*bte_value_hi32" 3 } } */
+/* { dg-final { scan-assembler-times "ascii \"B1.0\"\[\t \]+\[^\n\]*btf_string" 1 } } */
+/* { dg-final { scan-assembler-times "ascii \"B2.0\"\[\t \]+\[^\n\]*btf_string" 1 } } */
+/* { dg-final { scan-assembler-times "ascii \"B3.0\"\[\t \]+\[^\n\]*btf_string" 1 } } */
+/* { dg-final { scan-assembler-times "ascii \"C1.0\"\[\t \]+\[^\n\]*btf_string" 1 } } */
+/* { dg-final { scan-assembler-times "ascii \"C2.0\"\[\t \]+\[^\n\]*btf_string" 1 } } */
+/* { dg-final { scan-assembler-times "ascii \"C3.0\"\[\t \]+\[^\n\]*btf_string" 1 } } */
+/* { dg-final { scan-assembler-times "ascii \"D1.0\"\[\t \]+\[^\n\]*btf_string" 1 } } */
+/* { dg-final { scan-assembler-times "ascii \"D2.0\"\[\t \]+\[^\n\]*btf_string" 1 } } */
+/* { dg-final { scan-assembler-times "ascii \"D3.0\"\[\t \]+\[^\n\]*btf_string" 1 } } */
+/* { dg-final { scan-assembler-times "bte_value_lo32" 9 } } */
+/* { dg-final { scan-assembler-times "bte_value_hi32" 9 } } */
+
+enum default_enum
+{
+ B1 = 0xffffffffaa,
+ B2 = 0xbbbbbbbb,
+ B3 = 0xaabbccdd,
+} myenum1 = B1;
+
+enum explicit_unsigned
+{
+ C1 = 0xffffffffbbUL,
+ C2 = 0xbbbbbbbb,
+ C3 = 0xaabbccdd,
+} myenum2 = C1;
+
+enum signed64
+{
+ D1 = 0xffffffffaa,
+ D2 = 0xbbbbbbbb,
+ D3 = -0x1,
+} myenum3 = D1;
#define BTF_KIND_VAR 14 /* Variable. */
#define BTF_KIND_DATASEC 15 /* Section such as .bss or .data. */
#define BTF_KIND_FLOAT 16 /* Floating point. */
-#define BTF_KIND_MAX BTF_KIND_FLOAT
+#define BTF_KIND_ENUM64 19 /* Enumeration up to 64 bits. */
+#define BTF_KIND_MAX BTF_KIND_ENUM64
#define NR_BTF_KINDS (BTF_KIND_MAX + 1)
/* For some BTF_KINDs, struct btf_type is immediately followed by
#define BTF_INT_BOOL (1 << 2)
/* BTF_KIND_ENUM is followed by VLEN struct btf_enum entries,
- which describe the enumerators. Note that BTF currently only
- supports signed 32-bit enumerator values. */
+ which describe the enumerators. */
struct btf_enum
{
uint32_t name_off; /* Offset in string section of enumerator name. */
int32_t val; /* Enumerator value. */
};
+/* BTF_KF_ENUM_ holds the flags for kflags in BTF_KIND_ENUM{,64}. */
+#define BTF_KF_ENUM_UNSIGNED (0)
+#define BTF_KF_ENUM_SIGNED (1 << 0)
+
/* BTF_KIND_ARRAY is followed by a single struct btf_array. */
struct btf_array
{
uint32_t size; /* Size (in bytes) of variable. */
};
+/* BTF_KIND_ENUM64 is followed by VLEN struct btf_enum64 entries,
+ which describe the 64 bits enumerators. */
+struct btf_enum64
+{
+ uint32_t name_off; /* Offset in string section of enumerator name. */
+ uint32_t val_lo32; /* lower 32-bit value for a 64-bit value Enumerator */
+ uint32_t val_hi32; /* high 32-bit value for a 64-bit value Enumerator */
+};
+
#ifdef __cplusplus
}
#endif