This is the mail archive of the binutils@sourceware.org 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]

Add a -l:foo option


This patch makes "-l:foo" look for a file called exactly "foo", rather
than the usual "libfoo.a" or "libfoo.so".  This extension has been in
the VxWorks versions of binutils for a while now and I thought it might
be useful to a wider audience.  (E.g., I know I've wanted to do this
before in order to pick up board-specific crt files.)

Tested on:

    arm-aout
    arm-elf
    arm-wrs-vxworks
    i386-freebsd
    i386-linux-gnu
    i586-wrs-vxworks
    i686-mingw32
    mips-wrs-vxworks
    powerpc-wrs-vxworks
    sh-wrs-vxworks
    sparc64-linux-gnu
    sparc-linux-gnu
    sparc-netbsdelf
    sparc-sun-solaris2.6
    sparc-sun-solaris2.8
    sparc-wrs-vxworks
    x86_64-linux-gnu

OK to install?

Richard


ld/
200x-xx-xx  Richard Sandiford  <richard@codesourcery.com>
	    Daniel Jacobowitz  <dan@codesourcery.com>

	* NEWS: Mention -l:foo.
	* ld.texinfo: Document it.
	* ldlang.c (new_afile): If a lang_input_file_is_l_enum
	entry as a name beginning with a coloh, convert it to a
	lang_input_file_is_search_file_enum entry without the colon.

ld/testsuite/
	* ld-libs/lib-1.s, ld-libs/lib-2.s, ld-libs/lib-2.d,
	* ld-libs/libs.exp: New files.

Index: ld/NEWS
===================================================================
RCS file: /cvs/src/src/ld/NEWS,v
retrieving revision 1.73
diff -u -p -r1.73 NEWS
--- ld/NEWS	29 Jan 2007 16:28:40 -0000	1.73
+++ ld/NEWS	28 Mar 2007 13:49:51 -0000
@@ -1,4 +1,7 @@
 -*- text -*-
+* -l:foo now searches the library path for a filename called foo,
+  without converting it to libfoo.a or libfoo.so.
+
 * Add a new command line option '--default-script=FILE' or '-dT FILE'
   which specifies a replacement for the built in, default linker
   script.
Index: ld/ld.texinfo
===================================================================
RCS file: /cvs/src/src/ld/ld.texinfo,v
retrieving revision 1.191
diff -u -p -r1.191 ld.texinfo
--- ld/ld.texinfo	28 Mar 2007 09:08:52 -0000	1.191
+++ ld/ld.texinfo	28 Mar 2007 13:49:54 -0000
@@ -614,21 +614,24 @@ of the function.  By default, the linker
 function to call.
 
 @cindex archive files, from cmd line
-@kindex -l@var{archive}
-@kindex --library=@var{archive}
-@item -l@var{archive}
-@itemx --library=@var{archive}
-Add archive file @var{archive} to the list of files to link.  This
-option may be used any number of times.  @command{ld} will search its
-path-list for occurrences of @code{lib@var{archive}.a} for every
-@var{archive} specified.
+@kindex -l@var{namespec}
+@kindex --library=@var{namespec}
+@item -l@var{namespec}
+@itemx --library=@var{namespec}
+Add the archive or object file specified by @var{namespec} to the
+list of files to link.  This option may be used any number of times.
+If @var{namespec} is of the form @file{:@var{filename}}, @command{ld}
+will search the library path for a file called @var{filename}, otherise it
+will search the library path for a file called @file{lib@var{namespec}.a}.
 
 On systems which support shared libraries, @command{ld} may also search for
-libraries with extensions other than @code{.a}.  Specifically, on ELF
-and SunOS systems, @command{ld} will search a directory for a library with
-an extension of @code{.so} before searching for one with an extension of
-@code{.a}.  By convention, a @code{.so} extension indicates a shared
-library.
+files other than @file{lib@var{namespec}.a}.  Specifically, on ELF
+and SunOS systems, @command{ld} will search a directory for a library
+called @file{lib@var{namespec}.so} before searching for one called
+@file{lib@var{namespec}.a}.  (By convention, a @code{.so} extension
+indicates a shared library.)  Note that this behavior does not apply
+to @file{:@var{filename}}, which always specifies a file called
+@var{filename}.
 
 The linker will search an archive only once, at the location where it is
 specified on the command line.  If the archive defines a symbol which
Index: ld/ldlang.c
===================================================================
RCS file: /cvs/src/src/ld/ldlang.c,v
retrieving revision 1.255
diff -u -p -r1.255 ldlang.c
--- ld/ldlang.c	26 Mar 2007 11:10:44 -0000	1.255
+++ ld/ldlang.c	28 Mar 2007 13:49:55 -0000
@@ -913,6 +913,14 @@ new_afile (const char *name,
   lang_has_input_file = TRUE;
   p->target = target;
   p->sysrooted = FALSE;
+
+  if (file_type == lang_input_file_is_l_enum
+      && name[0] == ':' && name[1] != '\0')
+    {
+      file_type = lang_input_file_is_search_file_enum;
+      name = name + 1;
+    }
+
   switch (file_type)
     {
     case lang_input_file_is_symbols_only_enum:
Index: ld/testsuite/ld-libs/lib-1.s
===================================================================
--- ld/testsuite/ld-libs/lib-1.s.1	1970-01-01 01:00:00.000000000 +0100
+++ ld/testsuite/ld-libs/lib-1.s	2007-03-28 11:56:14.000000000 +0100
@@ -0,0 +1,2 @@
+	.globl	foo
+	.set	foo,0x2000
Index: ld/testsuite/ld-libs/lib-2.s
===================================================================
--- ld/testsuite/ld-libs/lib-2.s.1	1970-01-01 01:00:00.000000000 +0100
+++ ld/testsuite/ld-libs/lib-2.s	2007-03-28 11:56:08.000000000 +0100
@@ -0,0 +1,2 @@
+	.globl	bar
+	.set	bar,0x1000
Index: ld/testsuite/ld-libs/lib-2.d
===================================================================
--- ld/testsuite/ld-libs/lib-2.d.1	1970-01-01 01:00:00.000000000 +0100
+++ ld/testsuite/ld-libs/lib-2.d	2007-03-28 14:24:48.000000000 +0100
@@ -0,0 +1,4 @@
+#...
+0+1000 A bar
+0+2000 A foo
+#pass
Index: ld/testsuite/ld-libs/libs.exp
===================================================================
--- ld/testsuite/ld-libs/libs.exp.1	1970-01-01 01:00:00.000000000 +0100
+++ ld/testsuite/ld-libs/libs.exp	2007-03-28 13:12:54.000000000 +0100
@@ -0,0 +1,9 @@
+file mkdir tmpdir/libtmp
+
+# Check that -l: works.  The first "test" just creates an object file
+# for the second one.
+run_ld_link_tests {
+    {"-l: test (preparation)" "-r" "" {lib-1.s} {} "libtmp/anobject"}
+    {"-l: test" "-r -Ltmpdir/libtmp -l:anobject" "" {lib-2.s}
+     {{nm -C lib-2.d}} "lib-2"}
+}


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