* ld-elfweak/dsow.dsym: Adjust for non-zero ST_OTHER.
[binutils-gdb.git] / gas / as.c
index 5a5f823c7aef1509905b45e6d957f0382ed956db..0d5b46cc3d489f21d738d48cb537c0ab1938ff7d 100644 (file)
--- a/gas/as.c
+++ b/gas/as.c
@@ -1,6 +1,6 @@
 /* as.c - GAS main program.
    Copyright 1987, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
-   1999, 2000, 2001, 2002
+   1999, 2000, 2001, 2002, 2003, 2004, 2005
    Free Software Foundation, Inc.
 
    This file is part of GAS, the GNU Assembler.
@@ -17,8 +17,8 @@
 
    You should have received a copy of the GNU General Public License
    along with GAS; see the file COPYING.  If not, write to the Free
-   Software Foundation, 59 Temple Place - Suite 330, Boston, MA
-   02111-1307, USA.  */
+   Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
+   02110-1301, USA.  */
 
 /* Main program for AS; a 32-bit assembler of GNU.
    Understands command arguments.
@@ -42,6 +42,7 @@
 #include "macro.h"
 #include "dwarf2dbg.h"
 #include "dw2gencfi.h"
+#include "hash.h"
 
 #ifdef BFD_ASSEMBLER
 #include "bfdver.h"
@@ -87,12 +88,18 @@ int listing;
 
 /* Type of debugging to generate.  */
 enum debug_info_type debug_type = DEBUG_UNSPECIFIED;
+int use_gnu_debug_info_extensions = 0;
+
+#ifndef MD_DEBUG_FORMAT_SELECTOR
+#define MD_DEBUG_FORMAT_SELECTOR NULL
+#endif
+static enum debug_info_type (*md_debug_format_selector) (int *) = MD_DEBUG_FORMAT_SELECTOR;
 
 /* Maximum level of macro nesting.  */
 int max_macro_nest = 100;
 
 /* argv[0]  */
-char * myname;
+static char * myname;
 
 /* The default obstack chunk size.  If we set this to zero, the
    obstack code will use whatever will fit in a 4096 byte block.  */
@@ -122,6 +129,8 @@ static struct itbl_file_list *itbl_files;
 
 static long start_time;
 
+static int flag_macro_alternate;
+
 \f
 #ifdef USE_EMULATIONS
 #define EMULATION_ENVIRON "AS_EMULATION"
@@ -243,6 +252,8 @@ Options:\n\
                          s      include symbols\n\
                          =FILE  list to FILE (must be last sub-option)\n"));
 
