Author Topic: Problem using Nasm on OpenBSD x64  (Read 4854 times)

Offline pyro_akm

  • Jr. Member
  • *
  • Posts: 2
Problem using Nasm on OpenBSD x64
« on: November 11, 2019, 01:10:06 PM »
Hi.

I'm trying to use assembly code in a C application on OpenBSD AMD64.
I've got a segmentation fault on the first instruction of my assembly function: push rbp.
Here is my code:

main.c
void test(void);
void main(void)
{
  test();
  return;
}


test.asm
bits    64
global  test
section .code
test:
   push   rbp ;<-Crash here
   pop   rbp
   ret


makefile.mak
coptions=-c -Wall -Wno-uninitialized -Wno-strict-aliasing -Wno-write-strings -Wno-unused-result -Wno-missing-braces -O0 -g

test: \
main.o \
test.o

   gcc \
main.o \
test.o \
-lpthread \
-lstdc++ \
-lm \
-g -Wl,-s -Wl,-Map,test.map -o./test \

main.o: main.c
   gcc $(coptions) main.c -o./main.o
test.o: test.asm
   nasm -g -f elf64 -O3 -o ./test.o test.asm


Can someone help me?

Antoine Guillon

Offline pyro_akm

  • Jr. Member
  • *
  • Posts: 2
Re: Problem using Nasm on OpenBSD x64
« Reply #1 on: November 11, 2019, 01:20:20 PM »
I just find the problem.
Using section .text instead of section .code allow execution of the instructions without segmentation fault.

Antoine Guillon
« Last Edit: November 11, 2019, 01:24:43 PM by pyro_akm »