flat assembler
Message board for the users of flat assembler.
Index
> Unix > fasm on MacOS X [Snow Leopard / Lion] Goto page 1, 2 Next |
Author |
|
Shirk 21 Sep 2011, 21:20
Hi,
it took the better part of the evening to debug this but I've found and fixed a piece in the libc-fasm to get it running on OSX. The former steps used to run fasm on OSX consested of:
This steps are still working however the latest release (1.69.32 at the time of this writing) will complain about being 'out of memory' of one tries to assemble anything - even an empty file. I was able to backtrack the issue to the function 'open' in system.inc. The specific line that causes the problem is line 95: Code: 93 : jnz copy_path 94 : cmp edi,buffer+1000h 95 : ja out_of_memory 96 : ret I was confused about what could go wrong with this - it's basically just a comparison between the string position (edi) and the end of 'buffer' ('buffer+1000h'). So I went on to add some debugging output to that method to dump the assigned value of 'edi', the address of 'buffer' as well as 'buffer+1000h'. The results where puzzling: Code: flat assembler version 1.69.32 (16384 kilobytes memory) mov edi, buffer - edi: 99856 mov eax, buffer+1000h - eax: 98400 mov eax, buffer; add eax, 1000h - eax: 103952 error:out of memory It looks like the code assembled on linux behaves differently on OSX - look at the odd adress in 'edi'.. and 'buffer+1000h' is somehow resolved to just 'buffer' (or even less than that..)! The same code runs just fine on linux - no out of memory, no strange gaps in the addresses.. My proposed fix is to use the variant shown in my debug line #3 - load the address of buffer in a register and then add 1000h at runtime: Code: --- a/source/libc/system.inc 2011-07-24 00:42:00.000000000 +0200 +++ b/source/libc/system.inc 2011-09-21 23:03:12.000000000 +0200 @@ -91,7 +91,9 @@ stos byte [edi] or al,al jnz copy_path - cmp edi,buffer+1000h + mov eax,buffer + add eax,1000h + cmp edi,eax ja out_of_memory ret create: This code works on linux as well as on OSX - I tested it by assembling fasm with this modified version and then using that binary to in turn assemble itself. I got three working versions of fasm able to compile the fasm sources. - I hope this fix is acceptable, or at least a start for an osx version P.S. I'm eager to know the reason for this odd behavior - if someone knows it.. Cheers, Shirk
|
|||||||||||
21 Sep 2011, 21:20 |
|
revolution 03 Nov 2011, 20:20
This might be a problem with relocations.
I wonder if Tomasz has seen this thread? Perhaps someone might want to PM Tomasz? |
|||
03 Nov 2011, 20:20 |
|
metalfishx 03 Nov 2011, 22:54
I think forgot everything! I should start learning from 0 again... lol...
Anything I try to compile, compiles just fine, to object file, but when I try to link using gcc or ld I get this: ld: warning: ignoring file test.o, file was built for unsupported file format which is not the architecture being linked (i386) Undefined symbols for architecture i386: "_main", referenced from: start in crt1.10.6.o ld: symbol(s) not found for architecture i386 collect2: ld returned 1 exit status Any ideas? Thanks |
|||
03 Nov 2011, 22:54 |
|
metalfishx 03 Nov 2011, 23:06
OK using:
objconv -fmacho32 -nu test.o test_m.o Just figured the macho... that will convert the object. Then: ld -arch i386 -o test test_m.o /usr/lib/crt1.o -lc I get: ld: warning: -macosx_version_min not specificed, assuming 10.7 Undefined symbols for architecture i386: "__printf", referenced from: ___main in test_m.o "_main", referenced from: __start in crt1.o (maybe you meant: ___main) ld: symbol(s) not found for architecture i386 So looks like it's closer... but, its bad fasm doesn't really compiles to macho... |
|||
03 Nov 2011, 23:06 |
|
metalfishx 04 Nov 2011, 04:02
Ok! Got something compiled! lol!
This: Code: format ELF section '.text' executable public main extrn printf main: push ebp mov ebp, esp push ebx mov ebx, esp and esp, 0xfffffff0 sub esp, 12 push ebx add esp, 16 mov dword [esp], msgHelloWorld call printf sub esp, 16 pop ebx mov esp, ebx pop ebx mov esp, ebp pop ebp mov eax, 0 ret section '.data' writeable msgHelloWorld db 'Hello world from FASM!',0xA,0 Compiled and linked with: >fasm test.asm test.o >objconv -fmacho32 -nu test.o test_m.o >ld -arch i386 -macosx_version_min 10.7 -o test test_m.o /usr/lib/crt1.o -lc Attached is the fasm+objconv binaries for Mac Os X (Lion in my case, but should work on Snow and maybe Leopard?), you should have the SDK installed of course.
_________________ --------------------------------------- Roberto A. Berrospe Machin Ruta Internet, Florida Uruguay --------------------------------------- |
|||||||||||
04 Nov 2011, 04:02 |
|
STLVNUB 04 Nov 2011, 07:46
Another fellow Hackintosher??
Thanks for this |
|||
04 Nov 2011, 07:46 |
|
metalfishx 04 Nov 2011, 13:40
Yeah, well actually I am on a MacBook Air, but yes, I had hackintosh long time ago
|
|||
04 Nov 2011, 13:40 |
|
metalfishx 04 Nov 2011, 15:34
Hey, just an opinion now this is sticky; I opine that the title should change to "FASM on MacOS X [Snow Leopard / Lion]" maybe?
|
|||
04 Nov 2011, 15:34 |
|
metalfishx 04 Nov 2011, 16:42
64 bit works too...
Need to figure (learn) lots of things, but did a test using simple syscall, compiled and works good Code: format ELF64 section '.text' executable public main extrn printf extrn exit ;macro for create .size constant automatically struc db [data]{ common . db data .size = $ - . } ;testing using syscall main: mov rax, 0x2000004 ; sys_write mov rdi, 1 ; stdout mov rsi, qword msgHelloWorld ; string mov rdx, msgHelloWorld.size ; length syscall mov rax, 0x2000001 ; sys_exit xor rdi, rdi ; exit code syscall section '.data' writeable msgHelloWorld db 'Hello 64bit World from FASM!',0x0A,0 Compiled, converted and linked with: > fasm test64.asm test64.o > objconv -fmacho64 -nu test64.o test64_m.o > ld -arch x86_64 -macosx_version_min 10.6 -o test64 test64_m.o /usr/lib/crt1.o -lc _________________ --------------------------------------- Roberto A. Berrospe Machin Ruta Internet, Florida Uruguay --------------------------------------- |
|||
04 Nov 2011, 16:42 |
|
metalfishx 04 Nov 2011, 18:03
Hey guys, here you go.
I've attached fasm source, fasm and objconv binaries, and also a bash script "compile" i've created to make all these calls easier... The script is simple: Quote:
Thanks.
_________________ --------------------------------------- Roberto A. Berrospe Machin Ruta Internet, Florida Uruguay --------------------------------------- |
|||||||||||
04 Nov 2011, 18:03 |
|
metalfishx 04 Nov 2011, 23:12
More advances in testing 64 bits libc calls...
Code: format ELF64 ;new line nl = 0x0A section '.text' executable extrn printf extrn exit public main main: push rbp mov rbp, rsp sub rsp, 0x10 xor al, al lea rcx, qword [theMessage] mov rdi, rcx call printf mov rcx, 0 call exit pop rbp ret section '.data' writable theMessage db nl,nl,'*************************',nl,'FASM 64 bit printf call under OS X!',nl,'*************************',nl,nl,0 linking with ld will give you an error: Quote:
Why? ehmmmmmmmmmmm not sure (still learning hehe), any ideas?... But well, linking this with gcc works just fine! Use: gcc -m64 -o file file.o _________________ --------------------------------------- Roberto A. Berrospe Machin Ruta Internet, Florida Uruguay --------------------------------------- |
|||
04 Nov 2011, 23:12 |
|
revolution 05 Nov 2011, 04:06
metalfishx wrote: linking with ld will give you an error: |
|||
05 Nov 2011, 04:06 |
|
metalfishx 05 Nov 2011, 04:40
Hi! Thanks for the answer!
That wasn't the problem, I figured it out, It was my fault! (of course) I was missing libc.dylib ... Now I am calling ld this way: > ld -arch x86_64 -macosx_version_min 10.7 -o printf64 printf64.o /usr/lib/crt1.o /usr/lib/libc.dylib Attached is the modified "compile"; for now the libs are console only, but good for playing a little
_________________ --------------------------------------- Roberto A. Berrospe Machin Ruta Internet, Florida Uruguay --------------------------------------- |
|||||||||||
05 Nov 2011, 04:40 |
|
Shirk 14 Nov 2011, 16:17
Well.. so much for topic-reply notification - I totally missed 12 replies!
I'm going to pm / mail thomasz - let's see what he thinks about the patch (or the underlying issue). Thank's at all who read and added to this thread - especially to metalfishx for the binaries |
|||
14 Nov 2011, 16:17 |
|
metalfishx 14 Nov 2011, 16:32
Oh, you welcome; thank you all for for the great work with FASM...
_________________ --------------------------------------- Roberto A. Berrospe Machin Ruta Internet, Florida Uruguay --------------------------------------- |
|||
14 Nov 2011, 16:32 |
|
revolution 16 Nov 2011, 08:12
Shirk wrote: Well.. so much for topic-reply notification - I totally missed 12 replies! |
|||
16 Nov 2011, 08:12 |
|
Shirk 18 Nov 2011, 18:37
@revolution - no, it is checked but probably I've read a post without being logged in.
FYI - I PM'ed Thomasz and we agreed that it looks like a bug in objconv. Something related to a relocation type not properly handled in the conversion. So - do we have any alternative like objcopy or something else to convert the binary? |
|||
18 Nov 2011, 18:37 |
|
metalfishx 18 Nov 2011, 19:20
Would be amazing to have FASM to do the whole conversion
I have to admint that I been trying NASM for a while; it comes bundled with Mac OS X SDK and it handles everything, including macho format and things, but I went back to FASM; because I don't like NASM at all, the syntax, the macros, I prefer FASM all the way; it's like comparing C and Objective C... |
|||
18 Nov 2011, 19:20 |
|
zab 28 May 2012, 22:45
Hi guys,
I'm very new to FASM and assembly in general, so bear with me please. I've 2 Apple machines. One with OSX Lion (64bits) and the other one under OSX Snow Leopard (32bits). Can someone point please to a FASM binary so I can start learn programming on OSX? N.B: I'm not interested in doing any graphical programming with FASM, only console applications. Thanks Zab |
|||
28 May 2012, 22:45 |
|
Goto page 1, 2 Next < Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.