[Bug c/17176] New: internal compiler error on invalid inline assembler code

m dot a dot termeer at student dot tue dot nl gcc-bugzilla@gcc.gnu.org
Tue Aug 24 20:40:00 GMT 2004


i was trying to get a stack dump from a linux program and used some assembler to
do the trick. when compiling the following code

#include <stdio.h>

main() {
        char *stackptr;
        __asm__("movl %esp,%%eax" : "=eax"(stackptr) : : "eax");

        return 0;
}

with "gcc stack_crash.c" causes the output

dec@dec:~$ gcc stack_crash.c
stack_crash.c: In function `main':
stack_crash.c:20: Internal compiler error in instantiate_virtual_regs_1, at
function.c:3971
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://gcc.gnu.org/bugs.html> for instructions.

this is gcc version 3.2.3, or more complete, the output of gcc -v:

dec@dec:~$ gcc -v
Reading specs from /usr/lib/gcc-lib/i486-slackware-linux/3.2.3/specs
Configured with: ../gcc-3.2.3/configure --prefix=/usr --enable-shared
--enable-threads=posix --enable-__cxa_atexit --disable-checking --with-gnu-ld
--verbose --target=i486-slackware-linux --host=i486-slackware-linux
Thread model: posix
gcc version 3.2.3

to fix the problem, i upgraded my gcc version to 3.3.3 and now i get the
following output.

stack_crash.c: In function `main':
stack_crash.c:5: error: impossible constraint in `asm'

with gcc -v being

Reading specs from /usr/lib/gcc-lib/i486-pc-linux-gnu/3.3.3/specs
Configured with: /var/tmp/portage/gcc-3.3.3-r6/work/gcc-3.3.3/configure
--prefix=/usr --bindir=/usr/i486-pc-linux-gnu/gcc-bin/3.3
--includedir=/usr/lib/gcc-lib/i486-pc-linux-gnu/3.3.3/include
--datadir=/usr/share/gcc-data/i486-pc-linux-gnu/3.3
--mandir=/usr/share/gcc-data/i486-pc-linux-gnu/3.3/man
--infodir=/usr/share/gcc-data/i486-pc-linux-gnu/3.3/info --enable-shared
--host=i486-pc-linux-gnu --target=i486-pc-linux-gnu --with-system-zlib
--enable-languages=c,c++ --enable-threads=posix --enable-long-long
--disable-checking --disable-libunwind-exceptions --enable-cstdio=stdio
--enable-version-specific-runtime-libs
--with-gxx-include-dir=/usr/lib/gcc-lib/i486-pc-linux-gnu/3.3.3/include/g++-v3
--with-local-prefix=/usr/local --enable-shared --enable-nls
--without-included-gettext --disable-multilib --enable-__cxa_atexit
--enable-clocale=generic
Thread model: posix
gcc version 3.3.3 20040412 (Gentoo Linux 3.3.3-r6, ssp-3.3.2-2, pie-8.7.6)

so actually, this bug is already fixed. but i just felt like submitting it.

by the way, the correct asm code turned out to be

        unsigned char *stackptr = (unsigned char *)&stackptr;
        asm ("movl %%esp, %0\n" :"=r"(stackptr));

which works with both versions of gcc.

the bug was present on various linux systems, with different distributions,
processors and such.

-- 
           Summary: internal compiler error on invalid inline assembler code
           Product: gcc
           Version: 3.2.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: m dot a dot termeer at student dot tue dot nl
                CC: gcc-bugs at gcc dot gnu dot org
  GCC host triplet: various linux systems


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17176



More information about the Gcc-bugs mailing list