# This shell script emits a C file. -*- C -*-
# It does some substitutions.
-if [ -z "$MACHINE" ]; then
+if [ -z "$MACHINE" ]; then
OUTPUT_ARCH=${ARCH}
else
OUTPUT_ARCH=${ARCH}:${MACHINE}
(echo;echo;echo;echo;echo)>e${EMULATION_NAME}.c # there, now line numbers match ;-)
cat >>e${EMULATION_NAME}.c <<EOF
/* This file is part of GLD, the Gnu Linker.
- Copyright 1995, 1996, 1997, 1998, 1999, 2000, 2001
+ Copyright 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002
Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
on whether certain switches were set, but these switches pertain to the
Linux system and that particular version of coff. In the NT case, we
only determine if the subsystem is console or windows in order to select
- the correct entry point by default. */
-
+ the correct entry point by default. */
+
+#define TARGET_IS_${EMULATION_NAME}
+
+/* Do this before including bfd.h, so we prototype the right functions. */
+#ifdef TARGET_IS_arm_epoc_pe
+#define bfd_arm_pe_allocate_interworking_sections \
+ bfd_arm_epoc_pe_allocate_interworking_sections
+#define bfd_arm_pe_get_bfd_for_interworking \
+ bfd_arm_epoc_pe_get_bfd_for_interworking
+#define bfd_arm_pe_process_before_allocation \
+ bfd_arm_epoc_pe_process_before_allocation
+#endif
+
#include "bfd.h"
#include "sysdep.h"
#include "bfdlink.h"
#include "libiberty.h"
#include "ld.h"
#include "ldmain.h"
-#include "ldgram.h"
#include "ldexp.h"
#include "ldlang.h"
#include "ldfile.h"
#include "ldemul.h"
+#include "ldgram.h"
#include "ldlex.h"
#include "ldmisc.h"
#include "ldctor.h"
#include <ctype.h>
-#define TARGET_IS_${EMULATION_NAME}
-
/* Permit the emulation parameters to override the default section
alignment by setting OVERRIDE_SECTION_ALIGNMENT. FIXME: This makes
it seem that include/coff/internal.h should not define
#define PE_DEF_FILE_ALIGNMENT 0x00000200
#endif
-#ifdef TARGET_IS_arm_epoc_pe
-#define bfd_arm_pe_allocate_interworking_sections \
- bfd_arm_epoc_pe_allocate_interworking_sections
-#define bfd_arm_pe_get_bfd_for_interworking \
- bfd_arm_epoc_pe_get_bfd_for_interworking
-#define bfd_arm_pe_process_before_allocation \
- bfd_arm_epoc_pe_process_before_allocation
-#endif
-
static void gld_${EMULATION_NAME}_set_symbols PARAMS ((void));
static void gld_${EMULATION_NAME}_after_open PARAMS ((void));
static void gld_${EMULATION_NAME}_before_parse PARAMS ((void));
static char *gld_${EMULATION_NAME}_get_script PARAMS ((int *));
static int gld_${EMULATION_NAME}_parse_args PARAMS ((int, char **));
static void gld_${EMULATION_NAME}_finish PARAMS ((void));
-static boolean gld_${EMULATION_NAME}_open_dynamic_archive
+static boolean gld_${EMULATION_NAME}_open_dynamic_archive
PARAMS ((const char *, search_dirs_type *, lang_input_statement_type *));
+static void gld_${EMULATION_NAME}_list_options PARAMS ((FILE *));
+static void set_pe_name PARAMS ((char *, long));
+static void set_pe_subsystem PARAMS ((void));
+static void set_pe_value PARAMS ((char *));
+static void set_pe_stack_heap PARAMS ((char *, char *));
+
+#ifdef DLL_SUPPORT
+static boolean pe_undef_cdecl_match
+ PARAMS ((struct bfd_link_hash_entry *, PTR));
+static void pe_fixup_stdcalls PARAMS ((void));
+static int make_import_fixup PARAMS ((arelent *, asection *));
+static void pe_find_data_imports PARAMS ((void));
+#endif
+
+static boolean pr_sym PARAMS ((struct bfd_hash_entry *, PTR string));
+static boolean gld_${EMULATION_NAME}_unrecognized_file
+ PARAMS ((lang_input_statement_type *));
+static boolean gld_${EMULATION_NAME}_recognized_file
+ PARAMS ((lang_input_statement_type *));
+static int gld_${EMULATION_NAME}_find_potential_libraries
+ PARAMS ((char *, lang_input_statement_type *));
+
static struct internal_extra_pe_aouthdr pe;
static int dll;
#ifdef DLL_SUPPORT
config.dynamic_link = true;
config.has_shared = 1;
-/* link_info.pei386_auto_import = true; */
+ link_info.pei386_auto_import = -1;
#if (PE_DEF_SUBSYSTEM == 9) || (PE_DEF_SUBSYSTEM == 2)
#if defined TARGET_IS_mipspe || defined TARGET_IS_armpe
#define OPTION_DLL_ENABLE_AUTO_IMPORT (OPTION_NO_DEFAULT_EXCLUDES + 1)
#define OPTION_DLL_DISABLE_AUTO_IMPORT (OPTION_DLL_ENABLE_AUTO_IMPORT + 1)
#define OPTION_ENABLE_EXTRA_PE_DEBUG (OPTION_DLL_DISABLE_AUTO_IMPORT + 1)
+#define OPTION_EXCLUDE_LIBS (OPTION_ENABLE_EXTRA_PE_DEBUG + 1)
static struct option longopts[] = {
/* PE options */
{"base-file", required_argument, NULL, OPTION_BASE_FILE},
{"dll", no_argument, NULL, OPTION_DLL},
{"file-alignment", required_argument, NULL, OPTION_FILE_ALIGNMENT},
- {"heap", required_argument, NULL, OPTION_HEAP},
+ {"heap", required_argument, NULL, OPTION_HEAP},
{"image-base", required_argument, NULL, OPTION_IMAGE_BASE},
{"major-image-version", required_argument, NULL, OPTION_MAJOR_IMAGE_VERSION},
{"major-os-version", required_argument, NULL, OPTION_MAJOR_OS_VERSION},
{"output-def", required_argument, NULL, OPTION_OUT_DEF},
{"export-all-symbols", no_argument, NULL, OPTION_EXPORT_ALL},
{"exclude-symbols", required_argument, NULL, OPTION_EXCLUDE_SYMBOLS},
+ {"exclude-libs", required_argument, NULL, OPTION_EXCLUDE_LIBS},
{"kill-at", no_argument, NULL, OPTION_KILL_ATS},
{"add-stdcall-alias", no_argument, NULL, OPTION_STDCALL_ALIASES},
{"enable-stdcall-fixup", no_argument, NULL, OPTION_ENABLE_STDCALL_FIXUP},
fprintf (file, _(" --disable-stdcall-fixup Don't link _sym to _sym@nn\n"));
fprintf (file, _(" --enable-stdcall-fixup Link _sym to _sym@nn without warnings\n"));
fprintf (file, _(" --exclude-symbols sym,sym,... Exclude symbols from automatic export\n"));
+ fprintf (file, _(" --exclude-libs lib,lib,... Exclude libraries from automatic export\n"));
fprintf (file, _(" --export-all-symbols Automatically export all globals to DLL\n"));
fprintf (file, _(" --kill-at Remove @nn from exported symbols\n"));
fprintf (file, _(" --out-implib <file> Generate import library\n"));
fprintf (file, _(" --output-def <file> Generate a .DEF file for the built DLL\n"));
fprintf (file, _(" --warn-duplicate-exports Warn about duplicate exports.\n"));
- fprintf (file, _(" --compat-implib Create backward compatible import libs;\n"));
- fprintf (file, _(" create __imp_<SYMBOL> as well.\n"));
- fprintf (file, _(" --enable-auto-image-base Automatically choose image base for DLLs\n"));
- fprintf (file, _(" unless user specifies one\n"));
+ fprintf (file, _(" --compat-implib Create backward compatible import libs;\n\
+ create __imp_<SYMBOL> as well.\n"));
+ fprintf (file, _(" --enable-auto-image-base Automatically choose image base for DLLs\n\
+ unless user specifies one\n"));
fprintf (file, _(" --disable-auto-image-base Do not auto-choose image base. (default)\n"));
- fprintf (file, _(" --dll-search-prefix=<string> When linking dynamically to a dll witout an\n"));
- fprintf (file, _(" importlib, use <string><basename>.dll \n"));
- fprintf (file, _(" in preference to lib<basename>.dll \n"));
- fprintf (file, _(" --enable-auto-import Do sophistcated linking of _sym to \n"));
- fprintf (file, _(" __imp_sym for DATA references\n"));
+ fprintf (file, _(" --dll-search-prefix=<string> When linking dynamically to a dll without an\n\
+ importlib, use <string><basename>.dll \n\
+ in preference to lib<basename>.dll \n"));
+ fprintf (file, _(" --enable-auto-import Do sophistcated linking of _sym to \n\
+ __imp_sym for DATA references\n"));
fprintf (file, _(" --disable-auto-import Do not auto-import DATA items from DLLs\n"));
- fprintf (file, _(" --enable-extra-pe-debug Enable verbose debug output when building\n"));
- fprintf (file, _(" or linking to DLLs (esp. auto-import)\n"));
+ fprintf (file, _(" --enable-extra-pe-debug Enable verbose debug output when building\n\
+ or linking to DLLs (esp. auto-import)\n"));
#endif
}
const char *sver;
int len;
int i;
- static const struct
+ static const struct
{
const char *name;
const int value;
entry = alc_entry;
}
- lang_add_entry (entry, 1);
+ lang_add_entry (entry, 0);
return;
}
}
-
+
einfo (_("%P%F: invalid subsystem type %s\n"), optarg);
}
static void
set_pe_value (name)
char *name;
-
+
{
char *end;
-
+
set_pe_name (name, strtoul (optarg, &end, 0));
-
+
if (end == optarg)
einfo (_("%P%F: invalid hex number for PE parameter '%s'\n"), optarg);
char *comname;
{
set_pe_value (resname);
-
+
if (*optarg == ',')
{
optarg++;
break;
/* PE options */
- case OPTION_HEAP:
+ case OPTION_HEAP:
set_pe_stack_heap ("__size_of_heap_reserve__", "__size_of_heap_commit__");
break;
- case OPTION_STACK:
+ case OPTION_STACK:
set_pe_stack_heap ("__size_of_stack_reserve__", "__size_of_stack_commit__");
break;
case OPTION_SUBSYSTEM:
pe_dll_export_everything = 1;
break;
case OPTION_EXCLUDE_SYMBOLS:
- pe_dll_add_excludes (optarg);
+ pe_dll_add_excludes (optarg, 0);
+ break;
+ case OPTION_EXCLUDE_LIBS:
+ pe_dll_add_excludes (optarg, 1);
break;
case OPTION_KILL_ATS:
pe_dll_kill_ats = 1;
pe_dll_do_default_excludes = 0;
break;
case OPTION_DLL_ENABLE_AUTO_IMPORT:
- link_info.pei386_auto_import = true;
+ link_info.pei386_auto_import = 1;
break;
case OPTION_DLL_DISABLE_AUTO_IMPORT:
- link_info.pei386_auto_import = false;
+ link_info.pei386_auto_import = 0;
break;
case OPTION_ENABLE_EXTRA_PE_DEBUG:
pe_dll_extra_pe_debug = 1;
\f
#ifdef DLL_SUPPORT
-static unsigned long
+static unsigned long
strhash (const char *str)
{
const unsigned char *s;
{
long val = init[j].value;
lang_assignment_statement_type *rv;
- rv = lang_add_assignment (exp_assop ('=' ,init[j].symbol, exp_intop (val)));
+ rv = lang_add_assignment (exp_assop ('=', init[j].symbol,
+ exp_intop (val)));
if (init[j].size == sizeof(short))
*(short *)init[j].ptr = val;
else if (init[j].size == sizeof(int))
}
/* Restore the pointer. */
stat_ptr = save;
-
+
if (pe.FileAlignment >
pe.SectionAlignment)
{
opened, so registering the symbol as undefined will make a
difference. */
- if (! link_info.relocateable && entry_symbol != NULL)
- ldlang_add_undef (entry_symbol);
+ if (! link_info.relocateable && entry_symbol.name != NULL)
+ ldlang_add_undef (entry_symbol.name);
}
+/* 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 gave_warning_message = 0;
struct bfd_link_hash_entry *undef, *sym;
char *at;
- if (pe_dll_extra_pe_debug)
+ if (pe_dll_extra_pe_debug)
{
printf ("%s\n", __FUNCTION__);
}
-
+
for (undef = link_info.hash->undefs; undef; undef=undef->next)
if (undef->type == bfd_link_hash_undefined)
{
}
static int
-make_import_fixup (rel)
+make_import_fixup (rel, s)
arelent *rel;
+ asection *s;
{
struct symbol_cache_entry *sym = *rel->sym_ptr_ptr;
-/*
- bfd *b;
-*/
- if (pe_dll_extra_pe_debug)
+ if (pe_dll_extra_pe_debug)
{
- printf ("arelent: %s@%#x: add=%li\n", sym->name,
- (int) rel->address, rel->addend);
+ printf ("arelent: %s@%#lx: add=%li\n", sym->name,
+ (long) rel->address, (long) rel->addend);
}
- pe_create_import_fixup (rel);
+
+ {
+ int addend = 0;
+ if (!bfd_get_section_contents(s->owner, s, &addend, rel->address, sizeof(addend)))
+ {
+ einfo (_("%C: Cannot get section contents - auto-import exception\n"),
+ s->owner, s, rel->address);
+ }
+
+ if (addend == 0)
+ pe_create_import_fixup (rel);
+ else
+ {
+ einfo (_("%C: variable '%T' 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);
+ einfo ("%X");
+ }
+ }
+
return 1;
}
-char *pe_data_import_dll;
-
static void
pe_find_data_imports ()
{
{
/* C++ symbols are *long* */
char buf[4096];
- if (pe_dll_extra_pe_debug)
+ if (pe_dll_extra_pe_debug)
{
printf ("%s:%s\n", __FUNCTION__, undef->root.string);
}
sym = bfd_link_hash_lookup (link_info.hash, buf, 0, 0, 1);
if (sym && sym->type == bfd_link_hash_defined)
{
- einfo (_("Warning: resolving %s by linking to %s (auto-import)\n"),
- undef->root.string, buf);
- {
+ if (link_info.pei386_auto_import == -1)
+ info_msg (_("Info: resolving %s by linking to %s (auto-import)\n"),
+ undef->root.string, buf);
+ {
bfd *b = sym->u.def.section->owner;
asymbol **symbols;
int nsyms, symsize, i;
-
+
symsize = bfd_get_symtab_upper_bound (b);
symbols = (asymbol **) xmalloc (symsize);
nsyms = bfd_canonicalize_symtab (b, symbols);
for (i = 0; i < nsyms; i++)
{
- if (memcmp(symbols[i]->name, "__head_",
+ if (memcmp(symbols[i]->name, "__head_",
sizeof ("__head_") - 1))
continue;
if (pe_dll_extra_pe_debug)
{
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);
break;
}
}
- pe_walk_relocs_of_symbol (&link_info, undef->root.string,
+ pe_walk_relocs_of_symbol (&link_info, undef->root.string,
make_import_fixup);
/* let's differentiate it somehow from defined */
static boolean
pr_sym (h, string)
struct bfd_hash_entry *h;
- PTR string;
+ PTR string ATTRIBUTE_UNUSED;
{
- if (pe_dll_extra_pe_debug)
+ if (pe_dll_extra_pe_debug)
{
printf("+%s\n",h->string);
}
gld_${EMULATION_NAME}_after_open ()
{
- if (pe_dll_extra_pe_debug)
+ if (pe_dll_extra_pe_debug)
{
bfd *a;
struct bfd_link_hash_entry *sym;
printf("*%s\n",a->filename);
}
}
-
+
/* Pass the wacky PE command line options into the output bfd.
FIXME: This should be done via a function, rather than by
including an internal BFD header. */
-
- if (coff_data (output_bfd) == NULL || coff_data (output_bfd)->pe == NULL)
+
+ if (coff_data (output_bfd) == NULL || coff_data (output_bfd)->pe == 0)
einfo (_("%F%P: PE operations on non PE file.\n"));
pe_data (output_bfd)->pe_opthdr = pe;
if (pe_enable_stdcall_fixup) /* -1=warn or 1=disable */
pe_fixup_stdcalls ();
- pe_find_data_imports (output_bfd, &link_info);
+ pe_find_data_imports ();
pe_process_import_defs(output_bfd, &link_info);
if (link_info.shared)
{
int idata2 = 0, reloc_count=0, is_imp = 0;
asection *sec;
-
+
/* See if this is an import library thunk. */
for (sec = is->the_bfd->sections; sec; sec = sec->next)
{
is_imp = 1;
reloc_count += sec->reloc_count;
}
-
+
if (is_imp && !idata2 && reloc_count)
{
/* It is, look for the reference to head and see if it's
asymbol **symbols;
arelent **relocs;
int nrelocs;
-
+
symsize = bfd_get_symtab_upper_bound (is->the_bfd);
if (symsize < 1)
break;
relsize = bfd_get_reloc_upper_bound (is->the_bfd, sec);
if (relsize < 1)
break;
-
+
symbols = (asymbol **) xmalloc (symsize);
- symsize = bfd_canonicalize_symtab (is->the_bfd, symbols);
+ symsize = bfd_canonicalize_symtab (is->the_bfd, symbols);
if (symsize < 0)
{
einfo ("%X%P: unable to process symbols: %E");
return;
}
-
+
relocs = (arelent **) xmalloc ((size_t) relsize);
nrelocs = bfd_canonicalize_reloc (is->the_bfd, sec,
relocs, symbols);
einfo ("%X%P: unable to process relocs: %E");
return;
}
-
+
for (i = 0; i < nrelocs; i++)
{
struct symbol_cache_entry *s;
struct bfd_link_hash_entry * blhe;
bfd *other_bfd;
char *n;
-
+
s = (relocs[i]->sym_ptr_ptr)[0];
-
+
if (s->flags & BSF_LOCAL)
continue;
-
+
/* Thunk section with reloc to another bfd. */
blhe = bfd_link_hash_lookup (link_info.hash,
s->name,
false, false, true);
-
+
if (blhe == NULL
|| blhe->type != bfd_link_hash_defined)
continue;
-
+
other_bfd = blhe->u.def.section->owner;
-
+
if (strcmp (is->the_bfd->my_archive->filename,
other_bfd->my_archive->filename) == 0)
continue;
-
+
/* Rename this implib to match the other. */
n = (char *) xmalloc (strlen (other_bfd->my_archive->filename) + 1);
-
+
strcpy (n, other_bfd->my_archive->filename);
-
+
is->the_bfd->my_archive->filename = n;
}
}
}
\f
-static void
+static void
gld_${EMULATION_NAME}_before_allocation()
{
#ifdef TARGET_IS_ppcpe
}
#endif
return false;
-
+
}
static boolean
if (thumb_entry_symbol != NULL)
{
h = bfd_link_hash_lookup (link_info.hash, thumb_entry_symbol, false, false, true);
-
+
if (h != (struct bfd_link_hash_entry *) NULL
&& (h->type == bfd_link_hash_defined
|| h->type == bfd_link_hash_defweak)
{
static char buffer[32];
bfd_vma val;
-
+
/* Special procesing is required for a Thumb entry symbol. The
bottom bit of its address must be set. */
val = (h->u.def.value
+ bfd_get_section_vma (output_bfd,
h->u.def.section->output_section)
+ h->u.def.section->output_offset);
-
+
val |= 1;
-
+
/* Now convert this value into a string and store it in entry_symbol
where the lang_finish() function will pick it up. */
buffer[0] = '0';
buffer[1] = 'x';
-
+
sprintf_vma (buffer + 2, val);
-
- if (entry_symbol != NULL && entry_from_cmdline)
+
+ if (entry_symbol.name != NULL && entry_from_cmdline)
einfo (_("%P: warning: '--thumb-entry %s' is overriding '-e %s'\n"),
- thumb_entry_symbol, entry_symbol);
- entry_symbol = buffer;
+ thumb_entry_symbol, entry_symbol.name);
+ entry_symbol.name = buffer;
}
else
einfo (_("%P: warning: connot find thumb start symbol %s\n"), thumb_entry_symbol);
pe_exe_fill_sections (output_bfd, &link_info);
}
#endif
-
+
if (pe_out_def_filename)
pe_dll_generate_def_file (pe_out_def_filename);
#endif /* DLL_SUPPORT */
{
char *symname;
etree_type *e_align;
-
+
symname = (char *) xmalloc (ps - outsecname + sizeof "___start_");
sprintf (symname, "___start_%s", outsecname);
e_align = exp_unop (ALIGN_K,
lang_add_assignment (exp_assop ('=', symname, e_align));
}
}
-
+
if (link_info.relocateable || (s->flags & (SEC_LOAD | SEC_ALLOC)) == 0)
address = exp_intop ((bfd_vma) 0);
else
lang_leave_output_section_statement
((bfd_vma) 0, "*default*",
- (struct lang_output_section_phdr_list *) NULL, "*default*");
+ (struct lang_output_section_phdr_list *) NULL, NULL);
if (config.build_constructors && *ps == '\0')
{
stat_ptr back where we want it. */
if (place != NULL)
stat_ptr = &add;
-
+
symname = (char *) xmalloc (ps - outsecname + sizeof "___stop_");
sprintf (symname, "___stop_%s", outsecname);
lang_add_assignment (exp_assop ('=', symname,
stat_ptr = old;
- if (place != NULL)
+ if (place != NULL && os->bfd_section != NULL)
{
asection *snew, **pps;
if (place->section != NULL)
{
- /* Unlink the section. */
+ /* Unlink the section. */
for (pps = &output_bfd->sections;
*pps != snew;
pps = &(*pps)->next)
;
- *pps = snew->next;
+ bfd_section_list_remove (output_bfd, pps);
/* Now tack it on to the "place->os" section list. */
- snew->next = *place->section;
- *place->section = snew;
+ bfd_section_list_insert (output_bfd, place->section, snew);
}
/* Save the end of this list. Further ophans of this type will
filename = entry->filename;
string = (char *) xmalloc (strlen (search->name)
- + strlen (filename)
+ + strlen (filename)
+ sizeof "/lib.a.dll"
#ifdef DLL_SUPPORT
+ (pe_dll_search_prefix ? strlen (pe_dll_search_prefix) : 0)
{
#ifdef DLL_SUPPORT
if (pe_dll_search_prefix)
- {
+ {
/* Try "<prefix>foo.dll" (preferred dll name, if specified) */
sprintf (string, "%s/%s%s.dll", search->name, pe_dll_search_prefix, filename);
if (! ldfile_try_open_bfd (string, entry))
}
}
else /* pe_dll_search_prefix not specified */
-#endif
+#endif
{
/* Try "libfoo.dll" (preferred dll name) */
sprintf (string, "%s/lib%s.dll", search->name, filename);
sc="-f stringify.sed"
cat >>e${EMULATION_NAME}.c <<EOF
-{
+{
*isfile = 0;
if (link_info.relocateable == true && config.build_constructors == true)
cat >>e${EMULATION_NAME}.c <<EOF
-struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation =
+struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation =
{
gld_${EMULATION_NAME}_before_parse,
syslib_default,
gld_${EMULATION_NAME}_unrecognized_file,
gld_${EMULATION_NAME}_list_options,
gld_${EMULATION_NAME}_recognized_file,
- gld_${EMULATION_NAME}_find_potential_libraries
+ gld_${EMULATION_NAME}_find_potential_libraries,
+ NULL /* new_vers_pattern */
};
EOF