This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Reject multiple -o options


In fixing GCC PR driver/13577, I discovered both gas and ld silently
allow multiple -o options.  This patch fixes that.

Tested on i686-pc-linux-gnu, and manually for multiple -o usage

ok?

nathan
--
Nathan Sidwell    ::   http://www.codesourcery.com   ::     CodeSourcery LLC
nathan@codesourcery.com    ::     http://www.planetfall.pwp.blueyonder.co.uk

2004-03-05  Nathan Sidwell  <nathan@codesourcery.com>

	* as.c (parse_args): Reject multiple -o options.
	(main): Move default setting of output name.

	* ldlang.c (had_output_filename): Move into ...
	(lang_add_output): ... here.  Detect multiple settings.

Index: gas/as.c
===================================================================
RCS file: /cvs/src/src/gas/as.c,v
retrieving revision 1.51
diff -c -3 -p -r1.51 as.c
*** gas/as.c	27 Oct 2003 12:45:17 -0000	1.51
--- gas/as.c	5 Mar 2004 14:13:56 -0000
*************** the GNU General Public License.  This pr
*** 795,800 ****
--- 795,802 ----
  	  }
  
  	case 'o':
+ 	  if (out_file_name)
+ 	    as_fatal (_("output filename specified twice"));
  	  out_file_name = xstrdup (optarg);
  	  break;
  
*************** main (int argc, char ** argv)
*** 1008,1019 ****
  
    START_PROGRESS (myname, 0);
  
- #ifndef OBJ_DEFAULT_OUTPUT_FILE_NAME
- #define OBJ_DEFAULT_OUTPUT_FILE_NAME "a.out"
- #endif
- 
-   out_file_name = OBJ_DEFAULT_OUTPUT_FILE_NAME;
- 
    hex_init ();
  #ifdef BFD_ASSEMBLER
    bfd_init ();
--- 1010,1015 ----
*************** main (int argc, char ** argv)
*** 1029,1034 ****
--- 1025,1035 ----
    frag_init ();
    subsegs_begin ();
    parse_args (&argc, &argv);
+ #ifndef OBJ_DEFAULT_OUTPUT_FILE_NAME
+ #define OBJ_DEFAULT_OUTPUT_FILE_NAME "a.out"
+ #endif
+   if (!out_file_name)
+     out_file_name = OBJ_DEFAULT_OUTPUT_FILE_NAME;
    read_begin ();
    input_scrub_begin ();
    expr_begin ();
Index: ld/ldlang.c
===================================================================
RCS file: /cvs/src/src/ld/ldlang.c,v
retrieving revision 1.140
diff -c -3 -p -r1.140 ldlang.c
*** ld/ldlang.c	5 Mar 2004 11:26:04 -0000	1.140
--- ld/ldlang.c	5 Mar 2004 14:14:15 -0000
*************** struct bfd_sym_chain entry_symbol = { NU
*** 93,99 ****
  const char *entry_section = ".text";
  bfd_boolean entry_from_cmdline;
  bfd_boolean lang_has_input_file = FALSE;
- bfd_boolean had_output_filename = FALSE;
  bfd_boolean lang_float_flag = FALSE;
  bfd_boolean delete_output_file_on_failure = FALSE;
  struct lang_nocrossrefs *nocrossref_list;
--- 93,98 ----
*************** ldlang_add_file (lang_input_statement_ty
*** 3991,4002 ****
  void
  lang_add_output (const char *name, int from_script)
  {
    /* Make -o on command line override OUTPUT in script.  */
!   if (!had_output_filename || !from_script)
      {
        output_filename = name;
!       had_output_filename = TRUE;
      }
  }
  
  static lang_output_section_statement_type *current_section;
--- 3990,4006 ----
  void
  lang_add_output (const char *name, int from_script)
  {
+ static int had_output_filename = 0;
+  int priority = 2 - from_script;
+ 
    /* Make -o on command line override OUTPUT in script.  */
!   if (had_output_filename < priority)
      {
        output_filename = name;
!       had_output_filename = priority;
      }
+   else if (had_output_filename == priority)
+     einfo (_("%P%F:output filename specified twice"));
  }
  
  static lang_output_section_statement_type *current_section;

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]