BTF: Support for BTF_KIND_FLOAT
authorDavid Faust <david.faust@oracle.com>
Tue, 1 Jun 2021 16:22:59 +0000 (09:22 -0700)
committerDavid Faust <david.faust@oracle.com>
Fri, 2 Jul 2021 15:32:44 +0000 (08:32 -0700)
Add BTF_KIND_FLOAT, a new BTF type kind which has recently stabilized in
the linux kernel [1]. This kind is used for encoding floating point
types, and is of particular use when generating BTF for some s390
arch-specific kernel headers.

Also update some BTF tests which previously used floating point types to
check correct behavior for types with no BTF representation.

[1]: https://github.com/torvalds/linux/commit/b1828f0b04828aa8cccadf00a702f459caefeed9

include/ChangeLog:

* btf.h (struct btf_type): Update bit usage comment.
(BTF_INFO_KIND): Update bit mask.
(BTF_KIND_FLOAT): New define.
(BTF_KIND_MAX): Update.

gcc/ChangeLog:

* btfout.c (get_btf_kind): Support BTF_KIND_FLOAT.
(btf_asm_type): Likewise.

gcc/testsuite/ChangeLog:

* gcc.dg/debug/btf/btf-float-1.c: New test.
* gcc.dg/debug/btf/btf-function-3.c: Use different unrepresentable type.
* gcc.dg/debug/btf/btf-struct-2.c: Likewise.
* gcc.dg/debug/btf/btf-variables-2.c: Likewise.

gcc/btfout.c
gcc/testsuite/gcc.dg/debug/btf/btf-float-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/debug/btf/btf-function-3.c
gcc/testsuite/gcc.dg/debug/btf/btf-struct-2.c
gcc/testsuite/gcc.dg/debug/btf/btf-variables-2.c
include/btf.h

index e58c969..8cdd990 100644 (file)
@@ -124,6 +124,7 @@ get_btf_kind (uint32_t ctf_kind)
   switch (ctf_kind)
     {
     case CTF_K_INTEGER:  return BTF_KIND_INT;
+    case CTF_K_FLOAT:   return BTF_KIND_FLOAT;
     case CTF_K_POINTER:  return BTF_KIND_PTR;
     case CTF_K_ARRAY:    return BTF_KIND_ARRAY;
     case CTF_K_FUNCTION: return BTF_KIND_FUNC_PROTO;
@@ -627,6 +628,7 @@ btf_asm_type (ctf_container_ref ctfc, ctf_dtdef_ref dtd)
   switch (btf_kind)
     {
     case BTF_KIND_INT:
+    case BTF_KIND_FLOAT:
     case BTF_KIND_STRUCT:
     case BTF_KIND_UNION:
     case BTF_KIND_ENUM:
diff --git a/gcc/testsuite/gcc.dg/debug/btf/btf-float-1.c b/gcc/testsuite/gcc.dg/debug/btf/btf-float-1.c
new file mode 100644 (file)
index 0000000..6876df0
--- /dev/null
@@ -0,0 +1,20 @@
+/* Tests for BTF floating point type kinds. We expect a single record for each
+   of the base types: float, double and long double.  */
+
+/* { dg-do compile } */
+/* { dg-options "-O0 -gbtf -dA" } */
+
+/* { dg-final { scan-assembler-times "\[\t \]0x10000000\[\t \]+\[^\n\]*btt_info" 3 } } */
+
+/* { dg-final { scan-assembler-times "ascii \"float.0\"\[\t \]+\[^\n\]*btf_string" 1 } } */
+/* { dg-final { scan-assembler-times "ascii \"double.0\"\[\t \]+\[^\n\]*btf_string" 1 } } */
+/* { dg-final { scan-assembler-times "ascii \"long double.0\"\[\t \]+\[^\n\]*btf_string" 1 } } */
+
+float a;
+float b = 1.5f;
+
+double c;
+double d = -99.9;
+
+long double e;
+long double f = 1000.01;
index 35f96a2..c83b823 100644 (file)
@@ -16,7 +16,7 @@
 /* Exactly one function parameter should have type_id=0.  */
 /* { dg-final { scan-assembler-times "\[\t \]0\[\t \]+\[^\n\]*farg_type" 1 } } */
 
-int foo (int a, float f, long b)
+int foo (int a, float __attribute__((__vector_size__(16))) f, long b)
 {
   return 0;
 }
index 24514fc..c3aff09 100644 (file)
@@ -14,6 +14,6 @@
 struct with_float
 {
   int a;
-  float f;
+  float __attribute__((__vector_size__(16))) f;
   char c;
 } instance;
index 0f9742e..db0bdd7 100644 (file)
@@ -16,7 +16,7 @@
 /* { dg-final { scan-assembler-times "ascii \"myst.0\"\[\t \]+\[^\n\]*btf_string" 1 } } */
 
 int foo;
-float bar;
+float __attribute__((__vector_size__(16))) bar;
 int baz[10];
 
 struct st
index 3b1a4c3..bf720ee 100644 (file)
@@ -62,8 +62,8 @@ struct btf_type
   uint32_t info;       /* Encoded kind, variant length, kind flag:
                           - bits  0-15: vlen
                           - bits 16-23: unused
-                          - bits 24-27: kind
-                          - bits 28-30: unused
+                          - bits 24-28: kind
+                          - bits 29-30: unused
                           - bit     31: kind_flag
                           See accessor macros below.  */
 
@@ -79,7 +79,7 @@ struct btf_type
 
 /* The folloing macros access the information encoded in btf_type.info.  */
 /* Type kind. See below.  */
-#define BTF_INFO_KIND(info)    (((info) >> 24) & 0x0f)
+#define BTF_INFO_KIND(info)    (((info) >> 24) & 0x1f)
 /* Number of entries of variable length data following certain type kinds.
    For example, number of structure members, number of function parameters.  */
 #define BTF_INFO_VLEN(info)    ((info) & 0xffff)
@@ -108,7 +108,8 @@ struct btf_type
 #define BTF_KIND_FUNC_PROTO    13      /* Function Prototype.  */
 #define BTF_KIND_VAR           14      /* Variable.  */
 #define BTF_KIND_DATASEC       15      /* Section such as .bss or .data.  */
-#define BTF_KIND_MAX           BTF_KIND_DATASEC
+#define BTF_KIND_FLOAT         16      /* Floating point.  */
+#define BTF_KIND_MAX           BTF_KIND_FLOAT
 #define NR_BTF_KINDS           (BTF_KIND_MAX + 1)
 
 /* For some BTF_KINDs, struct btf_type is immediately followed by