ASLR 是否会导致 Dll 加载缓慢?

发布于 2024-09-16 16:36:35 字数 166 浏览 5 评论 0原文

在MSVC中,基地址随机化是默认选项。(从VS2005开始?)

所以,我不再手动重新设置dll的基地址。

但当我使用 VS2003 时,我重新调整了所有 dll 的基础以提高加载性能。

如果我使用 ASLR 选项,加载性能总是会下降?
(当然我还能得到其他好处)

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)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

清醇 2024-09-23 16:36:35

简短的回答是否定的。

在没有 ASLR 的系统(例如 XP)上,在非首选地址加载 DLL 会产生多种成本:

  1. 必须解析重定位部分,并且必须将修复应用于整个映像。
  2. 应用修复的行为会导致写时复制错误,这在 CPU 方面相对昂贵,并且还会强制从磁盘读取页面,即使应用程序本身没有引用它们。
  3. 每个在非首选地址加载 DLL 的进程都会获得写入的每个页面的私有副本,从而导致内存使用量增加。

第 2 项和第 3 项是迄今为止最大的成本,也是过去需要手动变基 DLL 的主要原因。

使用 ASLR,操作系统可以透明地应用修复,使 DLL 看起来像是实际加载到其首选地址。不存在写时复制错误,也不会创建进程专用页面。此外,修复仅应用于应用程序实际访问的页面,而不是整个图像,这意味着不会从磁盘读取额外的数据。

除此之外,手动变基方案无法防止所有基址冲突(例如,来自不同供应商的 DLL 可能会相互冲突,或者操作系统 DLL 可能由于修补程序而增加大小并溢出到为保留的范围内)其他一些 DLL 等)。 ASLR 在处理这些问题方面要高效得多,因此从整个系统来看,它实际上可以提高性能。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文