Author Topic: Unref'ed fn not discarded by Visual C linker  (Read 9314 times)

nobody

  • Guest
Unref'ed fn not discarded by Visual C linker
« on: May 26, 2009, 11:08:15 AM »
I have a lot of nasm assembly routines in a library but my program is only using a few of them.  Everything works fine but the linker always links ALL the nasm functions in the library, even if they are never called.  This results in a binary larger than it could be.  C-compiled functions in the same library that are unreferenced are successfully discarded.  I am using Windows with nasm 2.05.01, Visual Studio 2005 and Intel Compiler 9.1.  Has anyone experienced a similar issue?

I would really like it if the linker does as it should and automatically discards unused functions.  You'll see below that objdump outputs looks very different for C and nasm output - the symbol type ("ty") is different and the representation of function, labels, etc. seems to be very different too.  I can't find any options or tools to make nasm obj files look more like the C one.

Any ideas appreciated!


==Unreferenced C function example==

Linker message (/verbose):

Discarded _MyCFunction from SomeLib.lib(SomeFile.obj)

objdump output:

[180](sec 26)(fl 0x00)(ty  20)(scl   2) (nx 1) 0x00000000 _MyCFunction
_MyCFunction:
AUX tagndx 182 ttlsiz 0xde lnnos 13929 next 194
_FilterGeneric_doNoiseDetection :
65535 : 00000007
   2 : 0000000b
65535 : 0000000d
   2 : 00000021
   4 : 00000038
   6 : 0000003b
   7 : 00000049
   9 : 00000051
  13 : 00000070
  14 : 0000007c
  13 : 00000080
  14 : 00000082
  17 : 0000008d
  14 : 00000090
  15 : 00000092
  17 : 00000098
  18 : 0000009f
  19 : 000000a4
   7 : 000000a9
   6 : 000000bf
  21 : 000000d5

==Unreferenced  nasm function example ==

[ 18](sec  1)(fl 0x00)(ty   0)(scl   2) (nx 0) 0x0000074c _MyAsmFunction
[ 19](sec  1)(fl 0x00)(ty   0)(scl   3) (nx 0) 0x000007ef _MyAsmFunction.loop1
[ 20](sec  1)(fl 0x00)(ty   0)(scl   3) (nx 0) 0x00000800 _MyAsmFunction.loop2

nobody

  • Guest
Re: Unref'ed fn not discarded by Visual C linker
« Reply #1 on: May 26, 2009, 03:56:31 PM »
Hi,

I had a similar problem cross compiling elf-code on a win32 machine:
http://sourceforge.net/forum/forum.php?thread_id=2033147&forum_id=167169
There, it helped
strip -x ...

But here, you compile .obj using nasm -f obj ... for a win32 application? Then those .loop1 & .loop2 labels should be gone, already. Take i.e. alink.exe (or even VCC linker) to link your dll from the obj(s) and it will export only those labels marked "global".

Hint: I remember the VCC linker offers a switch making *all* lables global resp. external or other way arround provides a switch to suppress such a default behavior... don't remember excactly - have a look at that.

Martin

Jim

  • Guest
Re: Unref'ed fn not discarded by Visual C linker
« Reply #2 on: May 26, 2009, 08:02:01 PM »
/OPT:REF eliminates functions and/or data that are never referenced while /OPT:NOREF keeps functions and/or data that are never referenced.

http://msdn.microsoft.com/en-us/library/bxwfs976(VS.80).aspx

OpenWatcom's linker should also work ... it also had an option to drop unreferenced functions...