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_25-branch] Add extern_protected_data and set it for x86


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

commit 031994d25c8c8dc392ceb43abc2dfd9a851bc384
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Thu Mar 5 06:34:39 2015 -0800

    Add extern_protected_data and set it for x86
    
    With copy relocation, address of protected data defined in the shared
    library may be external.  This patch adds extern_protected_data and
    changes _bfd_elf_symbol_refs_local_p to return false for protected data
    if extern_protected_data is true.
    
    Backport from master:
    
    bfd/
    
    	PR ld/pr15228
    	PR ld/pr17709
    	* elf-bfd.h (elf_backend_data): Add extern_protected_data.
    	* elf32-i386.c (elf_backend_extern_protected_data): New.
    	Defined to 1.
    	* elf64-x86-64.c (elf_backend_extern_protected_data): Likewise.
    	* elflink.c (_bfd_elf_adjust_dynamic_copy): Don't error on
    	copy relocs against protected symbols if extern_protected_data
    	is true.
    	(_bfd_elf_symbol_refs_local_p): Don't return true on protected
    	non-function symbols if extern_protected_data is true.
    	* elfxx-target.h (elf_backend_extern_protected_data): New.
    	Default to 0.
    	(elfNN_bed): Initialize extern_protected_data with
    	elf_backend_extern_protected_data.
    
    ld/testsuite/
    
    	PR ld/pr15228
    	PR ld/pr17709
    	* ld-i386/i386.exp (i386tests): Add a test for PR ld/17709.
    	* ld-i386/pr17709-nacl.rd: New file.
    	* ld-i386/pr17709.rd: Likewise.
    	* ld-i386/pr17709a.s: Likewise.
    	* ld-i386/pr17709b.s: Likewise.
    	* ld-i386/protected3.d: Updated.
    	* ld-i386/protected3.s: Likewise.
    	* ld-x86-64/pr17709-nacl.rd: New file.
    	* ld-x86-64/pr17709.rd: Likewise.
    	* ld-x86-64/pr17709a.s: Likewise.
    	* ld-x86-64/pr17709b.s: Likewise.
    	* ld-x86-64/protected3.d: Updated.
    	* ld-x86-64/protected3.s: Likewise.
    	* ld-x86-64/x86-64.exp (x86_64tests): Add a test for PR ld/17709.

Diff:
---
 bfd/ChangeLog                          | 21 +++++++++++++++++++++
 bfd/elf-bfd.h                          |  4 ++++
 bfd/elf32-i386.c                       |  1 +
 bfd/elf64-x86-64.c                     |  1 +
 bfd/elflink.c                          |  9 ++++++---
 bfd/elfxx-target.h                     |  6 +++++-
 ld/testsuite/ChangeLog                 | 22 ++++++++++++++++++++++
 ld/testsuite/ld-i386/i386.exp          |  4 ++++
 ld/testsuite/ld-i386/pr17709-nacl.rd   |  4 ++++
 ld/testsuite/ld-i386/pr17709.rd        |  4 ++++
 ld/testsuite/ld-i386/pr17709a.s        |  8 ++++++++
 ld/testsuite/ld-i386/pr17709b.s        |  5 +++++
 ld/testsuite/ld-i386/protected3.d      |  3 ++-
 ld/testsuite/ld-i386/protected3.s      |  3 ++-
 ld/testsuite/ld-x86-64/pr17709-nacl.rd |  4 ++++
 ld/testsuite/ld-x86-64/pr17709.rd      |  4 ++++
 ld/testsuite/ld-x86-64/pr17709a.s      |  8 ++++++++
 ld/testsuite/ld-x86-64/pr17709b.s      |  5 +++++
 ld/testsuite/ld-x86-64/protected3.d    |  3 ++-
 ld/testsuite/ld-x86-64/protected3.s    |  3 ++-
 ld/testsuite/ld-x86-64/x86-64.exp      |  4 ++++
 21 files changed, 118 insertions(+), 8 deletions(-)

diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 79f333a..d12d966 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,24 @@
+2015-03-06  H.J. Lu  <hongjiu.lu@intel.com>
+
+	Backport from master
+	2015-03-05  H.J. Lu  <hongjiu.lu@intel.com>
+
+	PR ld/pr15228
+	PR ld/pr17709
+	* elf-bfd.h (elf_backend_data): Add extern_protected_data.
+	* elf32-i386.c (elf_backend_extern_protected_data): New.
+	Defined to 1.
+	* elf64-x86-64.c (elf_backend_extern_protected_data): Likewise.
+	* elflink.c (_bfd_elf_adjust_dynamic_copy): Don't error on
+	copy relocs against protected symbols if extern_protected_data
+	is true.
+	(_bfd_elf_symbol_refs_local_p): Don't return true on protected
+	non-function symbols if extern_protected_data is true.
+	* elfxx-target.h (elf_backend_extern_protected_data): New.
+	Default to 0.
+	(elfNN_bed): Initialize extern_protected_data with
+	elf_backend_extern_protected_data.
+
 2015-02-11  Alan Modra  <amodra@gmail.com>
 
 	Apply from master.
diff --git a/bfd/elf-bfd.h b/bfd/elf-bfd.h
index 5069376..c84bbc4 100644
--- a/bfd/elf-bfd.h
+++ b/bfd/elf-bfd.h
@@ -1355,6 +1355,10 @@ struct elf_backend_data
      in length rather than sec->size in length, if sec->rawsize is
      non-zero and smaller than sec->size.  */
   unsigned caches_rawsize : 1;
+
+  /* Address of protected data defined in the shared library may be
+     external, i.e., due to copy relocation.   */
+  unsigned extern_protected_data : 1;
 };
 
 /* Information about reloc sections associated with a bfd_elf_section_data
diff --git a/bfd/elf32-i386.c b/bfd/elf32-i386.c
index 2daf17b..73141ee 100644
--- a/bfd/elf32-i386.c
+++ b/bfd/elf32-i386.c
@@ -5107,6 +5107,7 @@ elf_i386_add_symbol_hook (bfd * abfd,
 #define elf_backend_want_plt_sym	0
 #define elf_backend_got_header_size	12
 #define elf_backend_plt_alignment	4
+#define elf_backend_extern_protected_data 1
 
 /* Support RELA for objdump of prelink objects.  */
 #define elf_info_to_howto		      elf_i386_info_to_howto_rel
diff --git a/bfd/elf64-x86-64.c b/bfd/elf64-x86-64.c
index 2581353..a6a4bfc 100644
--- a/bfd/elf64-x86-64.c
+++ b/bfd/elf64-x86-64.c
@@ -5696,6 +5696,7 @@ static const struct bfd_elf_special_section
 #define elf_backend_got_header_size	    (GOT_ENTRY_SIZE*3)
 #define elf_backend_rela_normal		    1
 #define elf_backend_plt_alignment           4
+#define elf_backend_extern_protected_data   1
 
 #define elf_info_to_howto		    elf_x86_64_info_to_howto
 
