Patch to add --warn-error flag to ld

J.T. Conklin jtc@redback.com
Tue Mar 6 16:47:00 GMT 2001


Since it seems some of my users don't seem to notice linker warnings,
I'd like to add a flag to turn warnings to errors, similar to gcc's
-Werror.

The enclosed patch is submitted for consideration.  In vfinfo(),
config.make_executable is set to false when config.warn_error is true.
It may be better to move this check from vfinfo() to einfo(), so that
calls to info_msg() (which may be benign messages, rather than warnings)
don't cause the link to fail.

        --jtc


2001-03-06  J.T. Conklin  <jtc@redback.com>

	* ld.texinfo: Document --warn-error.

	* ldmisc.c (vfinfo): Set flag to inhibit making executable if
 	warnings have been turned into errors.
	* lexsup.c (OPTION_WARN_ERROR): Define.
	(ld_options): Entry for --warn-error.
	(parse_args): Handle OPTION_WARN_ERROR.
	* ld.h (ld_config_type): Add warn_error.

Index: ld.h
===================================================================
RCS file: /cvs/src/src/ld/ld.h,v
retrieving revision 1.9
diff -c -r1.9 ld.h
*** ld.h	2000/10/09 15:09:17	1.9
--- ld.h	2001/03/06 23:20:09
***************
*** 192,197 ****
--- 192,200 ----
       changes due to the alignment of an input section.  */
    boolean warn_section_align;
  
+   /* If true, warning messages are fatal */
+   boolean warn_error;
+ 
    boolean sort_common;
  
    boolean text_read_only;
Index: ld.texinfo
===================================================================
RCS file: /cvs/src/src/ld/ld.texinfo,v
retrieving revision 1.33
diff -c -r1.33 ld.texinfo
*** ld.texinfo	2001/01/14 04:36:34	1.33
--- ld.texinfo	2001/03/06 23:20:13
***************
*** 1245,1250 ****
--- 1245,1254 ----
  is only meaningful on ELF platforms which support shared libraries.
  @xref{VERSION}.
  
+ @kindex --warn-error
+ @item --warn-error
+ Make all warnings into errors.
+ 
  @kindex --warn-comon
  @cindex warnings, on combining symbols
  @cindex combining symbols, warnings on
Index: ldmisc.c
===================================================================
RCS file: /cvs/src/src/ld/ldmisc.c,v
retrieving revision 1.4
diff -c -r1.4 ldmisc.c
*** ldmisc.c	2000/09/21 20:21:59	1.4
--- ldmisc.c	2001/03/06 23:20:14
***************
*** 399,404 ****
--- 399,407 ----
  	}
      }
  
+   if (config.warn_error)
+     config.make_executable = false;
+ 
    if (fatal == true)
      xexit (1);
  }
Index: lexsup.c
===================================================================
RCS file: /cvs/src/src/ld/lexsup.c,v
retrieving revision 1.29
diff -c -r1.29 lexsup.c
*** lexsup.c	2001/01/14 04:36:34	1.29
--- lexsup.c	2001/03/06 23:20:16
***************
*** 108,114 ****
  #define OPTION_VERSION_EXPORTS_SECTION	(OPTION_VERSION_SCRIPT + 1)
  #define OPTION_WARN_COMMON		(OPTION_VERSION_EXPORTS_SECTION + 1)
  #define OPTION_WARN_CONSTRUCTORS	(OPTION_WARN_COMMON + 1)
! #define OPTION_WARN_MULTIPLE_GP		(OPTION_WARN_CONSTRUCTORS + 1)
  #define OPTION_WARN_ONCE		(OPTION_WARN_MULTIPLE_GP + 1)
  #define OPTION_WARN_SECTION_ALIGN	(OPTION_WARN_ONCE + 1)
  #define OPTION_SPLIT_BY_RELOC		(OPTION_WARN_SECTION_ALIGN + 1)
--- 108,115 ----
  #define OPTION_VERSION_EXPORTS_SECTION	(OPTION_VERSION_SCRIPT + 1)
  #define OPTION_WARN_COMMON		(OPTION_VERSION_EXPORTS_SECTION + 1)
  #define OPTION_WARN_CONSTRUCTORS	(OPTION_WARN_COMMON + 1)
! #define OPTION_WARN_ERROR		(OPTION_WARN_CONSTRUCTORS + 1)
! #define OPTION_WARN_MULTIPLE_GP		(OPTION_WARN_ERROR + 1)
  #define OPTION_WARN_ONCE		(OPTION_WARN_MULTIPLE_GP + 1)
  #define OPTION_WARN_SECTION_ALIGN	(OPTION_WARN_ONCE + 1)
  #define OPTION_SPLIT_BY_RELOC		(OPTION_WARN_SECTION_ALIGN + 1)
***************
*** 377,382 ****
--- 378,386 ----
    { {"warn-constructors", no_argument, NULL, OPTION_WARN_CONSTRUCTORS},
        '\0', NULL, N_("Warn if global constructors/destructors are seen"),
        TWO_DASHES },
+   { {"warn-error", no_argument, NULL, OPTION_WARN_ERROR},
+      '\0', NULL, N_("Warning messages are fatal"),
+      TWO_DASHES },
    { {"warn-multiple-gp", no_argument, NULL, OPTION_WARN_MULTIPLE_GP},
        '\0', NULL, N_("Warn if the multiple GP values are used"), TWO_DASHES },
    { {"warn-once", no_argument, NULL, OPTION_WARN_ONCE},
***************
*** 1027,1032 ****
--- 1031,1039 ----
  	  break;
  	case OPTION_WARN_CONSTRUCTORS:
  	  config.warn_constructors = true;
+ 	  break;
+ 	case OPTION_WARN_ERROR:
+ 	  config.warn_error = true;
  	  break;
  	case OPTION_WARN_MULTIPLE_GP:
  	  config.warn_multiple_gp = true;


-- 
J.T. Conklin
RedBack Networks



More information about the Binutils mailing list