This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/71033] New: Segmentation fault c + intel assembly, unable to use EBX
- From: "formateu at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Mon, 09 May 2016 19:41:17 +0000
- Subject: [Bug c/71033] New: Segmentation fault c + intel assembly, unable to use EBX
- Auto-submitted: auto-generated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71033
Bug ID: 71033
Summary: Segmentation fault c + intel assembly, unable to use
EBX
Product: gcc
Version: 6.1.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: formateu at gmail dot com
Target Milestone: ---
Created attachment 38459
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=38459&action=edit
the preprocessed file
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-linux-gnu/6.1.1/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /build/gcc-multilib/src/gcc/configure --prefix=/usr
--libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man
--infodir=/usr/share/info --with-bugurl=https://bugs.archlinux.org/
--enable-languages=c,c++,ada,fortran,go,lto,objc,obj-c++ --enable-shared
--enable-threads=posix --enable-libmpx --with-system-zlib --with-isl
--enable-__cxa_atexit --disable-libunwind-exceptions --enable-clocale=gnu
--disable-libstdcxx-pch --disable-libssp --enable-gnu-unique-object
--enable-linker-build-id --enable-lto --enable-plugin
--enable-install-libiberty --with-linker-hash-style=gnu
--enable-gnu-indirect-function --enable-multilib --disable-werror
--enable-checking=release
Thread model: posix
gcc version 6.1.1 20160501 (GCC)
Program runs intel x86 assembly function in main. Use of the EBX register
inside that function causes segmentation fault (after return from function).
It seems like gcc is using EBX instead of EBP before function call.
Program compiled using clang works properly.
Bug was noticed firstly on gcc 5.3.0 version, but is still present on latest
repository version.
Used makefile:
CC=gcc
CFLAGS= -Wall -m32 -O0 -save-temps
all: main.o f.o
$(CC) $(CFLAGS) main.o f.o -o fun
main.o: main.c
$(CC) $(CFLAGS) -c main.c -o main.o
command : make && ./fun 2
f.o: f.s
nasm -f elf -g f.s -o f.o
main.c :
#include "f.h" //only void f(char*)
int main(int argc, char *argv[])
{
if(argc < 2) {
return 1;
}
f(argv[1]);
return 0;
}
f.s :
;f.i is not generated
section .text
global f
f:
push ebp
mov ebp, esp
mov eax, [ebp+8]
mov ebx, 9
begin:
mov cl, [eax]
cmp cl, 0
jz end
add cl, 1
mov [eax], cl
inc eax
jmp begin
end:
mov esp, ebp
pop ebp
ret