ld discards -lrt despite clock_gettime being used, and wrongfully fails to link

Bug #995787 reported by Mike Hommey
2
Affects Status Importance Assigned to Milestone
binutils (Ubuntu)
Invalid
Undecided
Unassigned

Bug Description

$ cat > test.c <<EOF
#include <time.h>
int main() {
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
return 0;
}
EOF

$ gcc -o test -lrt test.c
test.c:(.text+0x15): undefined reference to `clock_gettime'

Adding -Wl,--no-as-needed before -lrt makes it link. Using gold instead of BFD ld also makes it link. There is no reason why -Wl,--as-needed -lrt (--as-needed being the ubuntu default) should drop -lrt when one of its symbol is used, especially when dropping it makes the linkage fail...

Revision history for this message
Mike Hommey (mh-glandium) wrote :

Forget it, it's an ordering problem. (And I can't find how to close a bug)

Matthias Klose (doko)
Changed in binutils (Ubuntu):
status: New → Invalid
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.