]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
LoongArch: Modify inconsistent behavior of ld with --unresolved-symbols=ignore-all
authorticat_fp <fanpeng@loongson.cn>
Mon, 26 Feb 2024 03:11:35 +0000 (11:11 +0800)
committerliuzhensong <liuzhensong@loongson.cn>
Tue, 27 Feb 2024 06:22:23 +0000 (14:22 +0800)
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

index 1b5009e13b28f05f6d062341e23a1f4e79fda873..e96e0f53608ac7e0495a5f58abe7660742446bfb 100644 (file)
@@ -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);