DaemonForums  

Go Back   DaemonForums > Miscellaneous > Programming

Programming C, bash, Python, Perl, PHP, Java, you name it.

Reply
 
Thread Tools Display Modes
  #1   (View Single Post)  
Old 25th July 2017
billy_bazooka billy_bazooka is offline
Port Guard
 
Join Date: Sep 2016
Posts: 31
Default why does this simple assembly program abort trap?

Code:
section .note.openbsd.ident
align 2
dd 8, 4, 1
db 'OpenBSD', 0
dd 0
align 2

extern SDL_Init

section .text
global _start
_start:
  mov rdi, 0x20
  call SDL_Init
  xor eax, eax
  inc al
  syscall
i compile it like this
Code:
nasm -f elf64 main.asm -o main.o
ld -o main main.o -lc -m elf_x86_64_obsd -nopie -L/usr/local/lib -lSDL2 -L/usr/X11R6/lib -R/usr/X11/R6/lib
when i start it i get:
Code:
Abort trap
not really sure what i did wrong? can someone help?
Reply With Quote
  #2   (View Single Post)  
Old 26th July 2017
ibara ibara is offline
OpenBSD language porter
 
Join Date: Jan 2014
Posts: 783
Default

Even when whitespace isn't semantically important, it's still important. That's not how you write assembly.

Now, on to what you care about. Your ld(1) incantation is wrong. It's easier to use cc(1) to do the linking for you.

I fixed your main.asm:
Code:
        section .note.openbsd.ident
        align   2
        dd      8,4,1
        db      'OpenBSD',0
        dd      0
        align   2

        extern  SDL_Init

        section .text
        global  main
main:
        mov     edi,0x20        ; SDL_Init takes a uint32_t, not a uint64_t
        call    SDL_Init wrt ..plt      ; -fPIC
        mov     eax,1           ; Originally an xor eax,eax | inc al combo
        xor     edi,edi         ; You need a sane return code (otherwise it's 0x20)
        syscall
Then run:
Code:
$ nasm -f elf64 main.asm -o main.o
$ cc -L/usr/local/lib -L/usr/X11R6/lib -R/usr/X11R6/lib -o main main.o -lSDL2
Note that every line except for labels begins with a tab, labels are on their own lines, there is always a tab between the operator and the operands, there is no space before or after commas in the operand list, and comments are preceded by at least one tab. The sole exception to this is SDL_Init wrt ..plt but that is a limitation of the syntax (the equivalent AT&T syntax is SDL_Init@PLT, which doesn't exhibit this problem).

As an aside, I find Intel assembly syntax to be horrific. Unless there's a reason for you to be using nasm (and there are plenty, unfortunately) you might be better served learning AT&T assembly syntax and using as(1) as your assembler.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PF dynamic adding of ips to table (booby trap port) irukandji FreeBSD Security 8 5th December 2013 12:09 AM
learn assembly ephemera Book reviews 5 26th December 2012 06:29 PM
opera bug in openbsd 5.1 release with Abort Trap message daemonfowl OpenBSD Packages and Ports 2 26th May 2012 06:42 AM
Sparc assembly anyone? Randux Programming 4 24th June 2011 07:10 AM
Boot abort with gmirror problem lil_elvis2000 FreeBSD General 1 9th May 2008 08:06 PM


All times are GMT. The time now is 09:43 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Content copyright © 2007-2010, the authors
Daemon image copyright ©1988, Marshall Kirk McKusick