bug-binutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug ld/3612] New: --as-needed and order of libraries in linking


From: mennucc1 at debian dot org
Subject: [Bug ld/3612] New: --as-needed and order of libraries in linking
Date: 29 Nov 2006 13:32:38 -0000

hi

consider this simple file "pippo.c" , that tests linking with the dts library

vvvvvvvvvvvvvvvvvvvv
extern int dts_init();
       int main(){
           dts_init();
       }
^^^^^^^^^^^^^^^^^^^

here are some examples of compiling:
the following commands are fine:

$ gcc  -Wl,--as-needed  -o pippo pippo.c    -ldts -lm
$ gcc   -o pippo pippo.c  -lm  -ldts
$ gcc   -o pippo pippo.c    -ldts -lm

but this command fails:

$ gcc  -Wl,--as-needed  -o pippo pippo.c   -lm -ldts
/usr/lib/gcc/x86_64-linux-gnu/4.1.2/../../../../lib64/libdts.a(parse.o): In
function `dts_init':
(.text+0xcf): undefined reference to `cos'
[...]
collect2: ld returned 1 exit status


My interpretation is: 
when the linker sees '-lm', and sees that "pippo.c" is not calling anything in
it, it drops '-lm' ; then it reaches '-ldts' and links in dts_init() and finds
out that it needs sin() and cos() , and has no library to link to, and fails.

Here are two (mutually exclusive) requests:

1) you should explain this behavior in the docs;
 for example, you may add in the man page,where the option --as-needed
 is documented, a phrase as
 "When using --as-needed , the order in which the libraries appear in the
  command line is relevant: any library X
  must precede all libraries Y that offer symbols that X uses."
  
2) [feature request] I request that also 'ld --as-needed' may 
  be accept the latter compilation. For example, 'ld --as-needed' may read
  all libraries in command line and link them in order, properly
  flagging those that are really needed  ; at the end 
 of the process, it would then go again trough the list and only add 
 DT_NEEDED for those that are flagged.

thanks

a.

-- 
           Summary: --as-needed and order of libraries in linking
           Product: binutils
           Version: 2.17
            Status: NEW
          Severity: minor
          Priority: P2
         Component: ld
        AssignedTo: unassigned at sources dot redhat dot com
        ReportedBy: mennucc1 at debian dot org
                CC: bug-binutils at gnu dot org
 GCC build triplet: x86_64-linux-gnu
  GCC host triplet: x86_64-linux-gnu
GCC target triplet: x86_64-linux-gnu


http://sourceware.org/bugzilla/show_bug.cgi?id=3612

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]