]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
x86-64: Check ELF_COMMON_DEF_P for common symbols
authorH.J. Lu <hjl.tools@gmail.com>
Sat, 2 Sep 2017 01:53:26 +0000 (18:53 -0700)
committerH.J. Lu <hjl.tools@gmail.com>
Sat, 2 Sep 2017 02:54:15 +0000 (19:54 -0700)
bfd/

PR ld/22064
* elf64-x86-64.c (elf_x86_64_finish_dynamic_symbol): Check
ELF_COMMON_DEF_P for common symbols.

ld/

PR ld/22064
* testsuite/ld-x86-64/pr22064a.S: New file.
* testsuite/ld-x86-64/pr22064b.c: Likewise.
* testsuite/ld-x86-64/x86-64.exp: Run PR ld/22064 test.

(cherry picked from commit ad71ce8de7dba823f5fc478e6d5eba03f1a2e822)

bfd/ChangeLog
bfd/elf64-x86-64.c
ld/ChangeLog
ld/testsuite/ld-x86-64/pr22064a.S [new file with mode: 0644]
ld/testsuite/ld-x86-64/pr22064b.c [new file with mode: 0644]
ld/testsuite/ld-x86-64/x86-64.exp

index 93142541d0bba6e6a2bb2b183e1e44575477a76e..b5f1204e6405f588faa35f261bc747008ea7159b 100644 (file)
@@ -1,3 +1,9 @@
+2017-09-01  H.J. Lu  <hongjiu.lu@intel.com>
+
+       PR ld/22064
+       * elf64-x86-64.c (elf_x86_64_finish_dynamic_symbol): Check
+       ELF_COMMON_DEF_P for common symbols.
+
 2017-09-01  H.J. Lu  <hongjiu.lu@intel.com>
 
        PR ld/22061
index bc60012f1e621a6d6bfc2b8cfe50dccafafb9b4f..59926b6092fce8f683e4ea43cb4110599cec07bd 100644 (file)
@@ -6181,7 +6181,7 @@ elf_x86_64_finish_dynamic_symbol (bfd *output_bfd,
       else if (bfd_link_pic (info)
               && SYMBOL_REFERENCES_LOCAL (info, h))
        {
-         if (!h->def_regular)
+         if (!(h->def_regular || ELF_COMMON_DEF_P (h)))
            return FALSE;
          BFD_ASSERT((h->got.offset & 1) != 0);
          rela.r_info = htab->r_info (0, R_X86_64_RELATIVE);
index f4335cfe26421e6f6d972f2d47b1feffaf107244..24d0ed26a79e8f4041e6b5e7200af80f9721fe5f 100644 (file)
@@ -1,3 +1,10 @@
+2017-09-01  H.J. Lu  <hongjiu.lu@intel.com>
+
+       PR ld/22064
+       * testsuite/ld-x86-64/pr22064a.S: New file.
+       * testsuite/ld-x86-64/pr22064b.c: Likewise.
+       * testsuite/ld-x86-64/x86-64.exp: Run PR ld/22064 test.
+
 2017-09-01  H.J. Lu  <hongjiu.lu@intel.com>
 
        PR ld/22061
diff --git a/ld/testsuite/ld-x86-64/pr22064a.S b/ld/testsuite/ld-x86-64/pr22064a.S
new file mode 100644 (file)
index 0000000..8065a11
--- /dev/null
@@ -0,0 +1,33 @@
+       .section        .rodata.str1.1,"aMS",@progbits,1
+.LC0:
+       .string "PASS"
+       .text
+       .globl  main
+       .type   main, @function
+main:
+       movq    foo@GOTPCREL(%rip), %rax
+       cmpl    $0, (%rax)
+       jne     .L4
+       subq    $8, %rsp
+       call    foo_p@PLT
+       cmpq    foo@GOTPCREL(%rip), %rax
+       jne     .L2
+       movq    bar@GOTPCREL(%rip), %rax
+       cmpl    $-1, (%rax)
+       jne     .L2
+       call    bar_p@PLT
+       cmpq    bar@GOTPCREL(%rip), %rax
+       jne     .L2
+       leaq    .LC0(%rip), %rdi
+       call    puts@PLT
+.L2:
+       movl    $0, %eax
+       addq    $8, %rsp
+       ret
+.L4:
+       movl    $0, %eax
+       ret
+       .size   main, .-main
+       .comm   bar,8,4
+       .comm   foo,4,4
+       .section        .note.GNU-stack,"",@progbits
diff --git a/ld/testsuite/ld-x86-64/pr22064b.c b/ld/testsuite/ld-x86-64/pr22064b.c
new file mode 100644 (file)
index 0000000..d906545
--- /dev/null
@@ -0,0 +1,14 @@
+int foo[2];
+int bar[2] = { -1, -1 };
+
+int *
+foo_p (void)
+{
+  return foo;
+}
+
+int *
+bar_p (void)
+{
+  return bar;
+}
index 13c68b82ee393114f8b1287435dd636279217bb2..2535fb709124d6d9188730f8c41bbb25a5fb8efe 100644 (file)
@@ -1039,6 +1039,20 @@ if { [isnative] && [which $CC] != 0 } {
            {{readelf {-n} property-7.r}} \
            "property-7b.o" \
        ] \
+       [list \
+           "Build pr22064a.o" \
+           "" \
+           "" \
+           { pr22064a.S } \
+       ] \
+       [list \
+           "Build pr22064.so" \
+           "-shared" \
+           "-fPIC" \
+           { pr22064b.c } \
+           {} \
+           "pr22064.so" \
+       ] \
     ]
 
     run_ld_link_exec_tests [list \
@@ -1215,6 +1229,15 @@ if { [isnative] && [which $CC] != 0 } {
            {property-x86-2.S property-x86-1.S pass.c property-stack.S} \
            "property-5-static" "pass.out" \
        ] \
+       [list \
+           "Run pr22064" \
+           "-pie -Wl,--no-as-needed tmpdir/pr22064a.o tmpdir/pr22064.so" \
+           "" \
+           { dummy.s } \
+           "pr22064-pie" \
+           "pass.out" \
+           "-fPIE" \
+       ] \
     ]
 
     # Run-time tests which require working ifunc attribute support.