Skip to content

SIGILL on using GDB, in ld-linux-armhf.so.3 #766

Closed

Description

@sneakernets

Disclaimer: I'm using the latest firmware...

I am working on zdoom, a Doom source port. However, when I attach zdoom to GDB on the Raspberry Pi, I get this:

Program received signal SIGILL, Illegal instruction.
0xb6fe8acc in ?? () from /lib/ld-linux-armhf.so.3

bt produces nothing of worth.

This is interesting, in that the program "runs" fine otherwise, but not with gdb.

Compiler: gcc 4.6.3-14+rpi1
Linux: 3.18.3+

Activity

  1. popcornmix commented on Jan 23, 2015

    @popcornmix
    Collaborator

    I believe this is normal (I've seen this when debugging xbmc for a couple of years).
    I suspect the code is deliberately executing the illegal instruction with a signal handler enabled (e.g. to determine whether optional instructions are supported).
    See:
    http://stackoverflow.com/questions/15071625/gdb-ddd-program-received-signal-sigill

  2. sneakernets commented on Jan 23, 2015

    @sneakernets
    Author

    I actually checked for this too, but even when I use handle SIGILL pass nostop noprint, the program dies in gdb with the same error. I suppose I should have noted that in the first post.

    This has been hair-pullingly frustrating to figure out on my own for the past two weeks, so I threw in the towel today and submitted it as an issue. 😁

  3. nbrachet commented on Jan 30, 2015

    @nbrachet

    I have experienced this issue too after a recent upgrade -- sadly I don't remember which one.

    I traced this SIGILL down to a static initialization in my code. Still frustrating issue.

  4. popcornmix commented on Jan 31, 2015

    @popcornmix
    Collaborator

    @nbrachet A firmware/kernel upgrade, or other packages?

  5. nbrachet commented on Jan 31, 2015

    @nbrachet

    @popcornmix I'm afraid both.

  6. nbrachet commented on Jan 31, 2015

    @nbrachet

    If that helps the problem occurs whether I build with g++-4.6 or g++-4.8.

  7. popcornmix commented on Jan 31, 2015

    @popcornmix
    Collaborator

    If it was a firmware/kernel update that caused it, then downgrading should fix it. You can revert to an older version:
    http://raspberrypi.stackexchange.com/questions/15917/restore-kernel-version/15919#15919

  8. sneakernets commented on Feb 2, 2015

    @sneakernets
    Author

    If it helps, this started to be an issue around mid-december 2014.

  9. nbrachet commented on Feb 6, 2015

    @nbrachet

    I've tracked down the firmware version in which this bug appeared: cad071a, and it present up to the latest 93cb9a4

  10. sneakernets commented on Feb 6, 2015

    @sneakernets
    Author

    Yeah, it looks like 3.18 firmware update still has some rough edges. Thanks for letting me know!

  11. popcornmix commented on Feb 7, 2015

    @popcornmix
    Collaborator

    Unfortunately the kernel change was the 3.12 to 3.18 (so literally tens of thousands of commits...)
    Can you determine the instruction generating the exception (e.g. with "disas")

  12. popcornmix commented on Feb 7, 2015

    @popcornmix
    Collaborator

    One thing I've notice is 3.18 kernel reports:
    Features : half thumb fastmult vfp edsp java tls

    The older kernel reports:
    Features : swp half thumb fastmult vfp edsp java tls

    The (deprecated) swp feature was removed here:
    58171bf

    So if the instruction is a swp instruction this may be relevant.

  13. nbrachet commented on Feb 9, 2015

    @nbrachet

    Here's the disas:

    (gdb) run
    The program being debugged has been started already.
    Start it from the beginning? (y or n) y
    
    Starting program: test
    
    Program received signal SIGILL, Illegal instruction.
    0xb6fe8acc in ?? () from /lib/ld-linux-armhf.so.3
    (gdb) disas 0xb6fe8acc,0xb6fe8aff
    Dump of assembler code from 0xb6fe8acc to 0xb6fe8aff:
    => 0xb6fe8acc:  ldr r3, [pc, #164]  ; 0xb6fe8b78
       0xb6fe8ad0:  cmp r1, #0
       0xb6fe8ad4:  push    {r4}        ; (str r4, [sp, #-4]!)
       0xb6fe8ad8:  add r3, pc, r3
       0xb6fe8adc:  mov r2, r0
       0xb6fe8ae0:  beq 0xb6fe8b5c
       0xb6fe8ae4:  mov r0, #76 ; 0x4c
       0xb6fe8ae8:  ldr r12, [pc, #140] ; 0xb6fe8b7c
       0xb6fe8aec:  mul r0, r0, r1
       0xb6fe8af0:  add r12, pc, r12
       0xb6fe8af4:  add r0, r0, #56 ; 0x38
       0xb6fe8af8:  add r0, r0, r12
       0xb6fe8afc:  adds    r12, r2, #0
    End of assembler dump.
    

    Expanding on this...:

    (gdb) disas 0xb6fe8ac0,0xb6fe8aff
    Dump of assembler code from 0xb6fe8ac0 to 0xb6fe8aff:
       0xb6fe8ac0:  andeq   r12, r0, r12, lsr r4
       0xb6fe8ac4:  andeq   r12, r0, r8, lsl r5
       0xb6fe8ac8 <_dl_debug_state+0>:  bx  lr
    => 0xb6fe8acc:  ldr r3, [pc, #164]  ; 0xb6fe8b78
       0xb6fe8ad0:  cmp r1, #0
       0xb6fe8ad4:  push    {r4}        ; (str r4, [sp, #-4]!)
       0xb6fe8ad8:  add r3, pc, r3
       0xb6fe8adc:  mov r2, r0
       0xb6fe8ae0:  beq 0xb6fe8b5c
       0xb6fe8ae4:  mov r0, #76 ; 0x4c
       0xb6fe8ae8:  ldr r12, [pc, #140] ; 0xb6fe8b7c
       0xb6fe8aec:  mul r0, r0, r1
       0xb6fe8af0:  add r12, pc, r12
       0xb6fe8af4:  add r0, r0, #56 ; 0x38
       0xb6fe8af8:  add r0, r0, r12
       0xb6fe8afc:  adds    r12, r2, #0
    End of assembler dump.
    
  14. popcornmix commented on Feb 9, 2015

    @popcornmix
    Collaborator

    Can you post the binary that does this? (e.g. to dropbox or google drive)

  15. nbrachet commented on Feb 9, 2015

    @nbrachet

    https://dl.dropboxusercontent.com/u/1020551/rtpraspivid

    Offending code is:

        int traceroute(...)
        {
    #ifndef __ARM_EABI__
            static const uint16_t pid = getpid();
    #else
            // gdb (raspberrypi) trips with SIGILL!?!
            // see https://github.com/raspberrypi/linux/issues/766
                   const uint16_t pid = getpid();
    #endif
    ...
    

    When pid is defined as a static (as it is in the executable I posted to dropbox) the executable SIGILL in gdb.

    Note that the same problem happens if I replace the call to getpid() with a call to:

    static uint16_t foo()
    {
        return 1234;
    }
    

    But it does not happen if I replace the call to getpid() with a constant:

        static const uint16_t pid = 1234;
    

    It does feel like a stack corruption... Could gdb be corrupting the stack somehow?

  16. 35 remaining items

  17. popcornmix commented on Aug 31, 2016

    @popcornmix
    Collaborator

    @khuey Thanks for checking. Hopefully it will make it to stable at some point.

  18. XECDesign commented on Aug 31, 2016

    @XECDesign
    Contributor

    @popcornmix debian is not likely to bump gdb version in stable. Any reason not to patch 7.7.1 in our releases?

  19. popcornmix commented on Sep 1, 2016

    @popcornmix
    Collaborator

    @XECDesign yes that is an option.

    @Ferroin mentioned requesting this patch be applied to debian as it seems like a bug fix:
    See: raspberrypi/firmware#652

    If that happens we should get the patched version by default, but if not we can add a custom patch.

  20. Ferroin commented on Sep 1, 2016

    @Ferroin
    Contributor

    Short term, I'd suggest just doing a custom patch. I have not yet had a chance to file a bug against Debian (things kind of blew up at work shortly after I posted that comment), and it may take a while to convince them to include it, if they decide to include it at all.

  21. plugwash commented on Sep 1, 2016

    @plugwash

    Shiftplusone just pointed me at this. So far I have failed to reproduce it. Specificafically I have failed to get the compiler to spit out a "UNIX - GNU" binary.

  22. XECDesign commented on Sep 2, 2016

    @XECDesign
    Contributor

    @plugwash Just gave this a go myself. Compiled a kernel with CONFIG_OABI_COMPAT=n and a version of GDB with the patch applied. Using zdoom linked earlier as an example, without installing that version of GDB:

    pi@raspberrypi:~/zdoom/build $ gdb zdoom
    GNU gdb (Raspbian 7.7.1+dfsg-5) 7.7.1
    Copyright (C) 2014 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".
    Type "show configuration" for configuration details.
    For bug reporting instructions, please see:
    <http://www.gnu.org/software/gdb/bugs/>.
    Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.
    For help, type "help".
    Type "apropos word" to search for commands related to "word"...
    Reading symbols from zdoom...done.
    (gdb) run
    Starting program: /home/pi/zdoom/build/zdoom 
    
    Program received signal SIGILL, Illegal instruction.
    _dl_debug_initialize (ldbase=1685382482, ns=195904) at dl-debug.c:47
    47  dl-debug.c: No such file or directory.
    (gdb) 
    

    Installing the patched version of GDB and trying again...

    pi@raspberrypi:~/zdoom/build $ sudo dpkg -i ../../dev/gdb_7.7.1+dfsg-5+rpi1_armhf.deb 
    (Reading database ... 70074 files and directories currently installed.)
    Preparing to unpack .../gdb_7.7.1+dfsg-5+rpi1_armhf.deb ...
    Unpacking gdb (7.7.1+dfsg-5+rpi1) over (7.7.1+dfsg-5) ...
    Setting up gdb (7.7.1+dfsg-5+rpi1) ...
    Processing triggers for man-db (2.7.0.2-5) ...
    
    pi@raspberrypi:~/zdoom/build $ gdb zdoom
    GNU gdb (Raspbian 7.7.1+dfsg-5+rpi1) 7.7.1
    Copyright (C) 2014 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".
    Type "show configuration" for configuration details.
    For bug reporting instructions, please see:
    <http://www.gnu.org/software/gdb/bugs/>.
    Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.
    For help, type "help".
    Type "apropos word" to search for commands related to "word"...
    Reading symbols from zdoom...done.
    (gdb) run
    Starting program: /home/pi/zdoom/build/zdoom 
    [Thread debugging using libthread_db enabled]
    Using host libthread_db library "/lib/arm-linux-gnueabihf/libthread_db.so.1".
    ZDoom 2.9pre-1230-gbf5f10a - 2016-09-02 10:48:38 +0200 - SDL version
    Compiled on Sep  2 2016
    
    M_LoadDefaults: Load system defaults.
    Cannot find a game IWAD (doom.wad, doom2.wad, heretic.wad, etc.).
    Did you install ZDoom properly? You can do either of the following:
    
    1. Place one or more of these wads in ~/.config/zdoom/.
    2. Edit your ~/.config/zdoom/zdoom.ini and add the directories of your
    iwads to the list beneath [IWADSearch.Directories]
    [Inferior 1 (process 13140) exited with code 0377]
    (gdb)
    
  23. plugwash commented on Sep 3, 2016

    @plugwash

    did you compile that zdoom binary yourself? if so with what compiler on what version of raspbian?

  24. XECDesign commented on Sep 3, 2016

    @XECDesign
    Contributor

    Yes, straight forward compile using the toolchain from raspbian jessie.

    sudo apt-get install libsdl2-dev
    git clone https://github.com/rheit/zdoom.git
    cd zdoom/
    mkdir build
    cd build/
    cmake ../
    make -j4
    
    pi@raspberrypi:~/zdoom/build $ apt-cache policy gcc
    gcc:
      Installed: 4:4.9.2-2
      Candidate: 4:4.9.2-2
      Version table:
     *** 4:4.9.2-2 0
            500 http://mirrordirector.raspbian.org/raspbian/ jessie/main armhf Packages
            100 /var/lib/dpkg/status
    pi@raspberrypi:~/zdoom/build $ gcc -v
    Using built-in specs.
    COLLECT_GCC=gcc
    COLLECT_LTO_WRAPPER=/usr/lib/gcc/arm-linux-gnueabihf/4.9/lto-wrapper
    Target: arm-linux-gnueabihf
    Configured with: ../src/configure -v --with-pkgversion='Raspbian 4.9.2-10' --with-bugurl=file:///usr/share/doc/gcc-4.9/README.Bugs --enable-languages=c,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.9 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.9 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --disable-libitm --disable-libquadmath --enable-plugin --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-4.9-armhf/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-4.9-armhf --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-4.9-armhf --with-arch-directory=arm --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-objc-gc --enable-multiarch --disable-sjlj-exceptions --with-arch=armv6 --with-fpu=vfp --with-float=hard --enable-checking=release --build=arm-linux-gnueabihf --host=arm-linux-gnueabihf --target=arm-linux-gnueabihf
    Thread model: posix
    gcc version 4.9.2 (Raspbian 4.9.2-10) 
    
  25. frixhub commented on Nov 5, 2016

    @frixhub

    Good day,

    I'm developing on the Allwinner A20 & A33 CPUs, which contains ARM cores.
    I've first noticed the segfault during remote debugging, using gdbserver,
    from my host PC to the target. Debugging the the application directly on
    the target did not cause this problem. Performing the remote debugging from
    a 32-bit host to the 32-bit target made no difference. That seemed to
    eliminate the possibility of a 64/32 bit compatibility issue.

    My setup:
    Host PC:
    Kubuntu 16.04 64-bit
    Toolchain: gcc-linaro-6.1.1-2016.08
    : gdb version (Linaro_GDB-2016.08) 7.11.1.20160801-git
    Obtained from: https://releases.linaro.org/components/toolchain/binaries
    Target:
    Ubuntu 16.04 ARMHF
    : GDB version: (Ubuntu 7.11.1-0ubuntu1~16.04) 7.11.1

    Illustrating the problem

    Program: main.c
    #include <stdio.h>
    int main (void)
    {
    printf("Hallo world!\n");
    return 0;
    }
    Compile on host PC:
    $ arm-linux-gnueabihf-gcc -g main.c -o main_32
    File signature:
    $ file main_32
    main_32: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked,
    interpreter /lib/ld-linux-armhf.so.3, for GNU/Linux 2.6.32,
    BuildID[sha1]=cc1a4a1ff17da63f9f8362c84dffe54ee7fff4ff, not stripped

    Remote target:
    The executable (main_32) needs to be copied to the remote target
    $ gdbserver :5555 main_32
    Process main_32 created; pid = 904
    Listening on port 5555
    Remote debugging from host 192.168.7.2

    Host PC:
    $ arm-linux-gnueabihf-gdb ./main_32
    (gdb) target remote 192.168.7.1:5555
    Remote debugging using 192.168.7.1:5555
    Reading /lib/ld-linux-armhf.so.3 from remote target...
    warning: File transfers from remote targets can be slow. Use "set sysroot" to access files locally
    instead.
    Reading /lib/ld-linux-armhf.so.3 from remote target...
    Reading symbols from target:/lib/ld-linux-armhf.so.3...Reading /lib/ld-2.23.so from remote target...
    Reading /lib/.debug/ld-2.23.so from remote target...
    (no debugging symbols found)...done.
    0xb6fd7a40 in ?? () from target:/lib/ld-linux-armhf.so.3

    (gdb) continue
    Continuing.
    Program received signal SIGSEGV, Segmentation fault.
    0xb6fd9822 in ?? () from target:/lib/ld-linux-armhf.so.3

    To try and figure out where the segfault occurred the debug symbols need to be loaded.
    The gdb command 'set debug-file-directory' can be used to accomplish this. It seems that this command
    is only relative to the host PC filesystem and not according to the remote target file system.
    With 'set sysroot' the debugger can also be instructed to load all data locally instead of transferring it
    runtime over the network.

    Make sure the debug symbols are on the remote file system:

    apt-get install libc6-dbg

    Copy the full contents of the SD card residing on the Allwinner A20 rootfs to a local directory on
    the host PC: /opt/gnueabihf_rootfs

    Illustrating the solution

    Remote target:
    $ gdbserver :5555 main_32
    Process main_32 created; pid = 912
    Listening on port 5555
    Remote debugging from host 192.168.7.2

    Hallo world!
    Child exited with status 0

    Host PC:
    $ arm-linux-gnueabihf-gdb ./main_32
    (gdb) set debug-file-directory /opt/gnueabihf_rootfs/usr/lib/debug
    (gdb) set sysroot /opt/gnueabihf_rootfs
    (gdb) target remote 192.168.7.1:5555

    Remote debugging using 192.168.7.1:5555
    Reading symbols from /opt/gnueabihf_rootfs/lib/ld-linux-armhf.so.3...done.
    Reading symbols from /opt/gnueabihf_rootfs/usr/lib/debug/lib/arm-linux-gnueabihf/ld-2.23.so...done.
    0xb6fd7a40 in _start ()

    (gdb) continue
    Continuing.
    Cannot parse expression `.L966 4@r4'.
    warning: Probes-based dynamic linker interface failed.
    Reverting to original interface.

    Even though there is a warning regarding "Probes-based dynamic linker interface failed", the program
    keeps on running correctly. The thread describing the GDB patch about the linker interface can be
    read at: https://sourceware.org/ml/gdb-patches/2015-08/msg00629.html

    It appears the work around was introduced around August 2015, but if you do not specify the path to
    the debug symbols, the debugger still segfaults.

    The 'set debug-file-directory' and 'set sysroot' can be added to the .gdbinit file to be applied
    automatically when you start a remote debug session.

    Note: Activating the kernel option: CONFIG_OABI_COMPAT did not fix the problem on the Allwinner A20 or A33.

    Regards,
    Frikkie Thirion

  26. masoudr commented on Sep 1, 2018

    @masoudr

    Hi,
    I'm still facing this problem can anybody confirm what is the cause of the problem? kernel itself? I'm trying to cross-compile my app with linaro toolchain and using its debugger arm-linux-gnueabihf-gdb to debug remotely.

  27. added a commit that references this issue on Apr 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions