From a79e4fd07f9a645deecb099952e764087f4fe519 Mon Sep 17 00:00:00 2001 From: Peng Fan Date: Wed, 25 Mar 2026 10:25:04 +0800 Subject: [PATCH] LoongArch: common fix from upstream --- ...p-cross-segment-alignment-compensati.patch | 134 ++++++++++ ...rch-Fix-symbol-size-after-relaxation.patch | 241 ++++++++++++++++++ ...correct-display-of-FDEs-address-rang.patch | 99 +++++++ ...re-appropriate-assertions-for-the-re.patch | 85 ++++++ ...STATUS_SIZE-0x1e0-to-match-kernel-s-.patch | 32 +++ binutils.spec | 11 +- 6 files changed, 601 insertions(+), 1 deletion(-) create mode 100644 0001-LoongArch-Un-skip-cross-segment-alignment-compensati.patch create mode 100644 0002-LoongArch-Fix-symbol-size-after-relaxation.patch create mode 100644 0003-LoongArch-Fix-incorrect-display-of-FDEs-address-rang.patch create mode 100644 0004-LoongArch-Use-more-appropriate-assertions-for-the-re.patch create mode 100644 0005-LoongArch-set-PRSTATUS_SIZE-0x1e0-to-match-kernel-s-.patch diff --git a/0001-LoongArch-Un-skip-cross-segment-alignment-compensati.patch b/0001-LoongArch-Un-skip-cross-segment-alignment-compensati.patch new file mode 100644 index 0000000..0ba4d84 --- /dev/null +++ b/0001-LoongArch-Un-skip-cross-segment-alignment-compensati.patch @@ -0,0 +1,134 @@ +From 1dddb2f6b9210093a9c558ee0d643bcff544e5c8 Mon Sep 17 00:00:00 2001 +From: WANG Xuerui +Date: Mon, 16 Mar 2026 14:30:14 +0800 +Subject: [PATCH 1/6] LoongArch: Un-skip cross-segment alignment compensation + during relax pass 2 + +It turned out wrong to skip compensating for segment alignment if the +current section is closed for deletion, as my recent system update with +binutils trunk revealed link failures of many high-profile packages such +as ffmpeg, numpy and wxGTK -- the dreaded "relocation truncated to fit" +errors regarding improperly produced R_LARCH_PCREL20_S2. + +As it's near 2.45 branching time, revert the problematic change and +XFAIL the original test case for now. + +Suggested-by: Xi Ruoyao +Signed-off-by: WANG Xuerui +--- + bfd/elfnn-loongarch.c | 76 ++++++++++++++++++++----------------------- + 1 file changed, 35 insertions(+), 41 deletions(-) + +diff --git a/bfd/elfnn-loongarch.c b/bfd/elfnn-loongarch.c +index e5a9fd03..4925408c 100644 +--- a/bfd/elfnn-loongarch.c ++++ b/bfd/elfnn-loongarch.c +@@ -5324,19 +5324,17 @@ loongarch_relax_pcala_addi (bfd *abfd, asection *sec, asection *sym_sec, + symval = sec_addr (sec) + + loongarch_calc_relaxed_addr (info, symval - sec_addr (sec)); + +- /* If pc and symbol not in the same segment, add/sub segment alignment if the +- section has not undergone alignment processing because distances may grow +- after alignment. */ +- if (!loongarch_two_sections_in_same_segment (info->output_bfd, +- sec->output_section, +- sym_sec->output_section)) +- max_alignment = info->maxpagesize > max_alignment ? info->maxpagesize +- : max_alignment; +- +- if (symval > pc) +- pc -= (max_alignment > 4 ? max_alignment : 0); +- else if (symval < pc) +- pc += (max_alignment > 4 ? max_alignment : 0); ++ /* If pc and symbol not in the same segment, add/sub segment alignment. */ ++ if (!loongarch_two_sections_in_same_segment (info->output_bfd, ++ sec->output_section, ++ sym_sec->output_section)) ++ max_alignment = info->maxpagesize > max_alignment ? info->maxpagesize ++ : max_alignment; ++ ++ if (symval > pc) ++ pc -= (max_alignment > 4 ? max_alignment : 0); ++ else if (symval < pc) ++ pc += (max_alignment > 4 ? max_alignment : 0); + + const uint32_t pcaddi = LARCH_OP_PCADDI; + +@@ -5391,19 +5389,17 @@ loongarch_relax_call36 (bfd *abfd, asection *sec, asection *sym_sec, + symval = sec_addr (sec) + + loongarch_calc_relaxed_addr (info, symval - sec_addr (sec)); + +- /* If pc and symbol not in the same segment, add/sub segment alignment if the +- section has not undergone alignment processing because distances may grow +- after alignment. */ +- if (!loongarch_two_sections_in_same_segment (info->output_bfd, +- sec->output_section, +- sym_sec->output_section)) +- max_alignment = info->maxpagesize > max_alignment ? info->maxpagesize +- : max_alignment; ++ /* If pc and symbol not in the same segment, add/sub segment alignment. */ ++ if (!loongarch_two_sections_in_same_segment (info->output_bfd, ++ sec->output_section, ++ sym_sec->output_section)) ++ max_alignment = info->maxpagesize > max_alignment ? info->maxpagesize ++ : max_alignment; + +- if (symval > pc) +- pc -= (max_alignment > 4 ? max_alignment : 0); +- else if (symval < pc) +- pc += (max_alignment > 4 ? max_alignment : 0); ++ if (symval > pc) ++ pc -= (max_alignment > 4 ? max_alignment : 0); ++ else if (symval < pc) ++ pc += (max_alignment > 4 ? max_alignment : 0); + + /* Is pcalau12i + addi.d insns? */ + if (!LARCH_INSN_JIRL (jirl) +@@ -5459,10 +5455,10 @@ loongarch_relax_pcala_ld (bfd *abfd, asection *sec, + + /* If pc and symbol not in the same segment, add/sub segment alignment. */ + if (!loongarch_two_sections_in_same_segment (info->output_bfd, +- sec->output_section, +- sym_sec->output_section)) ++ sec->output_section, ++ sym_sec->output_section)) + max_alignment = info->maxpagesize > max_alignment ? info->maxpagesize +- : max_alignment; ++ : max_alignment; + + if (symval > pc) + pc -= (max_alignment > 4 ? max_alignment : 0); +@@ -5590,19 +5586,17 @@ loongarch_relax_tls_ld_gd_desc (bfd *abfd, asection *sec, asection *sym_sec, + symval = sec_addr (sec) + + loongarch_calc_relaxed_addr (info, symval - sec_addr (sec)); + +- /* If pc and symbol not in the same segment, add/sub segment alignment if the +- section has not undergone alignment processing because distances may grow +- after alignment. */ +- if (!loongarch_two_sections_in_same_segment (info->output_bfd, +- sec->output_section, +- sym_sec->output_section)) +- max_alignment = info->maxpagesize > max_alignment ? info->maxpagesize +- : max_alignment; +- +- if (symval > pc) +- pc -= (max_alignment > 4 ? max_alignment : 0); +- else if (symval < pc) +- pc += (max_alignment > 4 ? max_alignment : 0); ++ /* If pc and symbol not in the same segment, add/sub segment alignment. */ ++ if (!loongarch_two_sections_in_same_segment (info->output_bfd, ++ sec->output_section, ++ sym_sec->output_section)) ++ max_alignment = info->maxpagesize > max_alignment ? info->maxpagesize ++ : max_alignment; ++ ++ if (symval > pc) ++ pc -= (max_alignment > 4 ? max_alignment : 0); ++ else if (symval < pc) ++ pc += (max_alignment > 4 ? max_alignment : 0); + + const uint32_t pcaddi = LARCH_OP_PCADDI; + +-- +2.43.7 + diff --git a/0002-LoongArch-Fix-symbol-size-after-relaxation.patch b/0002-LoongArch-Fix-symbol-size-after-relaxation.patch new file mode 100644 index 0000000..7cdb216 --- /dev/null +++ b/0002-LoongArch-Fix-symbol-size-after-relaxation.patch @@ -0,0 +1,241 @@ +From c4c4bc0a59f06e2af6b9cc74b4f309230196b9b7 Mon Sep 17 00:00:00 2001 +From: Xi Ruoyao +Date: Wed, 6 Aug 2025 12:19:22 +0800 +Subject: [PATCH 2/6] LoongArch: Fix symbol size after relaxation + +There's a logic error in loongarch_relax_perform_deletes: when there's +not any delete operation of which the start address is strictly smaller +than the symbol address, splay_tree_predecessor() will return nullptr +and the symbol size will be unchanged even if some bytes of it are +removed. + +Make the logic more complete to fix this issue. Also factor out the +symbol size adjustment logic into a function to avoid code bloating. + +Tested-by: WANG Xuerui +Signed-off-by: Xi Ruoyao +--- + bfd/elfnn-loongarch.c | 102 ++++++++++-------- + .../ld-loongarch-elf/ld-loongarch-elf.exp | 2 + + .../ld-loongarch-elf/relax-sym-size-1.d | 7 ++ + .../ld-loongarch-elf/relax-sym-size-1.s | 8 ++ + .../ld-loongarch-elf/relax-sym-size-2.d | 7 ++ + .../ld-loongarch-elf/relax-sym-size-2.s | 19 ++++ + 6 files changed, 102 insertions(+), 43 deletions(-) + create mode 100644 ld/testsuite/ld-loongarch-elf/relax-sym-size-1.d + create mode 100644 ld/testsuite/ld-loongarch-elf/relax-sym-size-1.s + create mode 100644 ld/testsuite/ld-loongarch-elf/relax-sym-size-2.d + create mode 100644 ld/testsuite/ld-loongarch-elf/relax-sym-size-2.s + +diff --git a/bfd/elfnn-loongarch.c b/bfd/elfnn-loongarch.c +index 4925408c..86be86bf 100644 +--- a/bfd/elfnn-loongarch.c ++++ b/bfd/elfnn-loongarch.c +@@ -4852,6 +4852,60 @@ loongarch_relax_delete_or_nop (bfd *abfd, + bfd_put (32, abfd, LARCH_NOP, contents + addr); + } + ++/* If some bytes in a symbol is deleted, we need to adjust its size. */ ++static void ++loongarch_relax_resize_symbol (bfd_size_type *size, bfd_vma orig_value, ++ splay_tree pdops) ++{ ++ splay_tree_key key = (splay_tree_key)orig_value; ++ bfd_vma orig_end = orig_value + *size; ++ splay_tree_node node = splay_tree_predecessor (pdops, key); ++ ++ if (node) ++ { ++ bfd_vma addr = (bfd_vma)node->key; ++ struct pending_delete_op *op = (struct pending_delete_op *)node->value; ++ ++ /* This shouldn't happen unless people write something really insane like ++ .reloc ., R_LARCH_ALIGN, 60 ++ .rept 15 ++ 1: nop ++ .endr ++ .set x, 1b ++ .size x, . - 1b ++ But let's just try to make it "work" anyway. */ ++ if (orig_value < addr + op->size) ++ { ++ bfd_size_type n_deleted = op->size - (orig_value - addr); ++ if (n_deleted >= *size) ++ { ++ *size = 0; ++ return; ++ } ++ ++ *size -= n_deleted; ++ } ++ } ++ ++ node = splay_tree_lookup (pdops, key); ++ if (!node) ++ node = splay_tree_successor (pdops, key); ++ ++ for (; node; node = splay_tree_successor (pdops, node->key)) ++ { ++ bfd_vma addr = (bfd_vma)node->key; ++ struct pending_delete_op *op = (struct pending_delete_op *)node->value; ++ ++ if (addr >= orig_end) ++ return; ++ ++ if (orig_end < addr + op->size) ++ *size -= orig_end - addr; ++ else ++ *size -= op->size; ++ } ++} ++ + static void + loongarch_relax_perform_deletes (bfd *abfd, asection *sec, + struct bfd_link_info *link_info) +@@ -4950,30 +5004,8 @@ loongarch_relax_perform_deletes (bfd *abfd, asection *sec, + sym->st_value + = loongarch_calc_relaxed_addr (link_info, orig_value); + +- /* If the symbol *spans* some deleted bytes, that is its *end* is in +- the moved bytes but its *start* isn't, then we must adjust its +- size. +- +- This test needs to use the original value of st_value, otherwise +- we might accidentally decrease size when deleting bytes right +- before the symbol. */ +- bfd_vma sym_end = orig_value + sym->st_size; +- if (sym_end <= toaddr) +- { +- splay_tree_node node = splay_tree_predecessor ( +- pdops, (splay_tree_key)orig_value); +- for (; node; node = splay_tree_successor (pdops, node->key)) +- { +- bfd_vma addr = (bfd_vma)node->key; +- struct pending_delete_op *op +- = (struct pending_delete_op *)node->value; +- +- if (addr >= sym_end) +- break; +- if (orig_value <= addr && sym_end > addr) +- sym->st_size -= op->size; +- } +- } ++ if (orig_value + sym->st_size <= toaddr) ++ loongarch_relax_resize_symbol (&sym->st_size, orig_value, pdops); + } + } + +@@ -5020,29 +5052,13 @@ loongarch_relax_perform_deletes (bfd *abfd, asection *sec, + { + bfd_vma orig_value = sym_hash->root.u.def.value; + +- /* As above, adjust the value. */ ++ /* As above, adjust the value and size. */ + if (orig_value <= toaddr) + sym_hash->root.u.def.value + = loongarch_calc_relaxed_addr (link_info, orig_value); + +- /* As above, adjust the size if needed. */ +- bfd_vma sym_end = orig_value + sym_hash->size; +- if (sym_end <= toaddr) +- { +- splay_tree_node node = splay_tree_predecessor ( +- pdops, (splay_tree_key)orig_value); +- for (; node; node = splay_tree_successor (pdops, node->key)) +- { +- bfd_vma addr = (bfd_vma)node->key; +- struct pending_delete_op *op +- = (struct pending_delete_op *)node->value; +- +- if (addr >= sym_end) +- break; +- if (orig_value <= addr && sym_end > addr) +- sym_hash->size -= op->size; +- } +- } ++ if (orig_value + sym_hash->size <= toaddr) ++ loongarch_relax_resize_symbol (&sym_hash->size, orig_value, pdops); + } + } + } +diff --git a/ld/testsuite/ld-loongarch-elf/ld-loongarch-elf.exp b/ld/testsuite/ld-loongarch-elf/ld-loongarch-elf.exp +index 615548dc..9cf1096d 100644 +--- a/ld/testsuite/ld-loongarch-elf/ld-loongarch-elf.exp ++++ b/ld/testsuite/ld-loongarch-elf/ld-loongarch-elf.exp +@@ -47,6 +47,8 @@ if [istarget "loongarch64-*-*"] { + run_dump_test "tls-le-relax" + run_dump_test "relax-medium-call" + run_dump_test "relax-medium-call-1" ++ run_dump_test "relax-sym-size-1" ++ run_dump_test "relax-sym-size-2" + } + + if [istarget "loongarch32-*-*"] { +diff --git a/ld/testsuite/ld-loongarch-elf/relax-sym-size-1.d b/ld/testsuite/ld-loongarch-elf/relax-sym-size-1.d +new file mode 100644 +index 00000000..eec989f6 +--- /dev/null ++++ b/ld/testsuite/ld-loongarch-elf/relax-sym-size-1.d +@@ -0,0 +1,7 @@ ++#source: relax-sym-size-1.s ++#ld: ++#readelf: -s ++ ++#... ++ *[0-9]+: [0-9a-z]+ +8 .* _start ++#... +diff --git a/ld/testsuite/ld-loongarch-elf/relax-sym-size-1.s b/ld/testsuite/ld-loongarch-elf/relax-sym-size-1.s +new file mode 100644 +index 00000000..c70ac717 +--- /dev/null ++++ b/ld/testsuite/ld-loongarch-elf/relax-sym-size-1.s +@@ -0,0 +1,8 @@ ++.p2align 2 ++bar: ++ nop ++.globl _start ++_start: ++ la.pcrel $a0, bar ++ ret ++.size _start, . - _start +diff --git a/ld/testsuite/ld-loongarch-elf/relax-sym-size-2.d b/ld/testsuite/ld-loongarch-elf/relax-sym-size-2.d +new file mode 100644 +index 00000000..1388099d +--- /dev/null ++++ b/ld/testsuite/ld-loongarch-elf/relax-sym-size-2.d +@@ -0,0 +1,7 @@ ++#source: relax-sym-size-2.s ++#ld: ++#readelf: -s ++ ++#... ++ *[0-9]+: [0-9a-z]+ +64 .* _start ++#... +diff --git a/ld/testsuite/ld-loongarch-elf/relax-sym-size-2.s b/ld/testsuite/ld-loongarch-elf/relax-sym-size-2.s +new file mode 100644 +index 00000000..e02e16b7 +--- /dev/null ++++ b/ld/testsuite/ld-loongarch-elf/relax-sym-size-2.s +@@ -0,0 +1,19 @@ ++bar: ++ nop ++.p2align 6 ++ ++.reloc ., R_LARCH_ALIGN, 60 ++.rept 15 ++ 1: nop ++.endr ++ la.pcrel $a0, bar ++ ret ++ ++.reloc ., R_LARCH_ALIGN, 60 ++.rept 15 ++ 2: nop ++.endr ++ ++.globl _start ++.set _start, 1b ++.size _start, 2b - 1b +-- +2.43.7 + diff --git a/0003-LoongArch-Fix-incorrect-display-of-FDEs-address-rang.patch b/0003-LoongArch-Fix-incorrect-display-of-FDEs-address-rang.patch new file mode 100644 index 0000000..742201f --- /dev/null +++ b/0003-LoongArch-Fix-incorrect-display-of-FDEs-address-rang.patch @@ -0,0 +1,99 @@ +From e49f5021d14cd5c0209249f24bd5a9a7cae9e2d5 Mon Sep 17 00:00:00 2001 +From: Lulu Cai +Date: Tue, 26 Aug 2025 17:19:47 +0800 +Subject: [PATCH 4/6] LoongArch: Fix incorrect display of FDEs address ranges + when using objdump -Wf + +When parsing FDEs in `.eh_frame` using `objdump -Wf`, it is necessary to +resolve `BFD_RELOC_LARCH_32_PCREL` to determine the address ranges of +the FDEs. Set the `pcrel_offset` field of `BFD_RELOC_LARCH_32_PCREL` to +help `objdump` correctly compute the address ranges of the FDEs. + +Apply the same modification to BFD_RELOC_LARCH_64_PCREL. +--- + bfd/elfxx-loongarch.c | 4 ++-- + gas/testsuite/gas/loongarch/frame_pc.d | 22 ++++++++++++++++++++++ + gas/testsuite/gas/loongarch/frame_pc.s | 20 ++++++++++++++++++++ + 3 files changed, 44 insertions(+), 2 deletions(-) + create mode 100644 gas/testsuite/gas/loongarch/frame_pc.d + create mode 100644 gas/testsuite/gas/loongarch/frame_pc.s + +diff --git a/bfd/elfxx-loongarch.c b/bfd/elfxx-loongarch.c +index 83b4ee64..25f1b71c 100644 +--- a/bfd/elfxx-loongarch.c ++++ b/bfd/elfxx-loongarch.c +@@ -1388,7 +1388,7 @@ static loongarch_reloc_howto_type loongarch_howto_table[] = + false, /* partial_inplace. */ + 0, /* src_mask */ + 0xffffffff, /* dst_mask */ +- false, /* pcrel_offset */ ++ true, /* pcrel_offset */ + BFD_RELOC_LARCH_32_PCREL, /* bfd_reloc_code_real_type */ + NULL, /* adjust_reloc_bits */ + NULL), /* larch_reloc_type_name */ +@@ -1580,7 +1580,7 @@ static loongarch_reloc_howto_type loongarch_howto_table[] = + false, /* partial_inplace. */ + 0, /* src_mask */ + 0xffffffffffffffff, /* dst_mask */ +- false, /* pcrel_offset */ ++ true, /* pcrel_offset */ + BFD_RELOC_LARCH_64_PCREL, /* bfd_reloc_code_real_type */ + NULL, /* adjust_reloc_bits */ + NULL), /* larch_reloc_type_name */ +diff --git a/gas/testsuite/gas/loongarch/frame_pc.d b/gas/testsuite/gas/loongarch/frame_pc.d +new file mode 100644 +index 00000000..7bd862ba +--- /dev/null ++++ b/gas/testsuite/gas/loongarch/frame_pc.d +@@ -0,0 +1,22 @@ ++#objdump: -Wf -d -M no-aliases ++#skip: loongarch32-*-* ++ ++.*: file format .* ++ ++Contents of the .eh_frame section: ++#... ++00000014 0000000000000020 00000018 FDE cie=00000000 pc=0000000000000000..0000000000000020 ++ DW_CFA_advance_loc: 4 to 0000000000000004 ++#... ++ ++Disassembly of section .text: ++ ++0+0 <_start>: ++ 0: 02ffc063 addi.d \$sp, \$sp, -16 ++ 4: 29c02076 st.d \$fp, \$sp, 8 ++ 8: 02c04076 addi.d \$fp, \$sp, 16 ++ c: 0015000c or \$t0, \$zero, \$zero ++ 10: 00150184 or \$a0, \$t0, \$zero ++ 14: 28c02076 ld.d \$fp, \$sp, 8 ++ 18: 02c04063 addi.d \$sp, \$sp, 16 ++ 1c: 4c000020 jirl \$zero, \$ra, 0 +diff --git a/gas/testsuite/gas/loongarch/frame_pc.s b/gas/testsuite/gas/loongarch/frame_pc.s +new file mode 100644 +index 00000000..8344d737 +--- /dev/null ++++ b/gas/testsuite/gas/loongarch/frame_pc.s +@@ -0,0 +1,20 @@ ++ .align 2 ++ .globl _start ++ .type _start, @function ++_start: ++ .cfi_startproc ++ addi.d $sp,$sp,-16 ++ .cfi_def_cfa_offset 16 ++ st.d $fp,$sp,8 ++ .cfi_offset 22, -8 ++ addi.d $fp,$sp,16 ++ .cfi_def_cfa 22, 0 ++ or $t0,$zero,$zero ++ or $a0,$t0,$zero ++ ld.d $fp,$sp,8 ++ .cfi_restore 22 ++ addi.d $sp,$sp,16 ++ .cfi_def_cfa_register 3 ++ jr $ra ++ .cfi_endproc ++ .size _start, .-_start +-- +2.43.7 + diff --git a/0004-LoongArch-Use-more-appropriate-assertions-for-the-re.patch b/0004-LoongArch-Use-more-appropriate-assertions-for-the-re.patch new file mode 100644 index 0000000..10e708d --- /dev/null +++ b/0004-LoongArch-Use-more-appropriate-assertions-for-the-re.patch @@ -0,0 +1,85 @@ +From ebd3e6a6b5617fcb11aafa2ff6e1bda0fd0affe9 Mon Sep 17 00:00:00 2001 +From: Lulu Cai +Date: Tue, 16 Sep 2025 14:26:19 +0800 +Subject: [PATCH 5/6] LoongArch: Use more appropriate assertions for the + relocation of TLS LE + +PR ld/33427 + +Patches introduced in the GCC mainline: + +commit 8cad8f94b450be9b73d07bdeef7fa1778d3f2b96 +Author: H.J. Lu +Date: Fri Sep 5 15:40:51 2025 -0700 + + c: Update TLS model after processing a TLS variable + + Set a tentative TLS model in grokvardecl and update TLS mode with + the default TLS access model after a TLS variable has been fully + processed if the default TLS access model is stronger, + +triggered a linker error when building glibc using build-many-glibcs.py. + +See: https://sourceware.org/pipermail/binutils/2025-September/144225.html + +This fix uses more appropriate assertions. +--- + bfd/elfnn-loongarch.c | 2 +- + ld/testsuite/ld-loongarch-elf/ld-loongarch-elf.exp | 13 +++++++++++++ + ld/testsuite/ld-loongarch-elf/undefweak_le.s | 7 +++++++ + 3 files changed, 21 insertions(+), 1 deletion(-) + create mode 100644 ld/testsuite/ld-loongarch-elf/undefweak_le.s + +diff --git a/bfd/elfnn-loongarch.c b/bfd/elfnn-loongarch.c +index 86be86bf..1a746b92 100644 +--- a/bfd/elfnn-loongarch.c ++++ b/bfd/elfnn-loongarch.c +@@ -4350,7 +4350,7 @@ loongarch_elf_relocate_section (bfd *output_bfd, struct bfd_link_info *info, + case R_LARCH_TLS_LE_LO12_R: + case R_LARCH_TLS_LE64_LO20: + case R_LARCH_TLS_LE64_HI12: +- BFD_ASSERT (resolved_local && elf_hash_table (info)->tls_sec); ++ BFD_ASSERT (bfd_link_executable (info)); + + relocation += rel->r_addend; + relocation = tlsoff (info, relocation); +diff --git a/ld/testsuite/ld-loongarch-elf/ld-loongarch-elf.exp b/ld/testsuite/ld-loongarch-elf/ld-loongarch-elf.exp +index 9cf1096d..851bdeb9 100644 +--- a/ld/testsuite/ld-loongarch-elf/ld-loongarch-elf.exp ++++ b/ld/testsuite/ld-loongarch-elf/ld-loongarch-elf.exp +@@ -144,6 +144,19 @@ if [istarget "loongarch64-*-*"] { + "abs-global.out" \ + ] \ + ] ++ ++ ++ run_ld_link_tests \ ++ [list \ ++ [list \ ++ "undefind weak with tls le" \ ++ "" "-e0" \ ++ "" \ ++ {undefweak_le.s} \ ++ {} \ ++ "undefweak_le" \ ++ ] \ ++ ] + } + + if [istarget "loongarch64-*-*"] { +diff --git a/ld/testsuite/ld-loongarch-elf/undefweak_le.s b/ld/testsuite/ld-loongarch-elf/undefweak_le.s +new file mode 100644 +index 00000000..6e730182 +--- /dev/null ++++ b/ld/testsuite/ld-loongarch-elf/undefweak_le.s +@@ -0,0 +1,7 @@ ++_start: ++ lu12i.w $t0,%le_hi20_r(undefweak_le) ++ add.d $t0,$t0,$tp,%le_add_r(undefweak_le) ++ ld.d $t0,$t0,%le_lo12_r(undefweak_le) ++ ++ .weak undefweak_le ++ .hidden undefweak_le +-- +2.43.7 + diff --git a/0005-LoongArch-set-PRSTATUS_SIZE-0x1e0-to-match-kernel-s-.patch b/0005-LoongArch-set-PRSTATUS_SIZE-0x1e0-to-match-kernel-s-.patch new file mode 100644 index 0000000..45538d3 --- /dev/null +++ b/0005-LoongArch-set-PRSTATUS_SIZE-0x1e0-to-match-kernel-s-.patch @@ -0,0 +1,32 @@ +From b040b922dea959eb2e9e08ad6c99416680730ebc Mon Sep 17 00:00:00 2001 +From: lijian1 +Date: Mon, 24 Nov 2025 15:53:50 +0800 +Subject: [PATCH 6/6] LoongArch: set PRSTATUS_SIZE=0x1e0 to match kernel's + struct elf_prstatus size + +As PRSTATUS_SIZE is now with the value 0x1d8, which causes inconsistency with the kernel +definition and then can not lead to the correct branch for loongarch64 backend. + +With the correct value 0x1e0 for the master branch, the loongarch64 banckend will work well. + +Signed-off-by: Li Jian +--- + bfd/elfnn-loongarch.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/bfd/elfnn-loongarch.c b/bfd/elfnn-loongarch.c +index 1a746b92..d7120d0e 100644 +--- a/bfd/elfnn-loongarch.c ++++ b/bfd/elfnn-loongarch.c +@@ -6486,7 +6486,7 @@ loongarch_elf_copy_indirect_symbol (struct bfd_link_info *info, + _bfd_elf_link_hash_copy_indirect (info, dir, ind); + } + +-#define PRSTATUS_SIZE 0x1d8 ++#define PRSTATUS_SIZE 0x1e0 + #define PRSTATUS_OFFSET_PR_CURSIG 0xc + #define PRSTATUS_OFFSET_PR_PID 0x20 + #define ELF_GREGSET_T_SIZE 0x168 +-- +2.43.7 + diff --git a/binutils.spec b/binutils.spec index e06af62..81382f3 100644 --- a/binutils.spec +++ b/binutils.spec @@ -4,7 +4,7 @@ Summary: A GNU collection of binary utilities Name: binutils Version: 2.41 -Release: 25%{?dist} +Release: 26%{?dist} License: GPLv3+ URL: https://sourceware.org/binutils Source0: https://ftp.gnu.org/gnu/binutils/binutils-%{version}.tar.xz @@ -192,6 +192,11 @@ Patch3163: 0010-LoongArch-Batch-delete-bytes-at-the-end-of-each-rela.patch Patch3164: 0011-LoongArch-Allow-to-relax-instructions-into-NOPs-afte.patch Patch3165: 0012-LoongArch-Fix-errors-due-to-version-differences.patch Patch3166: LoongArch-fix-relaxation-overflowing.patch +Patch3167: 0001-LoongArch-Un-skip-cross-segment-alignment-compensati.patch +Patch3168: 0002-LoongArch-Fix-symbol-size-after-relaxation.patch +Patch3169: 0003-LoongArch-Fix-incorrect-display-of-FDEs-address-rang.patch +Patch3170: 0004-LoongArch-Use-more-appropriate-assertions-for-the-re.patch +Patch3171: 0005-LoongArch-set-PRSTATUS_SIZE-0x1e0-to-match-kernel-s-.patch Patch5000: update-OPTION-enum-start-value.patch #Purpose: Add support for sw64 ISA @@ -537,6 +542,10 @@ exit 0 %changelog +* Wed Mar 25 2026 Peng Fan - 2.41-26 +- [TYPE] bugfix +- [DESC] LoongArch: common fix from upstream + * Fri Mar 13 2026 Zhao Zhen - 2.41-25 - [TYPE] security - [DESC] fixed CVE-2025-11839 -- Gitee