Click here to Skip to main content
Licence CPOL
First Posted 5 Oct 2001
Views 66,936
Downloads 571
Bookmarked 25 times

Using the Rebase utility in project makefile

By Alex Fr | 5 Oct 2001
Setting the DLL base address in a project makefile using the Rebase utility

1
1 vote, 12.5%
2

3
3 votes, 37.5%
4
4 votes, 50.0%
5
3.90/5 - 15 votes
μ 3.90, σa 1.81 [?]

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


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

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
Generalmakefile vs postbuild step PinmemberBrian van der Beek22:50 17 Apr '03  
GeneralRe: makefile vs postbuild step PinmemberAlex Farber21:15 26 Apr '03  
GeneralI don't get it :confused: PinmemberMike Eriksson0:17 18 Oct '02  
GeneralRe: I don't get it :confused: PinmemberAlex F0:12 27 Oct '02  
GeneralRe: I don't get it :confused: PinmemberMike Eriksson22:11 28 Oct '02  

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

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

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