diff --git a/bfd/elflink.c b/bfd/elflink.c
index 9f4ee0e..f314842 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -2672,7 +2672,9 @@ _bfd_elf_adjust_dynamic_copy (struct bfd_link_info *info,
   /* Increment the size of DYNBSS to make room for the symbol.  */
   dynbss->size += h->size;
 
-  if (h->protected_def)
+  /* No error if extern_protected_data is true.  */
+  if (h->protected_def
+      && !get_elf_backend_data (dynbss->owner)->extern_protected_data)
     {
       info->callbacks->einfo
 	(_("%P: copy reloc against protected `%T' is invalid\n"),
@@ -2836,8 +2838,9 @@ _bfd_elf_symbol_refs_local_p (struct elf_link_hash_entry *h,
 
   bed = get_elf_backend_data (hash_table->dynobj);
 
-  /* STV_PROTECTED non-function symbols are local.  */
-  if (!bed->is_function_type (h->type))
+  /* If extern_protected_data is false, STV_PROTECTED non-function
+     symbols are local.  */
+  if (!bed->extern_protected_data && !bed->is_function_type (h->type))
     return TRUE;
 
   /* Function pointer equality tests may require that STV_PROTECTED
diff --git a/bfd/elfxx-target.h b/bfd/elfxx-target.h
index 64d2461..5fecf9c 100644
--- a/bfd/elfxx-target.h
+++ b/bfd/elfxx-target.h
@@ -113,6 +113,9 @@
 #ifndef elf_backend_caches_rawsize
 #define elf_backend_caches_rawsize 0
 #endif
+#ifndef elf_backend_extern_protected_data
+#define elf_backend_extern_protected_data 0
+#endif
 #ifndef elf_backend_stack_align
 #define elf_backend_stack_align 16
 #endif
@@ -797,7 +800,8 @@ static struct elf_backend_data elfNN_bed =
   elf_backend_want_dynbss,
   elf_backend_want_p_paddr_set_to_zero,
   elf_backend_default_execstack,
-  elf_backend_caches_rawsize
+  elf_backend_caches_rawsize,
+  elf_backend_extern_protected_data
 };
 
 /* Forward declaration for use when initialising alternative_target field.  */
diff --git a/ld/testsuite/ChangeLog b/ld/testsuite/ChangeLog
index 44a2b0a..120ece6 100644
--- a/ld/testsuite/ChangeLog
+++ b/ld/testsuite/ChangeLog
@@ -1,3 +1,25 @@
+2015-03-06  H.J. Lu  <hongjiu.lu@intel.com>
+
+	Backport from master
+	2015-03-05  H.J. Lu  <hongjiu.lu@intel.com>
+
+	PR ld/pr15228
+	PR ld/pr17709
+	* ld-i386/i386.exp (i386tests): Add a test for PR ld/17709.
+	* ld-i386/pr17709-nacl.rd: New file.
+	* ld-i386/pr17709.rd: Likewise.
+	* ld-i386/pr17709a.s: Likewise.
+	* ld-i386/pr17709b.s: Likewise.
+	* ld-i386/protected3.d: Updated.
+	* ld-i386/protected3.s: Likewise.
+	* ld-x86-64/pr17709-nacl.rd: New file.
+	* ld-x86-64/pr17709.rd: Likewise.
+	* ld-x86-64/pr17709a.s: Likewise.
+	* ld-x86-64/pr17709b.s: Likewise.
+	* ld-x86-64/protected3.d: Updated.
+	* ld-x86-64/protected3.s: Likewise.
+	* ld-x86-64/x86-64.exp (x86_64tests): Add a test for PR ld/17709.
+
 2015-02-11  Alan Modra  <amodra@gmail.com>
 
 	Apply from master.
diff --git a/ld/testsuite/ld-i386/i386.exp b/ld/testsuite/ld-i386/i386.exp
index 30be98a..477dd7b 100644
--- a/ld/testsuite/ld-i386/i386.exp
+++ b/ld/testsuite/ld-i386/i386.exp
@@ -191,6 +191,10 @@ set i386tests {
      "--32" {pr17306b.s} {} ""}
     {"PR ld/17306 (2)" "-melf_i386 -shared -Bsymbolic --just-symbols=tmpdir/pr17306b.o" ""
      "--32" {pr17306a.s} {} "libpr17306.so"}
+    {"PR ld/17709 (1)" "-melf_i386 -shared" ""
+     "--32" {pr17709a.s} {} "libpr17709.so"}
+    {"PR ld/17709 (2)" "-melf_i386 tmpdir/libpr17709.so" ""
+     "--32" {pr17709b.s} {{readelf -r pr17709.rd}} "pr17709"}
 }
 
 # So as to avoid rewriting every last test case here in a nacl variant,
diff --git a/ld/testsuite/ld-i386/pr17709-nacl.rd b/ld/testsuite/ld-i386/pr17709-nacl.rd
new file mode 100644
index 0000000..ac9d174
--- /dev/null
+++ b/ld/testsuite/ld-i386/pr17709-nacl.rd
@@ -0,0 +1,4 @@
+
+Relocation section '.rel\..*' at offset .* contains 1 entries:
+ Offset     Info    Type            Sym\.Value  Sym\. Name
+[0-9a-f ]+R_386_COPY +[0-9a-f]+ +foo
diff --git a/ld/testsuite/ld-i386/pr17709.rd b/ld/testsuite/ld-i386/pr17709.rd
new file mode 100644
index 0000000..ac9d174
--- /dev/null
+++ b/ld/testsuite/ld-i386/pr17709.rd
@@ -0,0 +1,4 @@
+
+Relocation section '.rel\..*' at offset .* contains 1 entries:
+ Offset     Info    Type            Sym\.Value  Sym\. Name
+[0-9a-f ]+R_386_COPY +[0-9a-f]+ +foo
diff --git a/ld/testsuite/ld-i386/pr17709a.s b/ld/testsuite/ld-i386/pr17709a.s
new file mode 100644
index 0000000..8750f5e
--- /dev/null
+++ b/ld/testsuite/ld-i386/pr17709a.s
@@ -0,0 +1,8 @@
+	.protected	foo
+.globl foo
+	.data
+	.align 4
+	.type	foo, @object
+	.size	foo, 4
+foo:
+	.long	1
diff --git a/ld/testsuite/ld-i386/pr17709b.s b/ld/testsuite/ld-i386/pr17709b.s
new file mode 100644
index 0000000..c57f404
--- /dev/null
+++ b/ld/testsuite/ld-i386/pr17709b.s
@@ -0,0 +1,5 @@
+	.text
+	.globl	_start
+	.type	_start, @function
+_start:
+	movl	foo, %eax
diff --git a/ld/testsuite/ld-i386/protected3.d b/ld/testsuite/ld-i386/protected3.d
index aafa2d8..47ab4e1 100644
--- a/ld/testsuite/ld-i386/protected3.d
+++ b/ld/testsuite/ld-i386/protected3.d
@@ -8,6 +8,7 @@
 Disassembly of section .text:
 
 0+[a-f0-9]+ <bar>:
-[ 	]*[a-f0-9]+:	8b 81 [a-f0-9][a-f0-9] [a-f0-9][a-f0-9] 00 00    	mov    0x[a-f0-9]+\(%ecx\),%eax
+[ 	]*[a-f0-9]+:	8b 81 [a-f0-9][a-f0-9] [a-f0-9][a-f0-9] ff ff    	mov    -0x[a-f0-9]+\(%ecx\),%eax
+[ 	]*[a-f0-9]+:	8b 00                	mov    \(%eax\),%eax
 [ 	]*[a-f0-9]+:	c3                   	ret    
 #pass
diff --git a/ld/testsuite/ld-i386/protected3.s b/ld/testsuite/ld-i386/protected3.s
index 7a605a2..4dd2115 100644
--- a/ld/testsuite/ld-i386/protected3.s
+++ b/ld/testsuite/ld-i386/protected3.s
@@ -10,6 +10,7 @@ foo:
 .globl bar
 	.type	bar, @function
 bar:
-	movl	foo@GOTOFF(%ecx), %eax
+	movl	foo@GOT(%ecx), %eax
+	movl	(%eax), %eax
 	ret
 	.size	bar, .-bar
diff --git a/ld/testsuite/ld-x86-64/pr17709-nacl.rd b/ld/testsuite/ld-x86-64/pr17709-nacl.rd
new file mode 100644
index 0000000..f1baa38
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/pr17709-nacl.rd
@@ -0,0 +1,4 @@
+
+Relocation section '.rela\..*' at offset .* contains 1 entries:
+ +Offset +Info +Type +Symbol's Value +Symbol's Name \+ Addend
+[0-9a-f ]+R_X86_64_COPY+[0-9a-f ]+ +foo \+ 0
diff --git a/ld/testsuite/ld-x86-64/pr17709.rd b/ld/testsuite/ld-x86-64/pr17709.rd
new file mode 100644
index 0000000..f1baa38
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/pr17709.rd
@@ -0,0 +1,4 @@
+
+Relocation section '.rela\..*' at offset .* contains 1 entries:
+ +Offset +Info +Type +Symbol's Value +Symbol's Name \+ Addend
+[0-9a-f ]+R_X86_64_COPY+[0-9a-f ]+ +foo \+ 0
diff --git a/ld/testsuite/ld-x86-64/pr17709a.s b/ld/testsuite/ld-x86-64/pr17709a.s
new file mode 100644
index 0000000..8750f5e
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/pr17709a.s
@@ -0,0 +1,8 @@
+	.protected	foo
+.globl foo
+	.data
+	.align 4
+	.type	foo, @object
+	.size	foo, 4
+foo:
+	.long	1
diff --git a/ld/testsuite/ld-x86-64/pr17709b.s b/ld/testsuite/ld-x86-64/pr17709b.s
new file mode 100644
index 0000000..c57f404
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/pr17709b.s
@@ -0,0 +1,5 @@
+	.text
+	.globl	_start
+	.type	_start, @function
+_start:
+	movl	foo, %eax
diff --git a/ld/testsuite/ld-x86-64/protected3.d b/ld/testsuite/ld-x86-64/protected3.d
index 22a36ac..d8f09da 100644
--- a/ld/testsuite/ld-x86-64/protected3.d
+++ b/ld/testsuite/ld-x86-64/protected3.d
@@ -8,6 +8,7 @@
 Disassembly of section .text:
 
 0+[a-f0-9]+ <bar>:
-[ 	]*[a-f0-9]+:	8b 05 ([0-9a-f]{2} ){4} *	mov    0x[a-f0-9]+\(%rip\),%eax        # [a-f0-9]+ <foo>
+[ 	]*[a-f0-9]+:	48 8b 05 ([0-9a-f]{2} ){4} *	mov    0x[a-f0-9]+\(%rip\),%rax        # [a-f0-9]+ <_DYNAMIC\+0x[a-f0-9]+>
+[ 	]*[a-f0-9]+:	8b 00                	mov    \(%rax\),%eax
 [ 	]*[a-f0-9]+:	c3                   	retq *
 #pass
diff --git a/ld/testsuite/ld-x86-64/protected3.s b/ld/testsuite/ld-x86-64/protected3.s
index e4af6e7..7538050 100644
--- a/ld/testsuite/ld-x86-64/protected3.s
+++ b/ld/testsuite/ld-x86-64/protected3.s
@@ -10,6 +10,7 @@ foo:
 .globl bar
 	.type	bar, @function
 bar:
-	movl	foo(%rip), %eax
+	movq	foo@GOTPCREL(%rip), %rax
+	movl	(%rax), %eax
 	ret
 	.size	bar, .-bar
diff --git a/ld/testsuite/ld-x86-64/x86-64.exp b/ld/testsuite/ld-x86-64/x86-64.exp
index 28e8108..c480530 100644
--- a/ld/testsuite/ld-x86-64/x86-64.exp
+++ b/ld/testsuite/ld-x86-64/x86-64.exp
@@ -144,6 +144,10 @@ set x86_64tests {
      "--64" {pr17306b.s} {} ""}
     {"PR ld/17306 (2)" "-melf_x86_64 -shared -Bsymbolic --just-symbols=tmpdir/pr17306b.o" ""
      "--64" {pr17306a.s} {} "libpr17306.so"}
+    {"PR ld/17709 (1)" "-melf_x86_64 -shared" ""
+     "--64" {pr17709a.s} {} "libpr17709.so"}
+    {"PR ld/17709 (2)" "-melf_x86_64 tmpdir/libpr17709.so" ""
+     "--64" {pr17709b.s} {{readelf -rW pr17709.rd}} "pr17709"}
 }
 
 # 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]