https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71030

            Bug ID: 71030
           Summary: Strange segmentation fault
           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 38457
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=38457&action=edit
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) 

Used makefile 
CC=gcc
CFLAGS= -Wall -m32         

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
f.o: f.s                   
  nasm -f elf -g f.s -o f.o

make && ./fun 2 2

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.

main.c file : 

#include "f.h" // only void f(int); + guardian

int main()
{
  int var = 4;
  f(var);
  return 0;
}

f.s file :

  section .text
  global f
f:
  push ebp
  mov ebp, esp
  mov eax, [ebp+8]
  mov ebx, 0
begin:
  mov cl, [eax]
  mov ebx, 0
  add cl, 1
  mov [eax], cl
  mov esp, ebp
  pop ebp
  ret

Reply via email to