Click here to Skip to main content
Click here to Skip to main content

Using the Rebase utility in project makefile

By , 5 Oct 2001
 

Introduction

A Dynamic-link library created in Microsoft Visual C++ has default base address 0x10000000. That means, when the process starts, the loader tries to load the Dll to this address in the process memory. However, if a number of Dlls have the same base address only one of them is loaded to it's default address. For all other Dlls the loader makes the relocation ie.  changes the memory addresses in Dll commands according to the new base address where the Dll is loaded. First, this takes additional time. Second (and more important) - the Dll code kept in process memory is changed. That means, when the Memory Manager needs memory pages for something else, it saves pages with the Dll code to the system paging file. This may reduce the working speed of large program.

Microsoft Visual Studio allows us to change the Dll base address in Project Settings:

Project Settings

But if your system contains a large number of Dlls, managing base addresses is difficult. The Rebase utility which comes both with Microsoft Framework SDK and Microsoft Visual Studio allows you to set optimal base addresses for a number of Dlls starting from some address. The SDK Help Rebase topic recommends to use address 0x60000000. The best place to do this is the  project makefile.

Demo projects

The Demo contains a number of projects. There are two Win32 Dlls Server1 and Server2. Each of them exports one function. The exe project Client calls these two functions. The Output files of these three projects are written to the Bin directory.

The Build project is a makefile which rebuilds Server1, Server2 and Client. This makefile is very simple and the only thing it can do is to make "Rebuild All" for three other projects in the Debug configuration. The interesting point is that it calls the Rebase utility which sets the base addressed for Server1 and Server12 dynamic-link libraries.

Open the Server1 project in Visual Studio and build it. Do the same with Server2 and with the Client projects. Now run the Dependency Walker utility (it comes with Visual Studio and is listed in the Microsoft Visual Studio Tools menu) and open the file bin\Client.exe:

Depends Utility 1

We can see that both Server1.dll and Server2.dll have the same base address 0x10000000. That means, when Client.exe starts, one of these libraries is relocated. If the project runs under Debugger in Windows NT, the Loader shows the appropriate message in the Output window for each relocated Dll.

Now open the Build project and build it (NOTE: Ensure that one of Microsoft SDK or Visual Studio Bin directories contains Rebase.exe is available through system Path). At the end of rebuilding process we see next lines:

REBASE: Total Size of mapping 0x0000000000080000
REBASE: Range 0x0000000060000000 -0x0000000060080000
This is the Rebase utility output. Now open the bin\Client.exe in Dependency Walker:

Depends Utility 2

We can see that Rebase did it's work. The last line of the Build Makefile is:
	-@rebase.exe -b 0x60000000 Server1.dll Server2.dll
The Base addresses in two libraries are updated and now they are not relocated when the Client.exe starts.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Alex Fr
Software Developer
Israel Israel
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
Generalmakefile vs postbuild stepmemberBrian van der Beek17 Apr '03 - 21:50 
GeneralRe: makefile vs postbuild stepmemberAlex Farber26 Apr '03 - 20:15 
GeneralI don't get it :confused:memberMike Eriksson17 Oct '02 - 23:17 
GeneralRe: I don't get it :confused:memberAlex F26 Oct '02 - 23:12 
GeneralRe: I don't get it :confused:memberMike Eriksson28 Oct '02 - 21:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web02 | 2.6.130516.1 | Last Updated 6 Oct 2001
Article Copyright 2001 by Alex Fr
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid