!244 add loongarch64 and sw_64 support

From: @yeqinglong01 
Reviewed-by: @eastb233 
Signed-off-by: @eastb233
This commit is contained in:
openeuler-ci-bot 2023-10-09 03:19:50 +00:00 committed by Gitee
commit 57d46caffa
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
9 changed files with 52898 additions and 5 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,35 @@
diff --git a/bfd/elfnn-loongarch.c b/bfd/elfnn-loongarch.c
index a623aa32..dc9f4e49 100644
--- a/bfd/elfnn-loongarch.c
+++ b/bfd/elfnn-loongarch.c
@@ -980,7 +980,7 @@ loongarch_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
(although we could actually do it here). */
if (h->type == STT_FUNC || h->type == STT_GNU_IFUNC || h->needs_plt)
{
- if (h->plt.refcount < 0
+ if (h->plt.refcount <= 0
|| (h->type != STT_GNU_IFUNC
&& (SYMBOL_REFERENCES_LOCAL (info, h)
|| (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
@@ -993,8 +993,6 @@ loongarch_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
h->plt.offset = MINUS_ONE;
h->needs_plt = 0;
}
- else
- h->needs_plt = 1;
return true;
}
diff --git a/ld/testsuite/ld-elf/shared.exp b/ld/testsuite/ld-elf/shared.exp
index 8b7069c2..718416b0 100644
--- a/ld/testsuite/ld-elf/shared.exp
+++ b/ld/testsuite/ld-elf/shared.exp
@@ -502,7 +502,7 @@ run_ld_link_tests [list \
# but that is just an optimization so don't complain loudly.
setup_xfail *-*-*
clear_xfail alpha-*-* bfin-*-linux* csky-*-* frv-*-* hppa*-*-* i?86-*-*
-clear_xfail ia64-*-* microblaze-*-* powerpc*-*-* x86_64-*-* xtensa-*-*
+clear_xfail ia64-*-* loongarch*-*-* microblaze-*-* powerpc*-*-* x86_64-*-* xtensa-*-*
run_ld_link_tests {
{"pr22374 function pointer initialization"
"" "tmpdir/pr22374.so" "" "pr22374a.s"

View File

@ -0,0 +1,26 @@
From 7ba7aee2bc5b2df22fdba26c436e64b1bc9e735a Mon Sep 17 00:00:00 2001
From: XingLi <lixing@loongson.cn>
Date: Wed, 26 Jul 2023 15:28:31 +0800
Subject: [PATCH 3/3] Fixup check file for ifunc reloc
---
ld/testsuite/ld-loongarch-elf/local-ifunc-reloc.d | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/ld/testsuite/ld-loongarch-elf/local-ifunc-reloc.d b/ld/testsuite/ld-loongarch-elf/local-ifunc-reloc.d
index 29f2d3f3..3723326b 100644
--- a/ld/testsuite/ld-loongarch-elf/local-ifunc-reloc.d
+++ b/ld/testsuite/ld-loongarch-elf/local-ifunc-reloc.d
@@ -5,6 +5,6 @@
.*: +file format .*
DYNAMIC RELOCATION RECORDS
-OFFSET +TYPE +VALUE
-[[:xdigit:]]+ R_LARCH_IRELATIVE +\*ABS\*\+0x[[:xdigit:]]+
-[[:xdigit:]]+ R_LARCH_64 +test
+OFFSET +TYPE +VALUE
+[[:xdigit:]]+ R_LARCH_IRELATIVE +\*ABS\*\+0x[[:xdigit:]]+
+[[:xdigit:]]+ R_LARCH_64 +test+
--
2.27.0

View File

@ -0,0 +1,26 @@
From 70a4a09cc223d761b261859fbf21af578894d776 Mon Sep 17 00:00:00 2001
From: XingLi <lixing@loongson.cn>
Date: Sat, 22 Jul 2023 15:49:36 +0800
Subject: [PATCH 2/3] Fixup gas check illegal for 'b label'
---
opcodes/loongarch-opc.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/opcodes/loongarch-opc.c b/opcodes/loongarch-opc.c
index be0de61c..e3833007 100644
--- a/opcodes/loongarch-opc.c
+++ b/opcodes/loongarch-opc.c
@@ -823,8 +823,8 @@ static struct loongarch_opcode loongarch_jmp_opcodes[] =
{ 0x0, 0x0, "bnez", "r,la", "bnez %1,%%b21(%2)", 0, 0, 0 },
{ 0x44000000, 0xfc000000, "bnez", "r5:5,sb0:5|10:16<<2", 0, 0, 0, 0 },
{ 0x0, 0x0, "jr", "r", "jirl $r0,%1,0", 0, 0, 0 },
- { 0x50000000, 0xfc000000, "b", "sb0:10|10:16<<2", 0, 0, 0, 0 },
{ 0x0, 0x0, "b", "la", "b %%b26(%1)", 0, 0, 0 },
+ { 0x50000000, 0xfc000000, "b", "sb0:10|10:16<<2", 0, 0, 0, 0 },
{ 0x4c000000, 0xfc000000, "jirl", "r0:5,r5:5,s10:16<<2", 0, 0, 0, 0 },
{ 0x0, 0x0, "bl", "la", "bl %%b26(%1)", 0, 0, 0 },
{ 0x54000000, 0xfc000000, "bl", "sb0:10|10:16<<2", 0, 0, 0, 0 },
--
2.27.0

View File

@ -0,0 +1,117 @@
From 534cfca985709515f4871f0aa1efc57c4e274a1a Mon Sep 17 00:00:00 2001
From: yala <zhaojunchao@loongson.cn>
Date: Fri, 3 Mar 2023 11:19:40 +0800
Subject: [PATCH] ld:Fix option unresolved-symbols=ignore-all does not work
when LARCH_64 appears alone
Change-Id: Id06b7b77deefa64a2ea2c9f10a63130e5e4aaf65
---
bfd/elfnn-loongarch.c | 11 +++++---
ld/testsuite/ld-undefined/undefine-ignored.c | 10 +++++++
.../ld-undefined/undefine-ignored.exp | 26 +++++++++++++++++++
3 files changed, 43 insertions(+), 4 deletions(-)
create mode 100644 ld/testsuite/ld-undefined/undefine-ignored.c
create mode 100644 ld/testsuite/ld-undefined/undefine-ignored.exp
diff --git a/bfd/elfnn-loongarch.c b/bfd/elfnn-loongarch.c
index 459dd0df..5bf528b9 100644
--- a/bfd/elfnn-loongarch.c
+++ b/bfd/elfnn-loongarch.c
@@ -1201,7 +1201,8 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
}
}
- if (h->root.type == bfd_link_hash_undefweak)
+ if (h->root.type == bfd_link_hash_undefweak ||
+ h->root.type == bfd_link_hash_undefined)
{
if (UNDEFWEAK_NO_DYNAMIC_RELOC (info, h)
|| ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
@@ -1211,7 +1212,8 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
{
/* Make sure this symbol is output as a dynamic symbol.
Undefined weak syms won't yet be marked as dynamic. */
- if (!bfd_elf_link_record_dynamic_symbol (info, h))
+ if (h->root.type == bfd_link_hash_undefweak &&
+ !bfd_elf_link_record_dynamic_symbol (info, h))
return false;
if (h->dynindx == -1)
@@ -2303,6 +2305,7 @@ loongarch_elf_relocate_section (bfd *output_bfd, struct bfd_link_info *info,
char tls_type;
bfd_vma relocation, off, ie_off;
int i, j;
+ bool ignored = false;
howto = loongarch_elf_rtype_to_howto (input_bfd, r_type);
if (howto == NULL || r_type == R_LARCH_GNU_VTINHERIT
@@ -2344,8 +2347,8 @@ loongarch_elf_relocate_section (bfd *output_bfd, struct bfd_link_info *info,
}
else
{
- bool warned, ignored;
+ bool warned;
RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
r_symndx, symtab_hdr, sym_hashes,
h, sec, relocation,
@@ -2497,7 +2500,7 @@ loongarch_elf_relocate_section (bfd *output_bfd, struct bfd_link_info *info,
{
if (h->dynindx == -1)
{
- if (h->root.type == bfd_link_hash_undefined)
+ if (h->root.type == bfd_link_hash_undefined && !ignored)
(*info->callbacks->undefined_symbol)
(info, name, input_bfd, input_section,
rel->r_offset, true);
diff --git a/ld/testsuite/ld-undefined/undefine-ignored.c b/ld/testsuite/ld-undefined/undefine-ignored.c
new file mode 100644
index 00000000..7955df04
--- /dev/null
+++ b/ld/testsuite/ld-undefined/undefine-ignored.c
@@ -0,0 +1,10 @@
+#include <stdio.h>
+// a is R_LARCH_64 type
+extern struct wl_interface a;
+
+struct wl_interface * b = &a;
+
+int main(void)
+{
+ return 0;
+}
diff --git a/ld/testsuite/ld-undefined/undefine-ignored.exp b/ld/testsuite/ld-undefined/undefine-ignored.exp
new file mode 100644
index 00000000..7975fbdc
--- /dev/null
+++ b/ld/testsuite/ld-undefined/undefine-ignored.exp
@@ -0,0 +1,26 @@
+set testund "undefined-ignored"
+set testfn "undefined-ignored function"
+set testline "undefined-ignored line"
+
+if [istarget loongarch*-*-*] {
+ if { ![is_remote host] && [which $CC] == 0 } {
+ verbose "Could not find C compiler!" 1
+ untested $testund
+ untested $testfn
+ untested $testline
+ } elseif { ![ld_compile "$CC -c" "$srcdir/$subdir/undefine-ignored.c" \
+ tmpdir/undefine-ignored.o] } {
+ verbose "Unable to compile test file!" 1
+ unresolved $testund
+ unresolved $testfn
+ unresolved $testline
+ }
+
+ if { ![is_elf_format] } then {
+ unsupported $testname
+ } elseif {![ld_link $ld tmpdir/a.out \
+ "-e main --unresolved-symbols=ignore-all tmpdir/undefine-ignored.o"]} then {
+ verbose "ld faile"
+ fail $testname
+ }
+}
--
2.27.0

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,506 @@
From 31896a5e1105c4d5c1954750c6145fbab040430d Mon Sep 17 00:00:00 2001
From: tangxiaolin <tangxiaolin@loongson.cn>
Date: Wed, 17 Aug 2022 15:12:43 +0800
Subject: [PATCH 1/3] LoongArch: gas: add support using constant variable in
instructions.
Instructions that can load immediate support using constant
variable like ".equ var, 123 li.w/d resgister, var".
gas/
* config/loongarch-parse.y
* config/tc-loongarch.c
Add four testcases.One is a program using constant variable,
one test using label is unsupported, and another two test
almost instructions that can load immediate.
gas/
* testsuite/gas/loongarch/li.d
* testsuite/gas/loongarch/li.s
* testsuite/gas/loongarch/imm_ins_label-fail.d
* testsuite/gas/loongarch/imm_ins_label-fail.l
* testsuite/gas/loongarch/imm_ins_label-fail.s
* testsuite/gas/loongarch/imm_ins.d
* testsuite/gas/loongarch/imm_ins.s
* testsuite/gas/loongarch/imm_ins_32.d
* testsuite/gas/loongarch/imm_ins_32.s
---
gas/config/loongarch-parse.y | 20 +++++
gas/config/tc-loongarch.c | 18 ----
gas/testsuite/gas/loongarch/imm_ins.d | 80 ++++++++++++++++++
gas/testsuite/gas/loongarch/imm_ins.s | 83 +++++++++++++++++++
gas/testsuite/gas/loongarch/imm_ins_32.d | 57 +++++++++++++
gas/testsuite/gas/loongarch/imm_ins_32.s | 60 ++++++++++++++
.../gas/loongarch/imm_ins_label-fail.d | 3 +
.../gas/loongarch/imm_ins_label-fail.l | 3 +
.../gas/loongarch/imm_ins_label-fail.s | 3 +
gas/testsuite/gas/loongarch/li.d | 21 +++++
gas/testsuite/gas/loongarch/li.s | 22 +++++
11 files changed, 352 insertions(+), 18 deletions(-)
create mode 100644 gas/testsuite/gas/loongarch/imm_ins.d
create mode 100644 gas/testsuite/gas/loongarch/imm_ins.s
create mode 100644 gas/testsuite/gas/loongarch/imm_ins_32.d
create mode 100644 gas/testsuite/gas/loongarch/imm_ins_32.s
create mode 100644 gas/testsuite/gas/loongarch/imm_ins_label-fail.d
create mode 100644 gas/testsuite/gas/loongarch/imm_ins_label-fail.l
create mode 100644 gas/testsuite/gas/loongarch/imm_ins_label-fail.s
create mode 100644 gas/testsuite/gas/loongarch/li.d
create mode 100644 gas/testsuite/gas/loongarch/li.s
diff --git a/gas/config/loongarch-parse.y b/gas/config/loongarch-parse.y
index 902d7204..87046877 100644
--- a/gas/config/loongarch-parse.y
+++ b/gas/config/loongarch-parse.y
@@ -100,6 +100,25 @@ my_getExpression (expressionS *ep, const char *str)
return ret;
}
+static void
+emit_const_var (const char *op)
+{
+ expressionS ep;
+
+ if (end <= top)
+ as_fatal (_("expr too huge"));
+
+ my_getExpression (&ep, op);
+
+ if (ep.X_op != O_constant)
+ as_bad ("illegal operand: %s", op);
+
+ top->value.X_op = O_constant;
+ top->value.X_add_number = ep.X_add_number;
+ top->type = BFD_RELOC_LARCH_SOP_PUSH_ABSOLUTE;
+ top++;
+}
+
static void
reloc (const char *op_c_str, const char *id_c_str, offsetT addend)
{
@@ -318,6 +337,7 @@ offsetT imm;
primary_expression
: INTEGER {emit_const ($1);}
+ | IDENTIFIER {emit_const_var ($1);}
| '(' expression ')'
| '%' IDENTIFIER '(' IDENTIFIER addend ')' {reloc ($2, $4, $5); free ($2); free ($4);}
| '%' IDENTIFIER '(' INTEGER addend ')' {reloc ($2, NULL, $4 + $5); free ($2);}
diff --git a/gas/config/tc-loongarch.c b/gas/config/tc-loongarch.c
index 93412b69..1e0d5ab5 100644
--- a/gas/config/tc-loongarch.c
+++ b/gas/config/tc-loongarch.c
@@ -582,24 +582,6 @@ loongarch_args_parser_can_match_arg_helper (char esc_ch1, char esc_ch2,
if (!ip->match_now)
break;
- if (esc_ch1 == 's')
- switch (esc_ch2)
- {
- case 'c':
- ip->match_now = reloc_num == 0;
- break;
- }
- else
- switch (esc_ch2)
- {
- case 'c':
- ip->match_now = reloc_num == 0 && 0 <= imm;
- break;
- }
-
- if (!ip->match_now)
- break;
-
ret = imm;
if (reloc_num)
{
diff --git a/gas/testsuite/gas/loongarch/imm_ins.d b/gas/testsuite/gas/loongarch/imm_ins.d
new file mode 100644
index 00000000..0ceaead3
--- /dev/null
+++ b/gas/testsuite/gas/loongarch/imm_ins.d
@@ -0,0 +1,80 @@
+#as:
+#objdump: -dr
+#skip: loongarch32-*-*
+
+.*:[ ]+file format .*
+
+
+Disassembly of section .text:
+
+00000000.* <.text>:
+[ ]+0:[ ]+03848c0c[ ]+ori[ ]+\$t0,[ ]+\$zero,[ ]+0x123
+[ ]+4:[ ]+15ffe00d[ ]+lu12i.w[ ]+\$t1,[ ]+-256\(0xfff00\)
+[ ]+8:[ ]+16001fed[ ]+lu32i.d[ ]+\$t1,[ ]+255\(0xff\)
+[ ]+c:[ ]+02bffc0e[ ]+addi.w[ ]+\$t2,[ ]+\$zero,[ ]+-1\(0xfff\)
+[ ]+10:[ ]+1601ffee[ ]+lu32i.d[ ]+\$t2,[ ]+4095\(0xfff\)
+[ ]+14:[ ]+0004b58b[ ]+alsl.w[ ]+\$a7,[ ]+\$t0,[ ]+\$t1,[ ]+0x2
+[ ]+18:[ ]+0006b58b[ ]+alsl.wu[ ]+\$a7,[ ]+\$t0,[ ]+\$t1,[ ]+0x2
+[ ]+1c:[ ]+0009358b[ ]+bytepick.w[ ]+\$a7,[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[ ]+ld.bu[ ]+\$t0,[ ]+\$t1,[ ]+256\(0x100\)
+[ ]+f8:[ ]+2a4401ac[ ]+ld.hu[ ]+\$t0,[ ]+\$t1,[ ]+256\(0x100\)
+[ ]+fc:[ ]+2a8401ac[ ]+ld.wu[ ]+\$t0,[ ]+\$t1,[ ]+256\(0x100\)
+[ ]+100:[ ]+2ac401a2[ ]+preld[ ]+0x2,[ ]+\$t1,[ ]+256\(0x100\)
+[ ]+104:[ ]+382c39a2[ ]+preldx[ ]+0x2,[ ]+\$t1,[ ]+\$t2
+[ ]+108:[ ]+2b048d8a[ ]+fld.s[ ]+\$ft2,[ ]+\$t0,[ ]+291\(0x123\)
+[ ]+10c:[ ]+2b448d8a[ ]+fst.s[ ]+\$ft2,[ ]+\$t0,[ ]+291\(0x123\)
+[ ]+110:[ ]+2b848d8a[ ]+fld.d[ ]+\$ft2,[ ]+\$t0,[ ]+291\(0x123\)
+[ ]+114:[ ]+2bc48d8a[ ]+fst.d[ ]+\$ft2,[ ]+\$t0,[ ]+291\(0x123\)
diff --git a/gas/testsuite/gas/loongarch/imm_ins.s b/gas/testsuite/gas/loongarch/imm_ins.s
new file mode 100644
index 00000000..f6a4e745
--- /dev/null
+++ b/gas/testsuite/gas/loongarch/imm_ins.s
@@ -0,0 +1,83 @@
+.equ a, 0x123
+.equ b, 0xfffff00000
+.equ c, 0xfffffffffff
+.equ d, 2
+.equ e,0x100
+
+li.w $r12, a
+li.d $r13, b
+li.d $r14, c
+
+alsl.w $r11,$r12,$r13,d
+alsl.wu $r11,$r12,$r13,d
+bytepick.w $r11,$r12,$r13,d
+bytepick.d $r11,$r12,$r13,d
+
+break d
+dbcl d
+syscall d
+
+alsl.d $r11,$r12, $r13,d
+slli.w $r11,$r12,d
+slli.d $r11,$r12,d
+srli.w $r11,$r12,d
+srli.d $r12,$r13,d
+srai.w $r12,$r13,d
+srai.d $r12,$r13,d
+
+bstrins.w $r12,$r13,d,d
+bstrins.d $r12,$r13,d,d
+bstrpick.d $r12,$r13,d,d
+bstrpick.d $r12,$r13,d,d
+
+slti $r12,$r13,a
+sltui $r12,$r13,a
+addi.w $r12,$r13,a
+addi.d $r12,$r13,a
+lu52i.d $r12,$r13,a
+andi $r12,$r13,d
+ori $r12,$r13,d
+xori $r12,$r13,d
+addu16i.d $r12,$r13,d
+lu12i.w $r12,a
+lu32i.d $r12,a
+pcaddi $r12,a
+pcalau12i $r12,a
+pcaddu12i $r12,a
+pcaddu18i $r12,a
+
+csrrd $r12,a
+csrwr $r12,a
+csrxchg $r12,$r13,d
+cacop d,$r13,d
+lddir $r12,$r13,d
+ldpte $r12,d
+
+invtlb d,$r13,$r14
+
+ll.w $r12,$r13,e
+sc.w $r12,$r13,e
+ll.d $r12,$r13,e
+sc.d $r12,$r13,e
+ldptr.w $r12,$r13,e
+stptr.w $r12,$r13,e
+ldptr.d $r12,$r13,e
+stptr.d $r12,$r13,e
+ld.b $r12,$r13,e
+ld.h $r12,$r13,e
+ld.w $r12,$r13,e
+ld.d $r12,$r13,e
+st.b $r12,$r13,e
+st.h $r12,$r13,e
+st.w $r12,$r13,e
+st.d $r12,$r13,e
+ld.bu $r12,$r13,e
+ld.hu $r12,$r13,e
+ld.wu $r12,$r13,e
+preld d,$r13,e
+preldx d,$r13,$r14
+
+fld.s $f10,$r12,a
+fst.s $f10,$r12,a
+fld.d $f10,$r12,a
+fst.d $f10,$r12,a
diff --git a/gas/testsuite/gas/loongarch/imm_ins_32.d b/gas/testsuite/gas/loongarch/imm_ins_32.d
new file mode 100644
index 00000000..0a826bfb
--- /dev/null
+++ b/gas/testsuite/gas/loongarch/imm_ins_32.d
@@ -0,0 +1,57 @@
+#as:
+#objdump: -dr
+#skip: loongarch64-*-*
+
+.*:[ ]+file format .*
+
+
+Disassembly of section .text:
+
+00000000.* <.text>:
+[ ]+0:[ ]+03848c0c[ ]+ori[ ]+\$t0,[ ]+\$zero,[ ]+0x123
+[ ]+4:[ ]+0004b58b[ ]+alsl.w[ ]+\$a7,[ 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1,[ ]+256\(0x100\)
+[ ]+9c:[ ]+298401ac[ ]+st.w[ ]+\$t0,[ ]+\$t1,[ ]+256\(0x100\)
+[ ]+a0:[ ]+2a0401ac[ ]+ld.bu[ ]+\$t0,[ ]+\$t1,[ ]+256\(0x100\)
+[ ]+a4:[ ]+2a4401ac[ ]+ld.hu[ ]+\$t0,[ ]+\$t1,[ ]+256\(0x100\)
+[ ]+a8:[ ]+2a8401ac[ ]+ld.wu[ ]+\$t0,[ ]+\$t1,[ ]+256\(0x100\)
+[ ]+ac:[ ]+2ac401a2[ ]+preld[ ]+0x2,[ ]+\$t1,[ ]+256\(0x100\)
+[ ]+b0:[ ]+382c39a2[ ]+preldx[ ]+0x2,[ ]+\$t1,[ ]+\$t2
+[ ]+b4:[ ]+2b048d8a[ ]+fld.s[ ]+\$ft2,[ ]+\$t0,[ ]+291\(0x123\)
+[ ]+b8:[ ]+2b448d8a[ ]+fst.s[ ]+\$ft2,[ ]+\$t0,[ ]+291\(0x123\)
diff --git a/gas/testsuite/gas/loongarch/imm_ins_32.s b/gas/testsuite/gas/loongarch/imm_ins_32.s
new file mode 100644
index 00000000..e105548e
--- /dev/null
+++ b/gas/testsuite/gas/loongarch/imm_ins_32.s
@@ -0,0 +1,60 @@
+.equ a, 0x123
+.equ d, 2
+.equ e,0x100
+
+li.w $r12, a
+
+alsl.w $r11,$r12,$r13,d
+alsl.wu $r11,$r12,$r13,d
+bytepick.w $r11,$r12,$r13,d
+
+break d
+dbcl d
+syscall d
+
+slli.w $r11,$r12,d
+srli.w $r11,$r12,d
+srai.w $r12,$r13,d
+
+bstrins.w $r12,$r13,d,d
+
+slti $r12,$r13,a
+sltui $r12,$r13,a
+addi.w $r12,$r13,a
+andi $r12,$r13,d
+ori $r12,$r13,d
+xori $r12,$r13,d
+lu12i.w $r12,a
+pcaddi $r12,a
+pcalau12i $r12,a
+pcaddu12i $r12,a
+pcaddu18i $r12,a
+
+csrrd $r12,a
+csrwr $r12,a
+csrxchg $r12,$r13,d
+cacop d,$r13,d
+lddir $r12,$r13,d
+ldpte $r12,d
+
+invtlb d,$r13,$r14
+
+ll.w $r12,$r13,e
+sc.w $r12,$r13,e
+ll.d $r12,$r13,e
+sc.d $r12,$r13,e
+ldptr.w $r12,$r13,e
+stptr.w $r12,$r13,e
+ld.h $r12,$r13,e
+ld.w $r12,$r13,e
+st.b $r12,$r13,e
+st.h $r12,$r13,e
+st.w $r12,$r13,e
+ld.bu $r12,$r13,e
+ld.hu $r12,$r13,e
+ld.wu $r12,$r13,e
+preld d,$r13,e
+preldx d,$r13,$r14
+
+fld.s $f10,$r12,a
+fst.s $f10,$r12,a
diff --git a/gas/testsuite/gas/loongarch/imm_ins_label-fail.d b/gas/testsuite/gas/loongarch/imm_ins_label-fail.d
new file mode 100644
index 00000000..4301a007
--- /dev/null
+++ b/gas/testsuite/gas/loongarch/imm_ins_label-fail.d
@@ -0,0 +1,3 @@
+#as:
+#source: imm_ins_label-fail.s
+#error_output: imm_ins_label-fail.l
diff --git a/gas/testsuite/gas/loongarch/imm_ins_label-fail.l b/gas/testsuite/gas/loongarch/imm_ins_label-fail.l
new file mode 100644
index 00000000..e0fec2fe
--- /dev/null
+++ b/gas/testsuite/gas/loongarch/imm_ins_label-fail.l
@@ -0,0 +1,3 @@
+.*Assembler messages:
+.*Error: illegal operand: Label
+.*Error: illegal operand: Label
diff --git a/gas/testsuite/gas/loongarch/imm_ins_label-fail.s b/gas/testsuite/gas/loongarch/imm_ins_label-fail.s
new file mode 100644
index 00000000..84b2d192
--- /dev/null
+++ b/gas/testsuite/gas/loongarch/imm_ins_label-fail.s
@@ -0,0 +1,3 @@
+Label:
+ li.w $r12, Label
+ addi.w $r12, $r13, Label
diff --git a/gas/testsuite/gas/loongarch/li.d b/gas/testsuite/gas/loongarch/li.d
new file mode 100644
index 00000000..850a3f48
--- /dev/null
+++ b/gas/testsuite/gas/loongarch/li.d
@@ -0,0 +1,21 @@
+#as:
+#objdump: -dr
+#skip: loongarch32-*-*
+
+.*:[ ]+file format .*
+
+
+Disassembly of section .text:
+
+00000000.* <_start>:
+[ ]+0:[ ]+03803c06[ ]+ori[ ]+\$a2,[ ]+\$zero,[ ]+0xf
+[ ]+4:[ ]+1a000005[ ]+pcalau12i[ ]+\$a1,[ ]+0
+[ ]+4:[ ]+R_LARCH_PCALA_HI20[ ]+.rodata
+[ ]+8:[ ]+02c000a5[ ]+addi.d[ ]+\$a1,[ ]+\$a1,[ ]+0
+[ ]+8:[ ]+R_LARCH_PCALA_LO12[ ]+.rodata
+[ ]+c:[ ]+03800404[ ]+ori[ ]+\$a0,[ ]+\$zero,[ ]+0x1
+[ ]+10:[ ]+0381000b[ ]+ori[ ]+\$a7,[ ]+\$zero,[ ]+0x40
+[ ]+14:[ ]+002b0000[ ]+syscall[ ]+0x0
+[ ]+18:[ ]+00150004[ ]+move[ ]+\$a0,[ ]+\$zero
+[ ]+1c:[ ]+0381740b[ ]+ori[ ]+\$a7,[ ]+\$zero,[ ]+0x5d
+[ ]+20:[ ]+002b0000[ ]+syscall[ ]+0x0
diff --git a/gas/testsuite/gas/loongarch/li.s b/gas/testsuite/gas/loongarch/li.s
new file mode 100644
index 00000000..e95a527f
--- /dev/null
+++ b/gas/testsuite/gas/loongarch/li.s
@@ -0,0 +1,22 @@
+.equ EXIT_SUCCESS, 0
+.equ STDOUT, 1
+.equ SYS_exit, 93
+.equ SYS_write, 64
+
+.section .rodata
+msg:
+ .string "hello, world!\n"
+ len = . - msg
+
+.text
+ .globl _start
+_start:
+ li.w $a2, len
+ la.local $a1, msg
+ li.w $a0, STDOUT
+ li.w $a7, SYS_write
+ syscall 0x0
+
+ li.w $a0, EXIT_SUCCESS
+ li.w $a7, SYS_exit
+ syscall 0x0
--
2.27.0

View File

@ -1,14 +1,14 @@
Summary: Binary utilities
Name: binutils
Version: 2.37
Release: 23
Release: 24
License: GPLv3+
URL: https://sourceware.org/binutils
Source: https://ftp.gnu.org/gnu/binutils/binutils-%{version}.tar.xz
# risc-v do not support gold linker.
%ifnarch riscv64
# risc-v loongarch64 do not support gold linker.
%ifnarch riscv64 loongarch64
%bcond_without gold
%else
%bcond_with gold
@ -81,6 +81,20 @@ Patch55: backport-CVE-2023-1972.patch
Patch56: backport-CVE-2022-48064.patch
Patch57: backport-CVE-2022-4285.patch
%ifarch loongarch64
# LoongArch-related patches start with Patch101
Patch1000: LoongArch-binutils-Add-LoongArch-support.patch
Patch1001: LoongArch-Fixup-unresolve-symbols-problem.patch
Patch1002: LoongArch-Fix-PLT-entry-generate-bug.patch
Patch1003: LoongArch-gas-add-support-using-constant-variable-in.patch
Patch1004: LoongArch-Fixup-gas-check-illegal-for-b-label.patch
Patch1005: LoongArch-Fixup-check-file-for-ifunc-reloc.patch
%endif
%ifarch sw_64
Patch1006: 1006-add-sw_64-support-not-upstream-new-files.patch
Patch1007: 1007-add-sw_64-support-not-upstream-modified-files.patch
%endif
Provides: bundled(libiberty)
Buildroot: %(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX)
@ -164,12 +178,12 @@ touch */configure
%build
CARGS=
case %{_target_platform} in i?86*|arm*|aarch64*|riscv64*)
case %{_target_platform} in i?86*|arm*|aarch64*|riscv64*|loongarch64*)
CARGS="$CARGS --enable-64-bit-bfd"
;;
esac
case %{_target_platform} in x86_64*|i?86*|aarch64*|riscv64*)
case %{_target_platform} in x86_64*|i?86*|aarch64*|riscv64*|loongarch64*)
CARGS="$CARGS --enable-targets=x86_64-pep --enable-relro=yes"
;;
esac
@ -301,6 +315,42 @@ INPUT ( %{_libdir}/libopcodes.a -lbfd )
EOF
%endif
%ifarch loongarch64
tee %{buildroot}%{_libdir}/libbfd.so <<EOF
/* GNU ld script */
OUTPUT_FORMAT(elf64-loongarch)
INPUT ( %{_libdir}/libbfd.a -liberty -lz -ldl )
EOF
tee %{buildroot}%{_libdir}/libopcodes.so <<EOF
/* GNU ld script */
OUTPUT_FORMAT(elf64-loongarch)
INPUT ( %{_libdir}/libopcodes.a -lbfd )
EOF
%endif
%ifarch sw_64
tee %{buildroot}%{_libdir}/libbfd.so <<EOF
/* GNU ld script */
OUTPUT_FORMAT(elf64-sw_64)
INPUT ( %{_libdir}/libbfd.a -liberty -lz -ldl )
EOF
tee %{buildroot}%{_libdir}/libopcodes.so <<EOF
/* GNU ld script */
OUTPUT_FORMAT(elf64-sw_64)
INPUT ( %{_libdir}/libopcodes.a -lbfd )
EOF
%endif
rm -f %{buildroot}%{_infodir}/dir
rm -rf %{buildroot}%{_prefix}/%{_target_platform}
@ -376,6 +426,12 @@ fi
%{_infodir}/bfd*info*
%changelog
* Thu Sep 07 2023 yeqinglong <yeqinglong@kylinsec.com.cn> - 2.37-24
- DESC:Add sw_64 support
- DESC:Add LoongArch support
- DESC:Fix LoongArch PLT entry generate bug
- DESC:Add .equ support for LoongArch and fix some bugs
* Tue Sep 05 2023 eastb233 <xiezhiheng@huawei.com> - 2.37-23
- Delete post, preun, postun for help package