[v1,1/6] LoongArch: include: Add support for linker relaxation.

Message ID 20221205080453.1352069-2-mengqinggang@loongson.cn
State Accepted
Headers
Series LoongArch linker relaxation support. |

Checks

Context Check Description
snail/binutils-gdb-check success Github commit url

Commit Message

mengqinggang Dec. 5, 2022, 8:04 a.m. UTC
  Add relocs and gas LARCH_opts.relax option.

include/ChangeLog:

	* elf/loongarch.h: Add relocs.
	* opcode/loongarch.h: Add LARCH_opts.relax and macro LARCH_NOP.
---
 include/elf/loongarch.h    | 20 ++++++++++++++++++++
 include/opcode/loongarch.h |  3 +++
 2 files changed, 23 insertions(+)
  

Comments

Xi Ruoyao Dec. 5, 2022, 8:24 a.m. UTC | #1
On Mon, 2022-12-05 at 16:04 +0800, mengqinggang wrote:
> Add relocs and gas LARCH_opts.relax option.
> 
> include/ChangeLog:
> 
>         * elf/loongarch.h: Add relocs.
>         * opcode/loongarch.h: Add LARCH_opts.relax and macro
> LARCH_NOP.
> ---
>  include/elf/loongarch.h    | 20 ++++++++++++++++++++
>  include/opcode/loongarch.h |  3 +++
>  2 files changed, 23 insertions(+)
> 
> diff --git a/include/elf/loongarch.h b/include/elf/loongarch.h
> index a6341b46791..0ecddd17b37 100644
> --- a/include/elf/loongarch.h
> +++ b/include/elf/loongarch.h
> @@ -229,6 +229,26 @@ RELOC_NUMBER (R_LARCH_32_PCREL, 99)
>  /* RELAX.  */
>  RELOC_NUMBER (R_LARCH_RELAX, 100)
>  

Please add the description of the following new relocation types into
the psELF ABI doc first.

> +/* relax delete.  */
> +RELOC_NUMBER (R_LARCH_DELETE, 101)
> +
> +/* relax align.  */
> +RELOC_NUMBER (R_LARCH_ALIGN, 102)
> +
> +/* pcaddi.  */
> +RELOC_NUMBER (R_LARCH_PCREL20_S2, 103)
> +
> +/* cfa.  */
> +RELOC_NUMBER (R_LARCH_CFA, 104)
> +
> +/* DW_CFA_advance_loc.  */
> +RELOC_NUMBER (R_LARCH_ADD6, 105)
> +RELOC_NUMBER (R_LARCH_SUB6, 106)
> +
> +/* unsinged leb128.  */

Typo: "unsigned".

I often mistype this too.

> +RELOC_NUMBER (R_LARCH_ADD_ULEB128, 107)
> +RELOC_NUMBER (R_LARCH_SUB_ULEB128, 108)
> +
  
mengqinggang Dec. 6, 2022, 2:59 a.m. UTC | #2
The new relocs document at here:
     https://github.com/loongson/LoongArch-Documentation/pull/77

在 2022/12/5 下午4:24, Xi Ruoyao 写道:
> On Mon, 2022-12-05 at 16:04 +0800, mengqinggang wrote:
>> Add relocs and gas LARCH_opts.relax option.
>>
>> include/ChangeLog:
>>
>>          * elf/loongarch.h: Add relocs.
>>          * opcode/loongarch.h: Add LARCH_opts.relax and macro
>> LARCH_NOP.
>> ---
>>   include/elf/loongarch.h    | 20 ++++++++++++++++++++
>>   include/opcode/loongarch.h |  3 +++
>>   2 files changed, 23 insertions(+)
>>
>> diff --git a/include/elf/loongarch.h b/include/elf/loongarch.h
>> index a6341b46791..0ecddd17b37 100644
>> --- a/include/elf/loongarch.h
>> +++ b/include/elf/loongarch.h
>> @@ -229,6 +229,26 @@ RELOC_NUMBER (R_LARCH_32_PCREL, 99)
>>   /* RELAX.  */
>>   RELOC_NUMBER (R_LARCH_RELAX, 100)
>>   
> Please add the description of the following new relocation types into
> the psELF ABI doc first.
>
>> +/* relax delete.  */
>> +RELOC_NUMBER (R_LARCH_DELETE, 101)
>> +
>> +/* relax align.  */
>> +RELOC_NUMBER (R_LARCH_ALIGN, 102)
>> +
>> +/* pcaddi.  */
>> +RELOC_NUMBER (R_LARCH_PCREL20_S2, 103)
>> +
>> +/* cfa.  */
>> +RELOC_NUMBER (R_LARCH_CFA, 104)
>> +
>> +/* DW_CFA_advance_loc.  */
>> +RELOC_NUMBER (R_LARCH_ADD6, 105)
>> +RELOC_NUMBER (R_LARCH_SUB6, 106)
>> +
>> +/* unsinged leb128.  */
> Typo: "unsigned".
>
> I often mistype this too.
>
>> +RELOC_NUMBER (R_LARCH_ADD_ULEB128, 107)
>> +RELOC_NUMBER (R_LARCH_SUB_ULEB128, 108)
>> +
  

Patch

diff --git a/include/elf/loongarch.h b/include/elf/loongarch.h
index a6341b46791..0ecddd17b37 100644
--- a/include/elf/loongarch.h
+++ b/include/elf/loongarch.h
@@ -229,6 +229,26 @@  RELOC_NUMBER (R_LARCH_32_PCREL, 99)
 /* RELAX.  */
 RELOC_NUMBER (R_LARCH_RELAX, 100)
 
+/* relax delete.  */
+RELOC_NUMBER (R_LARCH_DELETE, 101)
+
+/* relax align.  */
+RELOC_NUMBER (R_LARCH_ALIGN, 102)
+
+/* pcaddi.  */
+RELOC_NUMBER (R_LARCH_PCREL20_S2, 103)
+
+/* cfa.  */
+RELOC_NUMBER (R_LARCH_CFA, 104)
+
+/* DW_CFA_advance_loc.  */
+RELOC_NUMBER (R_LARCH_ADD6, 105)
+RELOC_NUMBER (R_LARCH_SUB6, 106)
+
+/* unsinged leb128.  */
+RELOC_NUMBER (R_LARCH_ADD_ULEB128, 107)
+RELOC_NUMBER (R_LARCH_SUB_ULEB128, 108)
+
 END_RELOC_NUMBERS (R_LARCH_count)
 
 /* Processor specific flags for the ELF header e_flags field.  */
diff --git a/include/opcode/loongarch.h b/include/opcode/loongarch.h
index c3922348a56..71570e9acc2 100644
--- a/include/opcode/loongarch.h
+++ b/include/opcode/loongarch.h
@@ -28,6 +28,8 @@  extern "C"
 {
 #endif
 
+  #define LARCH_NOP 0x03400000
+
   typedef uint32_t insn_t;
 
   struct loongarch_opcode
@@ -228,6 +230,7 @@  dec2 : [1-9][0-9]?
 #define ase_gpcr	isa.use_la_global_with_pcrel
 #define ase_gabs	isa.use_la_global_with_abs
 
+    int relax;
   } LARCH_opts;
 
   extern size_t loongarch_insn_length (insn_t insn);