Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!

Bug 236524

Summary: executable causes SIGFPE whenever linking against libc_p
Product: Gentoo Linux Reporter: Seong-Kook Shin <tanarrian>
Component: [OLD] DevelopmentAssignee: Gentoo Toolchain Maintainers <toolchain>
Status: RESOLVED DUPLICATE    
Severity: major    
Priority: High    
Version: unspecified   
Hardware: x86   
OS: Linux   
Whiteboard:
Package list:
Runtime testing required: ---

Description Seong-Kook Shin 2008-09-02 23:28:57 UTC
If I build an executable using -lc_p option of gcc to get the profile
information, the executable
always generate SIGFPE before entering main() function.

By the way, It seems fine if I only use -pg option of gcc,
it works fine.



Reproducible: Always

Steps to Reproduce:
1. 
   $ cat nop.c
   int main(void)
   {
     return 0;
   }
2.
   $ gcc -pg nop.c -lc_p
   $ ./a.out
   Floating point exception

3.
   
Actual Results:  
$ ./a.out
Floating point exception

$ gdb -q a.out
(no debugging symbols found)
Using host libthread_db library "/lib/libthread_db.so.1".
(gdb) r
Starting program: /home/cinsk/Documents/pesticide/a.out 

Program received signal SIGFPE, Arithmetic exception.
0x08054aad in profil ()
(gdb) bt
#0  0x08054aad in profil ()
#1  0x0805477d in moncontrol ()
#2  0x0804d0b2 in __gmon_start__ ()
#3  0xb7eff6b2 in ?? () from /usr/lib/gcc/i686-pc-linux-gnu/4.1.2/libgcc_s.so.1
#4  0x00000001 in ?? ()
#5  0xb7f45fc4 in ?? () from /lib/ld-linux.so.2
#6  0xbf81aa98 in ?? ()
#7  0xb7eff497 in ?? () from /usr/lib/gcc/i686-pc-linux-gnu/4.1.2/libgcc_s.so.1
#8  0xb7f082b0 in ?? ()
#9  0xb7dce000 in ?? ()
#10 0xbf81aac8 in ?? ()
#11 0xb7f38c45 in call_init (l=0xb7f08000, argc=134881060, argv=0x1, 
    env=0xb7f082b0) at dl-init.c:70
Backtrace stopped: previous frame inner to this frame (corrupt stack?)


Expected Results:  
The generated executable should not cause SIGFPE.


# emerge -pv glibc gcc binutils

These are the packages that would be merged, in order:

Calculating dependencies... done!
[ebuild   R   ] sys-devel/binutils-2.18-r3  USE="nls -multislot -multitarget -test -vanilla" 0 kB 
[ebuild   R   ] sys-devel/gcc-4.1.2  USE="fortran gtk mudflap nls (-altivec) -bootstrap -build -d -doc -gcj (-hardened) -ip28 -ip32r10k -libffi% (-multilib) -multislot (-n32) (-n64) -nocxx -objc -objc++ -objc-gc -test -vanilla" 38,847 kB 
[ebuild   R   ] sys-libs/glibc-2.6.1  USE="gd nls profile -debug -glibc-omitfp (-hardened) (-multilib) (-selinux) -vanilla" 16,007 kB 

Total: 3 packages (3 reinstalls), Size of downloads: 54,854 kB


# uname -a
Linux shar 2.6.23-gentoo-r9 #1 SMP Fri Mar 7 09:05:21 KST 2008 i686 Intel(R) Pentium(R) 4 CPU 2.60GHz GenuineIntel GNU/Linux


