#define U(CSTR) \
((is_underscoring () == 0) ? CSTR : "_" CSTR)
-/* Get size of constant string for a possible underscore prefixed
- C visible symbol. */
-#define U_SIZE(CSTR) \
- (sizeof (CSTR) + (is_underscoring () == 0 ? 0 : 1))
-
#define D(field,symbol,def,usc) {&pe.field, sizeof (pe.field), def, symbol, 0, usc}
static definfo init[] =
after_parse_default ();
}
-/* pe-dll.c directly accesses pe_data_import_dll,
- so it must be defined outside of #ifdef DLL_SUPPORT.
- Note - this variable is deliberately not initialised.
- This allows it to be treated as a common varaible, and only
- exist in one incarnation in a multiple target enabled linker. */
-char * pe_data_import_dll;
-
#ifdef DLL_SUPPORT
static struct bfd_link_hash_entry *pe_undef_found_sym;
}
}
-static int
-make_import_fixup (arelent *rel, asection *s, char *name)
+static void
+make_import_fixup (arelent *rel, asection *s, char *name, const char *symname)
{
struct bfd_symbol *sym = *rel->sym_ptr_ptr;
char addend[4];
+ bfd_vma _addend;
if (pe_dll_extra_pe_debug)
printf ("arelent: %s@%#lx: add=%li\n", sym->name,
einfo (_("%P: %C: cannot get section contents - auto-import exception\n"),
s->owner, s, rel->address);
- pe_create_import_fixup (rel, s, bfd_get_32 (s->owner, addend), name);
-
- return 1;
-}
-
-static void
-pe_find_data_imports (void)
-{
- struct bfd_link_hash_entry *undef, *sym;
- size_t namelen;
- char *buf, *name;
-
- if (link_info.pei386_auto_import == 0)
- return;
-
- namelen = 0;
- for (undef = link_info.hash->undefs; undef; undef = undef->u.undef.next)
- {
- if (undef->type == bfd_link_hash_undefined)
- {
- size_t len = strlen (undef->root.string);
- if (namelen < len)
- namelen = len;
- }
- }
- if (namelen == 0)
- return;
-
- /* We are being a bit cunning here. The buffer will have space for
- prefixes at the beginning. The prefix is modified here and in a
- number of functions called from this function. */
-#define PREFIX_LEN 32
- buf = xmalloc (PREFIX_LEN + namelen + 1);
- name = buf + PREFIX_LEN;
-
- for (undef = link_info.hash->undefs; undef; undef = undef->u.undef.next)
- {
- if (undef->type == bfd_link_hash_undefined)
- {
- char *impname;
-
- if (pe_dll_extra_pe_debug)
- printf ("%s:%s\n", __FUNCTION__, undef->root.string);
-
- strcpy (name, undef->root.string);
- impname = name - (sizeof "__imp_" - 1);
- memcpy (impname, "__imp_", sizeof "__imp_" - 1);
-
- sym = bfd_link_hash_lookup (link_info.hash, impname, 0, 0, 1);
-
- if (sym && sym->type == bfd_link_hash_defined)
- {
- bfd *b = sym->u.def.section->owner;
- asymbol **symbols;
- int nsyms, i;
-
- if (link_info.pei386_auto_import == -1)
- {
- static bfd_boolean warned = FALSE;
-
- info_msg (_("Info: resolving %s by linking to %s "
- "(auto-import)\n"), name, impname);
-
- /* PR linker/4844. */
- if (! warned)
- {
- warned = TRUE;
- einfo (_("%P: warning: auto-importing has been activated "
- "without --enable-auto-import specified on the "
- "command line; this should work unless it "
- "involves constant data structures referencing "
- "symbols from auto-imported DLLs\n"));
- }
- }
-
- if (!bfd_generic_link_read_symbols (b))
- {
- einfo (_("%F%P: %pB: could not read symbols: %E\n"), b);
- return;
- }
-
- symbols = bfd_get_outsymbols (b);
- nsyms = bfd_get_symcount (b);
-
- for (i = 0; i < nsyms; i++)
- {
- if (! CONST_STRNEQ (symbols[i]->name, U ("_head_")))
- continue;
-
- if (pe_dll_extra_pe_debug)
- printf ("->%s\n", symbols[i]->name);
-
- pe_data_import_dll = (char *) (symbols[i]->name
- + U_SIZE ("_head_") - 1);
- break;
- }
-
- pe_walk_relocs_of_symbol (&link_info, name, make_import_fixup);
-
- /* Let's differentiate it somehow from defined. */
- undef->type = bfd_link_hash_defweak;
- /* We replace original name with __imp_ prefixed, this
- 1) may trash memory 2) leads to duplicate symbol generation.
- Still, IMHO it's better than having name polluted. */
- undef->root.string = sym->root.string;
- undef->u.def.value = sym->u.def.value;
- undef->u.def.section = sym->u.def.section;
- }
- }
- }
- free (buf);
+ _addend = bfd_get_32 (s->owner, addend);
+ pe_create_import_fixup (rel, s, _addend, name, symname);
}
static bfd_boolean
pe_output_file_set_long_section_names (link_info.output_bfd);
#ifdef DLL_SUPPORT
- if (pe_enable_stdcall_fixup) /* -1=warn or 1=disable */
- pe_fixup_stdcalls ();
-
pe_process_import_defs (link_info.output_bfd, &link_info);
- pe_find_data_imports ();
+ if (link_info.pei386_auto_import) /* -1=warn or 1=enable */
+ pe_find_data_imports (U ("_head_"), make_import_fixup);
- /* As possibly new symbols are added by imports, we rerun
- stdcall/fastcall fixup here. */
- if (pe_enable_stdcall_fixup) /* -1=warn or 1=disable */
+ /* The implementation of the feature is rather dumb and would cause the
+ compilation time to go through the roof if there are many undefined
+ symbols in the link, so it needs to be run after auto-import. */
+ if (pe_enable_stdcall_fixup) /* -1=warn or 1=enable */
pe_fixup_stdcalls ();
#if defined (TARGET_IS_i386pe) \
#define U(CSTR) \
((is_underscoring () == 0) ? CSTR : "_" CSTR)
-/* Get size of constant string for a possible underscore prefixed
- C visible symbol. */
-#define U_SIZE(CSTR) \
- (sizeof (CSTR) + (is_underscoring () == 0 ? 0 : 1))
-
#define D(field,symbol,def,usc) {&pep.field, sizeof (pep.field), def, symbol, 0, usc}
static definfo init[] =
after_parse_default ();
}
-/* pep-dll.c directly accesses pep_data_import_dll,
- so it must be defined outside of #ifdef DLL_SUPPORT.
- Note - this variable is deliberately not initialised.
- This allows it to be treated as a common varaible, and only
- exist in one incarnation in a multiple target enabled linker. */
-char * pep_data_import_dll;
-
#ifdef DLL_SUPPORT
static struct bfd_link_hash_entry *pep_undef_found_sym;
}
}
-static int
-make_import_fixup (arelent *rel, asection *s, char *name)
+static void
+make_import_fixup (arelent *rel, asection *s, char *name, const char *symname)
{
struct bfd_symbol *sym = *rel->sym_ptr_ptr;
char addend[8];
printf (" pcrel");
printf (" %d bit rel.\n", (int) rel->howto->bitsize);
}
- pep_create_import_fixup (rel, s, _addend, name);
- return 1;
-}
-
-static void
-pep_find_data_imports (void)
-{
- struct bfd_link_hash_entry *undef, *sym;
- size_t namelen;
- char *buf, *name;
-
- if (link_info.pei386_auto_import == 0)
- return;
-
- namelen = 0;
- for (undef = link_info.hash->undefs; undef; undef = undef->u.undef.next)
- {
- if (undef->type == bfd_link_hash_undefined)
- {
- size_t len = strlen (undef->root.string);
- if (namelen < len)
- namelen = len;
- }
- }
- if (namelen == 0)
- return;
-
- /* We are being a bit cunning here. The buffer will have space for
- prefixes at the beginning. The prefix is modified here and in a
- number of functions called from this function. */
-#define PREFIX_LEN 32
- buf = xmalloc (PREFIX_LEN + namelen + 1);
- name = buf + PREFIX_LEN;
-
- for (undef = link_info.hash->undefs; undef; undef = undef->u.undef.next)
- {
- if (undef->type == bfd_link_hash_undefined)
- {
- char *impname;
-
- if (pep_dll_extra_pe_debug)
- printf ("%s:%s\n", __FUNCTION__, undef->root.string);
-
- strcpy (name, undef->root.string);
- impname = name - (sizeof "__imp_" - 1);
- memcpy (impname, "__imp_", sizeof "__imp_" - 1);
-
- sym = bfd_link_hash_lookup (link_info.hash, impname, 0, 0, 1);
-
- if (sym && sym->type == bfd_link_hash_defined)
- {
- bfd *b = sym->u.def.section->owner;
- asymbol **symbols;
- int nsyms, i;
-
- if (!bfd_generic_link_read_symbols (b))
- {
- einfo (_("%F%P: %pB: could not read symbols: %E\n"), b);
- return;
- }
-
- symbols = bfd_get_outsymbols (b);
- nsyms = bfd_get_symcount (b);
-
- for (i = 0; i < nsyms; i++)
- {
- if (! CONST_STRNEQ (symbols[i]->name, U ("_head_")))
- continue;
-
- if (pep_dll_extra_pe_debug)
- printf ("->%s\n", symbols[i]->name);
-
- pep_data_import_dll = (char *) (symbols[i]->name
- + U_SIZE ("_head_") - 1);
- break;
- }
-
- pep_walk_relocs_of_symbol (&link_info, name, make_import_fixup);
-
- /* Let's differentiate it somehow from defined. */
- undef->type = bfd_link_hash_defweak;
- /* We replace original name with __imp_ prefixed, this
- 1) may trash memory 2) leads to duplicate symbol generation.
- Still, IMHO it's better than having name polluted. */
- undef->root.string = sym->root.string;
- undef->u.def.value = sym->u.def.value;
- undef->u.def.section = sym->u.def.section;
- }
- }
- }
- free (buf);
+ pep_create_import_fixup (rel, s, _addend, name, symname);
}
static bfd_boolean
pep_output_file_set_long_section_names (link_info.output_bfd);
#ifdef DLL_SUPPORT
- if (pep_enable_stdcall_fixup) /* -1=warn or 1=disable */
- pep_fixup_stdcalls ();
-
pep_process_import_defs (link_info.output_bfd, &link_info);
- pep_find_data_imports ();
+ if (link_info.pei386_auto_import) /* -1=warn or 1=enable */
+ pep_find_data_imports (U ("_head_"), make_import_fixup);
- /* As possibly new symbols are added by imports, we rerun
- stdcall/fastcall fixup here. */
- if (pep_enable_stdcall_fixup) /* -1=warn or 1=disable */
+ /* The implementation of the feature is rather dumb and would cause the
+ compilation time to go through the roof if there are many undefined
+ symbols in the link, so it needs to be run after auto-import. */
+ if (pep_enable_stdcall_fixup) /* -1=warn or 1=enable */
pep_fixup_stdcalls ();
#ifndef TARGET_IS_i386pep
static unsigned char *edata_d, *reloc_d;
static size_t edata_sz, reloc_sz;
static int runtime_pseudo_relocs_created = 0;
-static int runtime_pseudp_reloc_v2_init = 0;
+static bfd_boolean runtime_pseudp_reloc_v2_init = FALSE;
typedef struct
{
static struct bfd_section *current_sec;
-void
-pe_walk_relocs_of_symbol (struct bfd_link_info *info,
- char *name,
- int (*cb) (arelent *, asection *, char *))
+static void
+pe_walk_relocs (struct bfd_link_info *info,
+ char *name,
+ const char *symname,
+ struct bfd_hash_table *import_hash,
+ void (*cb) (arelent *, asection *, char *, const char *))
{
bfd *b;
asection *s;
{
struct bfd_symbol *sym = *relocs[i]->sym_ptr_ptr;
- if (!strcmp (name, sym->name))
- cb (relocs[i], s, name);
+ /* Warning: the callback needs to be passed NAME directly. */
+ if (import_hash)
+ {
+ if (bfd_hash_lookup (import_hash, sym->name, FALSE, FALSE))
+ {
+ strcpy (name, sym->name);
+ cb (relocs[i], s, name, symname);
+ }
+ }
+ else
+ {
+ if (strcmp (name, sym->name) == 0)
+ cb (relocs[i], s, name, symname);
+ }
}
free (relocs);
}
}
+void
+pe_find_data_imports (const char *symhead,
+ void (*cb) (arelent *, asection *, char *, const char *))
+{
+ struct bfd_link_hash_entry *undef;
+ const size_t headlen = strlen (symhead);
+ size_t namelen = 0;
+ char *buf, *name;
+ struct bfd_hash_table *import_hash;
+
+ for (undef = link_info.hash->undefs; undef; undef = undef->u.undef.next)
+ if (undef->type == bfd_link_hash_undefined)
+ {
+ size_t len = strlen (undef->root.string);
+ if (namelen < len)
+ namelen = len;
+ }
+ if (namelen == 0)
+ return;
+
+ /* For the pseudo-relocation support version 2, we can collect the symbols
+ that are subject to auto-import and adjust the relocations en masse. */
+ if (link_info.pei386_runtime_pseudo_reloc == 2)
+ {
+ import_hash
+ = (struct bfd_hash_table *) xmalloc (sizeof (struct bfd_hash_table));
+ if (!bfd_hash_table_init (import_hash,
+ bfd_hash_newfunc,
+ sizeof (struct bfd_hash_entry)))
+ einfo (_("%F%P: bfd_hash_table_init failed: %E\n"));
+ }
+ else
+ import_hash = NULL;
+
+ /* We are being a bit cunning here. The buffer will have space for
+ prefixes at the beginning. The prefix is modified here and in a
+ number of functions called from this function. */
+#define PREFIX_LEN 32
+ buf = xmalloc (PREFIX_LEN + namelen + 1);
+ name = buf + PREFIX_LEN;
+
+ for (undef = link_info.hash->undefs; undef; undef = undef->u.undef.next)
+ if (undef->type == bfd_link_hash_undefined)
+ {
+ struct bfd_link_hash_entry *sym;
+ char *impname;
+
+ if (pe_dll_extra_pe_debug)
+ printf ("%s:%s\n", __FUNCTION__, undef->root.string);
+
+ strcpy (name, undef->root.string);
+ impname = name - (sizeof "__imp_" - 1);
+ memcpy (impname, "__imp_", sizeof "__imp_" - 1);
+
+ sym = bfd_link_hash_lookup (link_info.hash, impname, 0, 0, 1);
+
+ if (sym && sym->type == bfd_link_hash_defined)
+ {
+ if (import_hash)
+ bfd_hash_lookup (import_hash, undef->root.string, TRUE, FALSE);
+ else
+ {
+ bfd *b = sym->u.def.section->owner;
+ const char *symname = NULL;
+ asymbol **symbols;
+ int nsyms, i;
+
+ if (!bfd_generic_link_read_symbols (b))
+ {
+ einfo (_("%F%P: %pB: could not read symbols: %E\n"), b);
+ return;
+ }
+
+ symbols = bfd_get_outsymbols (b);
+ nsyms = bfd_get_symcount (b);
+
+ for (i = 0; i < nsyms; i++)
+ if (strncmp (symbols[i]->name, symhead, headlen) == 0)
+ {
+ if (pe_dll_extra_pe_debug)
+ printf ("->%s\n", symbols[i]->name);
+
+ symname = symbols[i]->name + headlen;
+ break;
+ }
+
+ /* If the symobl isn't part of an import table, there is no
+ point in building a fixup, this would give rise to link
+ errors for mangled symbols instead of the original one. */
+ if (symname)
+ pe_walk_relocs (&link_info, name, symname, NULL, cb);
+ else
+ continue;
+ }
+
+ /* Let's differentiate it somehow from defined. */
+ undef->type = bfd_link_hash_defweak;
+ undef->u.def.value = sym->u.def.value;
+ undef->u.def.section = sym->u.def.section;
+
+ if (link_info.pei386_auto_import == -1)
+ {
+ static bfd_boolean warned = FALSE;
+
+ info_msg (_("Info: resolving %s by linking to %s "
+ "(auto-import)\n"), name, impname);
+
+ /* PR linker/4844. */
+ if (!warned)
+ {
+ einfo (_("%P: warning: auto-importing has been activated "
+ "without --enable-auto-import specified on the "
+ "command line; this should work unless it "
+ "involves constant data structures referencing "
+ "symbols from auto-imported DLLs\n"));
+ warned = TRUE;
+ }
+ }
+ }
+ }
+
+ /* If we have the import hash table, walk the relocations only once. */
+ if (import_hash)
+ {
+ pe_walk_relocs (&link_info, name, NULL, import_hash, cb);
+ bfd_hash_table_free (import_hash);
+ free (import_hash);
+ }
+
+ free (buf);
+}
+
/* Gather all the relocations and build the .reloc section. */
static void
static asymbol **symtab;
static int symptr;
static int tmp_seq;
-static int tmp_seq2;
static const char *dll_filename;
static char *dll_symname;
return abfd;
}
-static bfd *
-make_singleton_name_imp (const char *import, bfd *parent)
-{
- /* Name thunks go to idata$4. */
- asection *id5;
- unsigned char *d5;
- char *oname;
- bfd *abfd;
-
- oname = xmalloc (20);
- sprintf (oname, "nmimp%06d.o", tmp_seq2);
- tmp_seq2++;
-
- abfd = bfd_create (oname, parent);
- bfd_find_target (pe_details->object_target, abfd);
- bfd_make_writable (abfd);
-
- bfd_set_format (abfd, bfd_object);
- bfd_set_arch_mach (abfd, pe_details->bfd_arch, 0);
-
- symptr = 0;
- symtab = xmalloc (3 * sizeof (asymbol *));
- id5 = quick_section (abfd, ".idata$5", SEC_HAS_CONTENTS, 2);
- quick_symbol (abfd, "__imp_", import, "", id5, BSF_GLOBAL, 0);
-
- /* We need space for the real thunk and for the null terminator. */
- bfd_set_section_size (abfd, id5, PE_IDATA5_SIZE * 2);
- d5 = xmalloc (PE_IDATA5_SIZE * 2);
- id5->contents = d5;
- memset (d5, 0, PE_IDATA5_SIZE * 2);
- quick_reloc (abfd, 0, BFD_RELOC_RVA, 2);
- save_relocs (id5);
-
- bfd_set_symtab (abfd, symtab, symptr);
-
- bfd_set_section_contents (abfd, id5, d5, 0, PE_IDATA4_SIZE * 2);
-
- bfd_make_readable (abfd);
- return abfd;
-}
-
static bfd *
make_singleton_name_thunk (const char *import, bfd *parent)
{
return abfd;
}
-static char *
+static const char *
make_import_fixup_mark (arelent *rel, char *name)
{
/* We convert reloc to symbol, for later reference. */
current_sec, /* sym->section, */
rel->address, NULL, TRUE, FALSE, &bh);
- return fixup_name;
+ return bh->root.string;
}
/* .section .idata$2
quick_symbol (abfd, "__nm_thnk_", name, "", UNDSEC, BSF_GLOBAL, 0);
quick_symbol (abfd, U (""), symname, "_iname", UNDSEC, BSF_GLOBAL, 0);
- /* For relocator v2 we have to use the .idata$5 element and not
- fixup_name. */
- if (link_info.pei386_runtime_pseudo_reloc == 2)
- quick_symbol (abfd, "__imp_", name, "", UNDSEC, BSF_GLOBAL, 0);
- else
- quick_symbol (abfd, "", fixup_name, "", UNDSEC, BSF_GLOBAL, 0);
+ quick_symbol (abfd, "", fixup_name, "", UNDSEC, BSF_GLOBAL, 0);
bfd_set_section_size (abfd, id2, 20);
d2 = xmalloc (20);
unsigned char *rt_rel_d;
char *oname;
bfd *abfd;
+ bfd_size_type size;
+
oname = xmalloc (20);
sprintf (oname, "rtr%06d.o", tmp_seq);
tmp_seq++;
bfd_set_format (abfd, bfd_object);
bfd_set_arch_mach (abfd, pe_details->bfd_arch, 0);
- symptr = 0;
if (link_info.pei386_runtime_pseudo_reloc == 2)
{
- symtab = xmalloc ((runtime_pseudp_reloc_v2_init ? 3 : 6) * sizeof (asymbol *));
+ if (runtime_pseudp_reloc_v2_init)
+ size = 3 * sizeof (asymbol *);
+ else
+ size = 6 * sizeof (asymbol *);
}
else
- {
- symtab = xmalloc (2 * sizeof (asymbol *));
- }
- rt_rel = quick_section (abfd, ".rdata_runtime_pseudo_reloc",
- SEC_HAS_CONTENTS, 2);
+ size = 2 * sizeof (asymbol *);
+
+ symptr = 0;
+ symtab = xmalloc (size);
+
+ rt_rel
+ = quick_section (abfd, ".rdata_runtime_pseudo_reloc", SEC_HAS_CONTENTS, 2);
quick_symbol (abfd, "", fixup_name, "", UNDSEC, BSF_GLOBAL, 0);
if (link_info.pei386_runtime_pseudo_reloc == 2)
{
- size_t size = 12;
- if (! runtime_pseudp_reloc_v2_init)
- {
- size += 12;
- runtime_pseudp_reloc_v2_init = 1;
- }
+ size = 12;
+ if (!runtime_pseudp_reloc_v2_init)
+ {
+ size += 12;
+ runtime_pseudp_reloc_v2_init = TRUE;
+ }
+
quick_symbol (abfd, "__imp_", name, "", UNDSEC, BSF_GLOBAL, 0);
bfd_set_section_size (abfd, rt_rel, size);
rt_rel_d = xmalloc (size);
rt_rel->contents = rt_rel_d;
memset (rt_rel_d, 0, size);
- quick_reloc (abfd, size - 8, BFD_RELOC_RVA, 1);
- quick_reloc (abfd, size - 12, BFD_RELOC_RVA, 2);
- bfd_put_32 (abfd, bitsize, rt_rel_d + (size - 4));
- if (size != 12)
- bfd_put_32 (abfd, 1, rt_rel_d + 8);
+ quick_reloc (abfd, size - 8, BFD_RELOC_RVA, 1);
+ quick_reloc (abfd, size - 12, BFD_RELOC_RVA, 2);
+ bfd_put_32 (abfd, bitsize, rt_rel_d + (size - 4));
+ if (size != 12)
+ bfd_put_32 (abfd, 1, rt_rel_d + 8);
save_relocs (rt_rel);
bfd_set_symtab (abfd, symtab, symptr);
bfd_set_section_contents (abfd, rt_rel, rt_rel_d, 0, size);
- }
+ }
else
- {
+ {
bfd_set_section_size (abfd, rt_rel, 8);
rt_rel_d = xmalloc (8);
rt_rel->contents = rt_rel_d;
bfd_set_section_contents (abfd, rt_rel, rt_rel_d, 0, 8);
}
+
bfd_make_readable (abfd);
return abfd;
}
}
void
-pe_create_import_fixup (arelent *rel, asection *s, bfd_vma addend, char *name)
+pe_create_import_fixup (arelent *rel, asection *s, bfd_vma addend, char *name,
+ const char *symname)
{
- struct bfd_symbol *sym = *rel->sym_ptr_ptr;
- struct bfd_link_hash_entry *name_thunk_sym;
- struct bfd_link_hash_entry *name_imp_sym;
- char *fixup_name, *impname;
+ const char *fixup_name = make_import_fixup_mark (rel, name);
bfd *b;
- int need_import_table = 1;
-
- /* name buffer is allocated with space at beginning for prefixes. */
- impname = name - (sizeof "__imp_" - 1);
- memcpy (impname, "__imp_", sizeof "__imp_" - 1);
- name_imp_sym = bfd_link_hash_lookup (link_info.hash, impname, 0, 0, 1);
- impname = name - (sizeof "__nm_thnk_" - 1);
- memcpy (impname, "__nm_thnk_", sizeof "__nm_thnk_" - 1);
- name_thunk_sym = bfd_link_hash_lookup (link_info.hash, impname, 0, 0, 1);
-
- fixup_name = make_import_fixup_mark (rel, name);
-
- /* For version 2 pseudo relocation we don't need to add an import
- if the import symbol is already present. */
- if (link_info.pei386_runtime_pseudo_reloc == 2
- && name_imp_sym
- && name_imp_sym->type == bfd_link_hash_defined)
- need_import_table = 0;
-
- if (need_import_table == 1
- && (!name_thunk_sym || name_thunk_sym->type != bfd_link_hash_defined))
+ /* This is the original implementation of the auto-import feature, which
+ primarily relied on the OS loader to patch things up with some help
+ from the pseudo-relocator to overcome the main limitation. See the
+ comment at the beginning of the file for an overview of the feature. */
+ if (link_info.pei386_runtime_pseudo_reloc != 2)
{
- b = make_singleton_name_thunk (name, link_info.output_bfd);
- add_bfd_to_link (b, b->filename, &link_info);
+ struct bfd_link_hash_entry *name_thunk_sym;
+ /* name buffer is allocated with space at beginning for prefixes. */
+ char *thname = name - (sizeof "__nm_thnk_" - 1);
+ memcpy (thname, "__nm_thnk_", sizeof "__nm_thnk_" - 1);
+ name_thunk_sym = bfd_link_hash_lookup (link_info.hash, thname, 0, 0, 1);
- /* If we ever use autoimport, we have to cast text section writable.
- But not for version 2. */
- if (link_info.pei386_runtime_pseudo_reloc != 2)
+ if (!(name_thunk_sym && name_thunk_sym->type == bfd_link_hash_defined))
{
+ b = make_singleton_name_thunk (name, link_info.output_bfd);
+ add_bfd_to_link (b, b->filename, &link_info);
+
+ /* If we ever use autoimport, we have to cast text section writable. */
config.text_read_only = FALSE;
link_info.output_bfd->flags &= ~WP_TEXT;
}
- if (link_info.pei386_runtime_pseudo_reloc == 2)
+
+ if (addend == 0 || link_info.pei386_runtime_pseudo_reloc == 1)
{
- b = make_singleton_name_imp (name, link_info.output_bfd);
+ b = make_import_fixup_entry (name, fixup_name, symname,
+ link_info.output_bfd);
add_bfd_to_link (b, b->filename, &link_info);
}
}
- if ((addend == 0 || link_info.pei386_runtime_pseudo_reloc)
- && need_import_table == 1)
- {
- extern char * pe_data_import_dll;
- char * symname = pe_data_import_dll ? pe_data_import_dll : "unknown";
-
- b = make_import_fixup_entry (name, fixup_name, symname,
- link_info.output_bfd);
- add_bfd_to_link (b, b->filename, &link_info);
- }
-
- if ((link_info.pei386_runtime_pseudo_reloc != 0 && addend != 0)
+ /* In the original implementation, the pseudo-relocator was only used when
+ the addend was not null. In the new implementation, the OS loader is
+ completely bypassed and the pseudo-relocator does the entire work. */
+ if ((addend != 0 && link_info.pei386_runtime_pseudo_reloc == 1)
|| link_info.pei386_runtime_pseudo_reloc == 2)
{
if (pe_dll_extra_pe_debug)
link_info.output_bfd);
add_bfd_to_link (b, b->filename, &link_info);
- if (runtime_pseudo_relocs_created == 0)
+ if (runtime_pseudo_relocs_created++ == 0)
{
b = pe_create_runtime_relocator_reference (link_info.output_bfd);
add_bfd_to_link (b, b->filename, &link_info);
}
- runtime_pseudo_relocs_created++;
}
+
else if (addend != 0)
einfo (_("%X%P: %C: variable '%pT' can't be auto-imported; please read the documentation for ld's --enable-auto-import for details\n"),
- s->owner, s, rel->address, sym->name);
+ s->owner, s, rel->address, (*rel->sym_ptr_ptr)->name);
}
-
void
pe_dll_generate_implib (def_file *def, const char *impfilename, struct bfd_link_info *info)
{