From ab15cec8d38a5cbe166e0ad3100c14139d2a1632 Mon Sep 17 00:00:00 2001 From: Wenlong Zhang Date: Wed, 6 Mar 2024 08:54:51 +0000 Subject: [PATCH] Modify inconsistent behavior of ld with --unresolved-symbols=ignore-all (cherry picked from commit 0c809caf6ff91567df909c3b6bbfbd6f3f418eb1) --- ...-inconsistent-behavior-of-ld-with-un.patch | 60 +++++++++++++++++++ binutils.spec | 7 ++- 2 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 LoongArch-Modify-inconsistent-behavior-of-ld-with-un.patch diff --git a/LoongArch-Modify-inconsistent-behavior-of-ld-with-un.patch b/LoongArch-Modify-inconsistent-behavior-of-ld-with-un.patch new file mode 100644 index 0000000..2b2d75e --- /dev/null +++ b/LoongArch-Modify-inconsistent-behavior-of-ld-with-un.patch @@ -0,0 +1,60 @@ +From 268391acb9fa956bad24533e2cc0d1459dea1b3d Mon Sep 17 00:00:00 2001 +From: ticat_fp +Date: Mon, 26 Feb 2024 11:11:35 +0800 +Subject: [PATCH] LoongArch: Modify inconsistent behavior of ld with + --unresolved-symbols=ignore-all + +Remove duplicated check when producing executable files that reference external symbols +defined in other files. RELOC_FOR_GLOBAL_SYMBOL will check it. + +Testcase is: +resolv.c: +int main(int argc, char *argv[]) { + return argc; +} + +t.c: + +extern const struct my_struct ms1; +static const struct my_struct *ms = &ms1; + +t.h: +typedef struct my_struct { + char *str; + int i; +} my_struct; + +Compiling and linking command with: +gcc t.c -c ; gcc resolv.c -c +gcc resolv.o t.o -o resolv -Wl,--unresolved-symbols=ignore-all + +Got error as: +~/install/usr/bin/ld: t.o:(.data.rel+0x0): undefined reference to `ms1' +collect2: error: ld returned 1 exit status +--- + bfd/elfnn-loongarch.c | 9 +-------- + 1 file changed, 1 insertion(+), 8 deletions(-) + +diff --git a/bfd/elfnn-loongarch.c b/bfd/elfnn-loongarch.c +index 1b5009e13b2..e96e0f53608 100644 +--- a/bfd/elfnn-loongarch.c ++++ b/bfd/elfnn-loongarch.c +@@ -2868,14 +2868,7 @@ loongarch_elf_relocate_section (bfd *output_bfd, struct bfd_link_info *info, + else if (resolved_dynly) + { + if (h->dynindx == -1) +- { +- if (h->root.type == bfd_link_hash_undefined) +- (*info->callbacks->undefined_symbol) +- (info, name, input_bfd, input_section, +- rel->r_offset, true); +- +- outrel.r_info = ELFNN_R_INFO (0, r_type); +- } ++ outrel.r_info = ELFNN_R_INFO (0, r_type); + else + outrel.r_info = ELFNN_R_INFO (h->dynindx, r_type); + +-- +2.27.0 + diff --git a/binutils.spec b/binutils.spec index 2573d75..780bab7 100644 --- a/binutils.spec +++ b/binutils.spec @@ -2,7 +2,7 @@ Summary: A GNU collection of binary utilities Name: binutils%{?_with_debug:-debug} Version: 2.41 -Release: 2 +Release: 3 License: GPL-3.0-or-later AND (GPL-3.0-or-later WITH Bison-exception-2.2) AND (LGPL-2.0-or-later WITH GCC-exception-2.0) AND BSD-3-Clause AND GFDL-1.3-or-later AND GPL-2.0-or-later AND LGPL-2.1-or-later AND LGPL-2.0-or-later URL: https://sourceware.org/binutils @@ -174,6 +174,7 @@ Patch3006: LoongArch-Add-more-relaxation-testcases.patch Patch3007: LoongArch-fix-internal-error-when-as-handling-unsupp.patch Patch3008: as-Add-new-atomic-instructions-in-LoongArch-v1.1.patch Patch3009: as-Add-new-estimated-reciprocal-instructions-in-Loon.patch +Patch3010: LoongArch-Modify-inconsistent-behavior-of-ld-with-un.patch # Part 5000 - @@ -1265,6 +1266,10 @@ exit 0 #---------------------------------------------------------------------------- %changelog +* Wed Mar 6 2024 Wenlong Zhang - 2.41-3 +- LoongArch: sync patch from binutils upstream +- LoongArch: Modify inconsistent behavior of ld with --unresolved-symbols=ignore-all + * Wed Feb 28 2024 Peng Fan - 2.41-2 - LoongArch: sync patch from binutils upstream -- Gitee