News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

A real dumb-ass question!

Started by srod, December 01, 2006, 01:45:18 PM

Previous topic - Next topic

srod

Sorry about this one!  :red

I just need a little clarification about linking with .obj files.


When using GoLink to create an executable from two or more .obj files, do all functions within the .obj's find their way into the final .exe or are only the functions which are called linked in?

I'm a little confused because the help maual says that the .obj input files can be listed in any order and thus I'm wondering how it could be that only functions which are called can be linked in? Unless GoLink starts at the specified entry point that is?

A little clarification would be much appreciated.

Thanks.

Stephen.

(I apologise for cluttering up this board with my newbie type questions!)

jorgon

Hi Stephen

The linker puts all the code and data in the final exe whether or not that code or data has actually been "called" or referenced.

This means that it is possible to have in the exe code and data labels which are not actually referenced at all, either from within the exe itself or presented as an export for use by other executables.  GoLink provides the /unused switch which can report to you such labels at link time.
Author of the "Go" tools (GoAsm, GoLink, GoRC, GoBug)

srod

Thanks, that's cleared that one up.

Is this the same for dll's? I mean are they referenced in the final .exe if none of their functions are actually called but the dll is still included in the GoLink command file?

And, one more question ( ::)). Is it possible to use the GoTools to combine 2 or more object files into a single object file, kind of like a .lib I guess (although I'd prefer not to use .libs!)

Thanks again.

Stephen.

jorgon

No it's not the same for the dlls which you mention in the command line or file.  This is because none of the dlls' code or data is actually loaded into the executable being made.  When the executable is first started the system's loader will load those dlls which are needed by the executable in the virtual memory area used by the executable, if not already loaded (which most of them are!).  However, GoLink will not require a dll to be loaded in such a way unless the dll is actually referenced by the executable.  So if a dll is mentioned in the command line or file, although this fact will be noted in the exe, if no API is called from a particular dll it will not be loaded by the system loader when the executable is started.

QuoteAnd, one more question. Is it possible to use the GoTools to combine 2 or more object files into a single object file, kind of like a .lib I guess (although I'd prefer not to use .libs!)

The linker does this when making the final executable. 

Alternatively if you want to join two files containing asm source code you can do this with GoAsm by using #include path/filename, which will then treat the included file as part of your source code provided it has an extension beginning with "a".

Apart from these two methods the Go tools do not provide a way to join up two object files since this is not normally something you would want to do.
Author of the "Go" tools (GoAsm, GoLink, GoRC, GoBug)

srod

Quote from: jorgon on December 01, 2006, 03:06:02 PM
No it's not the same for the dlls which you mention in the command line or file.  This is because none of the dlls' code or data is actually loaded into the executable being made.

Sorry, I worded the question poorly. But thanks, you answered what I intended my question to ask by what followed!  :U

I understand now. Thanks.