NEWS and documentation for alias default-args related concept and commands.
[deliverable/binutils-gdb.git] / ld / ldmain.c
index 43602fe85a46a12aa491c7db8f5b7deb5f39daf1..d34d30ae3371a88e94abb5d9774a8325149daee9 100644 (file)
@@ -1,5 +1,5 @@
 /* Main program of GNU linker.
-   Copyright (C) 1991-2018 Free Software Foundation, Inc.
+   Copyright (C) 1991-2020 Free Software Foundation, Inc.
    Written by Steve Chamberlain steve@cygnus.com
 
    This file is part of the GNU Binutils.
@@ -25,7 +25,9 @@
 #include "libiberty.h"
 #include "progress.h"
 #include "bfdlink.h"
+#include "ctf-api.h"
 #include "filenames.h"
+#include "elf/common.h"
 
 #include "ld.h"
 #include "ldmain.h"
 #include "ldfile.h"
 #include "ldemul.h"
 #include "ldctor.h"
-#ifdef ENABLE_PLUGINS
+#if BFD_SUPPORTS_PLUGINS
 #include "plugin.h"
 #include "plugin-api.h"
-#endif /* ENABLE_PLUGINS */
+#endif /* BFD_SUPPORTS_PLUGINS */
 
 /* Somewhere above, sys/stat.h got included.  */
 #if !defined(S_ISDIR) && defined(S_IFDIR)
@@ -77,7 +79,7 @@ int ld_canon_sysroot_len;
 int g_switch_value = 8;
 
 /* Nonzero means print names of input files as processed.  */
-bfd_boolean trace_files;
+unsigned int trace_files;
 
 /* Nonzero means report actions taken by the linker, and describe the linker script in use.  */
 bfd_boolean verbose;
@@ -148,7 +150,9 @@ static struct bfd_link_callbacks link_callbacks =
   einfo,
   info_msg,
   minfo,
-  ldlang_override_segment_assignment
+  ldlang_override_segment_assignment,
+  ldlang_ctf_apply_strsym,
+  ldlang_write_ctf_late
 };
 
 static bfd_assert_handler_type default_bfd_assert_handler;
@@ -160,7 +164,7 @@ static void
 ld_cleanup (void)
 {
   bfd_cache_close_all ();
-#ifdef ENABLE_PLUGINS
+#if BFD_SUPPORTS_PLUGINS
   plugin_call_cleanup ();
 #endif
   if (output_filename && delete_output_file_on_failure)
@@ -209,7 +213,8 @@ main (int argc, char **argv)
 
   expandargv (&argc, &argv);
 
-  bfd_init ();
+  if (bfd_init () != BFD_INIT_MAGIC)
+    einfo (_("%F%P: fatal error: libbfd ABI mismatch\n"));
 
   bfd_set_error_program_name (program_name);
 
@@ -263,6 +268,7 @@ main (int argc, char **argv)
   config.make_executable = TRUE;
   config.magic_demand_paged = TRUE;
   config.text_read_only = TRUE;
+  config.print_map_discarded = TRUE;
   link_info.disable_target_specific_optimizations = -1;
 
   command_line.warn_mismatch = TRUE;
@@ -280,6 +286,8 @@ main (int argc, char **argv)
   link_info.keep_memory = TRUE;
   link_info.combreloc = TRUE;
   link_info.strip_discarded = TRUE;
+  link_info.prohibit_multiple_definition_absolute = FALSE;
+  link_info.textrel_check = DEFAULT_LD_TEXTREL_CHECK;
   link_info.emit_hash = DEFAULT_EMIT_SYSV_HASH;
   link_info.emit_gnu_hash = DEFAULT_EMIT_GNU_HASH;
   link_info.callbacks = &link_callbacks;
@@ -300,6 +308,7 @@ main (int argc, char **argv)
 #ifdef DEFAULT_NEW_DTAGS
   link_info.new_dtags = DEFAULT_NEW_DTAGS;
 #endif
+  link_info.start_stop_visibility = STV_PROTECTED;
 
   ldfile_add_arch ("");
   emulation = get_emulation (argc, argv);
@@ -314,10 +323,10 @@ main (int argc, char **argv)
   if (config.hash_table_size != 0)
     bfd_hash_set_default_size (config.hash_table_size);
 
-#ifdef ENABLE_PLUGINS
+#if BFD_SUPPORTS_PLUGINS
   /* Now all the plugin arguments have been gathered, we can load them.  */
   plugin_load_plugins ();
-#endif /* ENABLE_PLUGINS */
+#endif /* BFD_SUPPORTS_PLUGINS */
 
   ldemul_set_symbols ();
 
@@ -326,7 +335,7 @@ main (int argc, char **argv)
   if (saved_script_handle == NULL
       && command_line.default_script != NULL)
     {
-      ldfile_open_command_file (command_line.default_script);
+      ldfile_open_script_file (command_line.default_script);
       parser_input = input_script;
       yyparse ();
     }
@@ -411,7 +420,7 @@ main (int argc, char **argv)
       einfo (_("%F%P: no input files\n"));
     }
 
-  if (trace_files)
+  if (verbose)
     info_msg (_("%P: mode %s\n"), emulation);
 
   ldemul_after_parse ();
@@ -432,6 +441,7 @@ main (int argc, char **argv)
                     config.map_filename);
            }
        }
+      link_info.has_map_file = TRUE;
     }
 
   lang_process ();
