flat assembler
Message board for the users of flat assembler.
Index
> Compiler Internals > FASM AS LIB |
Author |
|
revolution 30 Dec 2008, 01:49
wrote: ... read error at adress 290465279 ... BTW, you can use print statements (or int3 instructions) to show if various parts have been reached. |
|||
30 Dec 2008, 01:49 |
|
master92 30 Dec 2008, 10:54
revolution wrote: Can you give more information about the error. Is the value you give hex or decimal? My guess is decimal since it is so large. Is that value the instruction pointer or a data pointer? At what stage of the process does it fail? Does it pass the preprocessor stage? Parser? Assembler? Formatter? Where? Is the error in the assembler lib or your wrapper code? The read error address the debugger (from PureBasic, no ASM debugger) gives out is decimal, but as I said the memory area at this address is far away from the area that has been allocated with AllocateMemory in my test application (which is translated to the HeapAlloc WINAPI function) and far away from the area the executable is mapped into memory (I checked that with the PureBasic debugger). I don't know what kind of pointer that actually is. I only know that a instruction in the Assemble function causes to read at that specified memory address but this address actually isn't allocated for this process. I'm not very familiar with ASM debugging, I've been using the debugger of my programming language, and this one only shows me that the memory access violation occurs in the Assemble function. The error must have something to do with the assembler lib because my wrapper code works when calling the fasm_Assemble function with the same parameters from the original dll. As I said, I'm sad, but I don't know how to efficiently debug the ASM Code, I think I'll write some Messagebox macro to see at which part of the ASM Code the error occurs. Thanks P.S.: Because I heard the word wrapper: I'm not going to integrate FASM into my executable and publish that as my own assembler =) This is only a test application. The final executable will be something like a compiler or something similar, in any case the ASM Code is generated at runtime dependent on the user's input and FASM is used to translate it into executable code. |
|||
30 Dec 2008, 10:54 |
|
revolution 30 Dec 2008, 11:42
I recommend Ollydbg for debugging ASM.
|
|||
30 Dec 2008, 11:42 |
|
master92 30 Dec 2008, 12:01
|
|||
30 Dec 2008, 12:01 |
|
master92 31 Dec 2008, 00:07
Ok, it crashes directly after entering the Assemble function.
When i put a return statement right after the Assemble label the Assemble function returns properly ( who would have expected that =) ) Code: Assemble: ret virtual at esp+4 ... But when I try Code: Assemble: invoke MessageBox,0,"TEST","TEST",MB_OK ret the code crashes at this MessageBox !!??!! I didn't understand the complex interface of Ollydbg, the only thing I could find out that it crashes right after entering the Assemble function (which I also found out with my MessageBox debugging method...) Anyone a solution? It think it could have to do with the calling convention, the way parameters are passed etc... Functions that do not call anything (like the Assembler_Init function) return properly but otherwise the program crashes... |
|||
31 Dec 2008, 00:07 |
|
revolution 31 Dec 2008, 01:55
Be more specific about what happens when you say "crashes". The are many things that can make it "crash". Examine the code at the point of the "crash" with Ollydbg. Just let it run (F9) and when it crashes you get to see the where it happened with all the gory details of registers contents and instruction location etc.
|
|||
31 Dec 2008, 01:55 |
|
Yardman 31 Dec 2008, 07:12
[ Post removed by author. ]
Last edited by Yardman on 04 Apr 2012, 03:34; edited 1 time in total |
|||
31 Dec 2008, 07:12 |
|
master92 01 Jan 2009, 14:49
Ok, after some debugging and hundreds of test tries I actually don't know how to go on.
OllyDBG shows the following messagebox (actually the same message as the PureBasic debugger shows): Error Don't know how to continue because memory at address 57A425FF is not readable. Try to change EIP or pass exception to program. @Yardman I made all the changes you suggested but there's no noticeable difference... So the last thing I tried was the following simple code: Code: format MS COFF include 'fasm\include\win32a.inc' extrn '_MessageBoxA@16' as MessageBox:Dword section '.data' data readable writeable _teststring: db "TEST",0 section '.code' code readable executable public _test@0 _test@0: invoke MessageBox,0,_teststring,_teststring,0 ret with the following simple PureBasic code: Code: Import "test.lib" test() As "_test@0" EndImport test() The error occurs even in this simple messagebox code! Perhaps there's some incompatibility with FASM and the two linkers I tried... I actually don't know how to continue... Another part of my application consists of a parser engine written in MASM originally designed as a DLL. I had no problems converting it into a lib. I even didn't had to change very much of the code, only renaming the DllMain into Parser_Init and the fdwReason variable testing in DllMain. And I actually thought here it would be easy, too, but the first thing was that FASM doesn't allow me to import functions when exporting aa a MS COFF object file (MASM supports that, it import the whole lib into the object file!!!). The problem was not that big, only write some EXTRN statements and import the needed LIBS when linking the final executable... But now I've that problem and I don't find out why this fucking invalid memory access occurs. Anyone a suggestion where the problem is or is there another way to convert FASM into a library file? |
|||
01 Jan 2009, 14:49 |
|
revolution 01 Jan 2009, 15:02
I don't have PureBasic so I can't test this for you. Perhaps you can zip the exe and attach it. It may give a clue about what has been linked etc.
|
|||
01 Jan 2009, 15:02 |
|
master92 01 Jan 2009, 19:36
revolution wrote: I don't have PureBasic so I can't test this for you. Perhaps you can zip the exe and attach it. It may give a clue about what has been linked etc. The Purebasic Compiler uses FASM as backend, too. It generates ASM output and sends it to FASM, which generates a MS COFF file which is linked by a 3rd party compiler (I think polib.exe from Pelles C Compiler). Here's the zip (attachment) with the sourcecode, the linked lib (linked with MASM32 Library Manager) and the final test executable. The generated ASM output (for FASM) by the PureBasic Compiler (exports as MS COFF, so I think a additional linker is required for linking into executable (must import the Windows Library kernel32.lib and the test.lib)), but I already compiled this one and added the executable into the attachment! So the fully source is provided for FASM. (The error must be somewhere... I hope...) Code: ; ; PureBasic 4.20 (Windows - x86) generated code ; ; (c) 2008 Fantaisie Software ; ; The header must remain intact for Re-Assembly ; ; :System ; KERNEL32 ; :Import ; D:\Projekte\Compiler\Development\assembler\test.lib ; format MS COFF ; extrn _test@0 extrn _ExitProcess@4 extrn _GetModuleHandleA@4 extrn _HeapCreate@12 extrn _HeapDestroy@4 ; extrn _memset extrn _PB_StringBase extrn PB_StringBase extrn _SYS_InitString@0 ; extrn _PB_StringBasePosition public _PB_Instance public _PB_ExecutableType public _PB_MemoryBase public PB_Instance public PB_MemoryBase public _PB_EndFunctions public _PB_DEBUGGER_LineNumber public _PB_DEBUGGER_IncludedFiles macro pb_public symbol { public _#symbol public symbol _#symbol: symbol: } macro pb_align value { rb (value-1) - ($-_PB_DataSection + value-1) mod value } macro pb_bssalign value { rb (value-1) - ($-_PB_BSSSection + value-1) mod value } public PureBasicStart ; section '.code' code readable executable ; ; PureBasicStart: ; PUSH dword I_BSSEnd-I_BSSStart PUSH dword 0 PUSH dword I_BSSStart CALL _memset ADD esp,12 PUSH dword 0 CALL _GetModuleHandleA@4 MOV [_PB_Instance],eax PUSH dword 0 PUSH dword 4096 PUSH dword 0 CALL _HeapCreate@12 MOV [PB_MemoryBase],eax CALL _SYS_InitString@0 ; : ; Import "test.lib" ; test() As "_test@0" ; EndImport ; ; test() CALL _test@0 _PB_EOP_NoValue: PUSH dword 0 _PB_EOP: CALL _PB_EndFunctions PUSH dword [PB_MemoryBase] CALL _HeapDestroy@4 CALL _ExitProcess@4 _PB_EndFunctions: RET ; ; section '.data' data readable writeable ; _PB_DataSection: _PB_DEBUGGER_LineNumber: dd -1 _PB_DEBUGGER_IncludedFiles: dd 0 _PB_ExecutableType: dd 0 public _SYS_StaticStringStart _SYS_StaticStringStart: pb_public PB_NullString db 0 public _SYS_StaticStringEnd _SYS_StaticStringEnd: align 4 align 4 s_s: dd 0 dd -1 align 4 ; section '.bss' readable writeable _PB_BSSSection: align 4 ; I_BSSStart: _PB_MemoryBase: PB_MemoryBase: rd 1 _PB_Instance: PB_Instance: rd 1 ; align 4 PB_DataPointer rd 1 align 4 align 4 align 4 align 4 I_BSSEnd: section '.data' data readable writeable SYS_EndDataSection:
|
|||||||||||
01 Jan 2009, 19:36 |
|
master92 01 Jan 2009, 23:19
Ok, some debugging information... (the little MessageBox testapp)
this part seems to be relevant: The calling of the MessageBox function in my test app (disassembled by OllyDbg) PUSH 0 PUSH test.00403004 ; ASCII "TEST" PUSH test.00403004 ; ASCII "TEST" PUSH 0 CALL DWORD PTR DS:[402068] The memory access violation occurs on that CALL The four push statements pass the four parameters to the stack... the call parameter usually jumps to the specified address... OllyDbg translates the DS:[402068] memory pointer into the absolute hex address 30A425FF which is far away from the mapped executable code in memory... but I think there's no possibility influencing that... because the memory addresses are translated by the linker I think... Memory addresses in .OBJ files are not fixed, they are relocatable and generated by the linker when linking the final executable as far as I know... I give up... I think I do not get my .lib in that way... Anyone a suggestion how to merge FASM into a working .lib file (probably another way, another linker, a completely different solution)? The problem is that FASM cannot output library files... so I initially decided to output it as MS COFF and link it with another linker... But it seems that my way doesn't work... |
|||
01 Jan 2009, 23:19 |
|
revolution 02 Jan 2009, 00:32
To solve your problem you have to have this line
Code: stdcall MessageBox,0,_teststring,_teststring,0 |
|||
02 Jan 2009, 00:32 |
|
Yardman 02 Jan 2009, 01:36
[ Post removed by author. ]
Last edited by Yardman on 04 Apr 2012, 03:35; edited 1 time in total |
|||
02 Jan 2009, 01:36 |
|
master92 02 Jan 2009, 14:20
All problems have been solved
Quote:
Yeah stdcall worked... And Yardman's solution too... I thought invoke and stdcall would be the same... So I'd have to replace alle invokes in FASM source with stdcall... And I didn't know that PureBasic could import .obj files directly... Works fine... Now I have two working solutions... Thank you for your help! Great forum here... |
|||
02 Jan 2009, 14:20 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.