diff mbox series

[v2] bpf: write CO-RE relocation record size only once

Message ID 20220118211130.7459-1-david.faust@oracle.com
State New
Headers show
Series [v2] bpf: write CO-RE relocation record size only once | expand

Commit Message

David Faust Jan. 18, 2022, 9:11 p.m. UTC
[Changed from v1: Adjust to account for file renaming so patch applies.]

The CO-RE relocation record size should be written only once in the
.BTF.ext section, not once for each section with relocations.

Tested for bpf-unknown-none. OK to install?
Thanks.

gcc/ChangeLog:

	* config/bpf/coreout.cc (output_btfext_header): Account for
	4-byte record size in core_relo_len.
	(output_btfext_core_sections): Only write record size once.
	* config/bpf/coreout.h (btf_ext_section_header): Delete unused
	member.

gcc/testsuite/ChangeLog:

	* gcc.target/bpf/core-section-1.c: Adjust expected record size
	occurrences.
---
 gcc/config/bpf/coreout.cc                     | 14 +++++++++-----
 gcc/config/bpf/coreout.h                      |  1 -
 gcc/testsuite/gcc.target/bpf/core-section-1.c |  2 +-
 3 files changed, 10 insertions(+), 7 deletions(-)

Comments

Jose E. Marchesi Jan. 18, 2022, 9:17 p.m. UTC | #1
Hi David.

> [Changed from v1: Adjust to account for file renaming so patch applies.]
>
> The CO-RE relocation record size should be written only once in the
> .BTF.ext section, not once for each section with relocations.
>
> Tested for bpf-unknown-none. OK to install?

This is OK.
Thanks for the patch.

