Author Topic: Question about object files  (Read 2022 times)

0 Members and 1 Guest are viewing this topic.

Arnold

  • Guest
Question about object files
« on: March 27, 2019, 02:57:55 AM »
Hi Charles,

the more I learn about freebasic, the more I get impressed by the options of this compiler. I used the options -v, -C and -R to create oxygen.dll in \inc\OXFBSRC

go3.bat:
Code: [Select]
set compile=d:\programme\fbwin32\fbc

:: use copy of \tools\OxyDateTimeStamper.exe
OxyDateTimeStamper.exe

%compile% -v -C -R -dll oxygen.bas

::upx --brute oxygen.dll
::copy oxygen.dll OxygenBasic

pause

It is interesting to see what happens and that the created files can be preserved. The (formatted) output in my console is:

Code: Text
  1. D:\OxygenBasic\inc\OXFBSRC>d:\programme\fbwin32\fbc -v -C -R -dll oxygen.bas
  2. FreeBASIC Compiler - Version 1.05.0 (01-31-2016), built for win32 (32bit)
  3. Copyright (C) 2004-2016 The FreeBASIC development team.
  4. standalone
  5. target:       win32, 486, 32bit
  6. compiling:    oxygen.bas -o oxygen.asm (main module)
  7.  
  8. assembling:   d:\programme\fbwin32\bin\win32\as.exe --32 --strip-local-absolute "oxygen.asm" -o "oxygen.o"
  9.  
  10. linking:      d:\programme\fbwin32\bin\win32\ld.exe -m i386pe -o "oxygen.dll" -subsystem console --dll
  11.               -enable-stdcall-fixup -e _DllMainCRTStartup@12 "d:\programme\fbwin32\lib\win32\fbextra.x"
  12.              --stack 1048576,1048576 --output-def "oxygen.def" -s
  13.              -L "d:\programme\fbwin32\lib\win32" -L "." "d:\programme\fbwin32\lib\win32\dllcrt2.o"
  14.              "d:\programme\fbwin32\lib\win32\crtbegin.o" "d:\programme\fbwin32\lib\win32\fbrt0.o"
  15.              "oxygen.o"
  16.              "-(" -lkernel32 -loleaut32 -luser32 -lfb -lgcc -lmsvcrt -lmingw32 -lmingwex -lmoldname -lgcc_eh "-)"                    
  17.              "d:\programme\fbwin32\lib\win32\crtend.o"
  18.  
  19. creating import library:    d:\programme\fbwin32\bin\win32\dlltool.exe --def "oxygen.def"
  20.                             --dllname "oxygen.dll" --output-lib "liboxygen.dll.a"
  21.  

Oxygen.dll created with Freebasic has a very good reputation with AV-Scanners. (0/70). The reputation of oxygen.dll created in \inc\OXSC is not so good. I looked for differences and noticed these:

Oxygen (fbc):
File type   Win32 DLL
Magic   PE32 executable for MS Windows (DLL) (console) Intel 80386 32-bit
EntryPoint   0x1410
ImageFileCharacteristics   Executable, No line numbers, No symbols, 32-bit, No debug, DLL
PEType   PE32
Subsystem   Windows command line

Oxygen (O2)
File type   Win32 DLL
Magic   PE32 executable for MS Windows (DLL) (GUI) Intel 80386 32-bit
EntryPoint   0x1000
ImageFileCharacteristics   Executable, 32-bit, DLL
Subsystem   Windows GUI
SubsystemVersion   4.0

fbc creates a console executable, O2 seems not to do this. Could this be a reason for the different behaviour of AV-Scanners?

In theory it should be possible to create an object file of \inc\OXSC\BuildOxygenDLL.o2bas too? But I must admit that I would have no idea what libs could be used to link against this (theoretical) object file.

Roland
« Last Edit: March 28, 2019, 01:06:35 AM by Arnold »

Aurel

  • Guest
Re: Question about object files
« Reply #1 on: March 27, 2019, 07:40:56 AM »
Quote
The reputation of oxygen.dll created in \inc\OXSC is not so good.

Hi Arnold
I am not sure what you mean under AVscanners...which one?
I have no problem with my Kaspersky.

Arnold

  • Guest
Re: Question about object files
« Reply #2 on: March 28, 2019, 01:10:34 AM »
Hello,

