/* Main program of GNU linker.
- Copyright (C) 1991, 92, 93, 94, 1995 Free Software Foundation, Inc.
+ Copyright (C) 1991, 92, 93, 94, 95, 96, 1997 Free Software Foundation, Inc.
Written by Steve Chamberlain steve@cygnus.com
This file is part of GLD, the Gnu Linker.
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
-along with GLD; see the file COPYING. If not, write to
-the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
-
+along with GLD; see the file COPYING. If not, write to the Free
+Software Foundation, 59 Temple Place - Suite 330, Boston, MA
+02111-1307, USA. */
#include "bfd.h"
#include "sysdep.h"
#include <string.h>
+#ifdef HAVE_SBRK
+#ifdef NEED_DECLARATION_SBRK
+extern PTR sbrk ();
+#endif
+#endif
+
static char *get_emulation PARAMS ((int, char **));
static void set_scripts_dir PARAMS ((void));
static boolean unattached_reloc PARAMS ((struct bfd_link_info *,
const char *, bfd *, asection *,
bfd_vma));
-static boolean notice_ysym PARAMS ((struct bfd_link_info *, const char *,
- bfd *, asection *, bfd_vma));
+static boolean notice PARAMS ((struct bfd_link_info *, const char *,
+ bfd *, asection *, bfd_vma));
static struct bfd_link_callbacks link_callbacks =
{
reloc_overflow,
reloc_dangerous,
unattached_reloc,
- notice_ysym
+ notice
};
struct bfd_link_info link_info;
xatexit (remove_output);
+ /* Set the default BFD target based on the configured target. Doing
+ this permits the linker to be configured for a particular target,
+ and linked against a shared BFD library which was configured for
+ a different target. The macro TARGET is defined by Makefile. */
+ if (! bfd_set_default_target (TARGET))
+ {
+ einfo ("%X%P: can't set BFD default target to `%s': %E\n", TARGET);
+ xexit (1);
+ }
+
/* Initialize the data about options. */
trace_files = trace_file_tries = version_printed = false;
whole_archive = false;
link_info.traditional_format = false;
link_info.strip = strip_none;
link_info.discard = discard_none;
- link_info.lprefix_len = 1;
- link_info.lprefix = "L";
link_info.keep_memory = true;
link_info.input_bfds = NULL;
link_info.create_object_symbols_section = NULL;
link_info.hash = NULL;
link_info.keep_hash = NULL;
+ link_info.notice_all = false;
link_info.notice_hash = NULL;
link_info.wrap_hash = NULL;
if (config.map_file != NULL)
lang_map ();
+ if (command_line.cref)
+ output_cref (config.map_file != NULL ? config.map_file : stdout);
+ if (nocrossref_list != NULL)
+ check_nocrossrefs ();
/* Even if we're producing relocateable output, some non-fatal errors should
be reported in the exit status. (What non-fatal errors, if any, do we
output_filename);
}
- if (output_bfd->iostream)
- fclose ((FILE *) (output_bfd->iostream));
+ /* The file will be removed by remove_output. */
- unlink (output_filename);
xexit (1);
}
else
{
if (! bfd_close (output_bfd))
einfo ("%F%B: final close failed: %E\n", output_bfd);
+
+ /* If the --force-exe-suffix is enabled, and we're making an
+ executable file and it doesn't end in .exe, copy it to one which does. */
+
+ if (! link_info.relocateable && command_line.force_exe_suffix)
+ {
+ int len = strlen (output_filename);
+ if (len < 4
+ || (strcasecmp (output_filename + len - 4, ".exe") != 0
+ && strcasecmp (output_filename + len - 4, ".dll") != 0))
+ {
+ FILE *src;
+ FILE *dst;
+ const int bsize = 4096;
+ char *buf = xmalloc (bsize);
+ int l;
+ char *dst_name = xmalloc (len + 5);
+ strcpy (dst_name, output_filename);
+ strcat (dst_name, ".exe");
+ src = fopen (output_filename, FOPEN_RB);
+ dst = fopen (dst_name, FOPEN_WB);
+
+ if (!src)
+ einfo ("%X%P: unable to open for source of copy `%s'\n", output_filename);
+ if (!dst)
+ einfo ("%X%P: unable to open for destination of copy `%s'\n", dst_name);
+ while ((l = fread (buf, 1, bsize, src)) > 0)
+ {
+ int done = fwrite (buf, 1, l, dst);
+ if (done != l)
+ {
+ einfo ("%P: Error writing file `%s'\n", dst_name);
+ }
+ }
+ fclose (src);
+ if (!fclose (dst))
+ {
+ einfo ("%P: Error closing file `%s'\n", dst_name);
+ }
+ free (dst_name);
+ free (buf);
+ }
+ }
}
END_PROGRESS (program_name);
char *emulation;
int i;
- emulation = (char *) getenv (EMULATION_ENVIRON);
+ emulation = getenv (EMULATION_ENVIRON);
if (emulation == NULL)
emulation = DEFAULT_EMULATION;
}
else if (strcmp (argv[i], "-mips1") == 0
|| strcmp (argv[i], "-mips2") == 0
- || strcmp (argv[i], "-mips3") == 0)
+ || strcmp (argv[i], "-mips3") == 0
+ || strcmp (argv[i], "-mips4") == 0)
{
/* FIXME: The arguments -mips1, -mips2 and -mips3 are
passed to the linker by some MIPS compilers. They
/* FIXME: The following fields are not set: header.next,
header.type, closed, passive_position, symbol_count,
- next_real_file, is_archive, target, real, common_section,
- common_output_section, complained. This bit of code is from the
- old decode_library_subfile function. I don't know whether any of
- those fields matters. */
+ next_real_file, is_archive, target, real. This bit of code is
+ from the old decode_library_subfile function. I don't know
+ whether any of those fields matters. */
ldlang_add_file (input);
FIXME: It would be cleaner to somehow ignore symbols defined in
sections which are being discarded. */
if ((osec->output_section != NULL
+ && ! bfd_is_abs_section (osec)
&& bfd_is_abs_section (osec->output_section))
|| (nsec->output_section != NULL
+ && ! bfd_is_abs_section (nsec)
&& bfd_is_abs_section (nsec->output_section)))
return true;
if (! info.found)
einfo ("%B: %s\n", abfd, warning);
+
+ if (entry == NULL)
+ free (asymbols);
}
return true;
return true;
}
-/* This is called when a symbol in notice_hash is found. Symbols are
- put in notice_hash using the -y option. */
+/* This is called if link_info.notice_all is set, or when a symbol in
+ link_info.notice_hash is found. Symbols are put in notice_hash
+ using the -y option. */
-/*ARGSUSED*/
static boolean
-notice_ysym (info, name, abfd, section, value)
+notice (info, name, abfd, section, value)
struct bfd_link_info *info;
const char *name;
bfd *abfd;
asection *section;
bfd_vma value;
{
- einfo ("%B: %s %s\n", abfd,
- bfd_is_und_section (section) ? "reference to" : "definition of",
- name);
+ if (! info->notice_all
+ || (info->notice_hash != NULL
+ && bfd_hash_lookup (info->notice_hash, name, false, false) != NULL))
+ einfo ("%B: %s %s\n", abfd,
+ bfd_is_und_section (section) ? "reference to" : "definition of",
+ name);
+
+ if (command_line.cref || nocrossref_list != NULL)
+ add_cref (name, abfd, section, value);
+
return true;
}