However, resolving base address conflicts is so easy that there is hardly any reason not to do it. To end this overview, I checked the base addresses of executable modules built by the compilers that I have:.
The address range for an application that is not reserved by any version of Windows is from 0x to 0x The system DLLs for Windows are currently based in memory from 0x to 0x on the Intel processors and from 0x to 0x on the MIPS processors. When selecting base addresses for DLLs, Microsoft suggests that you select them from the top of the allowed address range downwards, in order to avoid conflicts with memory allocated dynamically by the application which is allocated from the bottom up.
In conclusion, the most suitable address range for DLLs is from 0x through 0x6f Microsoft, seeking portability where it cannot be achieved, proposes to reduce the range further to 0x through 0x in order to accommodate both Intel and MIPS processors. After selecting a load address for a DLL, you have to tell it to the linker. Note again that applications. The linker options are:. The drawbacks of the manual rebasing scheme are that the table is difficult to memorize, and that choosing a base address only on the first letter is too simplistic.
This worked in the sense that it resolved nearly all of the conflicts, but the procedure became even harder to know by heart, now requiring two tables instead of one. This called for an automatic solution. And while I was at it, why stop at considering only two letters of the filename?
Libase is a little post-link utility that I wrote that chooses a base address of a DLL considering all letters in the filename and rebases the DLL to that address. You do not need to add linker flags to use it; instead, Libase must run after the linker has finished. Libase is configurable via a. The hash is adapted from the well-known hash function published in Compilers: Principles, Techniques and Tools by Aho, Sethi, and Ullman page as P.
The source code for Libase is in libase. In its default configuration, Libase disregards the case of characters in a filename. That is, the files mylib. DLL are rebased to the same address. To use Libase, simply run it with the path to a DLL on the command line.
Libase can rebase multiple DLLs in one invocation, but unlike the Platform SDK utility Rebase, it does not choose consecutive, non-overlapping addresses; Libase chooses the base address for each DLL from a hash of its filename. One added feature of Libase is that it keeps the addresses to which it has rebased all modules that it has seen in its. This allows you to check whether a collision has occurred and to which DLLs that collision applies. The implementation of Libase is trivial for the remainder except for the frustration of the SDK documentation for the ReBaseImage function mismatching the prototype in imagehlp.
You will get a warning for a DLL whose size exceeds the step size, because the report in the. In closing, I would like to mention that to have a DLL load quickly, the first step is to make sure that Windows can locate it quickly. My advice is to keep implicitly loaded DLLs in the same directory as the application that uses them and to use a full path for DLLs that the application loads explicitly. Ruediger R. This article does exhaustive tests on the load-time degradation of DLLs that must be rebased by the operating system at load time.
John Robbins. Microsoft, proposes to reduce the range further to 0x through 0x in order to accommodate with MIPS processors too,. Let's look at this code: Using the code Let's look at a simple piece of code. In that case, the code that changes the " i " variable to 5 should be: MOV [0x], 5 But the code in the file's image looks like this: MOV [0x], 5 If the code from the file's image without changing the address is allowed to execute, some 4-byte value in the first DLL module will be overwritten with the value 5.
This yields a difference of 0x, which is then added to the address in the machine code instruction, giving us this: MOV [0x], 5 To avoid this, instead change the settings while compilation so as to give different base addresses during compilation itself. Now this code in the second DLL will reference its " i " variable correctly.
There are two major drawbacks when a module cannot load at its preferred base address: The loader has to iterate through the relocation section and modify a lot of the module's code. This produces a major performance hit and can really hurt an application's initialization time. As the loader writes to the module's code pages, the system's copy-on-write mechanism forces these pages to be backed by the system's paging file. This was my first article, hope all of you liked it.
Acknowledgement and References I would like to acknowledge author Mr. It only counts when the machine starts to get under load with lots of processes competing for memory.
And the fragmentation of the paging file. But clearly, rebasing is a very cheap optimization. The Address column gives you a good hint what base address would be a good choice. Leave ample space between them so you don't constantly have to tweak this as your program grows. I'd like to provide one answer myself, although the answers of Hans Passant and others are describing the tradeoffs already pretty well.
After recently fiddling with DLL base addresses in our application, I will here give my conclusion:. I think that, unless you can prove otherwise, providing DLLs with a non-default Base Address is an exercise in futility. This includes rebasing my DLLs. For the DLLs I control , given the average application, each DLL will be loaded into memory only once anyway, so the load on the paging file should be minimal. But see the comment of Michal Burr in another answer about Terminal Server environment.
If DLLs are provided with a fixed base address without rebasing it will actually increase address space fragmentation, as sooner or later these addresses won't match anymore. In our app we had given all DLLs a fixed base address for other legacy reasons, and not because of address space fragmentation without using rebase. Rebasing via rebase.
It is another step in the build process that has to be maintained and checked, so it has to have some benefit. So to sum up, I think that rebasing isn't worth the trouble except for special cases like the system DLLs. The real work happened when the pages of the DLL ultimately got swapped in.
The raw page was swapped off the disk, then the fix-ups were applied on the fly to the raw page, thereby relocating it. The fixed-up page was then mapped into the process's address space and the program was allowed to continue. Looking at how this process is done read the whole thing , I personally suspect that part of the "rebasing is evil" stance dates back to the olden days of Win9x and low memory conditions.
Look, now there's a non-historical piece on Old New Thing :. Back in the day, one of the things you were exhorted to do was rebase your DLLs so that they all had nonoverlapping address ranges, thereby avoiding the cost of runtime relocation. Is this still important nowadays? Conclusion: It doesn't hurt to rebase, just in case, but understand that the payoff will be extremely rare.
That will cover pretty much all of the real-world scenarios. If you happen to fall into one of the very rare cases where ASLR is not available, then your program will still work. It just may run a little slower due to the relocation penalty. ASLR actually does a better job of avoiding collisions than manual rebasing, since ASLR can view the system as a whole, whereas manual rebasing requires you to know all the DLLs that are loaded into your process, and coordinating base addresses across multiple vendors is generally not possible.
They fail to argue however, if this speeds up application load times to any significant amount. The load time change is minimal, because the v-table is what gets updated with the new addresses. If the dlls were rebased - and the rebased dlls don't collide with any other dlls - then instead of swapping them out to the page file and back , the system just overwrites the memory and reloads the dll from the original on the hard drive.
The benefit is only relevant when systems are paging stuff in and out of main memory. The last time I made efforts to keep databases of applications and their base addresses was back in VB6 days, when the computers in our offices and data centers were lucky to have even MB of RAM. We'll send a magic link to your inbox. Email Address. All Sign in options.
Enter a Email Address. Choose your interests Get the latest news, expert insights and market research, sent straight to your inbox. Newsletter Topics Select minimum 1 topic.
Anonymous February 24, 0 Comments. Register or Login.
0コメント