I know there are other experts besides Charles and Mike in this forum. Maybe someone can help me with this problem, which I find very interesting. I found this topic in the Fasm forum (solution by Vortex):

link the MS COFF example:
https://board.flatassembler.net/topic.php?t=4135

I used the mscoff.asm example of Fasm, created a .obj file which I linked with several linkers. The .asm, .obj, batch files and created exe files are in the attached zip file. To create the exe files the corresponding lib files must be copied into the folders.

mscoff.asm:
Code: [Select]
; example of making Win32 COFF object file

format MS COFF

extrn '__imp__MessageBoxA@16' as MessageBox:dword

section '.text' code readable executable

 public _demo

 _demo:
push 0
push _caption
push _message
push 0
call [MessageBox]
ret

section '.data' data readable writeable

 _caption db 'Win32 assembly',0
 _message db 'Coffee time!',0

It is very interesting that object files can be linked to exe files with the correct libraries. Unfortunately, I have not yet found an extended example that I could investigate. Perhaps someone can refer me to a link?

Roland

Aurel

  • Guest
Re: Question about object files
« Reply #3 on: March 28, 2019, 02:36:08 AM »
Of course ..i am not expert and in general i am not interested for this thematic
but long time ago i tried to study Libry Compiler (written in VB6) you can find it just type...
there you can find how MZ stub looks,data sections..etc ...

Arnold

  • Guest
Re: Question about object files
« Reply #4 on: March 28, 2019, 08:04:54 AM »
Hi Aurel,

thank you. Thinking about it, I suppose I try static linking, using an object file created e.g. in Freebasic with another language e.g. coded in C. Maybe this is not possible at all. I do not know if the small example above is only an exception.

Charles Pegge

  • Guest
Re: Question about object files
« Reply #5 on: March 29, 2019, 01:06:28 AM »
Hi Roland,

Static-linking is toolchain-specific, which allows Gnu languages (like GCC and FreeBasic) modules to be mixed. These would not be compatible with VisualStudio.

Arnold

  • Guest
Re: Question about object files
« Reply #6 on: March 29, 2019, 02:50:44 AM »
Thank you, Charles. I came to the same conclusion. In the meantime I found this interesting link which shows the possibilities of Freebasic and Mingw C:

SOLVED : How to compile c emitted code with mingw toolchain:
https://www.freebasic.net/forum/viewtopic.php?f=3&t=27457&p=258758&hilit=dll#p258758

There are many useful library functions created in Freebasic or C, but most of the time they are static linked. If it is possible to create the corresponding dlls, I think this could save some work to use these functions in Oxygenbasic too. Perhaps this is only wishful thinking.

Roland

JRS

  • Guest
Re: Question about object files
« Reply #7 on: March 29, 2019, 07:30:22 AM »
The problem with the FreeBasic to C translator is the code being generated isn't human readable.  :o

Alex_Longard

  • Guest
Re: Question about object files
« Reply #8 on: March 29, 2019, 07:58:02 PM »
Hi Arnold,
GCC and FB generate elf format object files, this not compatible with MS coff linkers.

I want to link lib.a with Oxygen, only this not work in current O2 linker :(

Mike Lobanovsky

  • Guest
Re: Question about object files
« Reply #9 on: March 30, 2019, 02:02:54 AM »
There's that classic object file converter utility by Agner Fog that can convert just about anything into just about anything.

Very helpful. Very clever. But covered by GNU GPL.

Alex_Longard

  • Guest
Re: Question about object files
« Reply #10 on: March 30, 2019, 02:50:01 AM »
Hi Mike!
Big thanks for this tool.
It's can convert GCC object files for Tinycc?


Mike Lobanovsky

  • Guest
Re: Question about object files
« Reply #11 on: March 30, 2019, 03:38:27 AM »
No Alex,

It can't. It works only for the object files that are 100% compliant with the respective object standards. TinyC Compeler's .o object files and .a libraries aren't fully compliant with the ELF standard.

But since TCC's ANSI C is a subset of GCC ANSI C, you may try and recompile the respective .o and .a files directly from the sources, if available, using a GCC build of your choice -- preferably MinGW because the MS Windows build of TCC is designed to use a MinGW set of system include files.

Then you will be able to freely convert the resulting object and library files into any format and/or platform that objconv supports.