/me compiles those with gfortran -S -fverbose-asm
Well, I can't tell *why* it happens, but I can tell what happens here: The segfaulting version initialises a .long 7 (labeled .LC0) in rodata, then tries to write to it right before calling ircon_. Since it's read-only, well, writing to it segfaults.
Well, I can't tell *why* it happens, but I can tell what happens here: The segfaulting version initialises a .long 7 (labeled .LC0) in rodata, then tries to write to it right before calling ircon_. Since it's read-only, well, writing to it segfaults.
Code:
$ cat works.s .file "foo.f" # GNU F95 version 4.1.1 (Gentoo 4.1.1-r1) (i686-pc-linux-gnu) # compiled by GNU C version 4.1.1 (Gentoo 4.1.1-r1). .text .globl MAIN__ .type MAIN__, @function MAIN__: pushl %ebp # movl %esp, %ebp #, subl $40, %esp #, movl $0, 8(%esp) #, movl $127, 4(%esp) #, movl $70, (%esp) #, call _gfortran_set_std # movl $7, -8(%ebp) #, istart leal -8(%ebp), %eax #, tmp59 movl %eax, (%esp) # tmp59, call ircon_ # movl %eax, -4(%ebp) # D.593, i leave ret .size MAIN__, .-MAIN__ .globl ircon_ .type ircon_, @function ircon_: pushl %ebp # movl %esp, %ebp #, movl 8(%ebp), %eax # istart, istart movl $5, (%eax) #, (* istart) popl %ebp # ret .size ircon_, .-ircon_ .ident "GCC: (GNU) 4.1.1 (Gentoo 4.1.1-r1)" .section .note.GNU-stack,"",@progbits
Code:
$ cat segfaults.s .file "foo.f" # GNU F95 version 4.1.1 (Gentoo 4.1.1-r1) (i686-pc-linux-gnu) # compiled by GNU C version 4.1.1 (Gentoo 4.1.1-r1). .section .rodata .align 4 .LC0: .long 7 .text .globl MAIN__ .type MAIN__, @function MAIN__: pushl %ebp # movl %esp, %ebp #, subl $40, %esp #, movl $0, 8(%esp) #, movl $127, 4(%esp) #, movl $70, (%esp) #, call _gfortran_set_std # movl $.LC0, (%esp) #, call ircon_ # movl %eax, -4(%ebp) # D.593, i leave ret .size MAIN__, .-MAIN__ .globl ircon_ .type ircon_, @function ircon_: pushl %ebp # movl %esp, %ebp #, movl 8(%ebp), %eax # istart, istart movl $5, (%eax) #, (* istart) popl %ebp # ret .size ircon_, .-ircon_ .ident "GCC: (GNU) 4.1.1 (Gentoo 4.1.1-r1)" .section .note.GNU-stack,"",@progbits
Code:
$ diff works.s segfaults.s 4a5,8 > .section .rodata > .align 4 > .LC0: > .long 7 16,18c20 < movl $7, -8(%ebp) #, istart < leal -8(%ebp), %eax #, tmp59 < movl %eax, (%esp) # tmp59, --- > movl $.LC0, (%esp) #,
Comment