Visual c++ 更改x64应用程序的入口点不会生成reloc表

Visual c++ 更改x64应用程序的入口点不会生成reloc表,visual-c++,linker,portable-executable,relocation,Visual C++,Linker,Portable Executable,Relocation,我创建了一个简单的应用程序,并希望最小化大小 该应用程序如下所示: #include "stdafx.h" #include <Windows.h> #pragma comment(linker, "/ENTRY:testfc") #pragma check_stack(off) #pragma runtime_checks("su",off) int testfc() { MessageBoxA(0, "test", "test", 0); return 0

我创建了一个简单的应用程序,并希望最小化大小

该应用程序如下所示:

#include "stdafx.h"
#include <Windows.h>
#pragma comment(linker, "/ENTRY:testfc")


#pragma check_stack(off)
#pragma runtime_checks("su",off) 

int testfc()
{
    MessageBoxA(0, "test", "test", 0);
    return 0;
}

int main()
{
    MessageBoxA(0, "main", "main", 0);
    return 0;
}
#包括“stdafx.h”
#包括
#pragma注释(链接器,“/ENTRY:testfc”)
#杂注检查堆栈(关闭)
#pragma运行时检查(“su”,关闭)
int testfc()
{
MessageBoxA(0,“测试”,“测试”,0);
返回0;
}
int main()
{
MessageBoxA(0,“主”,“主”,0);
返回0;
}

通过
#pragma注释(linker,“/ENTRY:testfc”)
我可以看到链接器没有生成任何relocs,链接器中启用了
/DYNAMICBASE
选项,因此这很奇怪。Hovewer如果我删除
#pragma注释(linker,“/ENTRY:testfc”)
并返回到原始入口点,就会生成relocs。如何更改入口点但保留重定位表?这只发生在x64版本中,而x86版本中我没有这样的问题。

重新定位绝对不依赖于入口点。若链接器不产生任何relocs——这只意味着代码中并没有实际的重新定位——就并没有什么可产生的

当您使用
#pragma comment(linker,“/ENTRY:testfc”)
时,您的代码很小-只有
int testfc()
和所有(并且您忘记了其中的调用
ExitProcess
,这是错误)。字符串
“test”
在x86代码中是生成relocs的,因为这里使用了字符串的绝对地址。但是x64使用rip寻址。所以这里真的没有关系

当您评论
#pragma comment(linker,“/ENTRY:testfc”)
时,情况发生了严重变化。链接器默认使用
mainCRTStartup
as。因此,CRT代码被链接。
mainCRTStartup
(调用您的
main
)已经有一些重定位