Subject: RE: Difference with DLL creation
From: [email-masked] (Colin Peters)

8 May 1997 09:27:32 -0700
Approved: [email-masked]
Distribution: cygnus
Message-ID: <01BC5BFC.1185D140.cygnus.gnu-win32@gbird0>
Mime-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Original-To: "'RAFAELDP'" <[email-masked]>
Original-Cc: "'GNU-Win32'" <[email-masked]>
Original-Sender: [email-masked]

RAFAELDP[SMTP:[email-masked]] wrote:
>Please wich is the diference in the creation of DLL, I have the choice of
>creating no-relocatable dlls or relocatable dlls.

The difference happens when your DLL is loaded by a program. The operating
system has to map the code of the DLL into a portion of the address space
of the program that loads it. For example, your DLL might contain three
0x100 byte long functions with offsets in the file of 0x0000 0x0100 and
0x200. If the DLL is mapped to address 0x02000000 for example, then the
addresses that the program needs to call to use the DLL functions are
0x02000000, 0x02000100 and 0x02000200 respectively (actually the point
is not so much the calling program as the DLL's internal calls, see
below).

DLLs contain a number which tells the operating system where they would
like to be mapped. For example the above DLL might contain a number
saying that it would like to be mapped at 0x02000000. If the DLL can
rely on being mapped to this position then it can include function calls
to it's own code (and references to it's static data) and it will know
what addresses the code (or data) will be at.

But that would require that all processes leave the space between
0x02000000 and 0x02000300 in their address space free. They can't use
it for their own code or (more likely) load another DLL into the same
address. If two DLLs both want this space and neither can be moved
(i.e. they are both not relocatable) then a program that uses both DLLs
cannot run. The operating system will simply not load it successfully.

A relocatable DLL (or program) still says what address it would like
to be loaded at. But it is also marked as relocatable, and contains
a section of data indicating what data within the DLL has to be fixed
up if the DLL is not loaded in the preferred location (pointers to
functions within the DLL code, or static data for example). When loading
a relocatable DLL the operating system tries to put it in the requested
position, but if the space is occupied it finds a big enough spot and
uses the relocation data to fix the DLL (well, the copy in RAM) and
load it in the free location.

You can't tell what other DLLs might be loaded at the same time as your
DLL (unless no one else will ever use your DLL), or what code or data
might be occupying the addresses you would like to put your DLL at, so
basically DLLs must be relocatable. It also saves you the hassle of
trying to juggle base addresses and code+static data sizes to make
sure that all DLLs can load successfully. Just leave it to the operating
system.

Summary: relocatable is best.

Colin.

PS. This is my understanding based on what I've read and heard. I'm not
    a certified Microsoft support guy or anything like that.

-- Colin Peters - [email-masked]
-- Saga University Dept. of Information Science
-- http://www.fu.is.saga-u.ac.jp/~colin/index.html
-- http://www.geocities.com/Tokyo/Towers/6162/

-
For help on using this list (especially unsubscribing), send a message to
"[email-masked]" with one line of text: "help".