News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

FreeBasic Runtime Library test

Started by guga, February 22, 2022, 06:07:12 PM

Previous topic - Next topic

guga

HI JJ

I´m aware of that. Why FB developers insists to use gcc to compile this, is something way out of my head. It could be much better developed if it was written in masm, fasm, NAsm, GoAsm or even RosAsm (Although i never had time to build a version that uses lib yet). I remember an old Basic compiler that was also very good, one called BCX Translator, that could also be used to translated basic code to C, but used LCC for that (An old and very good C compiler. It was good specially because it was really simple and the internal runtime routines well organized). But, at least BCX was able to compile itself without dependencies and the internal coding was excellent. I ported hundreds of BCX routines to RosAsm years ago on the old RosAsm forum.

The developers of FB could make it a more robust project if they simply get rid of gcc and force FB to compile itself without those dependencies and under total control of the user, or at least use a assembler to create their apps and routines. Is not a bad project, but those internal problems results on buggy and slow apps and hard to port.
Coding in Assembly requires a mix of:
80% of brain, passion, intuition, creativity
10% of programming skills
10% of alcoholic levels in your blood.

My Code Sites:
http://rosasm.freeforums.org
http://winasm.tripod.com

Vortex

Hi Guga,

QuoteI´m aware of that. Why FB developers insists to use gcc to compile this, is something way out of my head. It could be much better developed if it was written in masm, fasm, NAsm, GoAsm or even RosAsm

I think the choice of gcc depends on the cross-platform audience of FreeBASIC. The compiler can be used on Linux and FreeBSD too. gcc supports those operating systems including Windows.

Personally, I like the FreeBASIC project. The projects of FB forum members Paul Squires, Xusinboy Bekchanov and Vanya are impressive. There are also other members there doing nice jobs.

Another nice Basic compiler, PureBasic is moving to gcc :

Quoteà partir de la version 6.0 PureBasic utilisera gcc pour compiler (à la place de Fasm), plus d'infos sur le blog https://www.purebasic.fr/blog/

Petite correction : gcc ne va pas remplacer Fasm, les 2 seront maintenus. Cependant j'imagine que si PureBasic devait fonctionner pour un nouveau processeur, Fred ne développera pas une version ASM, dans ce cas il faudra compiler avec gcc. à suivre ...

Translation :

QuoteBeginning from version 6.0, PureBasic will use gcc to compile (instead of Fasm), more info on the blog https://www.purebasic.fr/blog/

Small correction: gcc will not replace Fasm, both will be maintained. However I imagine that if PureBasic should work for a new processor, Fred will not develop an ASM version, in this case it will have to be compiled with gcc. to be continued ...

https://purebasic.developpez.com/actu/315253/PureBasic-6-0-Alpha-1-est-disponible-sur-votre-compte/

https://www.purebasic.fr/blog/

TimoVJL

Perhaps a LLVM optimizer and libs are good reason for that.
May the source be with you

Vortex

Hi Guga and Jack,

Today, I am trying to rebuild the same simple FB example posted to the forum. Running the executable built by the FB compiler, I am receiving the error message :

QuoteThe procedure entry point of fb_End could not be located in the dynamic link library FbRtl32.dll

D:\FreeBASIC>fbc32 Sample.bas FbRtl32.a

D:\FreeBASIC>\PellesC\bin\podump.exe /IMPORTS Sample.exe | find "fb_"
         10E  fb_End
         1F4  fb_Init
         269  fb_PrintString
         2B0  fb_StrDelete
         2B4  fb_StrInit
         3F7  fb_hRtExit
         3F8  fb_hRtInit


D:\FreeBASIC>\PellesC\bin\podump.exe /EXPORTS FbRtl32.dll | find "fb_End"
            105   104  636E79A0  fb_End@4


FbRtl32.dll is the renamed copy of FbRtl32D.dll

Attached is the sample code.

guga

I dont know what FB is doing when trying to compile the example.  What procedure entry point means ? Is the function fb_end it's talking about ? Do FreeBasic uses a def file too ? Maybe that´s the reason why it´s not finding the exported function.

