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]

Re: [patch binutils]: Fix PR/13682 for dlltool


ä 2012/2/15 18:37, Kai Tietz åé:
Hi,

this patch adds delayed-load-library feature for x64 Windows targets.
As this feature is dependent to used runtime, I omitted here a special
testcase (as was done for x86 Windows).

ChangeLog binutils

2012-02-15 Kai Tietz<ktietz@redhat.com>

	PR binutils/13682
	* NEWS: Mention new feature.
	* dlltool.c (i386_x64_dljtab): New stub-code for x64
	delayed-load feature.
	(i386_x64_trampoline): New trampoline-code for x64
	delayed-load feature.
	(make_one_lib_file): Add support for x64 delayed-load
	feature.
	(make_delay_head): Likewise.

Tested for i686-w64-mingw32, and x86_64-w64-mingw32.  Also checked for
regressions for i686-pc-cygwin.
Ok for apply?

Regards,
Kai

Index: binutils/NEWS
===================================================================
RCS file: /cvs/src/src/binutils/NEWS,v
retrieving revision 1.106
diff -u -r1.106 NEWS
--- binutils/NEWS	2 Nov 2011 03:09:01 -0000	1.106
+++ binutils/NEWS	15 Feb 2012 10:34:02 -0000
@@ -1,5 +1,7 @@
  -*- text -*-

+* Add support for x64 Windows target of the delayed-load-library.
+
  * Add support for the Renesas RL78 architecture.

  Changes in 2.22:
Index: binutils/dlltool.c
===================================================================
RCS file: /cvs/src/src/binutils/dlltool.c,v
retrieving revision 1.104
diff -u -r1.104 dlltool.c
--- binutils/dlltool.c	9 Feb 2012 04:51:44 -0000	1.104
+++ binutils/dlltool.c	15 Feb 2012 10:34:03 -0000
@@ -515,6 +515,14 @@
    0xE9, 0x00, 0x00, 0x00, 0x00        /* jmp __tailMerge__dllname        */
  };

