Bug 1287805

Summary: -Wl,--as-needed ignored for -pthread
Product: [Fedora] Fedora Reporter: Jaroslav Škarvada <jskarvad>
Component: gccAssignee: Jakub Jelinek <jakub>
Status: CLOSED EOL QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 22CC: davejohansen, jakub, jwakely, law, mpolacek
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2016-07-19 18:33:29 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Jaroslav Škarvada 2015-12-02 17:48:03 UTC
Description of problem:
If gcc called as linker with -Wl,--as-needed followed by -pthread, the libpthread is added as unused direct dependency.

Version-Release number of selected component (if applicable):
gcc-5.1.1-4.fc22.x86_64

How reproducible:
Always

Steps to Reproduce:
1. gcc -Wl,--as-needed -shared -fPIC OBJ1 OBJ2 libtest.so
2. ldd -u ./libtest.so
3. gcc -Wl,--as-needed -shared -fPIC OBJ1 OBJ2 -pthread libtest.so
4. ldd -u ./libtest.so

Actual results:
Unused direct dependencies:
	/lib64/libpthread.so.0

Expected results:
No unused direct dependencies

Additional info:
I checked manual page, but it doesn't seem there is written that this shouldn't work.

Comment 1 Jonathan Wakely 2015-12-02 19:49:24 UTC
-pthread is not simply equivalent to -lpthread, so I wouldn't have expected it to work like that anyway.

If you want to link with "--as-needed -lpthread" then you can use that (in addition to -pthread if you want).

Note that for the C++ runtime library the current behaviour is useful, because the pthread symbols are only referenced through weak symbols, so --as-needed -pthread would fail to consider the symbols "needed" and would fail to link libpthread.so even when the code uses e.g std::mutex and libpthread is definitely needed.

Comment 2 Jaroslav Škarvada 2015-12-03 09:14:06 UTC
Please could you mention it in documentation (manual page)?

Comment 3 Fedora End Of Life 2016-07-19 18:33:29 UTC
Fedora 22 changed to end-of-life (EOL) status on 2016-07-19. Fedora 22 is
no longer maintained, which means that it will not receive any further
security or bug fix updates. As a result we are closing this bug.

If you can reproduce this bug against a currently maintained version of
Fedora please feel free to reopen this bug against that version. If you
are unable to reopen this bug, please file a new report against the
current release. If you experience problems, please add a comment to this
bug.

Thank you for reporting this bug and we are sorry it could not be fixed.