User avatar
drougge
Posts: 5
Joined: Mon Aug 20, 2012 8:03 pm

gdb can't run programs linked against libcrypto

Mon Aug 20, 2012 8:15 pm

On raspbian (updated yesterday), I can't run a program linked with libcrypto from gdb. It doesn't matter what the program contains. Example:

Code: Select all

% cat test.c
int main(void) { return 0; }
% gcc -o test test.c -lcrypto
% gdb ./test
GNU gdb (GDB) 7.4.1-debian
Copyright (C) 2012 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 "arm-linux-gnueabihf".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/drougge/prg/test...(no debugging symbols found)...done.
(gdb) r
Starting program: /home/drougge/prg/test 

Program received signal SIGILL, Illegal instruction.
0x400864c0 in ?? () from /usr/lib/arm-linux-gnueabihf/libcrypto.so.1.0.0
(gdb)
I'm not sure this belongs in the C forum, but then again, only programmers are likely to notice.

Anyway, I suppose the first test would be if someone else verifies that it's not just my system. And if so I suppose it's a bug in gdb or libcrypto.

Aydan
Posts: 747
Joined: Fri Apr 13, 2012 11:48 am
Location: Germany, near Lake Constance

Re: gdb can't run programs linked against libcrypto

Tue Aug 21, 2012 10:02 am

Might be a stupid question, but does the program run outside of gdb?

plugwash
Forum Moderator
Forum Moderator
Posts: 3845
Joined: Wed Dec 28, 2011 11:45 pm

Re: gdb can't run programs linked against libcrypto

Tue Aug 21, 2012 10:09 am

Does the program run without gdb?

A break in a debugger doesn't nessacerally mean a bug in the code. One way of doing runtime detection of whether a CPU feature exists is to try doing it and deal with the sigill that results if you can't.

User avatar
Paeryn
Posts: 3592
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: gdb can't run programs linked against libcrypto

Tue Aug 21, 2012 4:46 pm

You can tell gdb to not stop on signals.

Code: Select all

(gdb) handle SIGILL nostop
will allow your program to continue, gdb will just tell you that the signal was received.
As plugwash said, libcrypto is probably handling the SIGILL itself to test for processor features. Running under gdb, gdb is catching it.
Using your example, the program runs normally under gdb:

Code: Select all

Reading symbols from /home/pi/test/test...done.
(gdb) handle SIGILL nostop
Signal        Stop      Print   Pass to program Description
SIGILL        No        Yes     Yes             Illegal instruction
(gdb) r
Starting program: /home/pi/test/test

Program received signal SIGILL, Illegal instruction.

Program received signal SIGILL, Illegal instruction.
[Inferior 1 (process 1592) exited normally]
(gdb) 
Edit:
Use: handle SIGILL nostop noprint to prevent gdb from telling you that it saw the signal.
She who travels light — forgot something.

User avatar
drougge
Posts: 5
Joined: Mon Aug 20, 2012 8:03 pm

Re: gdb can't run programs linked against libcrypto

Tue Aug 21, 2012 8:40 pm

Paeryn wrote:You can tell gdb to not stop on signals.

Code: Select all

(gdb) handle SIGILL nostop
will allow your program to continue, gdb will just tell you that the signal was received.
...
Edit:
Use: handle SIGILL nostop noprint to prevent gdb from telling you that it saw the signal.
Excelent. So the bug was actually in my understanding of what gdb does. (I'm not sure I consider breaking on a signal the program had a handler for is a great default though.)

User avatar
Paeryn
Posts: 3592
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: gdb can't run programs linked against libcrypto

Wed Aug 22, 2012 1:28 am

drougge wrote:Excelent. So the bug was actually in my understanding of what gdb does. (I'm not sure I consider breaking on a signal the program had a handler for is a great default though.)
What if there was an actual problem rather than the fake one that libcrypto is using to test the processor's instruction set? You would want gdb to break then. gdb has no way of knowing if the signal handler you set will work so it defaults to stopping the program.
You can also tell gdb to continue from a signal break by passing the signal back...

Code: Select all

(gdb) r
Starting program: /home/pi/test/test 

Program received signal SIGILL, Illegal instruction.
0x400844c0 in ?? () from /usr/lib/arm-linux-gnueabihf/libcrypto.so.1.0.0
(gdb) signal SIGILL
Continuing with signal SIGILL.
Cannot access memory at address 0x0

Program received signal SIGILL, Illegal instruction.
0x400844c8 in ?? () from /usr/lib/arm-linux-gnueabihf/libcrypto.so.1.0.0
(gdb) signal SIGILL
Continuing with signal SIGILL.
Cannot access memory at address 0x0
[Inferior 1 (process 1566) exited normally]
(gdb)
SIGILL is triggered twice because libcrypto attempts to execute two separate armv7 instructions.
She who travels light — forgot something.

User avatar
drougge
Posts: 5
Joined: Mon Aug 20, 2012 8:03 pm

Re: gdb can't run programs linked against libcrypto

Wed Aug 22, 2012 1:27 pm

Paeryn wrote:What if there was an actual problem rather than the fake one that libcrypto is using to test the processor's instruction set? You would want gdb to break then. gdb has no way of knowing if the signal handler you set will work so it defaults to stopping the program.
But that's equally true for any signal and gdb doesn't break on all of them.

If you have a handler for SIGILL installed (not common!), I think it's a very reasonable assumption that you are doing exactly what libcrypto is doing here. And I'm going to assume that the signal handler is installed for all of two instructions (plus the code to remove it). It's not like a program normally has a handler for SIGILL installed.

So I'm still of the opinion that this is a strange default. Is there a reasonable case where you have a handler for SIGILL, but still want gdb to break on it, but just don't know that you want it so you don't ask for it? If there is, is this more common than my case (a library does something tricky I shouldn't have to know about, which is no way is related to what I'm trying to debug)?

catswhiskers
Posts: 1
Joined: Sun Oct 28, 2012 9:51 pm

Re: gdb can't run programs linked against libcrypto

Sun Oct 28, 2012 10:22 pm

Hi. Don't know if this helps but I'm having the same issue with an application called qupzilla - a qt browser compiled from source. This runs ok on my tegra arm ac100 laptop -also compiled from same source - running ubuntu 11.10 (libs older than the deb wheezy) but bombs out on trying to access any url. The suggestion is it's either libcrypto or the libqt4 libraries. So far I've recompiled libcrypto from deb sources but to no avail. Rebuilding QT4 however is another matter ... :(

Return to “C/C++”