]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
bpf: Fix access string default for CO-RE type based relocations
authorCupertino Miranda <cupertino.miranda@oracle.com>
Tue, 5 Mar 2024 11:53:56 +0000 (11:53 +0000)
committerCupertino Miranda <cupertino.miranda@oracle.com>
Wed, 20 Mar 2024 20:27:15 +0000 (20:27 +0000)
Although part of all CO-RE relocation data, type based relocations do
not require an access string.
Initial implementation defined it as an empty string.
On the other hand, libbpf when parsing the CO-RE relocations verifies
that those strings would contain "0", otherwise reports an error.
This patch makes GCC compliant with libbpf expectations.

gcc/Changelog:
* config/bpf/btfext-out.cc (cpf_core_reloc_add): Correct for new code.
Add assert to validate the string is set.
* config/bpf/core-builtins.cc (cr_final): Make string struct
field as const.
(process_enum_value): Correct for field type change.
(process_type): Set access string to "0".

gcc/testsuite/ChangeLog:
* gcc.target/bpf/core-builtin-type-based.c: Correct.
* gcc.target/bpf/core-builtin-type-id.c: Correct.

gcc/config/bpf/btfext-out.cc
gcc/config/bpf/core-builtins.cc
gcc/testsuite/gcc.target/bpf/core-builtin-type-based.c
gcc/testsuite/gcc.target/bpf/core-builtin-type-id.c

index 00d2501a976b4dd2ecff6498cf3602842a1f6547..7ec438fd1d106eefc164b1956751cadcd98899ef 100644 (file)
@@ -299,8 +299,9 @@ bpf_core_reloc_add (const tree type, const char * section_name,
 
   /* Buffer the access string in the auxiliary strtab.  */
   bpfcr->bpfcr_astr_off = 0;
-  if (accessor != NULL)
-    bpfcr->bpfcr_astr_off = btf_ext_add_string (accessor);
+  gcc_assert (accessor != NULL);
+  bpfcr->bpfcr_astr_off = btf_ext_add_string (accessor);
+
   bpfcr->bpfcr_type = get_btf_id (ctf_lookup_tree_type (ctfc, type));
   bpfcr->bpfcr_insn_label = label;
   bpfcr->bpfcr_kind = kind;
index 4256fea15e49a0e6a83d1c15698c83486fd6867b..70b14e48e6e5a30c26f1869392697244503ec707 100644 (file)
@@ -205,7 +205,7 @@ struct cr_local
 /* Core Relocation Final data */
 struct cr_final
 {
-  char *str;
+  const char *str;
   tree type;
   enum btf_core_reloc_kind kind;
 };
@@ -868,8 +868,10 @@ process_enum_value (struct cr_builtins *data)
        {
          if (TREE_VALUE (l) == expr)
            {
-             ret.str = (char *) ggc_alloc_atomic ((index / 10) + 1);
-             sprintf (ret.str, "%d", index);
+             char *tmp = (char *) ggc_alloc_atomic ((index / 10) + 1);
+             sprintf (tmp, "%d", index);
+             ret.str = (const char *) tmp;
+
              break;
            }
          index++;
@@ -987,7 +989,7 @@ process_type (struct cr_builtins *data)
              || data->kind == BPF_RELO_TYPE_MATCHES);
 
   struct cr_final ret;
-  ret.str = NULL;
+  ret.str = ggc_strdup ("0");
   ret.type = data->type;
   ret.kind = data->kind;
 
index 74a8d5a14d9dd2e8c21884f78619fa3a03295aa7..9d818133c084c67fd2586f643e506ce0a7596958 100644 (file)
@@ -56,3 +56,4 @@ int foo(void *data)
 /* { dg-final { scan-assembler-times "0x8\[\t \]+\[^\n\]*bpfcr_kind" 13 } } BPF_TYPE_EXISTS */
 /* { dg-final { scan-assembler-times "0x9\[\t \]+\[^\n\]*bpfcr_kind" 11 } } BPF_TYPE_SIZE */
 /* { dg-final { scan-assembler-times "0xc\[\t \]+\[^\n\]*bpfcr_kind" 13 } } BPF_TYPE_MATCHES */
+/* { dg-final { scan-assembler-times "bpfcr_astr_off \[(\"\]+0\[(\"\]+" 37 } } */
index 4b23288eac08b8ea09903c692dffa64845d8007e..9576b91bc940015966c833d1b7562f5dc7e26ff6 100644 (file)
@@ -38,3 +38,4 @@ int foo(void *data)
 /* { dg-final { scan-assembler-times "0\[\t \]+\[^\n\]*bpfcr_type" 0  { xfail *-*-* } } } */
 /* { dg-final { scan-assembler-times "0x6\[\t \]+\[^\n\]*bpfcr_kind" 13 } } BPF_TYPE_ID_LOCAL */
 /* { dg-final { scan-assembler-times "0x7\[\t \]+\[^\n\]*bpfcr_kind" 7 } } BPF_TYPE_ID_TARGET */
+/* { dg-final { scan-assembler-times "bpfcr_astr_off \[(\"\]+0\[(\"\]+" 20 } } */