News:

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

lib question

Started by bushpilot, November 18, 2005, 07:05:28 PM

Previous topic - Next topic

bushpilot

Hi Everyone,

Given a .lib file, how can one tell (programatically) at compile time if it is a static library, or a .lib tied to a dll?

Greg

NPNW

I don't understand the question?
Or I don't remember the answer :toothy

I had some other stuff and looked up some info to make sure I remembered it right.
Here is what I found.
The lib code would be used at compile time and inserts a copy of library code into your program. The dll code is referenced at runtime and the code is not inserted into your code.  Instead when your program calls the procedure the computer jumps to that dll code and runs the code in the dll. That way multiple programs can all use the same procedures in a dll and do not have to have the code in the program thus saving space.



bushpilot

Here's what I am trying to ask -

Given a library, mylib.lib, how can I tell whether it is a collection of objects (*.obj) ie a static library, or it is ties to a dynamic library - mylib.dll.

I need to be able to do this programatically.

Greg

MichaelW

I don't know how universal this is, but a search of the MASM32 lib directory for *.lib files containing ".obj" will return the three static libraries (debug.lib, fpu.lib, and masm32.lib), and a search for *.lib files containing ".dll" will return the import libraries (everything other than debug.lib, fpu.lib, and masm32.lib).


eschew obfuscation

bushpilot

Sorry, I seem to be failing to communicate....

I am not referring to the MASM32 libraries, but if I am given a library, is there a way to examine it to determine what type of library it is.

Also, I do not need a new tool, I know of a couple that can give this information, but I am trying to use this in a compiler project.  I want the compiler to programatically determine what type of library it is, and to take different actions depending on which it is.

Thanks for the help so far.

Greg

MichaelW

QuoteI am not referring to the MASM32 libraries, but if I am given a library, is there a way to examine it to determine what type of library it is.

I was not assuming that you were referring to the MASM32 libraries, as I associate you primarily with GoAsm. That is why I started with "I don't know how universal this is". After I did a quick web search and couldn't find any useful information on the internal structure, I decided to experiment with the libraries that I had handy. You might be able to derive (with difficulty) some useful information from the ld, dlltool, etc source files and/or manuals, available here:

http://ftp.gnu.org/gnu/binutils/

eschew obfuscation

P1

A simple parsing solution ???

polib /list MyLib.lib > MyLib.txt
Then parse the .txt file for whatever stats you want to collect.

Please note:  This does answer dependencies issues from the objects themselevs or the dlls for that matter.

Regards,  P1  :8)

bushpilot

Thanks MichaelW and P1.  I'll look your ideas over.

The reason why I need this is because GoAsm handles static and dynamic libraries differently than others.  The static ones are merged in the assembly stage, and the dynamic ones are linked by the linker.

Since I am working on a compiler that targets GoAsm, I need to know at compile-time which I need to do.

Thanks again!

Greg

Timbo

Greetings,

I am new here and this is my first post.  Yay me.  :cheekygreen:

I know I am a bit late in replying to this thread, but you can simply read the PE header of the .lib in question to determine if it is an import library or a static library I do believe.

zooba

Quote from: Timbo on February 07, 2006, 11:49:06 PM
you can simply read the PE header of the .lib in question to determine if it is an import library or a static library I do believe.

I think you'll find the LIB files aren't in PE format. They appear to be a combination of text and binary data.

Does GoAsm expect the developer to differentiate between import and static libraries or does the assembler do it? If the assembler does it, why do you need to figure it out? Since you are targeting GoAsm (presumably by that you mean your compiler is emitting GoAsm code) can't you let the assembler handle that part?

hutch--

Greg,

You actually need to be able to read the object module format to tell what in it or not. OMF, COFF and ELF are all documented if you bother to look for it.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

bushpilot

Thanks everyone for the help.

Zooba - GoAsm (in combination with GoLink) doesn't use import libraries at all.  A static library is used by GoAsm, and the import library is not necessary.  That's fine, but if it is used with POLink, then the static library needs to go to GoAsm, and the import library needs to go to POLink.

Greg

MichaelW

Something related that I came across:

http://win.asmcommunity.net/board/index.php?topic=22243.msg167660#msg167660

The linked PEview app was coded in GoAsm. It starts out with a hex dump of the entire file, and AFAICT decodes/identifies everything in the file. After examining several of the MASM32 lib files, and several of the PSDK lib files, I think you *might* be able to identify a static library by searching the file for ".obj".

eschew obfuscation

jorgon

Hi Greg

Sorry I've only just seen your query.

You can view the internals of lib files (and other files) using Wayne Radburn's PEView.
Matt Pietrek describes the format of the files in this article, although his description in his book Windows 95 System Programming Secrets is better.

The first IMAGE_ARCHIVE_LINKER_MEMBER has a list of function names in the offset table.   Each function has its own file offset.  Take a valid function name and, using the offset given in the offset table, follow it to its IMAGE_ARCHIVE_MEMBER_HEADER.  This is the header which describes where the function comes from.  The name given in that header will be "xxxxxx.obj" (the name of the object file) if the library contains code (static library).  If it is "xxxxxx.dll" instead, then you have an import library.  Note that if the name starts with "/" (forward slash) then it will be followed by an ASCII representation of a file offset in the LONGNAMES member (the object file or dll had a long name).
Author of the "Go" tools (GoAsm, GoLink, GoRC, GoBug)