Hi every1. Im in my second week of programming now (asm is my first language at all) so please forgive if the question is too simple.

Question:
To which .DLL is Masm32.LIB refering? I wonder because during the exploration of Masm Prostart i encountered the GetPercent function.
I tried to look it up on the Win32-API-Reference but didnt find it. Where i finally found it was in the Masm32.LIB (in the Masm32lib.hlp to be exact) but there seems to be no Masm32.dll. I know that a LIB can refer to any DLL not depending on the name of the LIB so i see no other way to find out but asking here.
Posted on 2004-11-30 05:45:31 by LittleEndian
Hi, there is a "make file" that do the work, inside the m32lib, for be exact: make.bat


@echo off turn off some messages

del masm32.lib : delete any existing MASM32 Library
the anterior should be more if exist masm32.lib

dir /b *.asm > ml.rsp : create a response file for ML.EXE
try the command by hand in a cmd window, the
> is for redirect the stdout to somewhere else, in this case ml.rsp
and will have all the .asm files
\masm32\bin\ml /c /coff @ml.rsp
assemble all the files listed in ml.rsp
if errorlevel 0 goto okml
if there no exist errors go to OKml
del ml.rsp else delete the rsp and print a error
then jump to end
echo ASSEMBLY ERROR BUILDING LIBRARY MODULES
goto theend

:okml
if the assembling of files where good
\masm32\bin\link -lib *.obj /out:masm32.lib
make a lib with each listed .obj in the dir
if exist masm32.lib goto oklink
link where OK, yes-> oklink

echo LINK ERROR BUILDING LIBRARY
echo The MASM32 Library was not built
goto theend

:oklink
copy masm32.lib \masm32\lib\masm32.lib
copy masm32.inc \masm32\include\masm32.inc
copy the created masm32.lib to the default lib dir,
and the already masm32.inc too


:theend
if exist masm32.lib del *.obj
if all where good, you will see, the .rsp file is not deleted.



This make.bat is executed when you install masm32 :), also you can execute it after, this go too for fpulib.


I think there no exist a dll file, the win32lib like you see in this process is obtained from some asm files generating obj (a intermediate file), then the are linked all togeter with the flag for generate a lib file, and that is, you can link the masm32 library.
Posted on 2004-11-30 09:16:16 by rea
There are a couple of different types of .lib files. The ones you are used to (kernel32.lib, user32.lib and so on) are called import libraries, meaning they refer to (or "import from") a .DLL. Another type, called static libraries, and are self-contained - rather than referring to a .DLL, they contain code and data that will be linked directly into your executable.
Posted on 2004-11-30 09:32:31 by f0dder
LittleEndian,

f0dder is right here, the MASM32 library is a collection of procedures that are built into a STATIC library so they do something different to an IMPORT library which is needed for an API function.

You can view the source for the entire MASM32 library from the editor so that you can see what code is in it and also how it is built.
Posted on 2004-11-30 10:04:15 by hutch--
Now i understand libraries a little better :)

Thanks alot all!
Posted on 2004-11-30 10:31:11 by LittleEndian
Another small detail for your understanding of libraries.

A DLL (Dynamic Loaded Library) file may contain any number of procedures. Even if you use only a single one of the available procedures in a DLL, the entire file must be loaded into memory so you can have access to that procedure. However, it does NOT add the procedure's code to your program to increase its size. But, in order for your program to run on another computer, that DLL must also be present on that computer.

On the other hand, a "static" library is a collection of procedures made available to a programmer. The library itself never gets loaded into memory. However, the code for only the procedures you may use from such library is directly inserted into your program at the linking stage, thus increasing its size. Your program is then self contained and would run on any compatible computer without the need of additional files.

Raymond
Posted on 2004-11-30 21:29:34 by Raymond
I have a question about the related to static library....


Like I understand a static library is "inserted" or more like linked with your others source files, that increase the size of your executable say like, if you have a static library about 500Kb, your programm will increase his size from 500Kb.


Even if you use only three functions of that library with the size of 10Kb each one.


Now, for what not was developed a special format for target this problem? (some like this):


    Have marks for code block inside the intermediate file (specially entry points) and global memory locations (global variables).

    Mark the dependencies of entry blocks, eg if you include only A, B and C, but C depend on X, X will be also included.


    Half of the work can be done without the need to modificate the structure of a normall lib, the problem is know where is he entry point of a function or even analising inside that block if depend in a global variable, the problem will be recognogize the termination (size of each entry block).


    and in that way, if posible recognogize, then you can link only three functions, calculate the block of each one, and analize this block if depend in a global variable, but wait, here other problem, how to know the size of a global variable?



    anyway, I dont know if that is what really do a static library, I havent never understood what mean insert code (all the library or only the used of the library?)


    If is realiable to have a format for such a library (checking dependencies to hitself) and only inserting the necesary blocks of code including the globals that are necesary, in a new OS would be reliable to have such static libraries?, or more to go in the way of loadable libraries?
