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>
Severity: normal CC: martin, tdalman
Priority: High    
Version: unspecified   
Hardware: AMD64   
OS: Linux   
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;
> }
$ g++ main.cpp -lboost_filesystem
$ ldd a.out |grep boost => /usr/lib/ (0x00007f8b704bc000) => /usr/lib/ (0x00007f8b6f794000)
$ ldd /usr/lib/ |grep boost => /usr/lib/ (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/ |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)
$ 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:

"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.