This is the mail archive of the binutils-cvs@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]

[binutils-gdb/binutils-2_26-branch] Bind defined symbol locally in PIE


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=d193fe3cdcba616062980eb72e06c9a280287b5b

commit d193fe3cdcba616062980eb72e06c9a280287b5b
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Thu Mar 17 10:48:03 2016 -0700

    Bind defined symbol locally in PIE
    
    Symbols defined in PIE should be bound locally, the same as -shared
    -Bsymbolic.
    
    Backport from master
    
    bfd/
    
    	PR ld/19827
    	* elf32-i386.c (elf_i386_check_relocs): Bind defined symbol
    	locally in PIE.
    	(elf_i386_relocate_section): Likewise.
    	* elf64-x86-64.c (elf_x86_64_check_relocs): Likewise.
    	(elf_x86_64_relocate_section): Likewise.
    
    ld/
    
    	PR ld/19827
    	* testsuite/ld-i386/i386.exp: Run PR ld/19827 tests.
    	* testsuite/ld-x86-64/x86-64.exp: Likewise.
    	* testsuite/ld-i386/pr19827.rd: New file.
    	* testsuite/ld-i386/pr19827a.S: Likewise.
    	* testsuite/ld-i386/pr19827b.S: Likewise.
    	* testsuite/ld-x86-64/pr19827.rd: Likewise.
    	* testsuite/ld-x86-64/pr19827a.S: Likewise.
    	* testsuite/ld-x86-64/pr19827b.S: Likewise.

Diff:
---
 bfd/ChangeLog                     | 12 ++++++++++++
 bfd/elf32-i386.c                  |  7 ++++---
 bfd/elf64-x86-64.c                |  7 ++++---
 ld/ChangeLog                      | 15 +++++++++++++++
 ld/testsuite/ld-i386/i386.exp     |  8 ++++++++
 ld/testsuite/ld-i386/pr19827.rd   |  5 +++++
 ld/testsuite/ld-i386/pr19827a.S   |  8 ++++++++
 ld/testsuite/ld-i386/pr19827b.S   |  2 ++
 ld/testsuite/ld-x86-64/pr19827.rd |  5 +++++
 ld/testsuite/ld-x86-64/pr19827a.S |  8 ++++++++
 ld/testsuite/ld-x86-64/pr19827b.S |  2 ++
 ld/testsuite/ld-x86-64/x86-64.exp |  8 ++++++++
 12 files changed, 81 insertions(+), 6 deletions(-)

diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 59e49fa..4741b19 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,15 @@
+2016-03-17  H.J. Lu  <hongjiu.lu@intel.com>
+
+	Backport from master
+	2016-03-15  H.J. Lu  <hongjiu.lu@intel.com>
+
+	PR ld/19827
+	* elf32-i386.c (elf_i386_check_relocs): Bind defined symbol
+	locally in PIE.
+	(elf_i386_relocate_section): Likewise.
+	* elf64-x86-64.c (elf_x86_64_check_relocs): Likewise.
+	(elf_x86_64_relocate_section): Likewise.
+
 2016-03-15  H.J. Lu  <hongjiu.lu@intel.com>
 
 	Backport from master