# emerge --info
Portage 2.1.4.4 (default-linux/x86/2007.0/desktop, gcc-4.1.2, glibc-2.6.1-r0, 2.6.23-gentoo-r9 i686)
=================================================================
System uname: 2.6.23-gentoo-r9 i686 Intel(R) Pentium(R) 4 CPU 2.60GHz
Timestamp of tree: Thu, 28 Aug 2008 23:00:01 +0000
distcc 2.18.3 i686-pc-linux-gnu (protocols 1 and 2) (default port 3632) [enabled]
ccache version 2.4 [enabled]
app-shells/bash:     3.2_p33
dev-java/java-config: 1.3.7, 2.1.6
dev-lang/python:     2.5.2-r6
dev-python/pycrypto: 2.0.1-r6
dev-util/ccache:     2.4-r7
sys-apps/baselayout: 1.12.11.1
sys-apps/sandbox:    1.2.18.1-r2
sys-devel/autoconf:  2.13, 2.61-r2
sys-devel/automake:  1.4_p6, 1.5, 1.6.3, 1.7.9-r1, 1.8.5-r3, 1.9.6-r2, 1.10.1
sys-devel/binutils:  2.18-r3
sys-devel/gcc-config: 1.4.0-r4
sys-devel/libtool:   1.5.26
virtual/os-headers:  2.6.23-r3
ACCEPT_KEYWORDS="x86"
CBUILD="i686-pc-linux-gnu"
CFLAGS="-march=pentium4 -ggdb -O2 -pipe"
CHOST="i686-pc-linux-gnu"
CONFIG_PROTECT="/etc /opt/openfire/resources/security/ /usr/kde/3.3/env /usr/kde/3.3/share/config /usr/kde/3.3/shutdown /usr/kde/3.4/env /usr/kde/3.4/share/config /usr/kde/3.4/shutdown /usr/kde/3.5/env /usr/kde/3.5/share/config /usr/kde/3.5/shutdown /usr/share/config"
CONFIG_PROTECT_MASK="/etc/ca-certificates.conf /etc/env.d /etc/env.d/java/ /etc/fonts/fonts.conf /etc/gconf /etc/revdep-rebuild /etc/terminfo /etc/texmf/web2c /etc/udev/rules.d"
CXXFLAGS="-march=pentium4 -ggdb -O2 -pipe"
DISTDIR="/usr/portage/distfiles"
FEATURES="ccache distcc distlocks metadata-transfer sandbox sfperms splitdebug strict unmerge-orphans userfetch"
GENTOO_MIRRORS="http://gentoo.gg3.net/ http://ftp.kaist.ac.kr/pub/gentoo http://ftp.gentoo.or.kr http://gentoo.osuosl.org http://www.ibiblio.org/pub/Linux/distributions/gentoo"
LANG="ko_KR.UTF8"
LINGUAS="en ko"
PKGDIR="/usr/portage/packages"
PORTAGE_RSYNC_OPTS="--recursive --links --safe-links --perms --times --compress --force --whole-file --delete --stats --timeout=180 --exclude=/distfiles --exclude=/local --exclude=/packages"
PORTAGE_TMPDIR="/var/tmp"
PORTDIR="/usr/portage"
PORTDIR_OVERLAY="/usr/local/portage /usr/portage/local/layman/sunrise"
SYNC="rsync://rsync.gentoo.org/gentoo-portage"
USE="X acl acpi alsa arts bash-completion berkdb bzip2 cairo cdr cjk cli cracklib crypt cups dbus dri dvd dvdr dvdread eds emacs emboss encode esd evo fam firefox fortran gdbm gif gnome gpm gstreamer gtk hal iconv isdnlog jpeg kerberos ldap mad midi mikmod mmx mmx2 mp3 mpeg mudflap ncurses nls nptl nptlonly nvidia ogg opengl openmp pam pcre pdf perl png ppds pppd python qt3 qt3support qt4 quicktime readline reflection samba sdl session spell spl sse sse2 ssl svg tcpd tiff truetype unicode vorbis win32codecs x86 xml xorg xv zlib" ALSA_CARDS="intel8x0" ALSA_PCM_PLUGINS="adpcm alaw asym copy dmix dshare dsnoop empty extplug file hooks iec958 ioplug ladspa lfloat linear meter mmap_emul mulaw multi null plug rate route share shm softvol" APACHE2_MODULES="actions alias auth_basic auth_digest authn_anon authn_dbd authn_dbm authn_default authn_file authz_dbm authz_default authz_groupfile authz_host authz_owner authz_user autoindex cache dav dav_fs dav_lock dbd deflate dir disk_cache env expires ext_filter file_cache filter headers ident imagemap include info log_config logio mem_cache mime mime_magic negotiation proxy proxy_ajp proxy_balancer proxy_connect proxy_http rewrite setenvif so speling status unique_id userdir usertrack vhost_alias" ELIBC="glibc" INPUT_DEVICES="keyboard mouse" KERNEL="linux" LCD_DEVICES="bayrad cfontz cfontz633 glk hd44780 lb216 lcdm001 mtxorb ncurses text" LINGUAS="en ko" USERLAND="GNU" VIDEO_CARDS="nvidia"
Unset:  CPPFLAGS, CTARGET, EMERGE_DEFAULT_OPTS, FFLAGS, INSTALL_MASK, LC_ALL, LDFLAGS, MAKEOPTS, PORTAGE_COMPRESS, PORTAGE_COMPRESS_FLAGS, PORTAGE_RSYNC_EXTRA_OPTS
Comment 1 Wormo (RETIRED) gentoo-dev 2008-09-03 06:53:33 UTC
Are you sure -lc_p is needed in this case? I thought -pg was sufficient when linking with gcc, and -lc_p is only explicitly passed when linking via ld

