I am having some weird issues with ELF binaries in linux.
This is my system ( uname -a ):
Linux 3.16.0-4-amd64
I have the following program (test.asm), I compile it using NASM:
; program just exits with code 0 using linux INT 80H SECTION .data SECTION .text GLOBAL _start _start: MOV EAX, 1 XOR EBX, EBX INT 0x80
I create three different executables:
nasm -f elf32 -o test32-i386.o test.asm ld -m elf_i386 -o test32-i386 test32-i386.o nasm -f elfx32 -o test32-x86_64.o test.asm ld -m elf32_x86_64 -o test32-x86_64 test32-x86_64.o nasm -f elf64 -o test64-x86_64.o test.asm ld -m elf_x86_64 -o test64-x86_64 test64-x86_64.o
This is the result of the file command:
test32-i386: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), statically linked, not stripped test32-x86_64: ELF 32-bit LSB executable, x86-64, version 1 (SYSV), statically linked, not stripped test64-x86_64: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, not stripped
It makes sense to me. However, their launch causes problems.
./test32-i386 : no problem, working fine../test64-x86_64 : the same, it works fine../test32-x86_64 , however, gives bash: ./test32-x86_64: cannot execute binary file: Exec format error
In addition, Valgrind produces ... interesting results.
valgrind ./test32-i386 : OKvalgrind ./test64-x86_64 : raises SIGILL (?!)valgrind ./test32-x86_64 : gives me ./test32-x86_64: 1: ./test32-x86_64: Syntax error: word unexpected (expecting ")")
So, we summarize:
Question 1: Why does Valgrind raise SIGILL when it starts ./test64-x86_64 , although the program works fine without Valgrind?
Question 2: Why can not I run ./test32-x86_64 ? Valgrind error gives that binary is very obscure ...