I have a 64 Bit PC using Debian 10 as the operating system with all updates installed.
The C - file, called main.c, looks very simple:
//**************************************
#include <stdio.h>
extern void test(void); // This is the function, that is defined in test.asm
int main(int argc, char * argv[]) {
printf("Start here !\n");
test();
printf("Ready !\n");
return 0;
}
// **************************************
The assembly file, called test.asm looks simple too:
The function only returns to the caller
;**************************************
default rel
section .data ; Data section, initialized variables
section .bss ; Data section, uninitialized variables
section .txt
global test
test:
ret
;**************************************
Now I create the obj file from test.asm using the following command line:
nasm -Wall -f elf64 test.asm -o test.o
This call functions without any error messages :)
Now I compile the file main.c and link both object files together main.o + test.o to an executable called 'main' using the following commandline:
gcc -Wall -m64 main.c test.o -o main
This call functions without any error messages too.
When I try to start the executable called main, the only thing the program does is to create a crash and an error message that shows me:
xxxx@debian:~/Assembler$ ./main
Start here !
Speicherzugriffsfehler
xxxx@debian:~/Assembler$
The error message "Speicherzugriffsfehler" means nothing else than Memory access error >:(
How can I solve this problem ?
Thank you for every help !
**********************************************************************************************************************
Here are some version information:
xxxx@debian:~/Assembler$ nasm -v
NASM version 2.14
xxxx@debian:~/Assembler$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/8/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 8.3.0-6' --with-bugurl=file:///usr/share/doc/gcc-8/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++ --prefix=/usr --with-gcc-major-version-only --program-suffix=-8 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-bootstrap --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --enable-default-pie --with-system-zlib --with-target-system-zlib --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 8.3.0 (Debian 8.3.0-6)
xxxx@debian:~/Assembler$ uname -r
5.10.34
xxxx@debian:~/Assembler$ uname -a
Linux debian 5.10.34 #1 SMP Tue May 4 18:56:34 CEST 2021 x86_64 GNU/Linux
xxxx@debian:~/Assembler$ file ./main
./main: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, BuildID[sha1]=509d09910779cccc2da737fc9827550b819530c8, not stripped