Linker bug? data_seg(".CRT$XIU") not merged into other .CRT segments
Using the x64 cross-compiler running on x86, linker and cl.exe file version "8.00.50727.42 (RTM.050727-4200)", the following code that works in x86 with the x86 cl.exe and link fails:
#pragma data_seg(".CRT$XIU")
static int (*initptr)() = APreCppInitFunction;
#pragma data_seg()
The problem occurs because cl.exe seems to create the data_seg as a DATA segment type (in x86 it gets generated as CODE), and link.exe does not merge the .CRT$XIU segment into the correct alphabetized sequence among the other CRT code segments (.CRT$XIA, etc.). Here is a sample from the x64 mapping file that results:
0001:00000b28 00000008H .CRT$XIA CODE
0001:00000b28 00000008H .CRT$XIAA CODE
0001:00000b28 00000008H .CRT$XIZ CODE
...
0004:00000000 00000008H .CRT$(XIU) DATA
In x86 the map is as expected:
0001:000005a0 00000004H .CRT$XIA CODE
0001:000005a4 00000004H .CRT$XIAA CODE
0001:000005ac 00000004H .CRT$XIC CODE
0001:000005a8 00000004H .CRT$XIU CODE
0001:0000059c 00000004H .CRT$XIZ CODE
Questions:
- Is this a known issue?
- Is there some cl.exe setting or #pragma setting that would let me ensure the data_seg gets compiled as a CODE segment? I tried changing this to a code_seg but the segment then does not appear in the map because it's really a read-only data segment. data_seg() has an optional third param that is ignored (according ot the docs), so that does not seem like a possibility.
- Is this fixed in VS2005 SP1? I cannot find a similar issue listed in the hotfixes for that release.

