Linking against libc built with profiling fails
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
glibc (Ubuntu) |
Fix Released
|
Undecided
|
Unassigned |
Bug Description
I'm trying to build my program with the libc profiling (from package libc6-prof) enabled, and it doesn't work at all.
$ lsb_release -rd
Description: Ubuntu 10.10
Release: 10.10
The README says I should add "-static-libgcc -lc_p" to my link line, but if I do that I get:
gcc -g -pg -o foobar ar.o arscan.o commands.o default.o dir.o expand.o file.o function.o getopt.o getopt1.o implicit.o job.o main.o misc.o read.o remake.o remote-stub.o rule.o signame.o strcache.o variable.o version.o vpath.o hash.o -lrt -static-libgcc -lc_p
read.o: In function `tilde_expand':
read.c:2968: warning: Using 'getpwnam' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/bin/ld: dynamic STT_GNU_IFUNC symbol `strcmp' with pointer equality in `/usr/lib/
collect2: ld returned 1 exit status
If I take out the -static-libgcc (but leave in -lc_p of course) I get the same error.
If I try linking my application statically, by adding -static to the link line, then I get just the warning:
read.c:2968: warning: Using 'getpwnam' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
and the link succeeds, but if I try to run the executable it simply coredumps:
$ ./foobar
Segmentation fault
GDB says:
(gdb) run
Starting program: foobar
Program received signal SIGSEGV, Segmentation fault.
0x000000000049be0b in __mcount_internal ()
Of course if I build without profiling it works fine.
I get the same error with gcc version 4.4.3 (Ubuntu 4.4.3-4ubuntu5) (Ubuntu 10.04). The problem occurs when compiling using both '--static' and '--export-dynamic' flags in gcc. If I compile with the flags separately everything works fine.
In older version of gcc, version 4.2.4 (Ubuntu 4.2.4-1ubuntu4) (Ubuntu 8.04), everything works perfectly.
Could it be that the error message is true and strcmp.o is compiled in the wrong way? I can compile program using strcmp with static links.
Example:
The problem can be reproduced with any program (i.e the simple program below).
#include <stdio.h>
int main(){
printf("Hello Ubuntu!\n");
return 0;
}
***Build on Ubuntu 10.04***
simon@simon-laptop ~/temp/ $ gcc --version
gcc (Ubuntu 4.4.3-4ubuntu5) 4.4.3
Copyright (C) 2009 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
simon@simon-laptop ~/temp $ gcc example.c -static -export-dynamic gcc/x86_ 64-linux- gnu/4.4. 3/../.. /../../ lib/libc. a(strcmp. o)' can not be used when making an executable; recompile with -fPIE and relink with -pie
/usr/bin/ld: dynamic STT_GNU_IFUNC symbol `strcmp' with pointer equality in `/usr/lib/
collect2: ld returned 1 exit status
simon@simon-laptop ~/temp $
***Build on Ubuntu 8.04***
simon@simon-laptop ~/temp $ gcc --version
gcc (GCC) 4.2.4 (Ubuntu 4.2.4-1ubuntu4)
Copyright (C) 2007 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
simon@simon-laptop ~/temp $ gcc example.c -static -export-dynamic
simon@simon-laptop ~/temp $