@@ -476,7 +486,7 @@ main (int argc, char **argv)
      want to ignore for relocatable output?)  */
   if (!config.make_executable && !force_make_executable)
     {
-      if (trace_files)
+      if (verbose)
        einfo (_("%P: link errors found, deleting executable `%s'\n"),
               output_filename);
 
@@ -582,21 +592,25 @@ static const char *
 get_sysroot (int argc, char **argv)
 {
   int i;
-  const char *path;
+  const char *path = NULL;
 
   for (i = 1; i < argc; i++)
     if (CONST_STRNEQ (argv[i], "--sysroot="))
-      return argv[i] + strlen ("--sysroot=");
+      path = argv[i] + strlen ("--sysroot=");
 
-  path = get_relative_sysroot (BINDIR);
-  if (path)
-    return path;
+  if (!path)
+    path = get_relative_sysroot (BINDIR);
 
-  path = get_relative_sysroot (TOOLBINDIR);
-  if (path)
-    return path;
+  if (!path)
+    path = get_relative_sysroot (TOOLBINDIR);
+
+  if (!path)
+    path = TARGET_SYSTEM_ROOT;
+
+  if (IS_DIR_SEPARATOR (*path) && path[1] == 0)
+    path = "";
 
-  return TARGET_SYSTEM_ROOT;
+  return path;
 }
 
 /* We need to find any explicitly given emulation in order to initialize the
@@ -804,19 +818,19 @@ add_archive_element (struct bfd_link_info *info,
   input = (lang_input_statement_type *)
       xcalloc (1, sizeof (lang_input_statement_type));
   input->header.type = lang_input_statement_enum;
-  input->filename = abfd->filename;
-  input->local_sym_name = abfd->filename;
+  input->filename = bfd_get_filename (abfd);
+  input->local_sym_name = bfd_get_filename (abfd);
   input->the_bfd = abfd;
 
-  parent = abfd->my_archive->usrdata;
+  parent = bfd_usrdata (abfd->my_archive);
   if (parent != NULL && !parent->flags.reload)
-    parent->next = (lang_statement_union_type *) input;
+    parent->next = input;
 
   /* Save the original data for trace files/tries below, as plugins
      (if enabled) may possibly alter it to point to a replacement
      BFD, but we still want to output the original BFD filename.  */
   orig_input = *input;
-#ifdef ENABLE_PLUGINS
+#if BFD_SUPPORTS_PLUGINS
   if (link_info.lto_plugin_active)
     {
       /* We must offer this archive member to the plugins to claim.  */
@@ -827,8 +841,8 @@ add_archive_element (struct bfd_link_info *info,
            {
              /* Don't claim new IR symbols after all IR symbols have
                 been claimed.  */
-             if (trace_files || verbose)
-               info_msg ("%pI: no new IR symbols to claimi\n",
+             if (verbose)
+               info_msg ("%pI: no new IR symbols to claim\n",
                          &orig_input);
              input->flags.claimed = 0;
              return FALSE;
@@ -837,7 +851,7 @@ add_archive_element (struct bfd_link_info *info,
          *subsbfd = input->the_bfd;
        }
     }
-#endif /* ENABLE_PLUGINS */
+#endif /* BFD_SUPPORTS_PLUGINS */
 
   ldlang_add_file (input);
 
@@ -849,6 +863,10 @@ add_archive_element (struct bfd_link_info *info,
       int len;
 
       h = bfd_link_hash_lookup (info->hash, name, FALSE, FALSE, TRUE);
+      if (h == NULL
+         && info->pei386_auto_import
+         && CONST_STRNEQ (name, "__imp_"))
+       h = bfd_link_hash_lookup (info->hash, name + 6, FALSE, FALSE, TRUE);
 
       if (h == NULL)
        from = NULL;
@@ -916,7 +934,9 @@ add_archive_element (struct bfd_link_info *info,
        minfo ("(%s)\n", name);
     }
 
-  if (trace_files || verbose)
+  if (verbose
+      || trace_files > 1
+      || (trace_files && bfd_is_thin_archive (orig_input.the_bfd->my_archive)))
     info_msg ("%pI\n", &orig_input);
   return TRUE;
 }
@@ -968,12 +988,13 @@ multiple_definition (struct bfd_link_info *info,
      discarded, and this is not really a multiple definition at all.
      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)))
+  if (!info->prohibit_multiple_definition_absolute
+      && ((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;
 
   name = h->root.string;
@@ -1331,8 +1352,7 @@ undefined_symbol (struct bfd_link_info *info,
   else
     {
       error_count = 0;
-      if (error_name != NULL)
-       free (error_name);
+      free (error_name);
       error_name = xstrdup (name);
     }
 
@@ -1408,7 +1428,7 @@ reloc_overflow (struct bfd_link_info *info,
   if (overflow_cutoff_limit == -1)
     return;
 
-  einfo ("%X%P: %H:", abfd, section, address);
+  einfo ("%X%H:", abfd, section, address);
 
   if (overflow_cutoff_limit >= 0
       && overflow_cutoff_limit-- == 0)
@@ -1461,7 +1481,7 @@ reloc_dangerous (struct bfd_link_info *info ATTRIBUTE_UNUSED,
                 asection *section,
                 bfd_vma address)
 {
-  einfo (_("%X%P: %H: dangerous relocation: %s\n"),
+  einfo (_("%X%H: dangerous relocation: %s\n"),
         abfd, section, address, message);
 }
 
@@ -1475,7 +1495,7 @@ unattached_reloc (struct bfd_link_info *info ATTRIBUTE_UNUSED,
                  asection *section,
                  bfd_vma address)
 {
-  einfo (_("%X%P: %H: reloc refers to symbol `%pT' which is not being output\n"),
+  einfo (_("%X%H: reloc refers to symbol `%pT' which is not being output\n"),
         abfd, section, address, name);
 }
 
This page took 0.026966 seconds and 4 git commands to generate.