+static const unsigned char i386_x64_dljtab[] =
+{
+  0xFF, 0x25, 0x00, 0x00, 0x00, 0x00, /* jmp __imp__function             */
+  0x48, 0x8d, 0x05,		      /* leaq rax, (__imp__function) */
+        0x00, 0x00, 0x00, 0x00,
+  0xE9, 0x00, 0x00, 0x00, 0x00        /* jmp __tailMerge__dllname        */
+};
+
  static const unsigned char arm_jtab[] =
  {
    0x00, 0xc0, 0x9f, 0xe5,	/* ldr  ip, [pc] */
@@ -591,6 +599,22 @@
    "\tpopl %%ecx\n"
    "\tjmp *%%eax\n";

+static const char i386_x64_trampoline[] =
+  "\tpushq %%rcx\n"
+  "\tpushq %%rdx\n"
+  "\tpushq %%r8\n"
+  "\tpushq %%r9\n"
+  "\tsubq  $40, %%rsp\n"
+  "\tmovq  %%rax, %%rdx\n"
+  "\tleaq  __DELAY_IMPORT_DESCRIPTOR_%s(%%rip), %%rcx\n"
+  "\tcall __delayLoadHelper2\n"
+  "\taddq  $40, %%rsp\n"
+  "\tpopq %%r9\n"
+  "\tpopq %%r8\n"
+  "\tpopq %%rdx\n"
+  "\tpopq %%rcx\n"
+  "\tjmp *%%rax\n";
+
  struct mac
  {
    const char *type;
@@ -735,7 +759,7 @@
      "jmp *", ".global", ".space", ".align\t2",".align\t4", "",
      "pe-x86-64",bfd_arch_i386,
      i386_jtab, sizeof (i386_jtab), 2,
-    i386_dljtab, sizeof (i386_dljtab), 2, 7, 12, i386_trampoline
+    i386_x64_dljtab, sizeof (i386_x64_dljtab), 2, 9, 14, i386_x64_trampoline
    }
    ,
    { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
@@ -2609,9 +2633,14 @@

  	      if (delay)
  	        {
-	          rel2->howto = bfd_reloc_type_lookup (abfd, BFD_RELOC_32);
+		  if (machine == MX86)
+		   rel2->howto = bfd_reloc_type_lookup (abfd,
+							BFD_RELOC_32_PCREL);
+	          else
+	            rel2->howto = bfd_reloc_type_lookup (abfd, BFD_RELOC_32);
  	          rel2->sym_ptr_ptr = rel->sym_ptr_ptr;
-	          rel3->howto = bfd_reloc_type_lookup (abfd, BFD_RELOC_32_PCREL);
+	          rel3->howto = bfd_reloc_type_lookup (abfd,
+						       BFD_RELOC_32_PCREL);
  	          rel3->sym_ptr_ptr = iname_lab_pp;
  	        }

@@ -2623,10 +2652,11 @@
  	case IDATA5:
  	  if (delay)
  	    {
-	      si->data = xmalloc (4);
-	      si->size = 4;
+	      si->size = create_for_pep ? 8 : 4;
+	      si->data = xmalloc (si->size);
  	      sec->reloc_count = 1;
  	      memset (si->data, 0, si->size);
+	      /* Point after jmp [__imp_...] instruction.  */
  	      si->data[0] = 6;
  	      rel = xmalloc (sizeof (arelent));
  	      rpp = xmalloc (sizeof (arelent *) * 2);
@@ -2634,7 +2664,10 @@
  	      rpp[1] = 0;
  	      rel->address = 0;
  	      rel->addend = 0;
-	      rel->howto = bfd_reloc_type_lookup (abfd, BFD_RELOC_32);
+	      if (create_for_pep)
+	        rel->howto = bfd_reloc_type_lookup (abfd, BFD_RELOC_64);
+	      else
+	        rel->howto = bfd_reloc_type_lookup (abfd, BFD_RELOC_32);
  	      rel->sym_ptr_ptr = secdata[TEXT].sympp;
  	      sec->orelocation = rpp;
  	      break;
@@ -3005,6 +3038,8 @@
    fprintf (f, "\n.section .data\n");
    fprintf (f, "__DLL_HANDLE_%s:\n", imp_name_lab);
    fprintf (f, "\t%s\t0\t%s Handle\n", ASM_LONG, ASM_C);
+  if (create_for_pep)
+    fprintf (f, "\t%s\t0\n", ASM_LONG);
    fprintf (f, "\n");

    fprintf (f, "%sStuff for compatibility\n", ASM_C);
@@ -3013,11 +3048,10 @@
      {
        fprintf (f, "\t.section\t.idata$5\n");
        /* NULL terminating list.  */
-#ifdef DLLTOOL_MX86_64
-      fprintf (f,"\t%s\t0\n\t%s\t0\n", ASM_LONG, ASM_LONG);
-#else
-      fprintf (f,"\t%s\t0\n", ASM_LONG);
-#endif
+      if (create_for_pep)
+        fprintf (f,"\t%s\t0\n\t%s\t0\n", ASM_LONG, ASM_LONG);
+      else
+        fprintf (f,"\t%s\t0\n", ASM_LONG);
        fprintf (f, "__IAT_%s:\n", imp_name_lab);
      }

@@ -3025,6 +3059,8 @@
      {
        fprintf (f, "\t.section\t.idata$4\n");
        fprintf (f, "\t%s\t0\n", ASM_LONG);
+      if (create_for_pep)
+        fprintf (f, "\t%s\t0\n", ASM_LONG);
        fprintf (f, "\t.section\t.idata$4\n");
        fprintf (f, "__INT_%s:\n", imp_name_lab);
      }
Ping ...

--
Best Regards,
xunxun


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