foo.c: asm ( ".globl bar\n\t" "bar:\n\t" "movl $5, %eax\n\t" "ret" ); main() { return bar(); }
$ gcc -g2 foo.c; ./a.out; echo $? 5 $ gcc foo.c -g3; ./a.out; echo $? Segmentation fault 139 Disassembly of the a.out compiled with -g3 gives: (gdb) disass main Dump of assembler code for function main: 0x08048364 <main+0>: push %ebp 0x08048365 <main+1>: mov %esp,%ebp 0x08048367 <main+3>: sub $0x8,%esp 0x0804836a <main+6>: and $0xfffffff0,%esp 0x0804836d <main+9>: mov $0x0,%eax 0x08048372 <main+14>: add $0xf,%eax 0x08048375 <main+17>: add $0xf,%eax 0x08048378 <main+20>: shr $0x4,%eax 0x0804837b <main+23>: shl $0x4,%eax 0x0804837e <main+26>: sub %eax,%esp 0x08048380 <main+28>: call 0x4852 0x08048385 <main+33>: leave 0x08048386 <main+34>: ret End of assembler dump. Note the call to an invalid location; it is this that causes the segfault. Seen in the wild in tetex-3.0 (uses asm functions in metafont). Workaround: don't use -g3. I will attach gcc -g3 -S foo.c output. -- Summary: -g3 (-ggdb3) emits broken calls to asm-defined functions Product: gcc Version: 3.4.6 Status: UNCONFIRMED Severity: normal Priority: P3 Component: debug AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: ed at catmur dot co dot uk GCC build triplet: i686-pc-linux-gnu GCC host triplet: i686-pc-linux-gnu GCC target triplet: i686-pc-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26908