Linking against libc built with profiling fails

Bug #667470 reported by Paul Smith
30
This bug affects 6 people
Affects Status Importance Assigned to Milestone
glibc (Ubuntu)
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/gcc/x86_64-linux-gnu/4.4.5/../../../../lib/libc_p.a(strcmp.op)' can not be used when making an executable; recompile with -fPIE and relink with -pie
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.

Revision history for this message
Simon (kattassen) wrote :

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
/usr/bin/ld: dynamic STT_GNU_IFUNC symbol `strcmp' with pointer equality in `/usr/lib/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
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 $

Revision history for this message
Simon (kattassen) wrote :

A workaround for the problem is to install the binutils-gold package. I don't know if this have any other undesired effects, but it solves the linking issue.

Revision history for this message
Launchpad Janitor (janitor) wrote :

Status changed to 'Confirmed' because the bug affects multiple users.

Changed in glibc (Ubuntu):
status: New → Confirmed
Revision history for this message
Dmitry Zelenkovsky (dmitry-zelenkovsky) wrote :

After installing binutils-gold package it became a bit better, but still not completely fixed:

/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/libc_p.a(elf-init.op):function __libc_csu_irel: error: undefined reference to '__rela_iplt_end'
/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/libc_p.a(elf-init.op):function __libc_csu_irel: error: undefined reference to '__rela_iplt_start'
/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/libc_p.a(elf-init.op):function __libc_csu_irel: error: undefined reference to '__rela_iplt_start'
/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/libc_p.a(elf-init.op):function __libc_csu_irel: error: undefined reference to '__rela_iplt_start'
/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/libc_p.a(elf-init.op):function __libc_csu_irel: error: undefined reference to '__rela_iplt_start'
collect2: ld returned 1 exit status

Revision history for this message
Chucky Ellison (ellisonch) wrote :

The workaround does not work for me, as once I installed binutils-gold, nothing linked correctly anymore (/usr/bin/ld: fatal error: Input/output error). I had to uninstall it for anything to link.

Revision history for this message
Balint Reczey (rbalint) wrote :

The libc6-prof package (in the form this bug has been written against) has been removed after the 14.04 release.

Changed in glibc (Ubuntu):
status: Confirmed → Fix Released
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers