This is the mail archive of the binutils@sources.redhat.com 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]

Re: RFC: PATCH: PR x86_64/584: Detect call on protected symbol


On Thu, Jan 20, 2005 at 11:17:55AM +0100, Andreas Schwab wrote:
> "H. J. Lu" <hjl@lucon.org> writes:
> 
> > I don't think we should worry about anything, like wrong insn, r_offset
> > == 0, jump table or data section.
> 
> At least we shouldn't crash.

How about this patch?


H.J.
----
2005-01-20  H.J. Lu  <hongjiu.lu@intel.com>

	PR 584
	* elf64-x86-64.c (is_32bit_relative_branch): New.
	(elf64_x86_64_relocate_section): Alllow R_X86_64_PC32 on a
	protected function symbol when building shared library for
	32bit relative branch instruction.

--- bfd/elf64-x86-64.c.prot	2005-01-11 09:10:28.000000000 -0800
+++ bfd/elf64-x86-64.c	2005-01-20 09:31:25.100049886 -0800
@@ -1745,6 +1745,24 @@ tpoff (struct bfd_link_info *info, bfd_v
   return address - htab->tls_size - htab->tls_sec->vma;
 }
 
+/* Is the instruction before OFFSET in CONTENTS a 32bit relative
+   branch?  */
+
+static bfd_boolean
+is_32bit_relative_branch (bfd_byte *contents, bfd_vma offset)
+{
+  /* Opcode		Instruction
+     0xe8		call
+     0xe9		jump
+     0x0f 0x8x		conditional jump */
+  return ((offset > 0
+	   && (contents [offset - 1] == 0xe8
+	       || contents [offset - 1] == 0xe9))
+	  || (offset > 1
+	      && contents [offset - 2] == 0x0f
+	      && (contents [offset - 1] & 0xf0) == 0x80));
+}
+
 /* Relocate an x86_64 ELF section.  */
 
 static bfd_boolean
@@ -1950,7 +1968,12 @@ elf64_x86_64_relocate_section (bfd *outp
 	  if (info->shared
 	      && !SYMBOL_REFERENCES_LOCAL (info, h)
 	      && (input_section->flags & SEC_ALLOC) != 0
-	      && (input_section->flags & SEC_READONLY) != 0)
+	      && (input_section->flags & SEC_READONLY) != 0
+	      && (!h->def_regular
+		  || r_type != R_X86_64_PC32
+		  || h->type != STT_FUNC
+		  || ELF_ST_VISIBILITY (h->other) != STV_PROTECTED
+		  || !is_32bit_relative_branch (contents, rel->r_offset)))
 	    {
 	      (*_bfd_error_handler)
 		(_("%B: relocation %s against `%s' can not be used when making a shared object; recompile with -fPIC"),


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