diff --git a/bfd/elf32-i386.c b/bfd/elf32-i386.c
index 0b76153..79f339e 100644
--- a/bfd/elf32-i386.c
+++ b/bfd/elf32-i386.c
@@ -1830,7 +1830,8 @@ do_size:
 	       && (sec->flags & SEC_ALLOC) != 0
 	       && (r_type != R_386_PC32
 		   || (h != NULL
-		       && (! SYMBOLIC_BIND (info, h)
+		       && (! (bfd_link_pie (info)
+			      || SYMBOLIC_BIND (info, h))
 			   || h->root.type == bfd_link_hash_defweak
 			   || !h->def_regular))))
 	      || (ELIMINATE_COPY_RELOCS
@@ -4289,8 +4290,8 @@ r_386_got32:
 	      else if (h != NULL
 		       && h->dynindx != -1
 		       && (r_type == R_386_PC32
-			   || !bfd_link_pic (info)
-			   || !SYMBOLIC_BIND (info, h)
+			   || !(bfd_link_executable (info)
+				|| SYMBOLIC_BIND (info, h))
 			   || !h->def_regular))
 		outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
 	      else
diff --git a/bfd/elf64-x86-64.c b/bfd/elf64-x86-64.c
index 8c98cea..e80fd20 100644
--- a/bfd/elf64-x86-64.c
+++ b/bfd/elf64-x86-64.c
@@ -2029,7 +2029,8 @@ do_size:
 	       && (sec->flags & SEC_ALLOC) != 0
 	       && (! IS_X86_64_PCREL_TYPE (r_type)
 		   || (h != NULL
-		       && (! SYMBOLIC_BIND (info, h)
+		       && (! (bfd_link_pie (info)
+			      || SYMBOLIC_BIND (info, h))
 			   || h->root.type == bfd_link_hash_defweak
 			   || !h->def_regular))))
 	      || (ELIMINATE_COPY_RELOCS
@@ -4641,8 +4642,8 @@ direct:
 	      else if (h != NULL
 		       && h->dynindx != -1
 		       && (IS_X86_64_PCREL_TYPE (r_type)
-			   || ! bfd_link_pic (info)
-			   || ! SYMBOLIC_BIND (info, h)
+			   || !(bfd_link_executable (info)
+				|| SYMBOLIC_BIND (info, h))
 			   || ! h->def_regular))
 		{
 		  outrel.r_info = htab->r_info (h->dynindx, r_type);
diff --git a/ld/ChangeLog b/ld/ChangeLog
index 7cd6599..e74db8c 100644
--- a/ld/ChangeLog
+++ b/ld/ChangeLog
@@ -1,3 +1,18 @@
+2016-03-17  H.J. Lu  <hongjiu.lu@intel.com>
+
+	Backport from master
+	2016-03-15  H.J. Lu  <hongjiu.lu@intel.com>
+
+	PR ld/19827
+	* testsuite/ld-i386/i386.exp: Run PR ld/19827 tests.
+	* testsuite/ld-x86-64/x86-64.exp: Likewise.
+	* testsuite/ld-i386/pr19827.rd: New file.
+	* testsuite/ld-i386/pr19827a.S: Likewise.
+	* testsuite/ld-i386/pr19827b.S: Likewise.
+	* testsuite/ld-x86-64/pr19827.rd: Likewise.
+	* testsuite/ld-x86-64/pr19827a.S: Likewise.
+	* testsuite/ld-x86-64/pr19827b.S: Likewise.
+
 2016-03-15  H.J. Lu  <hongjiu.lu@intel.com>
 
 	Backport from master
diff --git a/ld/testsuite/ld-i386/i386.exp b/ld/testsuite/ld-i386/i386.exp
index 0cc9645..1916c24 100644
--- a/ld/testsuite/ld-i386/i386.exp
+++ b/ld/testsuite/ld-i386/i386.exp
@@ -195,6 +195,14 @@ set i386tests {
      "--32" {pr17709a.s} {} "libpr17709.so"}
     {"PR ld/17709 (2)" "-melf_i386 tmpdir/libpr17709.so" ""
      "--32" {pr17709b.s} {{readelf -r pr17709.rd}} "pr17709"}
+    {"Build pr19827a.o" "" ""
+     "--32" { pr19827a.S }}
+    {"Build pr19827b.so" "-melf_i386 -shared" ""
+     "--32" { pr19827b.S } {} "pr19827b.so"}
+    {"Build pr19827" "-melf_i386 -pie tmpdir/pr19827a.o tmpdir/pr19827b.so" ""
+     "--32" { dummy.s } {{readelf {-rW} pr19827.rd}} "pr19827"}
+    {"Build pr19827.so" "-melf_i386 -shared -Bsymbolic" ""
+     "--32" { pr19827a.S }  {{readelf {-rW} pr19827.rd}} "pr19827.so"}
 }
 
 # So as to avoid rewriting every last test case here in a nacl variant,
diff --git a/ld/testsuite/ld-i386/pr19827.rd b/ld/testsuite/ld-i386/pr19827.rd
new file mode 100644
index 0000000..5d2a885
--- /dev/null
+++ b/ld/testsuite/ld-i386/pr19827.rd
@@ -0,0 +1,5 @@
+#readelf: -r --wide
+
+Relocation section '.rel.dyn' at offset 0x[0-9a-f]+ contains 1 entries:
+ Offset     Info    Type                Sym. Value  Symbol's Name
+[0-9a-f]+ +[0-9a-f]+ +R_386_RELATIVE +
diff --git a/ld/testsuite/ld-i386/pr19827a.S b/ld/testsuite/ld-i386/pr19827a.S
new file mode 100644
index 0000000..cdf1d4b
--- /dev/null
+++ b/ld/testsuite/ld-i386/pr19827a.S
@@ -0,0 +1,8 @@
+	.text
+	.global _start
+_start:
+	.dc.a foo
+	.data
+	.globl foo
+foo:
+	.byte 0
diff --git a/ld/testsuite/ld-i386/pr19827b.S b/ld/testsuite/ld-i386/pr19827b.S
new file mode 100644
index 0000000..bb46e1d
--- /dev/null
+++ b/ld/testsuite/ld-i386/pr19827b.S
@@ -0,0 +1,2 @@
+	.data
+	.dc.a foo
diff --git a/ld/testsuite/ld-x86-64/pr19827.rd b/ld/testsuite/ld-x86-64/pr19827.rd
new file mode 100644
index 0000000..67eaacc
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/pr19827.rd
@@ -0,0 +1,5 @@
+#readelf: -r --wide
+
+Relocation section '.rela.dyn' at offset 0x[0-9a-f]+ contains 1 entries:
+    Offset             Info             Type               Symbol's Value  Symbol's Name \+ Addend
+[0-9a-f]+ +[0-9a-f]+ +R_X86_64_RELATIVE +[0-9a-f]+
diff --git a/ld/testsuite/ld-x86-64/pr19827a.S b/ld/testsuite/ld-x86-64/pr19827a.S
new file mode 100644
index 0000000..cdf1d4b
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/pr19827a.S
@@ -0,0 +1,8 @@
+	.text
+	.global _start
+_start:
+	.dc.a foo
+	.data
+	.globl foo
+foo:
+	.byte 0
diff --git a/ld/testsuite/ld-x86-64/pr19827b.S b/ld/testsuite/ld-x86-64/pr19827b.S
new file mode 100644
index 0000000..bb46e1d
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/pr19827b.S
@@ -0,0 +1,2 @@
+	.data
+	.dc.a foo
diff --git a/ld/testsuite/ld-x86-64/x86-64.exp b/ld/testsuite/ld-x86-64/x86-64.exp
index 90f856c..378c13f 100644
--- a/ld/testsuite/ld-x86-64/x86-64.exp
+++ b/ld/testsuite/ld-x86-64/x86-64.exp
@@ -148,6 +148,14 @@ set x86_64tests {
      "--64" {pr17709a.s} {} "libpr17709.so"}
     {"PR ld/17709 (2)" "-melf_x86_64 tmpdir/libpr17709.so" ""
      "--64" {pr17709b.s} {{readelf -rW pr17709.rd}} "pr17709"}
+    {"Build pr19827a.o" "" ""
+     "--64" { pr19827a.S }}
+    {"Build pr19827b.so" "-melf_x86_64 -shared" ""
+     "--64" { pr19827b.S } {} "pr19827b.so"}
+    {"Build pr19827" "-melf_x86_64 -pie tmpdir/pr19827a.o tmpdir/pr19827b.so" ""
+     "--64" { dummy.s } {{readelf {-rW} pr19827.rd}} "pr19827"}
+    {"Build pr19827.so" "-melf_x86_64 -shared -Bsymbolic" ""
+     "--64" { pr19827a.S }  {{readelf {-rW} pr19827.rd}} "pr19827.so"}
 }
 
 # So as to avoid rewriting every last test case here in a nacl variant,


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