[Bug c/63318] Hello World C program using inline assembly to invoke write(2) on amd64 Linux fails to print Hello World
ryao at gentoo dot org
gcc-bugzilla@gcc.gnu.org
Sat Sep 20 19:51:00 GMT 2014
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63318
Richard Yao <ryao at gentoo dot org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|RESOLVED |UNCONFIRMED
Resolution|INVALID |---
--- Comment #4 from Richard Yao <ryao at gentoo dot org> ---
Neither of the versions that you suggest work with my local GCC installation.
The first fails to compile, but will compile if I 's/string/hello/'. The second
compiles. Neither result in the compiler emitting "Hello World!\n". Clang does
work in all cases, except for the first before the correction is made.
Here is the output for the second version from GCC:
$ gcc -S -o - syscall.c -Wall -Wextra -fno-strict-aliasing -fwrapv
.file "syscall.c"
.text
.globl main
.type main, @function
main:
.LFB0:
.cfi_startproc
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp
.cfi_def_cfa_register 6
subq $48, %rsp
movq %fs:40, %rax
movq %rax, -8(%rbp)
xorl %eax, %eax
movabsq $8022916924116329800, %rax
movq %rax, -32(%rbp)
movl $560229490, -24(%rbp)
movw $10, -20(%rbp)
movq $14, -48(%rbp)
leaq -32(%rbp), %rax
#APP
# 8 "syscall.c" 1
movl $1, %eax
movl $1, %edi
movq %rax, %rsi
movl -48(%rbp), %edx
syscall
# 0 "" 2
#NO_APP
movq %rax, -40(%rbp)
movl $0, %eax
movq -8(%rbp), %rdx
xorq %fs:40, %rdx
je .L3
call __stack_chk_fail
.L3:
leave
.cfi_def_cfa 7, 8
ret
.cfi_endproc
.LFE0:
.size main, .-main
.ident "GCC: (Gentoo 4.8.3 p1.1, pie-0.5.9) 4.8.3"
.section .note.GNU-stack,"",@progbits
It is clear that this used to work. If the failure is because the compiler has
become more strict, then it should be possible to rewrite this in a way that
produces a working program. If we cannot, I think this would qualify as a
regression.
Gentoo does not yet package newer versions of GCC, so it is possible that this
is fixed in a newer version. If that is the case, I would like confirmation of
that. I am setting this back to Unconfirmed lest that it be forgotten before we
are on the same page.
More information about the Gcc-bugs
mailing list