IonicWind Software

Announcements => User Offerings => Topic started by: sapero on February 02, 2010, 07:49:21 PM

Title: Object files cleaner
Post by: sapero on February 02, 2010, 07:49:21 PM
This is a console utility which cleans your object files (*.o;*.obj) removing:
1. Static symbols (nasm: struc)
2. Imported, but unreferenced symbols (aurora/ebasic: interface@method)
3. Macro private labels (nasm: %$label or %%label)

When you create a static library from ebasic or aurora code using any COM interface, the parser is adding "bad" symbols to .asm file. For example, if you call Release method on IUnknown interface, "IUnknown@Release" symbol will appear in the object file. It will be not referenced, it is just added to symbol table. This is not a problem if you link such object with ebasic/aurora linker, but will cause serious problems with other linkers.

If your coding directly for nasm, and the code defines structures, all the struct members will appear in object file as static symbols, without references in relocations table. The big minus is that your object file may be 500KB in total, but only 2KB is holding the real part - your code.

The command line is simple, and accepts wildcards:
ObjectFileCleanerA ebasic1.o ebasic2.o   ... ebasicN.o
ObjectFileCleanerA *.o *.obj

There is ObjectFileCleanerA and ObjectFileCleanerW. The first one is ansi, and the second is unicode build.
To cleanup a static library, you need to extract it, cleanup the .o files, and then recreate the library. Use ar.exe, polib.exe or link.exe (or the wrapper for link: lib.exe) to extract/create a static library.

This is a dump of cleaning surface.o from dx2d.lib
>ObjectFileCleanerW surface.o
File: surface.o
- total 377 symbols
- remove: _astrcpy
- remove: _astrlen
- remove: _astrcat
- remove: _i64mul
- remove: _i64div
- remove: _ui64div
- remove: _i64rem
- remove: _ui64rem
- remove: C2DSurface@PutPixel
- remove: IDirectDrawSurface7@Release
- remove: IDirectDrawSurface7@Unlock
- remove: IDirectDrawSurface7@Lock
- remove: C2DSurface@VLine
- remove: IDirectDrawSurface7@Blt
- remove: IDirectDrawSurface7@Restore
- remove: C2DSurface@HLine
These symbols are defined as "extern", but not used.

References: Microsoft Portable Executable and Common Object File Format Specification .doc (http://www.microsoft.com/whdc/system/platform/firmware/PECOFF.mspx) .pdf (http://www.masm32.com/board/index.php?topic=13135.msg101990#msg101990)

EDIT: added handling of relative and full paths:ObjectFileCleanerA files\*.o c:\files\*.o
Title: Re: Object files cleaner
Post by: LarryMc on February 02, 2010, 08:21:33 PM
As always, nice utility Sapero.

LarryMc
Title: Re: Object files cleaner
Post by: sapero on February 03, 2010, 05:40:07 AM
Thanks Larry.
I have edited my attachment, because the part for absolute symbols was missing.
Added example clean_me.obj file with absolute symbols, nasm macro local labels, and with unreferenced external symbols.
Title: Re: Object files cleaner
Post by: Ficko on February 03, 2010, 09:50:45 AM
That's awesome thanks! ;)
Title: Re: Object files cleaner
Post by: sapero on February 03, 2010, 11:20:43 AM
Uploaded again, it can now handle relative and full paths:
ObjectFileCleanerW files\*.o c:\files\*.o "c:\my files\*.o"
Title: Re: Object files cleaner
Post by: whitenite1 on October 27, 2010, 09:19:57 PM
Sapero..

  I downloaded the file, and get an error when I try to unzip it. Can you send the file up again, or maybe to my inbox? Appreciate it, Thanks.

whitenite1
Title: Re: Object files cleaner
Post by: LarryMc on October 27, 2010, 09:40:26 PM
Quote from: whitenite1 on October 27, 2010, 09:19:57 PM
Sapero..

  I downloaded the file, and get an error when I try to unzip it. Can you send the file up again, or maybe to my inbox? Appreciate it, Thanks.

whitenite1
I had a copy of it so I replaced the one above.
You shouldn't have a problem downloading it now.

LarryMc
Title: Re: Object files cleaner
Post by: whitenite1 on October 28, 2010, 08:24:30 AM
Larry..
 
   Thank you. That one unzipped fine.

whitenite1