sergiu reznicencu
sergiu reznicencu

Reputation: 1039

Section not created in program-release version C++

I am storing some variables inside custom section in my program. During debugging session I can check it is created and that it contains the necessary data. But in release mode, it disappears!

Note: I am also creating an executable section which strangely is created in both version. The CPU platform seems to make no difference.

Why doesn't the "data" segment appear in the release version?

This is a short snapshot:

// 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();

The program (it's a dll) is compiled with a fixed base address and with /MT flag.

Release version x64. Only one segment appears-the executable one: Release version x64. Only one segment appears-the executable one

Debug version x64. Both segments show up: Debug version x64. Both segments show up

Upvotes: 0

Views: 153

Answers (1)

Reznicencu Bogdan
Reznicencu Bogdan

Reputation: 900

Try to disable Link-time optimizatizon scheme from the project's settings. To do that go to: Configuration Properties 🠂 General 🠂 Whole Program Optimisation and set to No Whole Program Optimisation.

Most likely it has something to do with the optimisations performed during linking. More details you can get from here : What's C++ optimization & Whole program optimization in visual studio

Upvotes: 1

Related Questions