/TSAWARE链接器标志对PE可执行文件有什么作用? [英] What does the /TSAWARE linker flag do to the PE executable?

查看:183
本文介绍了/TSAWARE链接器标志对PE可执行文件有什么作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在将/TSAWARE链接器标志添加到我的一个项目(Visual Studio 6)中之后,我很惊讶地在PE文件(.idata)中找到了一个新部分.如果未设置该标志,则导入将合并到.rdata中.

After adding the /TSAWARE linker flag to one of my projects (Visual Studio 6), I was surprised to find a new section in the PE file (.idata). If I don't set the flag, the imports are merged into .rdata.

为了说明问题",我们从一个简单的控制台程序开始:

To illustrate the "problem" we start out with a simple console program:

#include <stdio.h>
int main() 
{
    printf("hello world\n");
    return 0;
}

并使用:cl /Og /O1 /GF /WX /c main.c

然后使用

  • link /MACHINE:IX86 /SUBSYSTEM:CONSOLE /RELEASE /OUT:a.exe main.obj
  • link /MACHINE:IX86 /SUBSYSTEM:CONSOLE /RELEASE /OUT:b.exe /TSAWARE main.obj
  • link /MACHINE:IX86 /SUBSYSTEM:CONSOLE /RELEASE /OUT:a.exe main.obj
  • link /MACHINE:IX86 /SUBSYSTEM:CONSOLE /RELEASE /OUT:b.exe /TSAWARE main.obj

让我们比较一下dumpbin的输出:

Let's compare the dumpbin output:

Dump of file a.exe

File Type: EXECUTABLE IMAGE

  Summary

        4000 .data
        1000 .rdata
        5000 .text

Dump of file b.exe

File Type: EXECUTABLE IMAGE

  Summary

        4000 .data
        1000 .idata
        1000 .rdata
        5000 .text

因此,由于某些原因,链接器决定无法合并导入.

So for some reason, the linker decides that the imports cannot be merged.

但是,如果我们运行editbin /TSAWARE a.exe,则仅PE可选标头中的DLL特性字段会更改.

But if we run editbin /TSAWARE a.exe only the DLL characteristics field in the PE optional header is changed.

有人可以向我解释吗?这是链接器中的错误,还是由editbin更改的可执行文件最终在某些系统上不起作用?

Can anyone explain this to me? Is this a bug in the linker or can the executable changed by editbin end up not working on certain systems?

推荐答案

仅凭猜测:在终端服务器系统上,您希望图像中写入尽可能多的页面.如果未修改与该映像相对应的内存页,则可以将单个物理RAM页映射到使用该映像的eash会话中.如果修改了图像中的页面,则系统必须在所有会话中对该页面的每个实例执行写时复制操作,并使用不同的物理内存块来表示每个会话中的页面.

Only a guess: on a terminal server system, you want an image to have a few pages written to as possible. If a memory page that corresponds to the image is not modified, a single page of physical RAM can be mapped into eash session that is using that image. If a page from an image is modified, the system has to perform a copy-on-write operation for each instance of the page among all the sessions and use a different block of physical memory to represent the page in each session.

由于如果必须重定位要导入的DLL,通常需要修复映像的导入,因此保存导入的页面通常会被修改,因此无法参与会话之间的共享.如果链接器将导入与通常不修改的其他数据合并,则可能会不必要地增加写时复制页面的数量.

Since the imports for an image often need to be fixed up if the DLL that is being imported had to be relocated, the pages that hold the imports often get modified and therefore can't participate in sharing between the sessions. If the linker merges the imports with other data that is usually not modified, it might increase the number of copy-on-write pages unnecessarily.

这可能是一种优化,有助于减少跨会话复制的页面数量.

This may be a sort of optimization that helps reduce the number of copied pages across sessions.

就像我说的那样-这纯粹是猜测.

Like I said though - this is purely a guess.

这篇关于/TSAWARE链接器标志对PE可执行文件有什么作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