flat assembler
Message board for the users of flat assembler.
![]() |
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 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 Is the last one method the unique available to produce executables for FreeBSD? |
|||
![]() |
|
Tomasz Grysztar 19 Nov 2006, 15:25
Perhaps you need to use the "brandelf -t FreeBSD" command, or something like?
|
|||
![]() |
|
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. |
|||
![]() |
|
LocoDelAssembly 19 Nov 2006, 18:09
Thanks for consider this
![]() |
|||
![]() |
|
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 |
|||
![]() |
|
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). |
|||
![]() |
|
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. |
|||
![]() |
|
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 ![]() 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 ![]() |
|||
![]() |
|
LocoDelAssembly 20 Feb 2007, 23:09
Not sure if you are asking or not
![]() |
|||
![]() |
|
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.... ![]() |
|||
![]() |
|
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).
|
|||
![]() |
|
hamoz 21 Feb 2007, 00:24
LocoDelAssembly, I really thank you so much
![]() cheers newbie |
|||
![]() |
|
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. |
|||
![]() |
|
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.
|
||||||||||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.