Page 1 of 1

Small correction for the C++ / Visual C++ wiki entry

Posted: Thu Aug 05, 2010 2:25 am
by blobmiester
http://wiki.osdev.org/C%2B%2B#Visual_C.2B.2B

In the Global Objects, Visual C++ section it lists the init tables needed by the visual C compiler. It then merges it into the .data section. This was correct for visual C++ 6, it now needs to be merged into the .rdata section (because the CRT area is no longer read/write for some reason or another), otherwise there is an annoying linker warning (disclaimer: I find any warning annoying).

Here is the warning issued by visual C++ 7 and above (to help with people searching if they are having this warning):
warning LNK4254: section '.CRT' (40000040) merged into '.data' (C0000040) with different attributes
So instead of this:

Code: Select all

// ... snip
#pragma data_seg()
#pragma comment(linker, "/merge:.CRT=.data") // works fine in visual c++ 6
It needs to be this:

Code: Select all

// ... snip
#pragma data_seg()
#pragma comment(linker, "/merge:.CRT=.rdata") // for visual C++ 7 and above

Re: Small correction for the C++ wiki entry

Posted: Thu Aug 05, 2010 2:49 am
by Solar
blobmiester wrote:(disclaimer: I find any warning annoying).
Don't disclaim, don't be defensive about it.

Does, by any chance, Visual 6 accept the .rdata solution as well? In that case we wouldn't need to keep two versions in the Wiki.

Re: Small correction for the C++ wiki entry

Posted: Thu Aug 05, 2010 2:54 am
by blobmiester
Don't disclaim, don't be defensive about it.
Sorry about that. That's just my weird sense of humor. No offense meant.
Does, by any chance, Visual 6 accept the .rdata solution as well? In that case we wouldn't need to keep two versions in the Wiki.
Unfortunately no. The warning message is stating that the two merged sections have different attributes.

The attributes for the .CRT section is 0x40000040 for Visual C++ 7 and above and 0xC0000040 for Visual C++ 6.

The attributes for .data are 0xC0000040 and for .rdata they are 0x40000040.

So Visual C++ 6 should emit that same warning message if it's changed to rdata.

Re: Small correction for the C++ wiki entry

Posted: Thu Aug 05, 2010 5:00 am
by Solar
blobmiester wrote:
Don't disclaim, don't be defensive about it.
Sorry about that. That's just my weird sense of humor. No offense meant.
None taken. What I meant is that it's a good sign that you find warnings annoying. 8)