ARCH: amd64 I'm trying to learn some asm, but can't get an executable running. To start off I'm trying my hand on a hello world program http://www.int80h.org/bsdasm/ section 4.5 and chapter 5 with slight adaptations. Issuing the following commands results in:
$ yasm -f elf64 hello.s $ ld -s -o hello hello.o ld: hello.o: relocation R_X86_64_32 can not be used when making a shared object; recompile with -fPIC hello.o: could not read symbols: Bad value $ readelf -r hello.o Relocation section '.rela.text' at offset 0x64 contains 1 entries: Offset Info Type Sym. Value Sym. Name + Addend 000000000006 00030000000a R_X86_64_32 0000000000000000 .data + 0 $ ld -nopie -static -s -o hello hello.o $ hello hello: Exec format error. Binary file not executable. $ file hello hello: ELF 64-bit LSB executable, x86-64, version 1, statically linked, stripped This article http://www.tortall.net/projects/yasm/manual/html/objfmt-elf64.html mentions something about PIC, but I just can't understand what it's saying. I can't even figure out the syntax of wrt. All I found was a 16 bit nasm example dealing with segment registers. If someone can give me a nudge in the right direction, it would be highly appreciated. CODE: (copied from include files) %define stdin 0 %define stdout 1 %define stderr 2 ; syscall: "exit" ret: "void" args: "int" %define SYS_exit 1 ; syscall: "write" ret: "ssize_t" args: "int" "const void *" "size_t" %define SYS_write 4 %macro sys.exit 0 system SYS_exit %endmacro %macro sys.write 0 system SYS_write %endmacro section .text align 4 access.bsd.kernel: int 80h ret %macro system 1 mov rax,%1 call access.bsd.kernel %endmacro CODE: (hello.s) section .data hello db "Greetings y'all!",0ah hbytes equ $-hello section .text global _start _start: push dword hbytes push dword hello push dword stdout sys.write push dword 0 sys.exit -- http://www.fastmail.fm - A no graphics, no pop-ups email service _______________________________________________ Openbsd-newbies mailing list [email protected] http://mailman.theapt.org/listinfo/openbsd-newbies