http://sourceware.org/binutils/docs/gprof/Compiling.html
Comment 2 Wormo (RETIRED) gentoo-dev 2008-09-03 18:25:20 UTC
# use static linking because glibc with profiling is libc_p.a
gcc -pg nop.c -static
./a.out
gprof -q -b                        Call graph


granularity: each sample hit covers 2 byte(s) no time propagated

index % time    self  children    called     name
                0.00    0.00       1/1           __libc_start_main [817]
[1]      0.0    0.00    0.00       1         main [1]
-----------------------------------------------

Index by function name

   [1] main



Comment 3 Robin Johnson archtester Gentoo Infrastructure gentoo-dev Security 2008-09-03 20:09:38 UTC
wormo: from further in the gprof documentation:
"If you run the linker ld directly ... In addition, you would probably want to specify the profiling C library, libc_p.a, by writing `-lc_p' instead of the usual `-lc'. This is not absolutely necessary, but doing this gives you number-of-calls information for standard library functions such as read and open. For example: "

AFAIK, if you want to use c_p to profile libc, you have to use ld manually, Spanky might be able to comment better however.
Comment 4 Seong-Kook Shin 2008-09-04 04:22:12 UTC
(In reply to comment #2)
> # use static linking because glibc with profiling is libc_p.a
> gcc -pg nop.c -static
> ./a.out
> gprof -q -b                        Call graph
> 
> 
> granularity: each sample hit covers 2 byte(s) no time propagated
> 
> index % time    self  children    called     name
>                 0.00    0.00       1/1           __libc_start_main [817]
> [1]      0.0    0.00    0.00       1         main [1]
> -----------------------------------------------
> 
> Index by function name
> 
>    [1] main
> 

If I tried on my machine, I got SIGSEGV instead of SIGFPE.
Don't know why. (The configuration of my machine is already posted here)

$ gcc -static nop.c -lc_p
$ ./a.out
Segmentation fault
$ gdb -q a.out 
(no debugging symbols found)
Using host libthread_db library "/lib/libthread_db.so.1".
(gdb) r
Starting program: /home/cinsk/Documents/pesticide/a.out 
(no debugging symbols found)

Program received signal SIGSEGV, Segmentation fault.
0x0806e27b in __mcount_internal ()
(gdb) bt
#0  0x0806e27b in __mcount_internal ()
#1  0x00000000 in ?? ()
(gdb) 
Comment 5 SpanKY gentoo-dev 2008-09-07 06:39:36 UTC

*** This bug has been marked as a duplicate of bug 201376 ***