[Bug c/71030] New: Strange segmentation fault

2016-05-09 Thread formateu at gmail dot com
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

[Bug c/71030] Strange segmentation fault

2016-05-09 Thread formateu at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71030

--- Comment #2 from Mateusz Forc  ---
(In reply to H.J. Lu from comment #1)
> Please provide f.i.

f.i is not generated using -save-temps, how am I supposed to get this file?

[Bug c/71030] Strange segmentation fault

2016-05-09 Thread formateu at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71030

Mateusz Forc  changed:

   What|Removed |Added

 Status|WAITING |RESOLVED
 Resolution|--- |INVALID

[Bug c/71033] New: Segmentation fault c + intel assembly, unable to use EBX

2016-05-09 Thread formateu at gmail dot com
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

[Bug c/71033] Segmentation fault c + intel assembly, unable to use EBX

2016-05-09 Thread formateu at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71033

Mateusz Forc  changed:

   What|Removed |Added

 Status|UNCONFIRMED |RESOLVED
 Resolution|--- |INVALID

--- Comment #2 from Mateusz Forc  ---
(In reply to Uroš Bizjak from comment #1)
> x86 ABI requires that %ebx is preserved across function call. So, you need
> to save it to stack in f.s and restore it before function returs. Or, you
> can use %edx instead, which can be clobbered in function.