IonicWind Software
February 04, 2012, 09:53:55 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: IWB+ 1.00 (A Visual Designer for IWBasic 2.x)  released!
 
   Home   Help Login Register  
Pages: [1]
  Print  
Author Topic: Object files cleaner  (Read 975 times)
0 Members and 1 Guest are viewing this topic.
sapero
Senior Developer
Hero Member
*****
Offline Offline

Posts: 1292



« on: February 02, 2010, 09: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:
Code:
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
Code:
>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:
Code:
ObjectFileCleanerA files\*.o c:\files\*.o
« Last Edit: October 27, 2010, 11:38:12 PM by Larry McCaughn » Logged

LarryMc
Administrator
Hero Member
*****
Online Online

Posts: 3665


'All I like is finishing'


« Reply #1 on: February 02, 2010, 10:21:33 PM »

As always, nice utility Sapero.

LarryMc
Logged

Larry McCaughn Smiley
Author of IWB+, Custom Button Designer, Custom Chart Designer, and Snippet Manager
sapero
Senior Developer
Hero Member
*****
Offline Offline

Posts: 1292



« Reply #2 on: February 03, 2010, 07: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.
Logged

Ficko
Paid Subscriber
Sr. Member
*****
Offline Offline

Posts: 271



« Reply #3 on: February 03, 2010, 11:50:45 AM »

That's awesome thanks! Wink
Logged
sapero
Senior Developer
Hero Member
*****
Offline Offline

Posts: 1292



« Reply #4 on: February 03, 2010, 01:20:43 PM »

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

whitenite1
Jr. Member
**
Online Online

Posts: 83


« Reply #5 on: October 27, 2010, 11: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
Logged
LarryMc
Administrator
Hero Member
*****
Online Online

Posts: 3665


'All I like is finishing'


« Reply #6 on: October 27, 2010, 11:40:26 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
Logged

Larry McCaughn Smiley
Author of IWB+, Custom Button Designer, Custom Chart Designer, and Snippet Manager
whitenite1
Jr. Member
**
Online Online

Posts: 83


« Reply #7 on: October 28, 2010, 10:24:30 AM »

Larry..
 
   Thank you. That one unzipped fine.

whitenite1
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.15 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!


Google visited last this page January 12, 2012, 03:00:37 AM