我在程序的自定义部分中存储了一些变量。在调试会话期间,我可以检查它是否已创建并且其中包含必要的数据。但是在释放模式下,它消失了!
注意:我还在创建一个可执行部分,这两个版本都奇怪地创建了该部分。 CPU平台似乎没有什么区别。
为什么“数据”段没有出现在发行版本中?
这是一个简短的快照:
// Defnitions used for better code segmentation
#define store_variable(x) __declspec(allocate(x)) //for data segment
#define store_code(seg) __declspec(code_seg(seg)) //for execution segment
#pragma section(".eqwrt", read) //weird name because I thought there would be collision
store_variable(".eqwrt") UCHAR USER_DATA[SIZE];
store_variable(".eqwrt") USHORT Version = 1;
store_code(".wsect") bool sendError();
该程序(它是一个dll)使用固定的基地址和/ MT标志进行编译。
发行版本x64。仅出现一个段-可执行段:
调试版本x64。这两个部分均显示:
最佳答案
尝试从项目的设置中禁用Link-time optimizatizon
方案。
为此,请转到:Configuration Properties
🠂General
🠂Whole Program Optimisation
并设置为No Whole Program Optimisation
。
最有可能与链接期间执行的优化有关。
您可以从这里获得更多详细信息:What's C++ optimization & Whole program optimization in visual studio
关于c++ - 未在程序发布版本C++中创建的部分,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/55754505/