flat assembler
Message board for the users of flat assembler.
Index
> Unix > Hello World on FreeBSD |
Author |
|
LocoDelAssembly 19 Nov 2006, 14:10
What's wrong here?
Code: $ uname -vmp FreeBSD 6.1-RELEASE #0: Sun May 7 04:32:43 UTC 2006 root@opus.cse.buffalo.e du:/usr/obj/usr/src/sys/GENERIC i386 i386 $ cat hello-exe.asm format ELF executable entry main main: push mensaje.size push mensaje push 1 ; stdout mov eax, 4 ; sys_write push 0 ; dummy argument int $80 xor eax, eax ; sys_exit int $80 mensaje db "Hello World ", 10 mensaje.size = $-mensaje $ ./fasm hello-exe.asm flat assembler version 1.67.14 (16384 kilobytes memory) 3 passes, 121 bytes. $ chmod +x hello-exe $ ./hello-exe ELF binary type "0" not known. ./hello-exe: 1: Syntax error: "(" unexpected $ file hello-exe hello-exe: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), statically linked, stripped $ Note that producing an ELF object first and then using gcc to produce the executable works fine Code: $ uname -vmp FreeBSD 6.1-RELEASE #0: Sun May 7 04:32:43 UTC 2006 root@opus.cse.buffalo.e du:/usr/obj/usr/src/sys/GENERIC i386 i386 $ cat hello.asm format ELF public main main: push mensaje.size push mensaje push 1 ; stdout mov eax, 4 ; sys_write push 0 ; dummy argument int $80 xor eax, eax ; sys_exit int $80 mensaje db "Hello World ", 10 mensaje.size = $-mensaje $ ./fasm hello.asm flat assembler version 1.67.14 (16384 kilobytes memory) 3 passes, 377 bytes. $ gcc hello.o -o hello $ ./hello Hello World :D $ file hello hello: ELF 32-bit LSB executable, Intel 80386, version 1 (FreeBSD), dynamically linked (uses shared libs), not stripped $ file hello.o hello.o: ELF 32-bit LSB relocatable, Intel 80386, version 1 (SYSV), not stripped $ Is the last one method the unique available to produce executables for FreeBSD? |
|||
19 Nov 2006, 14:10 |
|
Tomasz Grysztar 19 Nov 2006, 15:25
Perhaps you need to use the "brandelf -t FreeBSD" command, or something like?
|
|||
19 Nov 2006, 15:25 |
|
Tomasz Grysztar 19 Nov 2006, 16:30
Well, it was already requested: http://board.flatassembler.net/topic.php?t=6163
I certainly should consider this. |
|||
19 Nov 2006, 16:30 |
|
LocoDelAssembly 19 Nov 2006, 18:09
Thanks for consider this
|
|||
19 Nov 2006, 18:09 |
|
LocoDelAssembly 30 Nov 2006, 21:23
Code: $ brandelf -t Linux hello-exe $ file hello-exe hello-exe: ELF 32-bit LSB executable, Intel 80386, version 1 (GNU/Linux), statically linked, stripped $ ./hello-exe Segmentation fault (core dumped) Now I see why the Linux examples doesn't work in FreeBSD, because fasm produces SYSV executables instead. Is there some difference between Unix SysV ABI and Linux ABI or just FreeBSD is too strict? PS: Note that the Segmentation fault is OK since the way I'm calling the kernel is for FreeBSD (I'm using the same source from the first post). PS2: And I have Linux ABI compatibility enabled of course |
|||
30 Nov 2006, 21:23 |
|
crc 02 Dec 2006, 04:58
The Linux ABI is different. The BSDs (at least on 32-bit) pass arguments to syscalls via the stack, where Linux uses registers. I believe that at least some of the function numbers differ as well.
FreeBSD does support the Linux ABI, but if you brand a FreeBSD executable as "Linux", it will try to run it with the Linux ABI and have problems quickly. As a side note, not all BSD's make use of branding. NetBSD for example checks for a ".note.netbsd.ident" section for branding information, rather than use a "brandelf" type tool. Given this, it is possible to make a program that works on both FreeBSD (after branding) and NetBSD (no branding needed if this section exists with the proper values). |
|||
02 Dec 2006, 04:58 |
|
LocoDelAssembly 02 Dec 2006, 14:16
crc, yes, I know that Linux ABI is different to FreeBSD ABI. My question was
Quote:
Thanks for the note about NetBSD, now we know that http://board.flatassembler.net/topic.php?t=6163 is not enough (if fasm just brands the executable instead of adding a note when found NetBSD) PD: Not that by strict I mean that FreeBSD refuses to execute SYSV executables when the same executables works on Linux with "SYSV" brand and "Linux" brand. |
|||
02 Dec 2006, 14:16 |
|
hamoz 20 Feb 2007, 18:26
LocoDelAssembly, that is your hello world example
I didnt use gcc to link the hello coz the current fasm gave me an executable file no hello.o < no object file > it works well after I have been allowed it as a root Quote: # ./fasm hello.asm tell me why I didnt need to gcc is it an advantage in the current fasm because the fasm is linked by gcc first time and we dont need it again I did it easily than yours thanks alot |
|||
20 Feb 2007, 18:26 |
|
LocoDelAssembly 20 Feb 2007, 23:09
Not sure if you are asking or not You don't need gcc for your files assembled with fasm because since you have specified "format ELF executable" it produces an executable and for that reason no linking is needed but a branding is required since fasm brands the executable as SysV and that doesn't work.
|
|||
20 Feb 2007, 23:09 |
|
hamoz 20 Feb 2007, 23:35
exactly I have been specified " format ELF executable "
but one question what does the brandelf command brand to if it is not SYSV.... |
|||
20 Feb 2007, 23:35 |
|
LocoDelAssembly 21 Feb 2007, 00:17
The branding specifies which type of ABI (Application Binary Interfase) the executable has, for example FreeBSD supports Linux executables so if you brand it as Linux, FreeBSD will execute it but since the kernel on FreeBSD is called different than Linux the executable will produce errors at runtime (The parameters on FreeBSD system call are passed in stack but on Linux are passed with registers).
|
|||
21 Feb 2007, 00:17 |
|
hamoz 21 Feb 2007, 00:24
LocoDelAssembly, I really thank you so much
cheers newbie |
|||
21 Feb 2007, 00:24 |
|
jb 26 Mar 2007, 23:23
I have a small patch for fasm to create an elf note for NetBSD 3.1/i386 executables. It allows a new flag (`note') in the segment directive. Here's a small example of how to use it:
$ cat test.asm format elf executable entry start start: push 47 push eax xor eax,eax inc eax int 0x80 include 'note.inc' $ cat note.inc segment note dd 0x00000007 dd 0x00000004 dd 0x00000001 dd 0x4274654e dd 0x00004453 dd 0x11f0e540 $ fasm test.asm flat assembler version 1.67.21 (16384 kilobytes memory) 3 passes, 148 bytes. $ file test test: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), for NetBSD 3.1, statically linked, stripped $ ./test; echo $? 47 $ readelf -l test Elf file type is EXEC (Executable file) Entry point 0x8048074 There are 2 program headers, starting at offset 52 Program Headers: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align LOAD 0x000074 0x08048074 0x08048074 0x00008 0x00008 RWE 0x1000 NOTE 0x00007c 0x0804907c 0x0804907c 0x00018 0x00018 0x4 To keep `file' accurate the alignment was changed from 4K to 4. RWE is a don't care. The note itself was created by picking a random executable (i.e. /bin/ls), looking at the segment header for the note to get offset and size (0x00018=24 bytes), and then doing a hexdump -e '6/4 "dd 0x%08x\n"' -n 24 -s 0x108 on /bin/ls. Here's the patch: $ rcsdiff -r1.1 -rnote formats.inc =================================================================== RCS file: formats.inc,v retrieving revision 1.1 retrieving revision 1.2 diff -r1.1 -r1.2 3630a3631,3632 > cmp ah,4 > je elf_note 3643a3646,3649 > elf_note: > mov byte [ebx],4 > mov word [ebx+1Ch],4 > jmp elf_segment_flags $ rcsdiff -r1.1 -rnote tables.inc =================================================================== RCS file: tables.inc,v retrieving revision 1.1 retrieving revision 1.2 diff -r1.1 -r1.2 273a274 > db 'note',19h,32 Crude, but effective. |
|||
26 Mar 2007, 23:23 |
|
LocoDelAssembly 13 Jul 2010, 23:41
Well, I can't remember how I managed to copy the text from the VirtualPC (or maybe changed the copy behavior in some version?), so I'll have to post a screenshot instead...
It is essentially the same code I posted at the beginning of this thread but now the linker nor brandelf are needed anymore (due to the latest changes in the ELF formatter) PS: Notice the "9" in the first line of the code, that is the value for FreeBSD ABI.
|
||||||||||
13 Jul 2010, 23:41 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.