* emultempl/hppaosf.em: Various fixes and support for linker stub
[deliverable/binutils-gdb.git] / ld / ldlang.c
index e2e8d5f7970345ce7fd5a3541d558007d0c3947e..0fb4a1856dab4d445c43923c8a63d0ce1b12cf57 100644 (file)
@@ -1,5 +1,5 @@
 /* Linker command language support.
-   Copyright 1991, 1992 Free Software Foundation, Inc.
+   Copyright 1991, 1992, 1993 Free Software Foundation, Inc.
 
 This file is part of GLD, the Gnu Linker.
 
@@ -32,6 +32,7 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
 #include "ldmisc.h"
 #include "ldindr.h"
 #include "ldctor.h"
+
 /* FORWARDS */
 static void print_statements PARAMS ((void));
 static void print_statement PARAMS ((lang_statement_union_type *,
@@ -73,7 +74,6 @@ boolean relaxing;
 lang_output_section_statement_type *abs_output_section;
 lang_statement_list_type *stat_ptr = &statement_list;
 lang_input_statement_type *script_file = 0;
-boolean option_longmap = false;
 lang_statement_list_type file_chain =
 {0};
 CONST char *entry_symbol = 0;
@@ -82,11 +82,11 @@ boolean lang_has_input_file = false;
 lang_output_section_statement_type *create_object_symbols = 0;
 boolean had_output_filename = false;
 boolean lang_float_flag = false;
+boolean delete_output_file_on_failure = false;
 
 /* IMPORTS */
 extern char *default_target;
 
-extern unsigned int undefined_global_sym_count;
 extern char *current_file;
 extern bfd *output_bfd;
 extern enum bfd_architecture ldfile_output_architecture;
@@ -96,7 +96,6 @@ extern ldsym_type *symbol_head;
 extern unsigned int commons_pending;
 extern args_type command_line;
 extern ld_config_type config;
-extern boolean had_script;
 extern boolean write_map;
 extern int g_switch_value;
 
@@ -326,6 +325,7 @@ lang_add_input_file (name, file_type, target)
 {
   /* Look it up or build a new one */
   lang_has_input_file = true;
+
 #if 0
   lang_input_statement_type *p;
 
@@ -351,10 +351,10 @@ lang_add_keepsyms_file (filename)
 {
   extern strip_symbols_type strip_symbols;
   if (keepsyms_file != 0)
-    info ("%X%P error: duplicated keep-symbols-file value\n");
+    info_msg ("%X%P: error: duplicated keep-symbols-file value\n");
   keepsyms_file = filename;
   if (strip_symbols != STRIP_NONE)
-    info ("%P `-keep-only-symbols-file' overrides `-s' and `-S'\n");
+    info_msg ("%P: `-keep-only-symbols-file' overrides `-s' and `-S'\n");
   strip_symbols = STRIP_SOME;
 }
 
@@ -569,7 +569,7 @@ init_os (s)
     s->bfd_section = bfd_make_section (output_bfd, s->name);
   if (s->bfd_section == (asection *) NULL)
     {
-      einfo ("%P%F output format %s cannot represent section called %s\n",
+      einfo ("%P%F: output format %s cannot represent section called %s\n",
             output_bfd->xvec->name, s->name);
     }
   s->bfd_section->output_section = s->bfd_section;
@@ -777,6 +777,7 @@ wild (s, section, file, target, output)
 /*
   read in all the files
   */
+
 static bfd *
 open_output (name)
      CONST char *CONST name;
@@ -801,17 +802,22 @@ open_output (name)
     {
       if (bfd_error == invalid_target)
        {
-         einfo ("%P%F target %s not found\n", output_target);
+         einfo ("%P%F: target %s not found\n", output_target);
        }
-      einfo ("%P%F problem opening output file %s, %E\n", name);
+      einfo ("%P%F: cannot open output file %s: %E\n", name);
     }
 
+  delete_output_file_on_failure = 1;
+
   /*  output->flags |= D_PAGED;*/
 
-  bfd_set_format (output, bfd_object);
-  bfd_set_arch_mach (output,
-                    ldfile_output_architecture,
-                    ldfile_output_machine);
+  if (! bfd_set_format (output, bfd_object))
+    einfo ("%P%F:%s: can not make object file: %E\n", name);
+  if (! bfd_set_arch_mach (output,
+                          ldfile_output_architecture,
+                          ldfile_output_machine))
+    einfo ("%P%F:%s: can not set architecture: %E\n", name);
+
   bfd_set_gp_size (output, g_switch_value);
   return output;
 }
@@ -948,7 +954,7 @@ lang_place_undefineds ()
       *def_ptr = def;
       def->name = ptr->name;
       def->section = &bfd_und_section;
-      Q_enter_global_ref (def_ptr, ptr->name);
+      enter_global_ref (def_ptr, ptr->name);
       ptr = ptr->next;
     }
 }
@@ -1050,7 +1056,7 @@ map_input_to_output_sections (s, target, output_section_statement)
            os->addr_tree = s->address_statement.address;
            if (os->bfd_section == (asection *) NULL)
              {
-               einfo ("%P%F can't set the address of undefined section %s\n",
+               einfo ("%P%F: cannot set the address of undefined section %s\n",
                       s->address_statement.section_name);
              }
          }
@@ -1189,6 +1195,8 @@ print_symbol (q)
   fprintf (config.map_file, " ");
   print_address (outside_symbol_address (q));
   fprintf (config.map_file, "              %s", q->name ? q->name : " ");
+  if (q->flags & BSF_WEAK)
+    fprintf (config.map_file, " *weak*");
   print_nl ();
 }
 