+  fprintf (stream, _("\
+  --alternate             initially turn on alternate macro syntax\n"));
   fprintf (stream, _("\
   -D                      produce assembler debugging messages\n"));
   fprintf (stream, _("\
@@ -274,9 +285,15 @@ Options:\n\
   fprintf (stream, _("\
   -f                      skip whitespace and comment preprocessing\n"));
   fprintf (stream, _("\
-  --gstabs                generate stabs debugging information\n"));
+  -g --gen-debug          generate debugging information\n"));
+  fprintf (stream, _("\
+  --gstabs                generate STABS debugging information\n"));
   fprintf (stream, _("\
-  --gdwarf2               generate DWARF2 debugging information\n"));
+  --gstabs+               generate STABS debug info with GNU extensions\n"));
+  fprintf (stream, _("\
+  --gdwarf-2              generate DWARF2 debugging information\n"));
+  fprintf (stream, _("\
+  --hash-size=<value>     set the hash table size close to <value>\n"));
   fprintf (stream, _("\
   --help                  show this message and exit\n"));
   fprintf (stream, _("\
@@ -300,6 +317,10 @@ Options:\n\
   fprintf (stream, _("\
   -R                      fold data section into text section\n"));
   fprintf (stream, _("\
+  --reduce-memory-overheads \n\
+                          prefer smaller memory use at the cost of longer\n\
+                          assembly times\n"));
+  fprintf (stream, _("\
   --statistics            print various measured statistics from execution\n"));
   fprintf (stream, _("\
   --strip-local-absolute  strip local absolute symbols\n"));
@@ -371,7 +392,7 @@ parse_args (int * pargc, char *** pargv)
     /* -K is not meaningful if .word is not being hacked.  */
     'K',
 #endif
-    'L', 'M', 'R', 'W', 'Z', 'a', ':', ':', 'D', 'I', ':', 'o', ':',
+    'L', 'M', 'R', 'W', 'Z', 'a', ':', ':', 'D', 'f', 'g', ':',':', 'I', ':', 'o', ':',
 #ifndef VMS
     /* -v takes an argument on VMS, so we don't make it a generic
        option.  */
@@ -403,65 +424,78 @@ parse_args (int * pargc, char *** pargv)
       OPTION_LISTING_CONT_LINES,
       OPTION_DEPFILE,
       OPTION_GSTABS,
+      OPTION_GSTABS_PLUS,
+      OPTION_GDWARF2,
       OPTION_STRIP_LOCAL_ABSOLUTE,
       OPTION_TRADITIONAL_FORMAT,
-      OPTION_GDWARF2,
       OPTION_WARN,
       OPTION_TARGET_HELP,
       OPTION_EXECSTACK,
       OPTION_NOEXECSTACK,
+      OPTION_ALTERNATE,
+      OPTION_HASH_TABLE_SIZE,
+      OPTION_REDUCE_MEMORY_OVERHEADS,
       OPTION_WARN_FATAL
+    /* When you add options here, check that they do
+       not collide with OPTION_MD_BASE.  See as.h.  */
     };
   
   static const struct option std_longopts[] =
   {
-    {"help", no_argument, NULL, OPTION_HELP},
-    /* getopt allows abbreviations, so we do this to stop it from
-       treating -k as an abbreviation for --keep-locals.  Some
-       ports use -k to enable PIC assembly.  */
-    {"keep-locals", no_argument, NULL, 'L'},
-    {"keep-locals", no_argument, NULL, 'L'},
-    {"mri", no_argument, NULL, 'M'},
-    {"nocpp", no_argument, NULL, OPTION_NOCPP},
-    {"statistics", no_argument, NULL, OPTION_STATISTICS},
-    {"version", no_argument, NULL, OPTION_VERSION},
-    {"dump-config", no_argument, NULL, OPTION_DUMPCONFIG},
-    {"verbose", no_argument, NULL, OPTION_VERBOSE},
-    {"emulation", required_argument, NULL, OPTION_EMULATION},
-    {"defsym", required_argument, NULL, OPTION_DEFSYM},
+    /* Note: commas are placed at the start of the line rather than
+       the end of the preceeding line so that it is simpler to
+       selectively add and remove lines from this list.  */
+    {"alternate", no_argument, NULL, OPTION_ALTERNATE}
+    /* The entry for "a" is here to prevent getopt_long_only() from
+       considering that -a is an abbreviation for --alternate.  This is
+       necessary because -a=<FILE> is a valid switch but getopt would
+       normally reject it since --alternate does not take an argument.  */
+    ,{"a", optional_argument, NULL, 'a'}
+    ,{"defsym", required_argument, NULL, OPTION_DEFSYM}
+    ,{"dump-config", no_argument, NULL, OPTION_DUMPCONFIG}
+    ,{"emulation", required_argument, NULL, OPTION_EMULATION}
+#if defined BFD_ASSEMBLER && (defined OBJ_ELF || defined OBJ_MAYBE_ELF)
+    ,{"execstack", no_argument, NULL, OPTION_EXECSTACK}
+    ,{"noexecstack", no_argument, NULL, OPTION_NOEXECSTACK}
+#endif
+    ,{"fatal-warnings", no_argument, NULL, OPTION_WARN_FATAL}
+    ,{"gdwarf-2", no_argument, NULL, OPTION_GDWARF2}
+    /* GCC uses --gdwarf-2 but GAS uses to use --gdwarf2,
+       so we keep it here for backwards compatibility.  */
+    ,{"gdwarf2", no_argument, NULL, OPTION_GDWARF2}
+    ,{"gen-debug", no_argument, NULL, 'g'}
+    ,{"gstabs", no_argument, NULL, OPTION_GSTABS}
+    ,{"gstabs+", no_argument, NULL, OPTION_GSTABS_PLUS}
+    ,{"hash-size", required_argument, NULL, OPTION_HASH_TABLE_SIZE}
+    ,{"help", no_argument, NULL, OPTION_HELP}
     /* New option for extending instruction set (see also -t above).
        The "-t file" or "--itbl file" option extends the basic set of
        valid instructions by reading "file", a text file containing a
        list of instruction formats.  The additional opcodes and their
        formats are added to the built-in set of instructions, and
        mnemonics for new registers may also be defined.  */
-    {"itbl", required_argument, NULL, OPTION_INSTTBL},
-    {"listing-lhs-width", required_argument, NULL, OPTION_LISTING_LHS_WIDTH},
-    {"listing-lhs-width2", required_argument, NULL, OPTION_LISTING_LHS_WIDTH2},
-    {"listing-rhs-width", required_argument, NULL, OPTION_LISTING_RHS_WIDTH},
-    {"listing-cont-lines", required_argument, NULL, OPTION_LISTING_CONT_LINES},
-    {"MD", required_argument, NULL, OPTION_DEPFILE},
-    {"gstabs", no_argument, NULL, OPTION_GSTABS},
-    {"strip-local-absolute", no_argument, NULL, OPTION_STRIP_LOCAL_ABSOLUTE},
-    {"traditional-format", no_argument, NULL, OPTION_TRADITIONAL_FORMAT},
-    {"gdwarf2", no_argument, NULL, OPTION_GDWARF2},
-    {"no-warn", no_argument, NULL, 'W'},
-    {"warn", no_argument, NULL, OPTION_WARN},
-    {"target-help", no_argument, NULL, OPTION_TARGET_HELP},
-#if defined BFD_ASSEMBLER && (defined OBJ_ELF || defined OBJ_MAYBE_ELF)
-    {"execstack", no_argument, NULL, OPTION_EXECSTACK},
-    {"noexecstack", no_argument, NULL, OPTION_NOEXECSTACK},
-#endif
-    /* Treat '-f' as a long switch so that getopt will not accept
-       -f<some-text> as a synonym for -f.  This can cause confusion
-       when -f switches are passed through from the compiler.
-       FIXME - should we handle other single character switches in the
-       same way ?  */
-    {"f", no_argument, NULL, 'f'},
-    {"fatal-warnings", no_argument, NULL, OPTION_WARN_FATAL},
-    {"fatal-warnings", no_argument, NULL, OPTION_WARN_FATAL}
-    /* When you add options here, check that they do not collide with
-       OPTION_MD_BASE.  See as.h.  */
+    ,{"itbl", required_argument, NULL, OPTION_INSTTBL}
+    /* getopt allows abbreviations, so we do this to stop it from
+       treating -k as an abbreviation for --keep-locals.  Some
+       ports use -k to enable PIC assembly.  */
+    ,{"keep-locals", no_argument, NULL, 'L'}
+    ,{"keep-locals", no_argument, NULL, 'L'}
+    ,{"listing-lhs-width", required_argument, NULL, OPTION_LISTING_LHS_WIDTH}
+    ,{"listing-lhs-width2", required_argument, NULL, OPTION_LISTING_LHS_WIDTH2}
+    ,{"listing-rhs-width", required_argument, NULL, OPTION_LISTING_RHS_WIDTH}
+    ,{"listing-cont-lines", required_argument, NULL, OPTION_LISTING_CONT_LINES}
+    ,{"MD", required_argument, NULL, OPTION_DEPFILE}
+    ,{"mri", no_argument, NULL, 'M'}
+    ,{"nocpp", no_argument, NULL, OPTION_NOCPP}
+    ,{"no-warn", no_argument, NULL, 'W'}
+    ,{"reduce-memory-overheads", no_argument, NULL, OPTION_REDUCE_MEMORY_OVERHEADS}
+    ,{"statistics", no_argument, NULL, OPTION_STATISTICS}
+    ,{"strip-local-absolute", no_argument, NULL, OPTION_STRIP_LOCAL_ABSOLUTE}
+    ,{"version", no_argument, NULL, OPTION_VERSION}
+    ,{"verbose", no_argument, NULL, OPTION_VERBOSE}
+    ,{"target-help", no_argument, NULL, OPTION_TARGET_HELP}
+    ,{"traditional-format", no_argument, NULL, OPTION_TRADITIONAL_FORMAT}
+    ,{"warn", no_argument, NULL, OPTION_WARN}
   };
 
   /* Construct the option lists from the standard list and the target
@@ -503,7 +537,7 @@ parse_args (int * pargc, char *** pargv)
          if (md_parse_option (optc, optarg) != 0)
            break;
          /* `-v' isn't included in the general short_opts list, so check for
-            it explicity here before deciding we've gotten a bad argument.  */
+            it explicitly here before deciding we've gotten a bad argument.  */
          if (optc == 'v')
            {
 #ifdef VMS
@@ -522,6 +556,8 @@ parse_args (int * pargc, char *** pargv)
                verbose = 1;
              break;
            }
+         else
+           as_bad (_("unrecognized option -%c%s"), optc, optarg ? optarg : "");
          /* Fall through.  */
 
        case '?':
@@ -564,7 +600,7 @@ parse_args (int * pargc, char *** pargv)
 #else
          printf (_("GNU assembler %s\n"), VERSION);
 #endif
-         printf (_("Copyright 2002 Free Software Foundation, Inc.\n"));
+         printf (_("Copyright 2005 Free Software Foundation, Inc.\n"));
          printf (_("\
 This program is free software; you may redistribute it under the terms of\n\
 the GNU General Public License.  This program has absolutely no warranty.\n"));
@@ -650,6 +686,25 @@ the GNU General Public License.  This program has absolutely no warranty.\n"));
          start_dependencies (optarg);
          break;
 
+       case 'g':
+         /* Some backends, eg Alpha and Mips, use the -g switch for their
+            own purposes.  So we check here for an explicit -g and allow
+            the backend to decide if it wants to process it.  */
+         if (   old_argv[optind - 1][1] == 'g'
+             && md_parse_option (optc, optarg))
+           continue;
+
+         if (md_debug_format_selector)
+           debug_type = md_debug_format_selector (& use_gnu_debug_info_extensions);
+         else if (IS_ELF)
+           debug_type = DEBUG_DWARF2;
+         else
+           debug_type = DEBUG_STABS;
+         break;
+
+       case OPTION_GSTABS_PLUS:
+         use_gnu_debug_info_extensions = 1;
+         /* Fall through.  */
        case OPTION_GSTABS:
          debug_type = DEBUG_STABS;
          break;
@@ -679,6 +734,7 @@ the GNU General Public License.  This program has absolutely no warranty.\n"));
        case OPTION_LISTING_LHS_WIDTH2:
          {
            int tmp = atoi (optarg);
+
            if (tmp > listing_lhs_width)
              listing_lhs_width_second = tmp;
          }
@@ -730,9 +786,25 @@ the GNU General Public License.  This program has absolutely no warranty.\n"));
          flag_always_generate_output = 1;
          break;
 
+       case OPTION_ALTERNATE:
+         optarg = old_argv [optind - 1];
+         while (* optarg == '-')
+           optarg ++;
+
+         if (strcmp (optarg, "alternate") == 0)
+           {
+             flag_macro_alternate = 1;
+             break;
+           }
+         optarg ++;
+         /* Fall through.  */
+
        case 'a':
          if (optarg)
            {
+             if (optarg != old_argv[optind] && optarg[-1] == '=')
+               --optarg;
+
              if (md_parse_option (optc, optarg) != 0)
                break;
 
@@ -789,6 +861,7 @@ the GNU General Public License.  This program has absolutely no warranty.\n"));
        case 'I':
          {                     /* Include file directory.  */
            char *temp = xstrdup (optarg);
+
            add_include_dir (temp);
            break;
          }
@@ -803,6 +876,24 @@ the GNU General Public License.  This program has absolutely no warranty.\n"));
        case 'X':
          /* -X means treat warnings as errors.  */
          break;
+
+       case OPTION_REDUCE_MEMORY_OVERHEADS:
+         /* The only change we make at the moment is to reduce
+            the size of the hash tables that we use.  */
+         set_gas_hash_table_size (4051);
+         break;
+
+       case OPTION_HASH_TABLE_SIZE:
+         {
+           unsigned long new_size;
+
+            new_size = strtoul (optarg, NULL, 0);
+            if (new_size)
+              set_gas_hash_table_size (new_size);
+            else
+              as_fatal (_("--hash-size needs a numeric argument"));
+           break;
+         }
        }
     }
 
@@ -980,7 +1071,6 @@ perform_an_assembly_pass (int argc, char ** argv)
 int
 main (int argc, char ** argv)
 {
-  int macro_alternate;
   int macro_strip_at;
   int keep_it;
 
@@ -1024,10 +1114,12 @@ main (int argc, char ** argv)
 #endif
 
   PROGRESS (1);
+  /* Call parse_args before any of the init/begin functions
+     so that switches like --hash-size can be honored.  */
+  parse_args (&argc, &argv);
   symbol_begin ();
   frag_init ();
   subsegs_begin ();
-  parse_args (&argc, &argv);
   read_begin ();
   input_scrub_begin ();
   expr_begin ();
@@ -1035,7 +1127,6 @@ main (int argc, char ** argv)
   if (flag_print_statistics)
     xatexit (dump_statistics);
 
-  macro_alternate = 0;
   macro_strip_at = 0;
 #ifdef TC_I960
   macro_strip_at = flag_mri;
@@ -1043,11 +1134,11 @@ main (int argc, char ** argv)
 #ifdef TC_A29K
   /* For compatibility with the AMD 29K family macro assembler
      specification.  */
-  macro_alternate = 1;
+  flag_macro_alternate = 1;
   macro_strip_at = 1;
 #endif
 
-  macro_init (macro_alternate, flag_mri, macro_strip_at, macro_expr);
+  macro_init (flag_macro_alternate, flag_mri, macro_strip_at, macro_expr);
 
   PROGRESS (1);
 
@@ -1145,7 +1236,7 @@ main (int argc, char ** argv)
     keep_it = 0;
 
   if (!keep_it)
-    unlink (out_file_name);
+    unlink_if_ordinary (out_file_name);
 
   input_scrub_end ();
 
@@ -1161,4 +1252,3 @@ main (int argc, char ** argv)
 
   xexit (EXIT_SUCCESS);
 }
-