This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[committed, PATCH] x86-64: Check ELF_COMMON_DEF_P for common symbols


Checked into master branch.  I will backport it to 2.29 branch.

H.J.
---
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.
---
 bfd/ChangeLog                     |  6 ++++++
 bfd/elf64-x86-64.c                |  2 +-
 ld/ChangeLog                      |  7 +++++++
 ld/testsuite/ld-x86-64/pr22064a.S | 33 +++++++++++++++++++++++++++++++++
 ld/testsuite/ld-x86-64/pr22064b.c | 14 ++++++++++++++
 ld/testsuite/ld-x86-64/x86-64.exp | 23 +++++++++++++++++++++++
 6 files changed, 84 insertions(+), 1 deletion(-)
 create mode 100644 ld/testsuite/ld-x86-64/pr22064a.S
 create mode 100644 ld/testsuite/ld-x86-64/pr22064b.c

diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 5dde137405..5ef77cce6c 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -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-02  Alan Modra  <amodra@gmail.com>
 
 	* elf-eh-frame.c (offset_adjust): Avoid false positive gcc warning.
diff --git a/bfd/elf64-x86-64.c b/bfd/elf64-x86-64.c
index 63aff4630f..26ab715daf 100644
--- a/bfd/elf64-x86-64.c
+++ b/bfd/elf64-x86-64.c
@@ -5330,7 +5330,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);
diff --git a/ld/ChangeLog b/ld/ChangeLog
index 4a45000813..2cda5e03fd 100644
--- a/ld/ChangeLog
+++ b/ld/ChangeLog
@@ -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-02  Alan Modra  <amodra@gmail.com>
 
 	* emultempl/msp430.em (eval_upper_either_sections): Make base_sec_name
diff --git a/ld/testsuite/ld-x86-64/pr22064a.S b/ld/testsuite/ld-x86-64/pr22064a.S
new file mode 100644
index 0000000000..8065a112d7
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/pr22064a.S
@@ -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
index 0000000000..d9065458ed
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/pr22064b.c
@@ -0,0 +1,14 @@
+int foo[2];
+int bar[2] = { -1, -1 };
+
+int *
+foo_p (void)
+{
+  return foo;
+}
+
+int *
+bar_p (void)
+{
+  return bar;
+}
diff --git a/ld/testsuite/ld-x86-64/x86-64.exp b/ld/testsuite/ld-x86-64/x86-64.exp
index bf73534c1b..83822dcfe9 100644
--- a/ld/testsuite/ld-x86-64/x86-64.exp
+++ b/ld/testsuite/ld-x86-64/x86-64.exp
@@ -1073,6 +1073,20 @@ if { [isnative] && [which $CC] != 0 } {
 	    {{error_output "pr21997-1a.err"}} \
 	    "pr21997-1a" \
 	] \
+	[list \
+	    "Build pr22064a.o" \
+	    "" \
+	    "" \
+	    { pr22064a.S } \
+	] \
+	[list \
+	    "Build pr22064.so" \
+	    "-shared" \
+	    "-fPIC" \
+	    { pr22064b.c } \
+	    {} \
+	    "pr22064.so" \
+	] \
     ]
 
     if  {[istarget "x86_64-*-linux*-gnux32"]} {
@@ -1363,6 +1377,15 @@ if { [isnative] && [which $CC] != 0 } {
 	    "pass.out" \
 	    "-fPIC" \
 	] \
+	[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.
-- 
2.13.5


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]