/* dlltool.c -- tool to generate stuff for PE style DLLs
- Copyright 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
- 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
+ Copyright (C) 1995-2014 Free Software Foundation, Inc.
This file is part of GNU Binutils.
.idata$7 = dll name (eg: "kernel32.dll"). (.idata$6 for ppc). */
-/* AIX requires this to be the first thing in the file. */
-#ifndef __GNUC__
-# ifdef _AIX
- #pragma alloca
-#endif
-#endif
-
-#define show_allnames 0
-
#include "sysdep.h"
#include "bfd.h"
#include "libiberty.h"
#include "safe-ctype.h"
#include <time.h>
-#include <sys/stat.h>
-#include <stdarg.h>
#include <assert.h>
#ifdef DLLTOOL_ARM
#endif /* defined (_WIN32) && ! defined (__CYGWIN32__) */
#endif /* ! HAVE_SYS_WAIT_H */
+#define show_allnames 0
+
/* ifunc and ihead data structures: ttk@cygnus.com 1997
When IMPORT declarations are encountered in a .def file the
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] */
"\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;
"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 }
}
static void
-inform VPARAMS ((const char * message, ...))
+inform (const char * message, ...)
{
- VA_OPEN (args, message);
- VA_FIXEDARG (args, const char *, message);
+ va_list args;
+
+ va_start (args, message);
if (!verbose)
return;
report (message, args);
- VA_CLOSE (args);
+ va_end (args);
}
static const char *
void
def_version (int major, int minor)
{
- printf ("VERSION %d.%d\n", major, minor);
+ printf (_("VERSION %d.%d\n"), major, minor);
}
void
char *errmsg_fmt, *errmsg_arg;
char *temp_base = choose_temp_base ();
- inform ("run: %s %s", what, args);
+ inform (_("run: %s %s"), what, args);
/* Count the args */
i = 0;
bfd *arfile = bfd_openr_next_archived_file (f, 0);
while (arfile)
{
+ bfd *next;
if (bfd_check_format (arfile, bfd_object))
scan_open_obj_file (arfile);
+ next = bfd_openr_next_archived_file (f, arfile);
bfd_close (arfile);
- arfile = bfd_openr_next_archived_file (f, arfile);
+ arfile = next;
}
#ifdef DLLTOOL_MCORE_ELF
unsigned char *data;
} sinfo;
+#define INIT_SEC_DATA(id, name, flags, align) \
+ { id, name, flags, align, NULL, NULL, NULL, 0, NULL }
+
#ifndef DLLTOOL_PPC
#define TEXT 0
#define DATA_SEC_FLAGS (SEC_ALLOC | SEC_LOAD | SEC_DATA)
#define BSS_SEC_FLAGS SEC_ALLOC
-#define INIT_SEC_DATA(id, name, flags, align) \
- { id, name, flags, align, NULL, NULL, NULL, 0, NULL }
static sinfo secdata[NSECS] =
{
INIT_SEC_DATA (TEXT, ".text", TEXT_SEC_FLAGS, 2),
static sinfo secdata[NSECS] =
{
- { TEXT, ".text", SEC_CODE | SEC_HAS_CONTENTS, 3},
- { PDATA, ".pdata", SEC_HAS_CONTENTS, 2},
- { RDATA, ".reldata", SEC_HAS_CONTENTS, 2},
- { IDATA5, ".idata$5", SEC_HAS_CONTENTS, 2},
- { IDATA4, ".idata$4", SEC_HAS_CONTENTS, 2},
- { IDATA6, ".idata$6", SEC_HAS_CONTENTS, 1},
- { IDATA7, ".idata$7", SEC_HAS_CONTENTS, 2},
- { DATA, ".data", SEC_DATA, 2},
- { BSS, ".bss", 0, 2}
+ INIT_SEC_DATA (TEXT, ".text", SEC_CODE | SEC_HAS_CONTENTS, 3),
+ INIT_SEC_DATA (PDATA, ".pdata", SEC_HAS_CONTENTS, 2),
+ INIT_SEC_DATA (RDATA, ".reldata", SEC_HAS_CONTENTS, 2),
+ INIT_SEC_DATA (IDATA5, ".idata$5", SEC_HAS_CONTENTS, 2),
+ INIT_SEC_DATA (IDATA4, ".idata$4", SEC_HAS_CONTENTS, 2),
+ INIT_SEC_DATA (IDATA6, ".idata$6", SEC_HAS_CONTENTS, 1),
+ INIT_SEC_DATA (IDATA7, ".idata$7", SEC_HAS_CONTENTS, 2),
+ INIT_SEC_DATA (DATA, ".data", SEC_DATA, 2),
+ INIT_SEC_DATA (BSS, ".bss", 0, 2)
};
#endif
iname_lab = bfd_make_empty_symbol (abfd);
iname_lab->name = head_label;
- iname_lab->section = (asection *) &bfd_und_section;
+ iname_lab->section = bfd_und_section_ptr;
iname_lab->flags = 0;
iname_lab->value = 0;
toc_symbol = bfd_make_empty_symbol (abfd);
toc_symbol->name = make_label (".", "toc");
- toc_symbol->section = (asection *)&bfd_und_section;
+ toc_symbol->section = bfd_und_section_ptr;
toc_symbol->flags = BSF_GLOBAL;
toc_symbol->value = 0;
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;
}
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);
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;
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);
{
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);
}
{
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);
}