The function uses one single parameters (code exit) to be used Internally it points to msvcrt exit. Also internally, it checks either a pointer to a variable used in another function called _set_mode is used or not. If the pointer is not being used, the functon goes directly to exit api from msvcrt (Take a look on the disassembled source code i provided earlier, maybe it can help)

In dodicat example i´m trying to port, all is needed is:

call 'FbRtl32.fb_End' 0

or

push 0
call 'FbRtl32.fb_End'

Perhaps Fb was not initialized somehow. Try using the older version of the Dll i made in masm to see what happens. If you want, i can try to send the full library from mingw to you try to compile. Maybe you got a better luck trying to compile this, getting rid of mangled names and also keeping the debug info. I tested it last night once again, i succeeded to remove gcc dependencies but one gcc dll was still being used (except on the FbRtl32D version).


Btw...here your example works ok. Try using the old dll made in masm to see what happens.
Coding in Assembly requires a mix of:
80% of brain, passion, intuition, creativity
10% of programming skills
10% of alcoholic levels in your blood.

My Code Sites:
http://rosasm.freeforums.org
http://winasm.tripod.com

guga

Quote from: Vortex on February 26, 2022, 08:36:26 PM
Personally, I like the FreeBASIC project. The projects of FB forum members Paul Squires, Xusinboy Bekchanov and Vanya are impressive. There are also other members there doing nice jobs.

I forgot..i don´t doubt the Fb users do their best to try to create great projects. My main concern with FB is the internal organization of the code, which btw the end user don´t have any control of. It´s also not fault of the developers, but the compiler they are using to build this thing.  (Well...it is only their fault for a matter of choice, not a matter of coding style, specially because they also have no control on what gcc is doing internally) Just take a look at the disassembled version of the dll and you will understand  what i mean with disorganized internal code (the previous version with the masm source)
Coding in Assembly requires a mix of:
80% of brain, passion, intuition, creativity
10% of programming skills
10% of alcoholic levels in your blood.

My Code Sites:
http://rosasm.freeforums.org
http://winasm.tripod.com

Vortex

Hi Guga,

The problem is clear. As you can see in my previous posting, the DLL exports a decorated version of fb_End and the executable imports the non-decoration symbol. This explains why I receive the error message.

guga

Quote from: Vortex on February 27, 2022, 05:35:36 AM
Hi Guga,

The problem is clear. As you can see in my previous posting, the DLL exports a decorated version of fb_End and the executable imports the non-decoration symbol. This explains why I receive the error message.

The "D" version you mean, right ? Yes, this version contains decorated names (I didn´t succeed to remove them), while on the undecorated version, it needs gcc dlls . I don´t know yet how to fix it, except continue to disassemble all the apis the way i was doing originally. If you want i can send to you the ".a" files to you try to see if you can use gcc to fix the newer version and unmangle all apis and also avoid the dependency of gcc dlls. What i tried to do is create 2 files.
1 - Containing full debug info and the undecorated names (for debugging purposes. I tried to create it without the decorated names, but didn´t suceeded))
2 - Other with all names undecorated without the debug info.

I never used gcc before. So i don´t know their commands to fix that properly. Let me know if you want the libraries and i´ll send to you all the contents of msys directory i used to fix these.
Coding in Assembly requires a mix of:
80% of brain, passion, intuition, creativity
10% of programming skills
10% of alcoholic levels in your blood.

My Code Sites:
http://rosasm.freeforums.org
http://winasm.tripod.com

Vortex

Hi Guga,

Yes, I used the debug version, exactly. With thanks to Jack who sent me the new libraries, I managed to build and run my sample project. It would be interesting to use the FB Runtime library with Masm.

gcc and Clang are very popular for cross-platform programming. The problem is that if you wish to support multiple platforms, you haven't much choices for backend C\C++ compilers.

Vortex

Hi Guga,

The 32-bit version of the FreeBASIC compiler does not depend on gcc at least on my first test. Here is a quick demonstration :

D:\FreeBASIC>ren D:\FreeBASIC\bin\win32\gcc.exe gcc.exe.bak

D:\FreeBASIC>fbc32 Sample.bas

D:\FreeBASIC>Sample.exe
This is a test.
This is a test.
This is a test.


D:\FreeBASIC>ren D:\FreeBASIC\bin\win32\as.exe as.exe.bak

