简体   繁体   English

在VS刚刚构建之后,“xxx.exe不是有效的Win32应用程序”

[英]“xxx.exe is not a valid Win32 application” after VS just built it

I have been successfully developing a WinAPI application in visual studio 2015 (using the IDE) on my Windows-7-64 PC. 我已经在Windows-7-64 PC上成功开发了Visual Studio 2015中的WinAPI应用程序(使用IDE)。 I usually test the program in Release mode. 我通常在发布模式下测试程序。

I then made some edits to my source. 然后我对我的来源进行了一些编辑。 The program compiled and linked without error but the program did not behave quite as I expected, so I switched to Debug mode and tried to build and run. 程序编译和链接没有错误,但程序没有像我预期的那样,所以我切换到调试模式,并尝试构建和运行。 Again VS compiled and linked without error but then complained 再次VS编译和链接没有错误,但然后抱怨

"Unable to start program 'f:\\dropbox\\blah\\x64\\Debug\\xxx.exe'. 'f:\\dropbox\\blah\\x64\\Debug\\xxx.exe' is not a valid Win32 application". “无法启动程序'f:\\ dropbox \\ blah \\ x64 \\ Debug \\ xxx.exe'。'f:\\ dropbox \\ blah \\ x64 \\ Debug \\ xxx.exe'不是有效的Win32应用程序”。

I thought it was strange, so I flipped back to release mode and tried again - the program started fine. 我觉得这很奇怪,所以我回到发布模式并再次尝试 - 程序开始很好。 I made some edits and re-built a few times, but then later VS declared 我做了一些编辑并重建了几次,但后来VS宣布了

"Unable to start program 'f:\\dropbox\\blah\\x64\\Release\\xxx.exe'. 'f:\\dropbox\\blah\\x64\\Release\\xxx.exe' is not a valid Win32 application". “无法启动程序'f:\\ dropbox \\ blah \\ x64 \\ Release \\ xxx.exe'。'f:\\ dropbox \\ blah \\ x64 \\ Release \\ xxx.exe'不是有效的Win32应用程序”。

I tried clean all, restarted VS, even restarted my PC.. but all to no avail, I still get exactly the same errors. 我试过干净所有,重新启动VS,甚至重新启动我的电脑..但都无济于事,我仍然得到完全相同的错误。

EDIT: After reading about similar reports, I tried pausing dropbox syncing. 编辑:在阅读类似报告后,我尝试暂停Dropbox同步。 It then seemed to work but only once or twice and then the problem returned. 它似乎工作但只有一两次然后问题又回来了。 I then tried switching off multi-processor compilation and this seems to have allowed the release version of my program to run again. 然后我尝试关闭多处理器编译,这似乎允许我的程序的发布版本再次运行。 I have since edited-rebuilt-run many (50+?) times without problem - but it still refuses to run the debug version. 我已经编辑 - 重建 - 运行很多(50 +?)次没有问题 - 但它仍然拒绝运行调试版本。

EDIT: FYI my antivirus software is Microsoft Security Essentials 编辑:仅供参考我的防病毒软件是Microsoft Security Essentials

EDIT: calling dumpbin and passing my (non-running debug exe) produces the following output: 编辑:调用dumpbin并传递我的(非运行的调试exe)产生以下输出:

File Type: EXECUTABLE IMAGE

  Summary

        1000 .00cfg
    77BB8000 .data
        1000 .gfids
        4000 .idata
        4000 .pdata
       31000 .rdata
        4000 .reloc
        1000 .rsrc
       DD000 .text

EDIT: Just tried compile-build-run on a different machine altogether (windows-10-64) that was linked via dropbox and have exactly the same symptoms, ie runs in release mode but not in debug mode. 编辑:刚尝试在不同的机器上完成编译 - 运行 - 运行(windows-10-64),它通过Dropbox链接并具有完全相同的症状,即在发布模式下运行但不在调试模式下运行。

