Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!

Bug 333395

Summary: -Wl,--as-needed breaks building legitimate applications
Product: Gentoo Linux Reporter: Dmitry Goncharov <dgoncharov>
Component: [OLD] UnspecifiedAssignee: Gentoo Linux bug wranglers <bug-wranglers>
Status: VERIFIED UPSTREAM    
Severity: normal CC: martin, tdalman
Priority: High    
Version: unspecified   
Hardware: AMD64   
OS: Linux   
Whiteboard:
Package list:
Runtime testing required: ---

Description Dmitry Goncharov 2010-08-19 09:00:19 UTC
The following is a sample bash session which demonstrates the problem.


$ cat << EOF > main.cpp
> #include <boost/filesystem.hpp>
> int main()
> {
>     boost::filesystem::path r("");
>     return 0;
> }
> EOF
$ g++ main.cpp -lboost_filesystem
$ ldd a.out |grep boost
        libboost_filesystem-1_42.so.1.42.0 => /usr/lib/libboost_filesystem-1_42.so.1.42.0 (0x00007f8b704bc000)
        libboost_system-1_42.so.1.42.0 => /usr/lib/libboost_system-1_42.so.1.42.0 (0x00007f8b6f794000)
$ ldd /usr/lib/libboost_filesystem-1_42.so.1.42.0 |grep boost
        libboost_system-1_42.so.1.42.0 => /usr/lib/libboost_system-1_42.so.1.42.0 (0x00007ff9008d1000)
$ g++ -Wl,--as-needed main.cpp -lboost_filesystem
/tmp/ccuL8xmr.o: In function `__static_initialization_and_destruction_0(int, int)':
main.cpp:(.text+0x52): undefined reference to `boost::system::get_system_category()'
main.cpp:(.text+0x5e): undefined reference to `boost::system::get_generic_category()'
main.cpp:(.text+0x6a): undefined reference to `boost::system::get_generic_category()'
main.cpp:(.text+0x76): undefined reference to `boost::system::get_generic_category()'
main.cpp:(.text+0x82): undefined reference to `boost::system::get_system_category()'
collect2: ld returned 1 exit status
$
$ nm -CD /usr/lib/libboost_system-1_42.so.1.42.0 |grep boost::system::get_system_category
0000000000001a80 T boost::system::get_system_category()

Reproducible: Always




$ g++ --version
g++ (Gentoo 4.4.4-r1 p1.0, pie-0.4.5) 4.4.4
$ ld --version
GNU ld (GNU Binutils) 2.20.1.20100303
$ uname -a
Linux blackbox 2.6.34-gentoo-r2 #1 SMP PREEMPT Wed Jul 14 12:14:21 MSD 2010 x86_64 Intel(R) Core(TM) i5 CPU 750 @ 2.67GHz GenuineIntel GNU/Linux
Comment 1 SpanKY gentoo-dev 2010-08-20 05:39:03 UTC
what exactly is your point ?  dont use --as-needed with your C++ apps that require specific behavior.

this has been discussed to death (simply google/read gentoo-dev mailing list).  there isnt really anything that can be done in the linker to detect this small corner case.
Comment 2 Dmitry Goncharov 2010-08-20 08:46:45 UTC
The point is that --as-needed is now enabled by default. Paludis (or portage) can no longer build my application.


Comment 3 Samuli Suominen (RETIRED) gentoo-dev 2010-08-20 13:53:31 UTC
(In reply to comment #2)
> The point is that --as-needed is now enabled by default. Paludis (or portage)
> can no longer build my application.
> 

Sure it can, read the documentation:

http://www.gentoo.org/proj/en/qa/asneeded.xml

"Code Listing 1.5: correct filter for --as-needed behaviour"
Comment 4 Dmitry Goncharov 2010-08-20 14:05:19 UTC
Thanks. Nice to know you already took care about it.