# GPG / libgcrypt oddity

## ab3ap

I moved to a new ~x86 machine a few weeks ago:

```
Linux ab3ap 3.0.4-gentoo #14 SMP Sat Sep 17 11:21:04 EDT 2011 i686 Intel(R) Core(TM) i7-2600 CPU @ 3.40GHz GenuineIntel GNU/Linux
```

and discovered that while gnupg and libgcrypt compiled just fine, I got a seg fault when running gpg.  So I ran gdb on it and discovered there were no debugging symbols:

```
mm@ab3ap ~/.gpg $ gdb gpg -e t

GNU gdb (Gentoo 7.3.1 p1) 7.3.1

Copyright (C) 2011 Free Software Foundation, Inc.

License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software: you are free to change and redistribute it.

There is NO WARRANTY, to the extent permitted by law.  Type "show copying"

and "show warranty" for details.

This GDB was configured as "i686-pc-linux-gnu".

For bug reporting instructions, please see:

<http://bugs.gentoo.org/>...

Reading symbols from /usr/bin/gpg...(no debugging symbols found)...done.

(gdb) run -e t

Starting program: /usr/bin/gpg -e t

You did not specify a user ID. (you may use "-r")

Current recipients:

Enter the user ID.  End with an empty line: markowski

Current recipients:

2048g/9E88D254 2008-01-29 "Mike Markowski <mm@udel.edu>"

Enter the user ID.  End with an empty line: 

File `t.gpg' exists. Overwrite? (y/N) y

Program received signal SIGSEGV, Segmentation fault.

0xb7ee6bc9 in ?? () from /usr/lib/libgcrypt.so.11

(gdb) where

#0  0xb7ee6bc9 in ?? () from /usr/lib/libgcrypt.so.11

#1  0xb7ee7254 in ?? () from /usr/lib/libgcrypt.so.11

#2  0xb7ee729c in ?? () from /usr/lib/libgcrypt.so.11

#3  0xb7ee8093 in ?? () from /usr/lib/libgcrypt.so.11

#4  0xb7ee82e4 in ?? () from /usr/lib/libgcrypt.so.11

#5  0xb7ee5b60 in ?? () from /usr/lib/libgcrypt.so.11

#6  0xb7ee6061 in ?? () from /usr/lib/libgcrypt.so.11

#7  0xb7ec817a in ?? () from /usr/lib/libgcrypt.so.11

#8  0xb7eca4f9 in ?? () from /usr/lib/libgcrypt.so.11

#9  0xb7ebc409 in gcry_cipher_setkey () from /usr/lib/libgcrypt.so.11

#10 0x080615be in ?? ()

#11 0x0808696e in ?? ()

#12 0x08052890 in ?? ()

#13 0xb7d59e16 in __libc_start_main () from /lib/libc.so.6

#14 0x0804d151 in ?? ()

Backtrace stopped: Not enough registers or memory available to unwind further

(gdb) quit
```

So I copied the source tar balls from /usr/portage/distfiles, untarred and did the ol' configure/make/make install (after setting CFLAGS to -g).  The funny thing is...it then worked fine!  Note that I mistakenly did not add -g to CFLAGS but set it to only that.  Could the -O2 be the culprit?

I'm curious what might be happening.  Thanks for any insights,

Mike

PS make.conf:

```
ab3ap gnupg-2.0.18 # more /etc/make.conf

# These settings were set by the catalyst build script that automatically

# built this stage.

# Please consult /usr/share/portage/config/make.conf.example for a more

# detailed example.

CFLAGS="-O2 -march=i686 -pipe"

CXXFLAGS="${CFLAGS}"

# WARNING: Changing your CHOST is not something that should be done lightly.

# Please consult http://www.gentoo.org/doc/en/change-chost.xml before changing.

CHOST="i686-pc-linux-gnu"

ACCEPT_KEYWORDS="~x86"

MAKEOPTS="-j9"

USE="aalib alsa cdr cdrw css dbus dvd dvdr encode ffmpeg flac gtk \

-introspection -ipv6 java kde hal id3tag jpeg jpeg2k mmx mp3 \

nptl offensive ogg opengl png qt3support sdl smp sndfile speex sse2 svg \

tiff timidity truetype vim-syntax vorbis X"

INPUT_DEVICES="evdev"

VIDEO_CARDS="nvidia"

LINGUAS="en"

EMERGE_DEFAULT_OPTS="--autounmask=n"

ACCEPT_LICENSE="dlj-1.1 PUEL skype-eula Oracle-BCLA-JavaSE"

```

----------

## Hu

There appear to be two culprits.  First, you did not use -g in the CFLAGS of the Portage-compiled version.  Second, you did not tell Portage to preserve debug symbols, so they were stripped on install.

Using -O2 may reduce the precision of debugging information, but will never remove it entirely.

----------

## ab3ap

But why would lack of debugging information cause gpg to seg fault?  (You can see it in my gdb output.)

I just reread my original note and see I didn't write it very clearly.  Here's what has me confused:

- gpg seg faults when trying to encrypt.

- I start gdb & discover no debugging info.

- I recompile with -g and suddenly gpg works without any seg fault!

----------

## Hu

Debugging information should not be relevant to whether it crashes.  When you said "it works fine", I interpreted that to mean that debugging now works fine, and that the crash occurred in all cases.

Remove the hand-built gpg, rebuild the Portage-managed one with debugging symbols, and see what happens.  If it still faults, then you can debug it.  If the problem went away, then there is nothing more to do.

----------