Posted on 2004-11-30 22:32:24 by rea
hgb

Although I always try to be as specific as possible, maybe I should expand a little more for readers who may not be fully familiar with the English language. This is what I wrote:
However, the code for only the procedures you may use from such library is directly inserted into your program at the linking stage, thus increasing its size.

ONLY THE PROCEDURES YOU USE are inserted into your program, NOT the entire library. Only C++ would do that to you, bloating a 1k program to 300k.

Raymond
Posted on 2004-11-30 23:01:42 by Raymond
ohh, I see. Thx.
Posted on 2004-11-30 23:36:52 by rea
To be a bit more explicit... the linking is done on .obj file boundary, not .lib boundary. A .lib file is just an archive of .obj files. So if you use a single routine from a .obj (inside a .lib or not), the entire .obj file will be linked in.

This is why routines are usually separated into multiple .obj files.

There's extensions to the MS COFF object format, COMDEF and COMDAT iirc, that allow function level linking - which is obviously more fine-grained than the usual linking style. I haven't seen any assembler supporting this, but most C/C++ compilers worth their salt does.
Posted on 2004-12-01 01:40:36 by f0dder
Granularity is actually an old problem that effects library design. If you bundle a whole pile of procedures together in a single module, call ANY of the procedures and you get the whole lot. The simple and effective answer is to put every procedure in a seperate module and you don't pick up any dead code at all.

It would be reasonably rare these days to see a library designed in that manner as the problem is well understood and it takes little extra work to place each one in its own module.
Posted on 2004-12-01 04:45:26 by hutch--

If you bundle a whole pile of procedures together in a single module, call ANY of the procedures and you get the whole lot.

Unless COMDEF/COMDAT records are present in the object file - then granularity will be per-function.
Posted on 2004-12-01 07:08:02 by f0dder
This is why routines are usually separated into multiple .obj files.


Now I understand for what hutch-- put each function in a separate .asm file for get a obj of each one and then make the lib, when I was watching that, I was thinking, if all are FPU functions, for what not join them in a single file? :), thx for the explanation.


Then my anterior post move not to target libraryes, but for target .obj files.



Because is a intermediate file that I will like to make some manipulations, then I think I can add some more things for only get the necesary functions and global variables that affect each function, I can "see" that a function can:


    ? Depend on other function.
    ? Use other function.
    ? Use a global space

    Each function have a specific size and each global variable have a specific size.


    Now supose that you have a big library... say something big like (matlab) or some like that, and you have the obj that the size is about 10Mb (dont know, is a example :P), you only whant to have the function for calculate XThing, the size of this function is about 2Kb, this function use another one that the size is only about 40b, but this one depend on a function that initialize a global table about 200Kb.

    Then when linking to this obj, the linker should know this format, calculate a dependence three for functions, and a use three for functions and data with is respective size and you have taked a powerfull function for calculate X thing, altough some things where aded by the use/depend but not the whole obj file.

    COMDEF/COMDAT


    I question, some thing like that is what make such records.. I will try find info.


    Now I reredact my question:

    If is realiable to have a format for such a object file (checking dependencies to hitself) and only inserting the necesary blocks of code including the globals variables that are necesary, in a new OS would be reliable to have such object files?, or more to go in the way of loadable libraries?, or more join this concept of dependency/use with the loadable libraryes????
Posted on 2004-12-01 09:01:13 by rea
hgb, if I'm not mistaken it's all described in the official Microsoft PE/COFF reference - http://www.microsoft.com/whdc/system/platform/firmware/PECOFF.mspx . Also, try googling for things like "function level linking", "comdef", "comdat" and so on. It works pretty well in practice - of course the linker has to support it, but the ms linker does (check out /opt:ref, /opt:noref, /opt:icf linker switches).

I asked privalov about supporting this in FASM, but didn't get any reply - and the thread is gone from the fasm board as old threads are automatically deleted.
Posted on 2004-12-01 09:13:44 by f0dder
Thx, actually I am having a question that I need answer first.


I have in mind some things :). Hope I can do near some of the things I have in mind.

Bad about old post, I was trying to find one in masm forum, but havent finded it :S :).
Posted on 2004-12-01 12:34:14 by rea