User account creation filtered due to spam.

Bug 50250 - Driver documentation on -l does not mention shared libraries
Summary: Driver documentation on -l does not mention shared libraries
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: driver (show other bugs)
Version: 4.7.0
: P3 minor
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: documentation
: 69540 77275 (view as bug list)
Depends on:
Blocks:
 
Reported: 2011-08-31 12:21 UTC by Richard Biener
Modified: 2016-08-25 01:29 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2016-08-17 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Richard Biener 2011-08-31 12:21:39 UTC
Forwarded from http://bugzilla.novell.com/show_bug.cgi?id=674696

The documentation says

-----------
@cindex Libraries
@item -l@var{library}
@itemx -l @var{library}
@opindex l
Search the library named @var{library} when linking.  (The second
alternative with the library as a separate argument is only for
POSIX compliance and is not recommended.)

It makes a difference where in the command you write this option; the
linker searches and processes libraries and object files in the order they
are specified.  Thus, @samp{foo.o -lz bar.o} searches library @samp{z}
after file @file{foo.o} but before @file{bar.o}.  If @file{bar.o} refers
to functions in @samp{z}, those functions may not be loaded.

The linker searches a standard list of directories for the library,
which is actually a file named @file{lib@var{library}.a}.  The linker
then uses this file as if it had been specified precisely by name.

The directories searched include several standard system directories
plus any that you specify with @option{-L}.

Normally the files found this way are library files---archive files
whose members are object files.  The linker handles an archive file by
scanning through it for members which define symbols that have so far
been referenced but not defined.  But if the file that is found is an
ordinary object file, it is linked in the usual fashion.  The only
difference between using an @option{-l} option and specifying a file name
is that @option{-l} surrounds @var{library} with @samp{lib} and @samp{.a}
and searches several directories.
--------

note how it specifically mentions -lX searches for libX.a.  But:

gcc t.c -lX

also finds libX.so which it should not, according to the above documentation.

The documentation should be clarified and refer to whatever used target linker
documentation.
Comment 1 Andrew Pinski 2016-08-17 22:34:15 UTC
*** Bug 77275 has been marked as a duplicate of this bug. ***
Comment 2 Andrew Pinski 2016-08-17 22:34:32 UTC
*** Bug 69540 has been marked as a duplicate of this bug. ***
Comment 3 Andrew Pinski 2016-08-17 22:35:28 UTC
Confirmed.

Really this documentation should just point to ld's documentation on your system since -l is passed directly without any change.  As it is also incorrect for windows systems.
Comment 4 Tom Payerle 2016-08-24 22:24:39 UTC
In the interest of actually getting this fixed, may I suggest the following
revised wording:
----------------
Search the library named @var{library} when linking.  (The second
alternative with the library as a separate argument is only for
POSIX compliance and is not recommended.)

This is actually just passed directly to the linker, so the exact behavior is dependent on your linker.  The description below is provided as a courtesy to users; your linker documentation should be considered definitive and should be referred to for more details.

Typically, the linker will search a list of directories for a library with a
name matching @var{library}.  On Unix-like systems, this is usually a file
named @file{lib@var{library}.@var{ext}} where @var{ext} is @samp{.a} for static libraries or @samp{.so} for dynamic libraries.  The list of directories searched
typically consists of several standard directories (system dependent) as well as
directories added with the @option{-L} option.

Note that in general it makes a difference where in the command you write this option: the linker typically processes libraries and object files in the order they are specified.  Symbols in object files (or even other libraries specified with the @samp{-l} option) that follow the @samp{-l@var{library}} option on the command line might not get resolved.  
----------------

I think the above provides the same basic information as the original to the casual reader while making it clear that one needs to read the linker documentation for details.
Comment 5 Manuel López-Ibáñez 2016-08-25 01:29:35 UTC
(In reply to Tom Payerle from comment #4)
> In the interest of actually getting this fixed, may I suggest the following
> revised wording:

Create a diff patch against ^/trunk:

See point 8 here: https://gcc.gnu.org/wiki/GettingStarted#Basics:_Contributing_to_GCC_in_10_easy_steps

Send to gcc-patches with "[doc]" somewhere in the subject (see examples of subjects in the archives: https://gcc.gnu.org/ml/gcc-patches/

CC docs co-maintainers (you can find their emails in the MAINTAINERS file).