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]

[PATCH RFA] Add support for a 'ld -nostdlib' flag.


The following patch adds a '-nostdlib' flag to ld.

NetBSD has supported this flag in its linker (GNU ld w/ local mods,
this being one 8-) for years, as a way to get the linker to ignore
"built-in" library paths (e.g. library paths from the built in or
explicitly-specified linker scripts) in various circumstances.

Anyway, the following is a reimplementation from scratch, which causes
'ld' to ignore all library paths not explicitly specified on the
command line.  That's a slightly different meaning of the flag than
used historically in NetBSD, but due to a quirk of the NetBSD ld build
process (SCRIPTDIR was set incorrectly) the result is the same, and
the change is (IMO) cleaner.

I've verified that this change is OK with the person who's doing most
of the NetBSD tool maintenance (in NetBSD) these days.  I've been
running with it in my sources here for a While (and using it to build
NetBSD bits 8-).


So, what say you?



chris
===================================================================
2001-11-01  Chris Demetriou  <cgd@broadcom.com>

	* ld.texinfo (Options): Document new option, -nostdlib.
	* lexsup.c (OPTION_NOSTDLIB): New definition.
	(ld_options): Add entry for "nostdlib".
	(parse_args): Handle OPTIONS_NOSTDLIB.
	* ldfile.c (ldfile_add_library_path): Don't add directories
	to the search path if they weren't specified on the command line
	and -nostdlib was specified.
	* ld.h (ld_config_type): New member only_cmd_line_lib_dirs.

Index: ld.h
===================================================================
RCS file: /cvs/src/src/ld/ld.h,v
retrieving revision 1.15
diff -u -r1.15 ld.h
--- ld.h	2001/09/29 12:57:54	1.15
+++ ld.h	2001/11/01 22:46:55
@@ -214,6 +214,10 @@
 
   unsigned int split_by_reloc;
   bfd_size_type split_by_file;
+
+  /* If set, only search library directories explicitly selected
+     on the command line.  */
+  boolean only_cmd_line_lib_dirs;
 } ld_config_type;
 
 extern ld_config_type config;
Index: ld.texinfo
===================================================================
RCS file: /cvs/src/src/ld/ld.texinfo,v
retrieving revision 1.55
diff -u -r1.55 ld.texinfo
--- ld.texinfo	2001/10/31 14:19:22	1.55
+++ ld.texinfo	2001/11/01 22:46:56
@@ -1110,6 +1110,12 @@
 errors during the link process; it exits without writing an output file
 when it issues any error whatsoever.
 
+@kindex -nostdlib
+@item -nostdlib
+Only search library directories explicitly specified on the
+command line.  Library directories specified in linker scripts
+(including linker scripts specified on the command line) are ignored.
+
 @ifclear SingleFormat
 @kindex --oformat
 @item --oformat @var{output-format}
Index: ldfile.c
===================================================================
RCS file: /cvs/src/src/ld/ldfile.c,v
retrieving revision 1.13
diff -u -r1.13 ldfile.c
--- ldfile.c	2001/09/19 05:33:33	1.13
+++ ldfile.c	2001/11/01 22:46:56
@@ -79,6 +79,9 @@
 {
   search_dirs_type *new;
 
+  if (!cmdline && config.only_cmd_line_lib_dirs)
+    return;
+
   new = (search_dirs_type *) xmalloc (sizeof (search_dirs_type));
   new->next = NULL;
   new->name = name;
Index: lexsup.c
===================================================================
RCS file: /cvs/src/src/ld/lexsup.c,v
retrieving revision 1.43
diff -u -r1.43 lexsup.c
--- lexsup.c	2001/10/31 15:41:19	1.43
+++ lexsup.c	2001/11/01 22:46:56
@@ -133,6 +133,7 @@
 #define OPTION_DISCARD_NONE		(OPTION_ALLOW_SHLIB_UNDEFINED + 1)
 #define OPTION_SPARE_DYNAMIC_TAGS	(OPTION_DISCARD_NONE + 1)
 #define OPTION_NO_DEFINE_COMMON		(OPTION_SPARE_DYNAMIC_TAGS + 1)
+#define OPTION_NOSTDLIB			(OPTION_NO_DEFINE_COMMON + 1)
 
 /* The long options.  This structure is used for both the option
    parsing and the help text.  */
@@ -330,6 +331,8 @@
       '\0', NULL, N_("Create an output file even if errors occur"), TWO_DASHES },
   { {"noinhibit_exec", no_argument, NULL, OPTION_NOINHIBIT_EXEC},
       '\0', NULL, NULL, NO_HELP },
+  { {"nostdlib", no_argument, NULL, OPTION_NOSTDLIB},
+      '\0', NULL, N_("Only use library directories specified on\n\t\t\t\tthe command line"), ONE_DASH },
   { {"oformat", required_argument, NULL, OPTION_OFORMAT},
       '\0', N_("TARGET"), N_("Specify target of output file"), EXACTLY_TWO_DASHES },
   { {"qmagic", no_argument, NULL, OPTION_IGNORE},
@@ -770,6 +773,9 @@
 	  break;
 	case OPTION_NOINHIBIT_EXEC:
 	  force_make_executable = true;
+	  break;
+	case OPTION_NOSTDLIB:
+	  config.only_cmd_line_lib_dirs = true;
 	  break;
 	case OPTION_NO_WHOLE_ARCHIVE:
 	  whole_archive = false;


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