]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
btf: Emit labels in DATASEC bts_offset entries.
authorCupertino Miranda <cupertino.miranda@oracle.com>
Tue, 26 Mar 2024 11:59:47 +0000 (11:59 +0000)
committerCupertino Miranda <cupertino.miranda@oracle.com>
Tue, 26 Mar 2024 16:18:00 +0000 (16:18 +0000)
GCC was defining bts_offset entry to always contain 0.
When comparing with clang, the same entry is instead a label to the
respective variable or function. The assembler emits relocations for
those labels.

gcc/ChangeLog:
PR target/114431
* btfout.cc (get_name_for_datasec_entry): Add function.
(btf_asm_datasec_entry): Print label when possible.

gcc/testsuite/ChangeLog:
* gcc.dg/debug/btf/btf-datasec-1.c: Correct for new
implementation.
* gcc.dg/debug/btf/btf-datasec-2.c: Likewise
* gcc.dg/debug/btf/btf-pr106773.c: Likewise

gcc/btfout.cc
gcc/testsuite/gcc.dg/debug/btf/btf-datasec-1.c
gcc/testsuite/gcc.dg/debug/btf/btf-datasec-2.c
gcc/testsuite/gcc.dg/debug/btf/btf-pr106773.c

index 7aabd99f3e7c5cf6c23aa61c26344f1191d052de..2e2b3524e835489573383b0d55573f7853c88b25 100644 (file)
@@ -1014,13 +1014,41 @@ btf_asm_func_type (ctf_container_ref ctfc, ctf_dtdef_ref dtd, ctf_id_t id)
   btf_asm_type_ref ("btt_type", ctfc, get_btf_id (ref_id));
 }
 
+/* Collect the name for the DATASEC reference required to be output as a
+   symbol. */
+
+static const char *
+get_name_for_datasec_entry (ctf_container_ref ctfc, ctf_id_t ref_id)
+{
+  if (ref_id >= num_types_added + 1
+      && ref_id < num_types_added + num_vars_added + 1)
+    {
+      /* Ref to a variable.  Should only appear in DATASEC entries.  */
+      ctf_id_t var_id = btf_relative_var_id (ref_id);
+      ctf_dvdef_ref dvd = ctfc->ctfc_vars_list[var_id];
+      return dvd->dvd_name;
+    }
+  else if (ref_id >= num_types_added + num_vars_added + 1)
+    {
+      /* Ref to a FUNC record.  */
+      size_t func_id = btf_relative_func_id (ref_id);
+      ctf_dtdef_ref ref_type = (*funcs)[func_id];
+      return get_btf_type_name (ref_type);
+    }
+  return NULL;
+}
+
 /* Asm'out a variable entry following a BTF_KIND_DATASEC.  */
 
 static void
 btf_asm_datasec_entry (ctf_container_ref ctfc, struct btf_var_secinfo info)
 {
+  const char *symbol_name = get_name_for_datasec_entry (ctfc, info.type);
   btf_asm_type_ref ("bts_type", ctfc, info.type);
-  dw2_asm_output_data (4, info.offset, "bts_offset");
+  if (symbol_name == NULL)
+    dw2_asm_output_data (4, info.offset, "bts_offset");
+  else
+    dw2_asm_output_offset (4, symbol_name, NULL, "bts_offset");
   dw2_asm_output_data (4, info.size, "bts_size");
 }
 
index 77df88648c54ded6f9d06649f3dad8dc826ee253..8557c38c20d8d2569e3d01fc97ebc6b753000437 100644 (file)
 /* { dg-final { scan-assembler-times "0xf000003\[\t \]+\[^\n\]*btt_info" 2 } } */
 /* { dg-final { scan-assembler-times "0xf000001\[\t \]+\[^\n\]*btt_info" 1 } } */
 
-/* The offset entry for each variable in a DATSEC should be 0 at compile time.  */
-/* { dg-final { scan-assembler-times "0\[\t \]+\[^\n\]*bts_offset" 7 } } */
+/* The offset entry for each variable in a DATSEC should contain a label.  */
+/* { dg-final { scan-assembler-times ".4byte\[\t \]\[a-e\]\[\t \]+\[^\n\]*bts_offset" 5 } } */
+/* { dg-final { scan-assembler-times "my_cstruct\[\t \]+\[^\n\]*bts_offset" 1 } } */
+/* { dg-final { scan-assembler-times "bigarr\[\t \]+\[^\n\]*bts_offset" 1 } } */
 
 /* Check that strings for each DATASEC have been added to the BTF string table.  */
 /* { dg-final { scan-assembler-times "ascii \".data.0\"\[\t \]+\[^\n\]*btf_aux_string" 1 } } */
index d6f3358d6fb02f31b868a65f40d98f3b71dadf25..857d830e446544bf5de47c2b305c382171145ed8 100644 (file)
@@ -9,8 +9,11 @@
 /* { dg-final { scan-assembler-times " BTF_KIND_DATASEC '.foo_sec'\[\\r\\n\]+\[^\\r\\n\]*0xf000001\[\t \]+\[^\n\]*btt_info" 1 } } */
 /* { dg-final { scan-assembler-times " BTF_KIND_DATASEC '.bar_sec'\[\\r\\n\]+\[^\\r\\n\]*0xf000002\[\t \]+\[^\n\]*btt_info" 1 } } */
 
-/* Function entries should have offset and size of 0 at compile time.  */
-/* { dg-final { scan-assembler-times "0\[\t \]+\[^\n\]*bts_offset" 3 } } */
+/* Function entries should have offset with a label and size of 0 at compile time.  */
+/* { dg-final { scan-assembler-times "chacha\[\t \]+\[^\n\]*bts_offset" 1 } } */
+/* { dg-final { scan-assembler-times "bar\[\t \]+\[^\n\]*bts_offset" 1 } } */
+/* { dg-final { scan-assembler-times "foo\[\t \]+\[^\n\]*bts_offset" 1 } } */
+
 /* { dg-final { scan-assembler-times "0\[\t \]+\[^\n\]*bts_size" 3 } } */
 
 extern int foo (int a) __attribute__((section(".foo_sec")));
index 940f129408dc1bcd293cc16acda23820349002e8..c06220eb5204bdbcc4cc93a38998039d6ec92486 100644 (file)
@@ -11,7 +11,7 @@
 
 /* { dg-final { scan-assembler-times "ascii \"foo.0\"\[\t \]+\[^\n\]*btf_string" 1 } } */
 
-/* { dg-final { scan-assembler-times "0\[\t \]+\[^\n\]*bts_offset" 1 } } */
+/* { dg-final { scan-assembler-times "foo\[\t \]+\[^\n\]*bts_offset" 1 } } */
 /* { dg-final { scan-assembler-times "1\[\t \]+\[^\n\]*bts_size" 1 } } */
 
 extern const void foo __attribute__((weak)) __attribute__((section (".ksyms")));