public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH v1] LoongArch: gas: Adjust DWARF CIE alignment factors
@ 2024-04-30  2:29 mengqinggang
  2024-04-30  2:57 ` Jinyang He
  0 siblings, 1 reply; 2+ messages in thread
From: mengqinggang @ 2024-04-30  2:29 UTC (permalink / raw)
  To: binutils
  Cc: xuchenghua, chenglulu, cailulu, xry111, i.swmail, maskray,
	luweining, hejinyang, mengqinggang

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.  */
+#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
-- 
2.36.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH v1] LoongArch: gas: Adjust DWARF CIE alignment factors
  2024-04-30  2:29 [PATCH v1] LoongArch: gas: Adjust DWARF CIE alignment factors mengqinggang
@ 2024-04-30  2:57 ` Jinyang He
  0 siblings, 0 replies; 2+ messages in thread
From: Jinyang He @ 2024-04-30  2:57 UTC (permalink / raw)
  To: mengqinggang, binutils
  Cc: xuchenghua, chenglulu, cailulu, xry111, i.swmail, maskray, luweining

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-04-30  2:57 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-30  2:29 [PATCH v1] LoongArch: gas: Adjust DWARF CIE alignment factors mengqinggang
2024-04-30  2:57 ` Jinyang He

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).