EDIT: On the advice of Michael Burr I ran dependancy walker on my (non-working) debug exe and it reported these errors: 编辑:根据Michael Burr的建议,我在我的(非工作)调试exe上运行了dependancy walker,它报告了这些错误: 在此输入图像描述 then out of curiosity I thought I'd have a look at what dep-walker said about my (working) release exe and found that I got exactly the same list of errors!... upon more searching I found this SO question in which it was concluded: "The gist of it: As someone elsewhere stated, the tool is a bit dated by now and does not always work properly with newer OS. Thus keep an eye open and don't get mislead by missing 'API-MS-WIN-CORE-COM-L1-1-0.DLL', ... the problem probably lies entirely elsewhere." 然后出于好奇,我以为我会看看dep-walker对我的(工作)发布exe的说法,发现我得到完全相同的错误列表!...在更多搜索时我发现了这个问题 ,其中得出的结论是:“它的要点:正如其他人所说的那样,该工具现在有点陈旧,并且在新的操作系统上并不总能正常工作。因此请密切关注并且不要因错过'API-MS而误导-WIN-CORE-COM-L1-1-0.DLL',......问题可能完全在其他地方。“

EDIT: I switch between debug and release mode from the selection box on the left in the image below and I run the program by clicking the green triangle. 编辑:我从下图中左侧的选择框切换调试和释放模式,然后单击绿色三角形运行程序。 在此输入图像描述

EDIT: I generated the map file for the debug exe. 编辑:我生成了调试exe的映射文件。 It's too big to show here, but it starts off with the following lines... 它太大了,不能在这里展示,但它从以下几行开始......

 Timestamp is 5811bed3 (Thu Oct 27 09:46:11 2016)

 Preferred load address is 0000000140000000

 Start         Length     Name                   Class
 0001:00000000 00002840H .text$di                CODE
 0001:00002840 000da860H .text$mn                CODE
 0001:000dd0a0 00001020H .text$mn$00             CODE
 0001:000de0c0 00001eb0H .text$x                 CODE
 0001:000dff70 0000104bH .text$yd                CODE
 0002:00000000 00000110H .CRT$XCA                DATA
 0002:00000110 00000110H .CRT$XCAA               DATA
 0002:00000220 00000110H .CRT$XCL                DATA
 0002:00000330 00000128H .CRT$XCU                DATA
 0002:00000458 00000110H .CRT$XCZ                DATA
 0002:00000568 00000110H .CRT$XIA                DATA
 0002:00000678 00000110H .CRT$XIAA               DATA
 0002:00000788 00000110H .CRT$XIAC               DATA
 0002:00000898 00000110H .CRT$XIZ                DATA
 0002:000009a8 00000110H .CRT$XPA                DATA
 0002:00000ab8 00000110H .CRT$XPZ                DATA
 0002:00000bc8 00000110H .CRT$XTA                DATA
 0002:00000cd8 00000118H .CRT$XTZ                DATA
 0002:00000df0 0002c960H .rdata                  DATA
 0002:0002d750 00000998H .rdata$r                DATA
 0002:0002e0e8 00000178H .rdata$zzzdbg           DATA
 0002:0002e260 00000110H .rtc$IAA                DATA
 0002:0002e370 00000188H .rtc$IMZ                DATA
 0002:0002e4f8 00000110H .rtc$IZZ                DATA
 0002:0002e608 00000110H .rtc$TAA                DATA
 0002:0002e718 00000188H .rtc$TMZ                DATA
 0002:0002e8a0 00000110H .rtc$TZZ                DATA
 0002:0002e9b0 00003b68H .xdata                  DATA
 0002:00032518 00000275H .xdata$x                DATA
 0002:0003278d 00000000H .edata                  DATA
 0003:00000000 000023e0H .data                   DATA
 0003:000023e0 00000580H .data$r                 DATA
 0003:00002960 77376001H .bss                    DATA
 0004:00000000 0000369cH .pdata                  DATA
 0005:00000000 00000ed0H .idata$5                DATA
 0005:00000ed0 000000c8H .idata$2                DATA
 0005:00000f98 00000018H .idata$3                DATA
 0005:00000fb0 00000ed0H .idata$4                DATA
 0005:00001e80 00001fc6H .idata$6                DATA
 0006:00000000 0000015eH .gfids$y                DATA
 0007:00000000 0000011bH .00cfg                  DATA
 0008:00000000 00000170H .rsrc$01                DATA
 0008:00000170 000002ccH .rsrc$02                DATA

  Address         Publics by Value              Rva+Base               Lib:Object

 0000:00000000       __guard_iat_table          0000000000000000     <absolute>
 0000:00000000       __guard_longjmp_count      0000000000000000     <absolute>
 0000:00000000       __guard_longjmp_table      0000000000000000     <absolute>
 0000:00000000       __guard_fids_count         0000000000000000     <absolute>
 0000:00000000       ___safe_se_handler_table   0000000000000000     <absolute>
 0000:00000000       ___safe_se_handler_count   0000000000000000     <absolute>
 0000:00000000       __guard_iat_count          0000000000000000     <absolute>
 0000:00000000       __guard_fids_table         0000000000000000     <absolute>
 0000:00000000       __dynamic_value_reloc_table 0000000000000000     <absolute>
 0000:00000100       __guard_flags              0000000000000100     <absolute>
 0000:00000000       __ImageBase                0000000140000000     <linker-defined>
 0001:00002aa0       ?readstring@@YAXPEAD0@Z    0000000140003aa0 f   COMMAND.obj
 0001:00002b70       ?make_phere@@YAXH@Z        0000000140003b70 f   COMMAND.obj
 0001:00002c50       ?load_snap@@YAXXZ          0000000140003c50 f   COMMAND.obj
 0001:00002d30       ?i_rand_0_n_inclusive@@YAHH@Z 0000000140003d30 f   COMMAND.obj
  77BB8000 .data

