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

All about the OSDev Wiki. Discussions about the organization and general structure of articles and how to use the wiki. Request changes here if you don't know how to use the wiki.
Post Reply
User avatar
blobmiester
Member
Member
Posts: 45
Joined: Fri Jul 16, 2010 9:49 am

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

Post 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
Last edited by Candy on Thu Aug 05, 2010 3:44 am, edited 1 time in total.
Reason: Changed title to indicate this isn't about the language
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: Small correction for the C++ wiki entry

Post 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.
Every good solution is obvious once you've found it.
User avatar
blobmiester
Member
Member
Posts: 45
Joined: Fri Jul 16, 2010 9:49 am

Re: Small correction for the C++ wiki entry

Post 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.
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: Small correction for the C++ wiki entry

Post 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)
Every good solution is obvious once you've found it.
Post Reply