Don't search for data import when auto-import is disabled.

This commit is contained in:
Nick Clifton 2002-12-17 12:16:38 +00:00
parent 9c3b31c636
commit 4cd898632a
2 changed files with 68 additions and 56 deletions

View File

@ -1,3 +1,8 @@
2002-12-17 Ralf Habacker <ralf.habacker@freenet.de>
* ld/emultempl/pe.em (pe_find_data_imports): Don't search for data
import when auto-import is disabled.
2002-12-17 Danny Smith <dannysmith@users.sourceforge.net> 2002-12-17 Danny Smith <dannysmith@users.sourceforge.net>
* emultempl/pe.em (..._recognized_file): Use LD_PATHMAX+1 to * emultempl/pe.em (..._recognized_file): Use LD_PATHMAX+1 to

View File

@ -132,7 +132,7 @@ static int make_import_fixup PARAMS ((arelent *, asection *));
static void pe_find_data_imports PARAMS ((void)); static void pe_find_data_imports PARAMS ((void));
#endif #endif
static bfd_boolean pr_sym PARAMS ((struct bfd_hash_entry *, PTR string)); static bfd_boolean pr_sym PARAMS ((struct bfd_hash_entry *, PTR));
static bfd_boolean gld_${EMULATION_NAME}_unrecognized_file static bfd_boolean gld_${EMULATION_NAME}_unrecognized_file
PARAMS ((lang_input_statement_type *)); PARAMS ((lang_input_statement_type *));
static bfd_boolean gld_${EMULATION_NAME}_recognized_file static bfd_boolean gld_${EMULATION_NAME}_recognized_file
@ -148,7 +148,7 @@ static char * thumb_entry_symbol = NULL;
static lang_assignment_statement_type *image_base_statement = 0; static lang_assignment_statement_type *image_base_statement = 0;
#ifdef DLL_SUPPORT #ifdef DLL_SUPPORT
static int pe_enable_stdcall_fixup = -1; /* 0=disable 1=enable */ static int pe_enable_stdcall_fixup = -1; /* 0=disable 1=enable. */
static char *pe_out_def_filename = NULL; static char *pe_out_def_filename = NULL;
static char *pe_implib_filename = NULL; static char *pe_implib_filename = NULL;
static int pe_enable_auto_image_base = 0; static int pe_enable_auto_image_base = 0;
@ -188,7 +188,7 @@ gld_${EMULATION_NAME}_before_parse()
/* PE format extra command line options. */ /* PE format extra command line options. */
/* Used for setting flags in the PE header. */ /* Used for setting flags in the PE header. */
#define OPTION_BASE_FILE (300 + 1) #define OPTION_BASE_FILE (300 + 1)
#define OPTION_DLL (OPTION_BASE_FILE + 1) #define OPTION_DLL (OPTION_BASE_FILE + 1)
#define OPTION_FILE_ALIGNMENT (OPTION_DLL + 1) #define OPTION_FILE_ALIGNMENT (OPTION_DLL + 1)
@ -279,7 +279,7 @@ static struct option longopts[] = {
/* PE/WIN32; added routines to get the subsystem type, heap and/or stack /* PE/WIN32; added routines to get the subsystem type, heap and/or stack
parameters which may be input from the command line */ parameters which may be input from the command line. */
typedef struct typedef struct
{ {
@ -320,6 +320,7 @@ static definfo init[] =
{ NULL, 0, 0, NULL, 0 } { NULL, 0, 0, NULL, 0 }
}; };
static void static void
gld_${EMULATION_NAME}_list_options (file) gld_${EMULATION_NAME}_list_options (file)
FILE * file; FILE * file;
@ -371,13 +372,15 @@ gld_${EMULATION_NAME}_list_options (file)
#endif #endif
} }
static void static void
set_pe_name (name, val) set_pe_name (name, val)
char *name; char *name;
long val; long val;
{ {
int i; int i;
/* Find the name and set it. */
/* Find the name and set it. */
for (i = 0; init[i].ptr; i++) for (i = 0; init[i].ptr; i++)
{ {
if (strcmp (name, init[i].symbol) == 0) if (strcmp (name, init[i].symbol) == 0)
@ -475,7 +478,6 @@ set_pe_subsystem ()
} }
static void static void
set_pe_value (name) set_pe_value (name)
char *name; char *name;
@ -491,6 +493,7 @@ set_pe_value (name)
optarg = end; optarg = end;
} }
static void static void
set_pe_stack_heap (resname, comname) set_pe_stack_heap (resname, comname)
char *resname; char *resname;
@ -508,7 +511,6 @@ set_pe_stack_heap (resname, comname)
} }
static int static int
gld_${EMULATION_NAME}_parse_args (argc, argv) gld_${EMULATION_NAME}_parse_args (argc, argv)
int argc; int argc;
@ -549,7 +551,7 @@ gld_${EMULATION_NAME}_parse_args (argc, argv)
} }
break; break;
/* PE options */ /* PE options. */
case OPTION_HEAP: case OPTION_HEAP:
set_pe_stack_heap ("__size_of_heap_reserve__", "__size_of_heap_commit__"); set_pe_stack_heap ("__size_of_heap_reserve__", "__size_of_heap_commit__");
break; break;
@ -686,7 +688,8 @@ strhash (const char *str)
return hash; return hash;
} }
/* Use the output file to create a image base for relocatable DLLs. */ /* Use the output file to create a image base for relocatable DLLs. */
static unsigned long static unsigned long
compute_dll_image_base (const char *ofile) compute_dll_image_base (const char *ofile)
{ {
@ -702,7 +705,7 @@ static void
gld_${EMULATION_NAME}_set_symbols () gld_${EMULATION_NAME}_set_symbols ()
{ {
/* Run through and invent symbols for all the /* Run through and invent symbols for all the
names and insert the defaults. */ names and insert the defaults. */
int j; int j;
lang_statement_list_type *save; lang_statement_list_type *save;
@ -725,7 +728,7 @@ gld_${EMULATION_NAME}_set_symbols ()
if (link_info.relocateable) if (link_info.relocateable)
return; return;
/* Glue the assignments into the abs section */ /* Glue the assignments into the abs section. */
save = stat_ptr; save = stat_ptr;
stat_ptr = &(abs_output_section->children); stat_ptr = &(abs_output_section->children);
@ -749,7 +752,7 @@ gld_${EMULATION_NAME}_set_symbols ()
if (j == IMAGEBASEOFF) if (j == IMAGEBASEOFF)
image_base_statement = rv; image_base_statement = rv;
} }
/* Restore the pointer. */ /* Restore the pointer. */
stat_ptr = save; stat_ptr = save;
if (pe.FileAlignment > if (pe.FileAlignment >
@ -798,7 +801,8 @@ pe_undef_cdecl_match (h, string)
PTR string; PTR string;
{ {
int sl; int sl;
sl = strlen (string); /* silence compiler warning */
sl = strlen (string); /* Silence compiler warning. */
if (h->type == bfd_link_hash_defined if (h->type == bfd_link_hash_defined
&& strncmp (h->root.string, string, sl) == 0 && strncmp (h->root.string, string, sl) == 0
&& h->root.string[sl] == '@') && h->root.string[sl] == '@')
@ -839,6 +843,7 @@ pe_fixup_stdcalls ()
undef->type = bfd_link_hash_defined; undef->type = bfd_link_hash_defined;
undef->u.def.value = sym->u.def.value; undef->u.def.value = sym->u.def.value;
undef->u.def.section = sym->u.def.section; undef->u.def.section = sym->u.def.section;
if (pe_enable_stdcall_fixup == -1) if (pe_enable_stdcall_fixup == -1)
{ {
einfo (_("Warning: resolving %s by linking to %s\n"), einfo (_("Warning: resolving %s by linking to %s\n"),
@ -855,7 +860,7 @@ pe_fixup_stdcalls ()
else else
{ {
/* The symbol is a cdecl symbol, so we look for stdcall /* The symbol is a cdecl symbol, so we look for stdcall
symbols - which means scanning the whole symbol table */ symbols - which means scanning the whole symbol table. */
pe_undef_found_sym = 0; pe_undef_found_sym = 0;
bfd_link_hash_traverse (link_info.hash, pe_undef_cdecl_match, bfd_link_hash_traverse (link_info.hash, pe_undef_cdecl_match,
(PTR) undef->root.string); (PTR) undef->root.string);
@ -865,6 +870,7 @@ pe_fixup_stdcalls ()
undef->type = bfd_link_hash_defined; undef->type = bfd_link_hash_defined;
undef->u.def.value = sym->u.def.value; undef->u.def.value = sym->u.def.value;
undef->u.def.section = sym->u.def.section; undef->u.def.section = sym->u.def.section;
if (pe_enable_stdcall_fixup == -1) if (pe_enable_stdcall_fixup == -1)
{ {
einfo (_("Warning: resolving %s by linking to %s\n"), einfo (_("Warning: resolving %s by linking to %s\n"),
@ -907,11 +913,14 @@ pe_find_data_imports ()
{ {
struct bfd_link_hash_entry *undef, *sym; struct bfd_link_hash_entry *undef, *sym;
if (link_info.pei386_auto_import == 0)
return;
for (undef = link_info.hash->undefs; undef; undef=undef->next) for (undef = link_info.hash->undefs; undef; undef=undef->next)
{ {
if (undef->type == bfd_link_hash_undefined) if (undef->type == bfd_link_hash_undefined)
{ {
/* C++ symbols are *long* */ /* C++ symbols are *long*. */
char buf[4096]; char buf[4096];
if (pe_dll_extra_pe_debug) if (pe_dll_extra_pe_debug)
@ -923,45 +932,43 @@ pe_find_data_imports ()
if (sym && sym->type == bfd_link_hash_defined) if (sym && sym->type == bfd_link_hash_defined)
{ {
if (link_info.pei386_auto_import == -1) bfd *b = sym->u.def.section->owner;
info_msg (_("Info: resolving %s by linking to %s (auto-import)\n"), asymbol **symbols;
undef->root.string, buf); int nsyms, symsize, i;
{ if (link_info.pei386_auto_import == -1)
bfd *b = sym->u.def.section->owner; info_msg (_("Info: resolving %s by linking to %s (auto-import)\n"),
asymbol **symbols; undef->root.string, buf);
int nsyms, symsize, i;
symsize = bfd_get_symtab_upper_bound (b); symsize = bfd_get_symtab_upper_bound (b);
symbols = (asymbol **) xmalloc (symsize); symbols = (asymbol **) xmalloc (symsize);
nsyms = bfd_canonicalize_symtab (b, symbols); nsyms = bfd_canonicalize_symtab (b, symbols);
for (i = 0; i < nsyms; i++) for (i = 0; i < nsyms; i++)
{ {
if (memcmp (symbols[i]->name, "__head_", if (memcmp (symbols[i]->name, "__head_",
sizeof ("__head_") - 1)) sizeof ("__head_") - 1))
continue; continue;
if (pe_dll_extra_pe_debug) if (pe_dll_extra_pe_debug)
printf ("->%s\n", symbols[i]->name); printf ("->%s\n", symbols[i]->name);
pe_data_import_dll = (char*) (symbols[i]->name + pe_data_import_dll = (char*) (symbols[i]->name +
sizeof ("__head_") - 1); sizeof ("__head_") - 1);
break; break;
} }
}
pe_walk_relocs_of_symbol (&link_info, undef->root.string, pe_walk_relocs_of_symbol (&link_info, undef->root.string,
make_import_fixup); make_import_fixup);
/* Let's differentiate it somehow from defined. */ /* Let's differentiate it somehow from defined. */
undef->type = bfd_link_hash_defweak; undef->type = bfd_link_hash_defweak;
/* We replace original name with __imp_ prefixed, this /* We replace original name with __imp_ prefixed, this
1) may trash memory 2) leads to duplicate symbol generation. 1) may trash memory 2) leads to duplicate symbol generation.
Still, IMHO it's better than having name poluted. */ Still, IMHO it's better than having name poluted. */
undef->root.string = sym->root.string; undef->root.string = sym->root.string;
undef->u.def.value = sym->u.def.value; undef->u.def.value = sym->u.def.value;
undef->u.def.section = sym->u.def.section; undef->u.def.section = sym->u.def.section;
} }
} }
} }
@ -1056,7 +1063,7 @@ gld_${EMULATION_NAME}_after_open ()
head/tail objects, causing an improper import table. We detect head/tail objects, causing an improper import table. We detect
those cases and rename the "other" import libraries to match those cases and rename the "other" import libraries to match
the one the head/tail come from, so that the linker will sort the one the head/tail come from, so that the linker will sort
things nicely and produce a valid import table. */ things nicely and produce a valid import table. */
LANG_FOR_EACH_INPUT_STATEMENT (is) LANG_FOR_EACH_INPUT_STATEMENT (is)
{ {
@ -1345,7 +1352,7 @@ gld_${EMULATION_NAME}_unrecognized_file (entry)
} }
#if 0 #if 0
/* Not sure if these *should* be set */ /* Not sure if these *should* be set. */
if (pe_def_file->version_major != -1) if (pe_def_file->version_major != -1)
{ {
pe.MajorImageVersion = pe_def_file->version_major; pe.MajorImageVersion = pe_def_file->version_major;
@ -1854,22 +1861,22 @@ gld_${EMULATION_NAME}_open_dynamic_archive (arch, search, entry)
giving up -- once here, and once when searching for a "static" lib. giving up -- once here, and once when searching for a "static" lib.
for a "static" lib. */ for a "static" lib. */
/* Try "libfoo.a" (import lib, or static lib, but must /* Try "libfoo.a" (import lib, or static lib, but must
take precedence over dll's) */ take precedence over dll's). */
sprintf (string, "%s/lib%s.a", search->name, filename); sprintf (string, "%s/lib%s.a", search->name, filename);
if (! ldfile_try_open_bfd (string, entry)) if (! ldfile_try_open_bfd (string, entry))
{ {
#ifdef DLL_SUPPORT #ifdef DLL_SUPPORT
if (pe_dll_search_prefix) if (pe_dll_search_prefix)
{ {
/* Try "<prefix>foo.dll" (preferred dll name, if specified) */ /* Try "<prefix>foo.dll" (preferred dll name, if specified). */
sprintf (string, "%s/%s%s.dll", search->name, pe_dll_search_prefix, filename); sprintf (string, "%s/%s%s.dll", search->name, pe_dll_search_prefix, filename);
if (! ldfile_try_open_bfd (string, entry)) if (! ldfile_try_open_bfd (string, entry))
{ {
/* Try "libfoo.dll" (default preferred dll name) */ /* Try "libfoo.dll" (default preferred dll name). */
sprintf (string, "%s/lib%s.dll", search->name, filename); sprintf (string, "%s/lib%s.dll", search->name, filename);
if (! ldfile_try_open_bfd (string, entry)) if (! ldfile_try_open_bfd (string, entry))
{ {
/* Finally, try "foo.dll" (alternate dll name) */ /* Finally, try "foo.dll" (alternate dll name). */
sprintf (string, "%s/%s.dll", search->name, filename); sprintf (string, "%s/%s.dll", search->name, filename);
if (! ldfile_try_open_bfd (string, entry)) if (! ldfile_try_open_bfd (string, entry))
{ {
@ -1955,8 +1962,8 @@ struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation =
gld_${EMULATION_NAME}_get_script, gld_${EMULATION_NAME}_get_script,
"${EMULATION_NAME}", "${EMULATION_NAME}",
"${OUTPUT_FORMAT}", "${OUTPUT_FORMAT}",
gld_${EMULATION_NAME}_finish, /* finish */ gld_${EMULATION_NAME}_finish,
NULL, /* create output section statements */ NULL, /* Create output section statements. */
gld_${EMULATION_NAME}_open_dynamic_archive, gld_${EMULATION_NAME}_open_dynamic_archive,
gld_${EMULATION_NAME}_place_orphan, gld_${EMULATION_NAME}_place_orphan,
gld_${EMULATION_NAME}_set_symbols, gld_${EMULATION_NAME}_set_symbols,
@ -1965,6 +1972,6 @@ struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation =
gld_${EMULATION_NAME}_list_options, gld_${EMULATION_NAME}_list_options,
gld_${EMULATION_NAME}_recognized_file, gld_${EMULATION_NAME}_recognized_file,
gld_${EMULATION_NAME}_find_potential_libraries, gld_${EMULATION_NAME}_find_potential_libraries,
NULL /* new_vers_pattern */ NULL /* new_vers_pattern. */
}; };
EOF EOF