* ldmain.c (warning_callback, warning_find_reloc): Prepend
[deliverable/binutils-gdb.git] / ld / ldmain.c
index 6eb3774123fee96c024039d7fdb94086a23a1f93..4a767bc51ede7522de8fc7893814bae5d1429bab 100644 (file)
@@ -68,7 +68,7 @@ const char *output_filename = "a.out";
 char *program_name;
 
 /* The prefix for system library directories.  */
-char *ld_sysroot;
+const char *ld_sysroot;
 
 /* The canonical representation of ld_sysroot.  */
 char * ld_canon_sysroot;
@@ -110,6 +110,8 @@ ld_config_type config;
 
 sort_type sort_section;
 
+static const char *get_sysroot
+  (int, char **);
 static char *get_emulation
   (int, char **);
 static void set_scripts_dir
@@ -201,47 +203,18 @@ main (int argc, char **argv)
 
   xatexit (remove_output);
 
-#ifdef TARGET_SYSTEM_ROOT_RELOCATABLE
-  ld_sysroot = make_relative_prefix (program_name, BINDIR,
-                                    TARGET_SYSTEM_ROOT);
-
-  if (ld_sysroot)
+  /* Set up the sysroot directory.  */
+  ld_sysroot = get_sysroot (argc, argv);
+  if (*ld_sysroot)
     {
-      struct stat s;
-      int res = stat (ld_sysroot, &s) == 0 && S_ISDIR (s.st_mode);
-
-      if (!res)
+      if (*TARGET_SYSTEM_ROOT == 0)
        {
-         free (ld_sysroot);
-         ld_sysroot = NULL;
-       }
-    }
-
-  if (! ld_sysroot)
-    {
-      ld_sysroot = make_relative_prefix (program_name, TOOLBINDIR,
-                                        TARGET_SYSTEM_ROOT);
-
-      if (ld_sysroot)
-       {
-         struct stat s;
-         int res = stat (ld_sysroot, &s) == 0 && S_ISDIR (s.st_mode);
-
-         if (!res)
-           {
-             free (ld_sysroot);
-             ld_sysroot = NULL;
-           }
+         einfo ("%P%F: this linker was not configured to use sysroots");
+         ld_sysroot = "";
        }
+      else
+       ld_canon_sysroot = lrealpath (ld_sysroot);
     }
-
-  if (! ld_sysroot)
-#endif
-    ld_sysroot = TARGET_SYSTEM_ROOT;
-
-  if (ld_sysroot && *ld_sysroot)
-    ld_canon_sysroot = lrealpath (ld_sysroot);
-
   if (ld_canon_sysroot)
     ld_canon_sysroot_len = strlen (ld_canon_sysroot);
   else
@@ -307,6 +280,7 @@ main (int argc, char **argv)
   link_info.allow_multiple_definition = FALSE;
   link_info.allow_undefined_version = TRUE;
   link_info.create_default_symver = FALSE;
+  link_info.default_imported_symver = FALSE;
   link_info.keep_memory = TRUE;
   link_info.notice_all = FALSE;
   link_info.nocopyreloc = FALSE;
@@ -369,6 +343,9 @@ main (int argc, char **argv)
        einfo (_("%P%F: -r and -shared may not be used together\n"));
     }
 
+   if (!config.dynamic_link && link_info.shared)
+     einfo (_("%P%F: -static and -shared may not be used together\n"));
+
   if (! link_info.shared)
     {
       if (command_line.filter_shlib)
@@ -583,6 +560,51 @@ main (int argc, char **argv)
   return 0;
 }
 
+/* If the configured sysroot is relocatable, try relocating it based on
+   default prefix FROM.  Return the relocated directory if it exists,
+   otherwise return null.  */
+
+static char *
+get_relative_sysroot (const char *from ATTRIBUTE_UNUSED)
+{
+#ifdef TARGET_SYSTEM_ROOT_RELOCATABLE
+  char *path;
+  struct stat s;
+
+  path = make_relative_prefix (program_name, from, TARGET_SYSTEM_ROOT);
+  if (path)
+    {
+      if (stat (path, &s) == 0 && S_ISDIR (s.st_mode))
+       return path;
+      free (path);
+    }
+#endif
+  return 0;
+}
+
+/* Return the sysroot directory.  Return "" if no sysroot is being used.  */
+
+static const char *
+get_sysroot (int argc, char **argv)
+{
+  int i;
+  const char *path;
+
+  for (i = 1; i < argc; i++)
+    if (strncmp (argv[i], "--sysroot=", strlen ("--sysroot=")) == 0)
+      return argv[i] + strlen ("--sysroot=");
+
+  path = get_relative_sysroot (BINDIR);
+  if (path)
+    return path;
+
+  path = get_relative_sysroot (TOOLBINDIR);
+  if (path)
+    return path;
+
+  return TARGET_SYSTEM_ROOT;
+}
+
 /* We need to find any explicitly given emulation in order to initialize the
    state that's needed by the lex&yacc argument parser (parse_args).  */
 
@@ -1178,11 +1200,11 @@ warning_callback (struct bfd_link_info *info ATTRIBUTE_UNUSED,
     return TRUE;
 
   if (section != NULL)
-    einfo ("%C: %s\n", abfd, section, address, warning);
+    einfo ("%C: %s%s\n", abfd, section, address, _("warning: "), warning);
   else if (abfd == NULL)
-    einfo ("%P: %s\n", warning);
+    einfo ("%P: %s%s\n", _("warning: "), warning);
   else if (symbol == NULL)
-    einfo ("%B: %s\n", abfd, warning);
+    einfo ("%B: %s%s\n", abfd, _("warning: "), warning);
   else
     {
       lang_input_statement_type *entry;
@@ -1220,7 +1242,7 @@ warning_callback (struct bfd_link_info *info ATTRIBUTE_UNUSED,
       bfd_map_over_sections (abfd, warning_find_reloc, &info);
 
       if (! info.found)
-       einfo ("%B: %s\n", abfd, warning);
+       einfo ("%B: %s%s\n", abfd, _("warning: "), warning);
 
       if (entry == NULL)
        free (asymbols);
@@ -1268,7 +1290,8 @@ warning_find_reloc (bfd *abfd, asection *sec, void *iarg)
          && strcmp (bfd_asymbol_name (*q->sym_ptr_ptr), info->symbol) == 0)
        {
          /* We found a reloc for the symbol we are looking for.  */
-         einfo ("%C: %s\n", abfd, sec, q->address, info->warning);
+         einfo ("%C: %s%s\n", abfd, sec, q->address, _("warning: "),
+                info->warning);
          info->found = TRUE;
          break;
        }
This page took 0.027147 seconds and 4 git commands to generate.