That's almost certainly the problem, you have a very large data section. 这几乎肯定是问题,你有一个非常大的数据部分。 Its size is suspiciously close to what it is possible for a single executable module on Windows. 它的大小非常接近Windows上单个可执行模块的可能性。 You can get a more consistent repro from this sample C program: 您可以从此示例C程序中获得更一致的repro:

unsigned char kaboom[0x7d000000];

int main()
{
    return 0;
}

Not a very good error message btw, Microsoft did not reserve an error code for this corner-case. 不是一个非常好的错误消息btw,微软没有为这个角落案例保留错误代码。 And sure, it is not going to repeat that well when you are close to the edge with 0x77BB8000. 当然,当你接近0x77BB8000的边缘时,它不会重复得那么好。 The executable image must fit a single view of the memory-mapped file that the loader creates to map the code and data into memory. 可执行映像必须适合加载器创建的内存映射文件的单个视图,以将代码和数据映射到内存中。 The view has a hard upper-limit of 2 gigabytes, fundamental for a 32-bit process and an MMF view size restriction even on the 64-bit version of Windows. 该视图具有2 GB的硬上限,即使在64位版本的Windows上,也是32位进程的基础和MMF视图大小限制。

The amount of space that is available for that data section varies from one run to the next. 可用于该数据部分的空间量因运行而异。 Subtracted from the view size are the non-mappable regions at the start and the end of the address space and the space required for the operating system DLLs (at least ntdll.dll and kernel32.dll) in a 32-bit EXE process. 从视图大小中减去的是地址空间的开头和结尾处的不可映射区域以及32位EXE进程中操作系统DLL(至少ntdll.dll和kernel32.dll)所需的空间。 And the space you lose due to ASLR (Address Space Layout Randomization), a number that changes. 由于ASLR(地址空间布局随机化)而丢失的空间,这个数字会发生变化。 And DLLs that are injected, like those used by anti-malware and Dropbox. 和注入的DLL一样,反恶意软件和Dropbox使用的DLL。

It can't be guessed why your data section needs to be so large. 无法猜测为什么您的数据部分需要如此之大。 Ask the linker to generate a .map file so you get a breakdown of the section, the large global variable ought to jump out. 要求链接器生成一个.map文件,以便获得该部分的细分,大型全局变量应该跳出来。 Be sure to target x64 so you have lots of address space available and use the free store (malloc etc) to allocate large arrays. 确保以x64为目标,以便有大量可用的地址空间,并使用免费存储(malloc等)来分配大型数组。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM