[Bug 995787] [NEW] ld discards -lrt despite clock_gettime being used, and wrongfully fails to link

Mike Hommey mh at glandium.org
Mon May 7 06:31:06 UTC 2012


Public bug reported:

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

** Affects: binutils (Ubuntu)
     Importance: Undecided
         Status: New

-- 
You received this bug notification because you are a member of Ubuntu
Foundations Bugs, which is subscribed to binutils in Ubuntu.
https://bugs.launchpad.net/bugs/995787

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

Status in “binutils” package in Ubuntu:
  New

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

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/binutils/+bug/995787/+subscriptions




More information about the foundations-bugs mailing list