April 28, 2024, 06:44:03 AM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Object files cleaner

Started by sapero, February 02, 2010, 07:49:21 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

sapero

February 02, 2010, 07:49:21 PM Last Edit: October 27, 2010, 09:38:12 PM by Larry McCaughn
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 .pdf

EDIT: added handling of relative and full paths:ObjectFileCleanerA files\*.o c:\files\*.o

LarryMc

As always, nice utility Sapero.

LarryMc
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

sapero

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.

Ficko


sapero

Uploaded again, it can now handle relative and full paths:
ObjectFileCleanerW files\*.o c:\files\*.o "c:\my files\*.o"

whitenite1

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

LarryMc

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
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

whitenite1

Larry..
 
   Thank you. That one unzipped fine.

whitenite1