D:\FreeBASIC>fbc32 Sample.bas
Sample.bas() error 91: Executable not found: "D:\FreeBASIC\bin\win32\as.exe"



jack

Quote from: guga on February 27, 2022, 05:43:14 AM

The "D" version you mean, right ? Yes, this version contains decorated names (I didn´t succeed to remove them), while on the undecorated version, it needs gcc dlls . I don´t know yet how to fix it
I commented on a previous post that you need to use -static not -s

Vortex

This time, testing the 64-bit compiler :

D:\FreeBASIC>ren D:\FreeBASIC\bin\win64\gcc.exe gcc.exe.bak

D:\FreeBASIC>fbc64 Sample.bas
Sample.bas() error 91: Executable not found: "D:\FreeBASIC\bin\win64\gcc.exe"

Using the -R switch :

fbc32 -R Sample.bas

The .asm file is preserved

fbc64 -R Sample.bas

The .c file is preserved for further processing by gcc.

guga

Quote from: jack on February 27, 2022, 06:07:39 AM
Quote from: guga on February 27, 2022, 05:43:14 AM

The "D" version you mean, right ? Yes, this version contains decorated names (I didn´t succeed to remove them), while on the undecorated version, it needs gcc dlls . I don´t know yet how to fix it
I commented on a previous post that you need to use -static not -s

Inded, you are right. I tried yesterday during night using static token, but wasn´t succeeding to remove the name mangling or dependency.

Now i gave another try and it seems to work ok, unmangling the names, without gcc dependency and also containing the debug info :)

The batch file i rewrite it as:


C:\msys64\mingw32\bin\gcc.exe -o FbRtl32D.dll *.o -shared -static -lgdi32 -lwinspool -lffi -lwinmm -Wl,--subsystem,windows
C:\msys64\mingw32\bin\gcc.exe -o FbRtl32.dll *.o -shared -static -lgdi32 -lwinspool -lffi -lwinmm -Wl,--subsystem,windows,--output-def,FbRtl32.def
C:\msys64\mingw32\bin\gcc.exe -o FbRtl32.dll *.o -shared -static -lgdi32 -lwinspool -lffi -lwinmm -Wl,--subsystem,windows,--kill-at
C:\msys64\mingw32\bin\dlltool.exe --kill-at -d FbRtl32.def -D FbRtl32.dll -l FbRtl32.a
pause


Please guys, see if it is ok now :)

The only thing i didn´t succeed yet is to remove the exported data on it. Jack, how to i remove from the exports, the DATA on the def file ? Can i simply edit the def file removing them ?

Coding in Assembly requires a mix of:
80% of brain, passion, intuition, creativity
10% of programming skills
10% of alcoholic levels in your blood.

My Code Sites:
http://rosasm.freeforums.org
http://winasm.tripod.com

jack

QuoteCan i simply edit the def file removing them ?
I don't see why not, there should be no problem

Vortex

Hi Guga,

I tested FbRtl32New.zip with FreeBASIC, it works fine on my preliminary tests. Here is the Masm32 version :

Converting FbRtl32.a to FbRtl32.lib :

lib2def FbRtl32.a

def2lib FbRtl32.def


FbRTDllTest.asm :

include     \masm32\include\masm32rt.inc

fb_StrInit      PROTO :DWORD,:DWORD,:DWORD,:DWORD,:DWORD
fb_PrintString  PROTO :DWORD,:DWORD,:DWORD
fb_StrDelete    PROTO :DWORD

FBSTRING STRUCT

  char  dd ?
  len   dd ?
  size_ dd ?

FBSTRING ENDS

.data

MyStr       db 'This is a test.',0

MyStrLen    equ $ - MyStr

.data?

.code

start:

    call    main
    invoke  ExitProcess,0

main PROC uses ebx

LOCAL s:FBSTRING

    mov     ebx,3

    invoke  fb_StrInit,ADDR s,-1,ADDR MyStr,\
            MyStrLen,0
_loop:

    invoke  fb_PrintString,0,ADDR s,1

    dec     ebx
    jnz     _loop

    invoke  fb_StrDelete,ADDR s
    ret

main ENDP

END start