[v1] LoongArch: gas: Adjust DWARF CIE alignment factors

Message ID 20240430022912.1760976-1-mengqinggang@loongson.cn
State New
Headers
Series [v1] LoongArch: gas: Adjust DWARF CIE alignment factors |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_binutils_build--master-arm success Testing passed
linaro-tcwg-bot/tcwg_binutils_build--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_binutils_check--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_binutils_check--master-arm success Testing passed

Commit Message

mengqinggang April 30, 2024, 2:29 a.m. UTC
  Set DWARF2_LINE_MIN_INSN_LENGTH (code alignment factor) to 4.
Set DWARF2_CIE_DATA_ALIGNMENT (data alignment factors) to -8.
It helps to save space.

Code Alignment Factor
An unsigned LEB128 encoded value that is factored out of all advance
location instructions that are associated with this CIE or its FDEs.
This value shall be multiplied by the delta argument of an adavance
location instruction to obtain the new location value.

Data Alignment Factor
A signed LEB128 encoded value that is factored out of all offset
instructions that are associated with this CIE or its FDEs. This value
shall be multiplied by the register offset argument of an offset
instruction to obtain the new offset value.
---
 gas/config/tc-loongarch.h | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
  

Comments

Jinyang He April 30, 2024, 2:57 a.m. UTC | #1
On 2024-04-30 10:29, mengqinggang wrote:

> Set DWARF2_LINE_MIN_INSN_LENGTH (code alignment factor) to 4.
> Set DWARF2_CIE_DATA_ALIGNMENT (data alignment factors) to -8.
> It helps to save space.
>
> Code Alignment Factor
> An unsigned LEB128 encoded value that is factored out of all advance
> location instructions that are associated with this CIE or its FDEs.
> This value shall be multiplied by the delta argument of an adavance
> location instruction to obtain the new location value.
>
> Data Alignment Factor
> A signed LEB128 encoded value that is factored out of all offset
> instructions that are associated with this CIE or its FDEs. This value
> shall be multiplied by the register offset argument of an offset
> instruction to obtain the new offset value.
> ---
>   gas/config/tc-loongarch.h | 10 +++++-----
>   1 file changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/gas/config/tc-loongarch.h b/gas/config/tc-loongarch.h
> index e0d0962e5f0..51bb4d51c11 100644
> --- a/gas/config/tc-loongarch.h
> +++ b/gas/config/tc-loongarch.h
> @@ -101,15 +101,15 @@ extern bool loongarch_frag_align_code (int, int);
>   
>   #define TC_FORCE_RELOCATION_LOCAL(FIX) 1
>   
> -/* Adjust debug_line after relaxation.  */
> -#define DWARF2_USE_FIXED_ADVANCE_PC 1
> -
>   /* Values passed to md_apply_fix don't include symbol values.  */
>   #define MD_APPLY_SYM_VALUE(FIX) 0
>   
>   #define TARGET_USE_CFIPOP 1
> -#define DWARF2_DEFAULT_RETURN_COLUMN 1 /* $ra.  */
> -#define DWARF2_CIE_DATA_ALIGNMENT -4
> +/* Adjust debug_line after relaxation.  */
> +#define DWARF2_USE_FIXED_ADVANCE_PC   1
> +#define DWARF2_LINE_MIN_INSN_LENGTH   4	    /* FDE Code Alignment Factor.  */

That may have a problem about DWARF2_LINE_MIN_INSN_LENGTH. The increment 
of DW_CFA_advance_loc is `DWARF2_LINE_MIN_INSN_LENGTH` times its value.
$ cat 1.s
.global test
.type test, @function
test:
.cfi_startproc
nop
.cfi_def_cfa_offset 32
break 0
.L1: la.pcrel $a0, .L1
break 1
.cfi_def_cfa_register 3
nop
.cfi_endproc
.size test, .-test
$ ./gas/as-new 1.s -o 1.o
$ ./binutils/readelf -Wwf 1.o
...
   DW_CFA_advance_loc: 64 to 0000000000000044
   DW_CFA_def_cfa_register: r3
...

$ ./binutils/readelf -Wr 1.o
...
Relocation section '.rela.eh_frame' at offset 0x200 contains 5 entries:
...
0000000000000028  0000000600000069 R_LARCH_ADD6 0000000000000014 L0^A + 0
0000000000000028  000000050000006a R_LARCH_SUB6 0000000000000004 L0^A + 0
...
This relocation diff is the real value of DW_CFA_advance_loc. Its value 
is (sym(0x6) - sym(0x5)), rather than ((sym(0x6) - 
sym(0x5))/DWARF2_LINE_MIN_INSN_LENGTH).

> +#define DWARF2_CIE_DATA_ALIGNMENT     (-8)  /* FDE Data Alignment Factor.  */
> +#define DWARF2_DEFAULT_RETURN_COLUMN  1	    /* FDE Return Address Register.  */
>   
>   #define tc_cfi_frame_initial_instructions	\
>     loongarch_cfi_frame_initial_instructions
  

Patch

diff --git a/gas/config/tc-loongarch.h b/gas/config/tc-loongarch.h
index e0d0962e5f0..51bb4d51c11 100644
--- a/gas/config/tc-loongarch.h
+++ b/gas/config/tc-loongarch.h
@@ -101,15 +101,15 @@  extern bool loongarch_frag_align_code (int, int);
 
 #define TC_FORCE_RELOCATION_LOCAL(FIX) 1
 
-/* Adjust debug_line after relaxation.  */
-#define DWARF2_USE_FIXED_ADVANCE_PC 1
-
 /* Values passed to md_apply_fix don't include symbol values.  */
 #define MD_APPLY_SYM_VALUE(FIX) 0
 
 #define TARGET_USE_CFIPOP 1
-#define DWARF2_DEFAULT_RETURN_COLUMN 1 /* $ra.  */
-#define DWARF2_CIE_DATA_ALIGNMENT -4
+/* Adjust debug_line after relaxation.  */
+#define DWARF2_USE_FIXED_ADVANCE_PC   1
+#define DWARF2_LINE_MIN_INSN_LENGTH   4	    /* FDE Code Alignment Factor.  */
+#define DWARF2_CIE_DATA_ALIGNMENT     (-8)  /* FDE Data Alignment Factor.  */
+#define DWARF2_DEFAULT_RETURN_COLUMN  1	    /* FDE Return Address Register.  */
 
 #define tc_cfi_frame_initial_instructions	\
   loongarch_cfi_frame_initial_instructions