Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does ASLR cause a slow loading of Dlls?

In MSVC, the Base Address Randomizaiton is a default option.(Since VS2005?)

So, I do not rebase manually the dll's base address anymore.

But I rebased my all dlls to improve loading performance when I use VS2003.

If I use ASLR option, the loading performance is always decreased?
(Of cource I can get other benefits)

like image 769
Benjamin Avatar asked Sep 01 '10 11:09

Benjamin


1 Answers

The short answer is no.

On a system without ASLR (e.g. XP), loading a DLL at a non-preferred address has several costs:

  1. The relocations section has to be parsed and fixups have to be applied to the entire image.
  2. The act of applying fixups causes copy-on-write faults which are relatively expensive CPU-wise, and also force pages to be read from disk even if they are not referenced by the app itself.
  3. Every process that loads the DLL at a non-preferred address gets a private copy of every page that is written to, leading to increased memory usage.

Items 2 and 3 are by far the biggest costs, and are the main reason why manually rebasing DLLs used to be necessary.

With ASLR, fixups are applied transparently by the OS, making it look like the DLL was actually loaded at its preferred address. There are no copy-on-write faults, and no process-private pages are created. Also, fixups are applied only to the pages that are actually accessed by the app, rather than the entire image, which means no extra data is read from disk.

In addition to that, manual rebasing schemes can't prevent all base address conflicts (for example, DLLs from different vendors can conflict with each other, or an OS DLL could increase in size due to a hotfix and spill over into a range reserved for some other DLL, etc.). ASLR is a lot more efficient at dealing with these issues, so when looking at the system as a whole it can actually improve performance.

like image 115
Pavel Lebedinsky Avatar answered Sep 26 '22 19:09

Pavel Lebedinsky