From bcb674cff702e0b46719839a0af4e1ab1619918c Mon Sep 17 00:00:00 2001 From: Richard Sandiford Date: Thu, 29 Mar 2007 17:16:05 +0000 Subject: [PATCH] ld/ 200x-xx-xx Richard Sandiford Daniel Jacobowitz * 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. --- ld/ChangeLog | 9 +++++++++ ld/NEWS | 3 +++ ld/ld.texinfo | 29 ++++++++++++++++------------- ld/ldlang.c | 8 ++++++++ ld/testsuite/ChangeLog | 5 +++++ ld/testsuite/ld-libs/lib-1.s | 2 ++ ld/testsuite/ld-libs/lib-2.d | 4 ++++ ld/testsuite/ld-libs/lib-2.s | 2 ++ ld/testsuite/ld-libs/libs.exp | 9 +++++++++ 9 files changed, 58 insertions(+), 13 deletions(-) create mode 100644 ld/testsuite/ld-libs/lib-1.s create mode 100644 ld/testsuite/ld-libs/lib-2.d create mode 100644 ld/testsuite/ld-libs/lib-2.s create mode 100644 ld/testsuite/ld-libs/libs.exp diff --git a/ld/ChangeLog b/ld/ChangeLog index 372a5d2179c..13e1e7deb21 100644 --- a/ld/ChangeLog +++ b/ld/ChangeLog @@ -1,3 +1,12 @@ +2007-03-29 Richard Sandiford + Daniel Jacobowitz + + * 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. + 2007-03-28 Richard Sandiford * ld.h (ld_config_type): Add rpath_separator. diff --git a/ld/NEWS b/ld/NEWS index 48e4432aebf..cbce99ccec2 100644 --- a/ld/NEWS +++ b/ld/NEWS @@ -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. diff --git a/ld/ld.texinfo b/ld/ld.texinfo index 8dfb4ab09f7..8d40f80c6cd 100644 --- a/ld/ld.texinfo +++ b/ld/ld.texinfo @@ -614,21 +614,24 @@ of the function. By default, the linker uses @code{_init} as the 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 diff --git a/ld/ldlang.c b/ld/ldlang.c index 85dd2719380..7731bfbea5e 100644 --- a/ld/ldlang.c +++ b/ld/ldlang.c @@ -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: diff --git a/ld/testsuite/ChangeLog b/ld/testsuite/ChangeLog index b57388a4046..0893e8e14ad 100644 --- a/ld/testsuite/ChangeLog +++ b/ld/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2007-03-29 Richard Sandiford + + * ld-libs/lib-1.s, ld-libs/lib-2.s, ld-libs/lib-2.d, + * ld-libs/libs.exp: New files. + 2007-03-28 Richard Sandiford * ld-vxworks/rpath-1.s, ld-vxworks/rpath-1.d, diff --git a/ld/testsuite/ld-libs/lib-1.s b/ld/testsuite/ld-libs/lib-1.s new file mode 100644 index 00000000000..7cc5e1d68c2 --- /dev/null +++ b/ld/testsuite/ld-libs/lib-1.s @@ -0,0 +1,2 @@ + .globl foo + .set foo,0x2000 diff --git a/ld/testsuite/ld-libs/lib-2.d b/ld/testsuite/ld-libs/lib-2.d new file mode 100644 index 00000000000..b055417d5ea --- /dev/null +++ b/ld/testsuite/ld-libs/lib-2.d @@ -0,0 +1,4 @@ +#... +0+1000 A bar +0+2000 A foo +#pass diff --git a/ld/testsuite/ld-libs/lib-2.s b/ld/testsuite/ld-libs/lib-2.s new file mode 100644 index 00000000000..af749d38e03 --- /dev/null +++ b/ld/testsuite/ld-libs/lib-2.s @@ -0,0 +1,2 @@ + .globl bar + .set bar,0x1000 diff --git a/ld/testsuite/ld-libs/libs.exp b/ld/testsuite/ld-libs/libs.exp new file mode 100644 index 00000000000..8609d652958 --- /dev/null +++ b/ld/testsuite/ld-libs/libs.exp @@ -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"} +}