@@ -1250,7 +1258,8 @@ print_input_section (in)
                    {
                      asymbol *q = *p;
 
-                     if (bfd_get_section (q) == i && q->flags & BSF_GLOBAL)
+                     if (bfd_get_section (q) == i
+                         && (q->flags & (BSF_GLOBAL | BSF_WEAK)) != 0)
                        {
                          print_symbol (q);
                        }
@@ -1620,11 +1629,10 @@ DEFUN (lang_size_sections, (s, output_section_statement, prev, fill, dot, relax)
        /* Ignore the size of the input sections, use the vma and size to */
        /* align against */
 
-
        after = ALIGN_N (os->bfd_section->vma +
-                     os->bfd_section->_raw_size,
-                     os->block_value);
-
+                       os->bfd_section->_raw_size,
+                       /* The coercion here is important, see ld.h.  */
+                       (bfd_vma) os->block_value);
 
        os->bfd_section->_raw_size = after - os->bfd_section->vma;
        dot = os->bfd_section->vma + os->bfd_section->_raw_size;
@@ -1640,7 +1648,7 @@ DEFUN (lang_size_sections, (s, output_section_statement, prev, fill, dot, relax)
               > os->region->origin + os->region->length)
             || ( os->region->origin > os->region->current ))
           {
-            einfo ("%X%P: Region %s is full (%B section %s)\n",
+            einfo ("%X%P: region %s is full (%B section %s)\n",
                    os->region->name,
                    os->bfd_section->owner,
                    os->bfd_section->name);
@@ -1831,7 +1839,7 @@ DEFUN (lang_do_assignments, (s, output_section_statement, fill, dot),
                                   lang_final_phase_enum, dot, &dot);
            s->data_statement.value = value.value;
            if (value.valid == false)
-             einfo ("%F%P: Invalid data statement\n");
+             einfo ("%F%P: invalid data statement\n");
          }
          switch (s->data_statement.type)
            {
@@ -1968,14 +1976,14 @@ lang_finish ()
   }
   else
   {
-    /* Can't find anything reasonable,
+    /* Cannot find anything reasonable,
        use the first address in the text section
        */
     asection *ts = bfd_get_section_by_name (output_bfd, ".text");
     if (ts)
     {
       if (warn)
-       einfo ("%P: Warning, can't find entry symbol %s, defaulting to %V\n",
+       einfo ("%P: warning: cannot find entry symbol %s, defaulting to %V\n",
              entry_symbol, ts->vma);
 
       bfd_set_start_address (output_bfd, ts->vma);
@@ -1983,7 +1991,7 @@ lang_finish ()
     else 
     {
       if (warn)
-       einfo ("%P: Warning, can't find entry symbol %s, not setting start address\n",
+       einfo ("%P: warning: cannot find entry symbol %s, not setting start address\n",
              entry_symbol);
     }
   }
@@ -2024,13 +2032,15 @@ lang_check ()
       else
        {
 
-         info ("%P: warning, %s architecture of input file `%B' incompatible with %s output\n",
+         info_msg ("%P: warning: %s architecture of input file `%B' is incompatible with %s output\n",
                bfd_printable_name (input_bfd), input_bfd,
                bfd_printable_name (output_bfd));
 
-         bfd_set_arch_mach (output_bfd,
-                            input_architecture,
-                            input_machine);
+         if (! bfd_set_arch_mach (output_bfd,
+                                  input_architecture,
+                                  input_machine))
+           einfo ("%P%F:%s: can't set architecture: %E\n",
+                  bfd_get_filename (output_bfd));
        }
 
     }
@@ -2123,14 +2133,16 @@ lang_common ()
                                                            name);
                          /* BFD backend must provide this section. */
                          if (newsec == (asection *) NULL)
-                           einfo ("%P%F: No output section %s", name);
+                           einfo ("%P%F: no output section %s", name);
                          com->section = newsec;
                        }
 
                      /*  Fix the size of the common section */
 
                      com->section->_raw_size =
-                       ALIGN_N (com->section->_raw_size, align);
+                       ALIGN_N (com->section->_raw_size,
+                                /* The coercion here is important, see ld.h.  */
+                                (bfd_vma) align);
 
                      /* Remember if this is the biggest alignment ever seen */
                      if (power_of_two > com->section->alignment_power)
@@ -2203,7 +2215,7 @@ lang_place_orphans ()
                      if (default_common_section ==
                          (lang_output_section_statement_type *) NULL)
                        {
-                         info ("%P: No [COMMON] command, defaulting to .bss\n");
+                         info_msg ("%P: no [COMMON] command, defaulting to .bss\n");
 
                          default_common_section =
                            lang_output_section_statement_lookup (".bss");
@@ -2259,7 +2271,7 @@ lang_set_flags (ptr, flags)
          /*      ptr->flag_loadable= state;*/
          break;
        default:
-         einfo ("%P%F illegal syntax in flags\n");
+         einfo ("%P%F: invalid syntax in flags\n");
          break;
        }
       flags++;
@@ -2438,26 +2450,13 @@ DEFUN (create_symbol, (name, flags, section),
   def->flags = flags;
   def->section = section;
   *def_ptr = def;
-  Q_enter_global_ref (def_ptr, name);
+  enter_global_ref (def_ptr, name);
   return def;
 }
 
 void
 lang_process ()
 {
-  if (had_script == false)
-    {
-      /* Read the emulation's appropriate default script.  */
-      char *scriptname = ldemul_get_script ();
-      /* sizeof counts the terminating NUL.  */
-      size_t size = strlen (scriptname) + sizeof ("-Tldscripts/");
-      char *buf = (char *) ldmalloc(size);
-
-      sprintf (buf, "-Tldscripts/%s", scriptname);
-      parse_line (buf, 0);
-      free (buf);
-    }
-
   lang_reasonable_defaults ();
   current_target = default_target;
 
@@ -2466,6 +2465,8 @@ lang_process ()
      file */
   lang_create_output_section_statements ();
 
+  ldemul_create_output_section_statements ();
+
   /* Create a dummy bfd for the script */
   lang_init_script_file ();
 
@@ -2514,50 +2515,41 @@ lang_process ()
   /* Now run around and relax if we can */
   if (command_line.relax)
     {
-      /* First time round is a trial run to get the 'worst case' addresses of the
-         objects if there was no relaxing */
+      /* First time round is a trial run to get the 'worst case'
+        addresses of the objects if there was no relaxing.  */
       lang_size_sections (statement_list.head,
                          (lang_output_section_statement_type *) NULL,
                          &(statement_list.head), 0, (bfd_vma) 0, false);
 
+      /* Move the global symbols around so the second pass of relaxing
+        can see them.  */
+      lang_relocate_globals ();
 
+      reset_memory_regions ();
 
-  /* Move the global symbols around so the second pass of relaxing can
-     see them */
-  lang_relocate_globals ();
-
-  reset_memory_regions ();
-
-  /* Do all the assignments, now that we know the final restingplaces
-     of all the symbols */
-
-  lang_do_assignments (statement_list.head,
-                      abs_output_section,
-                      0, (bfd_vma) 0);
+      /* Do all the assignments, now that we know the final resting
+        places of all the symbols.  */
 
+      lang_do_assignments (statement_list.head,
+                          abs_output_section,
+                          0, (bfd_vma) 0);
 
       /* Perform another relax pass - this time we know where the
-        globals are, so can make better guess */
+        globals are, so can make better guess */
       lang_size_sections (statement_list.head,
                          (lang_output_section_statement_type *) NULL,
                          &(statement_list.head), 0, (bfd_vma) 0, true);
-
-
-
     }
-
   else
     {
-      /* Size up the sections */
+      /* Size up the sections */
       lang_size_sections (statement_list.head,
                          abs_output_section,
                          &(statement_list.head), 0, (bfd_vma) 0, false);
-
     }
 
-
   /* See if anything special should be done now we know how big
-     everything is */
+     everything is */
   ldemul_after_allocation ();
 
   /* Do all the assignments, now that we know the final restingplaces
@@ -2576,6 +2568,12 @@ lang_process ()
   lang_check ();
 
   /* Final stuffs */
+
+  ldemul_finish ();
+  /* Size up the sections.  */
+  lang_size_sections (statement_list.head,
+                     abs_output_section,
+                     &(statement_list.head), 0, (bfd_vma) 0, false);
   lang_finish ();
 }
 
@@ -2694,7 +2692,7 @@ lang_startup (name)
 {
   if (startup_file != (char *) NULL)
     {
-      einfo ("%P%FMultiple STARTUP files\n");
+      einfo ("%P%Fmultiple STARTUP files\n");
     }
   first_file->filename = name;
   first_file->local_sym_name = name;
This page took 0.032516 seconds and 4 git commands to generate.