> Thanks.
>
> gcc/ChangeLog:
>
> 	* config/bpf/coreout.cc (output_btfext_header): Account for
> 	4-byte record size in core_relo_len.
> 	(output_btfext_core_sections): Only write record size once.
> 	* config/bpf/coreout.h (btf_ext_section_header): Delete unused
> 	member.
>
> gcc/testsuite/ChangeLog:
>
> 	* gcc.target/bpf/core-section-1.c: Adjust expected record size
> 	occurrences.
> ---
>  gcc/config/bpf/coreout.cc                     | 14 +++++++++-----
>  gcc/config/bpf/coreout.h                      |  1 -
>  gcc/testsuite/gcc.target/bpf/core-section-1.c |  2 +-
>  3 files changed, 10 insertions(+), 7 deletions(-)
>
> diff --git a/gcc/config/bpf/coreout.cc b/gcc/config/bpf/coreout.cc
> index f8ca2804207..4ec12ecd305 100644
> --- a/gcc/config/bpf/coreout.cc
> +++ b/gcc/config/bpf/coreout.cc
> @@ -259,7 +259,7 @@ output_btfext_header (void)
>    uint32_t core_relo_off = 0, core_relo_len = 0;
>  
>    /* Header core_relo_len is the sum total length in bytes of all CO-RE
> -     relocation sections.  */
> +     relocation sections, plus the 4 byte record size.  */
>    size_t i;
>    bpf_core_section_ref sec;
>    core_relo_len += vec_safe_length (bpf_core_sections)
> @@ -269,6 +269,9 @@ output_btfext_header (void)
>      core_relo_len +=
>        vec_safe_length (sec->relocs) * sizeof (struct btf_ext_reloc);
>  
> +  if (core_relo_len)
> +    core_relo_len += sizeof (uint32_t);
> +
>    dw2_asm_output_data (4, func_info_off, "func_info_offset");
>    dw2_asm_output_data (4, func_info_len, "func_info_len");
>  
> @@ -310,12 +313,13 @@ output_btfext_core_sections (void)
>  {
>    size_t i;
>    bpf_core_section_ref sec;
> +
> +  /* BTF Ext section info. */
> +  dw2_asm_output_data (4, sizeof (struct btf_ext_reloc),
> +		       "btfext_core_info_rec_size");
> +
>    FOR_EACH_VEC_ELT (*bpf_core_sections, i, sec)
>      {
> -      /* BTF Ext section info. */
> -      dw2_asm_output_data (4, sizeof (struct btf_ext_reloc),
> -			   "btfext_secinfo_rec_size");
> -
>        /* Section name offset, refers to the offset of a string with the name of
>  	 the section to which these CORE relocations refer, e.g. '.text'.
>  	 The string is buffered in the BTF strings table.  */
> diff --git a/gcc/config/bpf/coreout.h b/gcc/config/bpf/coreout.h
> index a9d7e364ba3..3c7bdfd8c2f 100644
> --- a/gcc/config/bpf/coreout.h
> +++ b/gcc/config/bpf/coreout.h
> @@ -33,7 +33,6 @@ extern "C"
>  
>  struct btf_ext_section_header
>  {
> -  uint32_t kind;
>    uint32_t sec_name_off;
>    uint32_t num_records;
>  };
> diff --git a/gcc/testsuite/gcc.target/bpf/core-section-1.c b/gcc/testsuite/gcc.target/bpf/core-section-1.c
> index 031acd5292e..4f16b087c1a 100644
> --- a/gcc/testsuite/gcc.target/bpf/core-section-1.c
> +++ b/gcc/testsuite/gcc.target/bpf/core-section-1.c
> @@ -35,4 +35,4 @@ int bar_func (struct T *t)
>  /* { dg-final { scan-assembler-times "ascii \"foo_sec.0\"\[\t \]+\[^\n\]*btf_aux_string" 1 } } */
>  /* { dg-final { scan-assembler-times "ascii \"bar_sec.0\"\[\t \]+\[^\n\]*btf_aux_string" 1 } } */
>  /* { dg-final { scan-assembler-times "bpfcr_type" 2 } } */
> -/* { dg-final { scan-assembler-times "btfext_secinfo_rec_size" 2 } } */
> +/* { dg-final { scan-assembler-times "btfext_core_info_rec_size" 1 } } */
David Faust Jan. 18, 2022, 9:44 p.m. UTC | #2
On 1/18/22 13:17, Jose E. Marchesi wrote:
> 
> Hi David.
> 
>> [Changed from v1: Adjust to account for file renaming so patch applies.]
>>
>> The CO-RE relocation record size should be written only once in the
>> .BTF.ext section, not once for each section with relocations.
>>
>> Tested for bpf-unknown-none. OK to install?
> 
> This is OK.
> Thanks for the patch.

Pushed, thanks

> 
>> Thanks.
>>
>> gcc/ChangeLog:
>>
>> 	* config/bpf/coreout.cc (output_btfext_header): Account for
>> 	4-byte record size in core_relo_len.
>> 	(output_btfext_core_sections): Only write record size once.
>> 	* config/bpf/coreout.h (btf_ext_section_header): Delete unused
>> 	member.
>>
>> gcc/testsuite/ChangeLog:
>>
>> 	* gcc.target/bpf/core-section-1.c: Adjust expected record size
>> 	occurrences.
>> ---
>>   gcc/config/bpf/coreout.cc                     | 14 +++++++++-----
>>   gcc/config/bpf/coreout.h                      |  1 -
>>   gcc/testsuite/gcc.target/bpf/core-section-1.c |  2 +-
>>   3 files changed, 10 insertions(+), 7 deletions(-)
>>
>> diff --git a/gcc/config/bpf/coreout.cc b/gcc/config/bpf/coreout.cc
>> index f8ca2804207..4ec12ecd305 100644
>> --- a/gcc/config/bpf/coreout.cc
>> +++ b/gcc/config/bpf/coreout.cc
>> @@ -259,7 +259,7 @@ output_btfext_header (void)
>>     uint32_t core_relo_off = 0, core_relo_len = 0;
>>   
>>     /* Header core_relo_len is the sum total length in bytes of all CO-RE
>> -     relocation sections.  */
>> +     relocation sections, plus the 4 byte record size.  */
>>     size_t i;
>>     bpf_core_section_ref sec;
>>     core_relo_len += vec_safe_length (bpf_core_sections)
>> @@ -269,6 +269,9 @@ output_btfext_header (void)
>>       core_relo_len +=
>>         vec_safe_length (sec->relocs) * sizeof (struct btf_ext_reloc);
>>   
>> +  if (core_relo_len)
>> +    core_relo_len += sizeof (uint32_t);
>> +
>>     dw2_asm_output_data (4, func_info_off, "func_info_offset");
>>     dw2_asm_output_data (4, func_info_len, "func_info_len");
>>   
>> @@ -310,12 +313,13 @@ output_btfext_core_sections (void)
>>   {
>>     size_t i;
>>     bpf_core_section_ref sec;
>> +
>> +  /* BTF Ext section info. */
>> +  dw2_asm_output_data (4, sizeof (struct btf_ext_reloc),
>> +		       "btfext_core_info_rec_size");
>> +
>>     FOR_EACH_VEC_ELT (*bpf_core_sections, i, sec)
>>       {
>> -      /* BTF Ext section info. */
>> -      dw2_asm_output_data (4, sizeof (struct btf_ext_reloc),
>> -			   "btfext_secinfo_rec_size");
>> -
>>         /* Section name offset, refers to the offset of a string with the name of
>>   	 the section to which these CORE relocations refer, e.g. '.text'.
>>   	 The string is buffered in the BTF strings table.  */
>> diff --git a/gcc/config/bpf/coreout.h b/gcc/config/bpf/coreout.h
>> index a9d7e364ba3..3c7bdfd8c2f 100644
>> --- a/gcc/config/bpf/coreout.h
>> +++ b/gcc/config/bpf/coreout.h
>> @@ -33,7 +33,6 @@ extern "C"
>>   
>>   struct btf_ext_section_header
>>   {
>> -  uint32_t kind;
>>     uint32_t sec_name_off;
>>     uint32_t num_records;
>>   };
>> diff --git a/gcc/testsuite/gcc.target/bpf/core-section-1.c b/gcc/testsuite/gcc.target/bpf/core-section-1.c
>> index 031acd5292e..4f16b087c1a 100644
>> --- a/gcc/testsuite/gcc.target/bpf/core-section-1.c
>> +++ b/gcc/testsuite/gcc.target/bpf/core-section-1.c
>> @@ -35,4 +35,4 @@ int bar_func (struct T *t)
>>   /* { dg-final { scan-assembler-times "ascii \"foo_sec.0\"\[\t \]+\[^\n\]*btf_aux_string" 1 } } */
>>   /* { dg-final { scan-assembler-times "ascii \"bar_sec.0\"\[\t \]+\[^\n\]*btf_aux_string" 1 } } */
>>   /* { dg-final { scan-assembler-times "bpfcr_type" 2 } } */
>> -/* { dg-final { scan-assembler-times "btfext_secinfo_rec_size" 2 } } */
>> +/* { dg-final { scan-assembler-times "btfext_core_info_rec_size" 1 } } */
diff mbox series

Patch

diff --git a/gcc/config/bpf/coreout.cc b/gcc/config/bpf/coreout.cc
index f8ca2804207..4ec12ecd305 100644
--- a/gcc/config/bpf/coreout.cc
+++ b/gcc/config/bpf/coreout.cc
@@ -259,7 +259,7 @@  output_btfext_header (void)
   uint32_t core_relo_off = 0, core_relo_len = 0;
 
   /* Header core_relo_len is the sum total length in bytes of all CO-RE
-     relocation sections.  */
+     relocation sections, plus the 4 byte record size.  */
   size_t i;
   bpf_core_section_ref sec;
   core_relo_len += vec_safe_length (bpf_core_sections)
@@ -269,6 +269,9 @@  output_btfext_header (void)
     core_relo_len +=
       vec_safe_length (sec->relocs) * sizeof (struct btf_ext_reloc);
 
+  if (core_relo_len)
+    core_relo_len += sizeof (uint32_t);
+
   dw2_asm_output_data (4, func_info_off, "func_info_offset");
   dw2_asm_output_data (4, func_info_len, "func_info_len");
 
@@ -310,12 +313,13 @@  output_btfext_core_sections (void)
 {
   size_t i;
   bpf_core_section_ref sec;
+
+  /* BTF Ext section info. */
+  dw2_asm_output_data (4, sizeof (struct btf_ext_reloc),
+		       "btfext_core_info_rec_size");
+
   FOR_EACH_VEC_ELT (*bpf_core_sections, i, sec)
     {
-      /* BTF Ext section info. */
-      dw2_asm_output_data (4, sizeof (struct btf_ext_reloc),
-			   "btfext_secinfo_rec_size");
-
       /* Section name offset, refers to the offset of a string with the name of
 	 the section to which these CORE relocations refer, e.g. '.text'.
 	 The string is buffered in the BTF strings table.  */
diff --git a/gcc/config/bpf/coreout.h b/gcc/config/bpf/coreout.h
index a9d7e364ba3..3c7bdfd8c2f 100644
--- a/gcc/config/bpf/coreout.h
+++ b/gcc/config/bpf/coreout.h
@@ -33,7 +33,6 @@  extern "C"
 
 struct btf_ext_section_header
 {
-  uint32_t kind;
   uint32_t sec_name_off;
   uint32_t num_records;
 };
diff --git a/gcc/testsuite/gcc.target/bpf/core-section-1.c b/gcc/testsuite/gcc.target/bpf/core-section-1.c
index 031acd5292e..4f16b087c1a 100644
--- a/gcc/testsuite/gcc.target/bpf/core-section-1.c
+++ b/gcc/testsuite/gcc.target/bpf/core-section-1.c
@@ -35,4 +35,4 @@  int bar_func (struct T *t)
 /* { dg-final { scan-assembler-times "ascii \"foo_sec.0\"\[\t \]+\[^\n\]*btf_aux_string" 1 } } */
 /* { dg-final { scan-assembler-times "ascii \"bar_sec.0\"\[\t \]+\[^\n\]*btf_aux_string" 1 } } */
 /* { dg-final { scan-assembler-times "bpfcr_type" 2 } } */
-/* { dg-final { scan-assembler-times "btfext_secinfo_rec_size" 2 } } */
+/* { dg-final { scan-assembler-times "btfext_core_info_rec_size" 1 } } */