Microsoft KB Archive/70360

= PRB: LINK Does Not Generate L2041 Error with /NOD and /DOSSEG =

Article ID: 70360

Article Last Modified on 10/23/2003

-

APPLIES TO


 * Microsoft LINK for MS-DOS 3.x
 * Microsoft LINK for MS-DOS 4.x
 * Microsoft LINK for MS-DOS 5.0x
 * Microsoft LINK for MS-DOS 5.1x
 * Microsoft LINK for MS-DOS 5.2x
 * Microsoft LINK for MS-DOS 5.3x
 * Microsoft LINK for MS-DOS 5.5
 * Microsoft LINK for MS-DOS 5.6
 * Microsoft LINK for OS/2 5.0x
 * Microsoft LINK for OS/2 5.1
 * Microsoft LINK for OS/2 5.11
 * Microsoft LINK for OS/2 5.13
 * Microsoft LINK for OS/2 5.15

-



This article was previously published under Q70360



SYMPTOMS
An attempt to link an application using /NOD and /DOSSEG succeeds without an error message, even though the combined size of the stack and data for the DGROUP segment exceeds 64K. This occurs even though the compiler is designed to cause /DOSSEG segment ordering and thus enable the linker to generate a L2041 error.



CAUSE
The LINK command line being used does not enable segment ordering, so DGROUP is not even being created.



RESOLUTION
Specify a run-time library on the LINK command line that defines the segments needed to create DGROUP. All Microsoft C Run-Time libraries do this.



MORE INFORMATION
If the LINK command line includes the /NOD option but not /DOSSEG and no run-time libraries are specified, then segment ordering is not enabled. Adding the /DOSSEG option to the LINK command line but still omitting run-time libraries will still not give the L2041 error message, even though segment ordering will be enabled.

This is because the /DOSSEG switch only forces a certain segment class ordering convention; it doesn't actually define the segments that compose DGROUP. As a result, the &quot;L2041: stack plus data exceed 64K&quot; message can't be generated because there is no DGROUP to which the stack and data segments belong.

Linking with C run-time libraries introduces both the grouping and implementation of data segments to form DGROUP, so in cases where the code contributes more then 64k of data to DGROUP, error L2041 is given.

Note that Microsoft high-level language run-time libraries automatically enable the /DOSSEG option by means of a special object-module record included in libraries. To enable the /DOSSEG option in code developed with the Microsoft Macro Assembler (MASM), specify the .DOSSEG directive in a MASM source code file.

The following C source code example demonstrates this problem. Each of the following LINK command lines demonstrate the possible scenarios and the error messages that result.

Command line 1: link test;

Result set 1:

LINK : fatal error L2041: stack plus data exceed 64k

Command line 2: link /NOD test;

Result set 2:

LINK : warning L4021: no stack segment

(unresolved externals)

LINK : warning L4038: program has no starting address

NOTE: This result set does not include the L2041 error -- an error that you might expect.

Command line 3: link /NOD /DOSSEG test;

Result set 3:

LINK : warning L4021: no stack segment (unresolved externals) LINK : warning L4038: program has no starting address

NOTE: This result set contains the same errors as those generated when the /NOD switch is specified by itself.

Sample Code
/* * Compile options needed: /c */

unsigned char a[30*1024] = {0}; /* 30k         */ unsigned char b[30*1024] = {0}; /* 30k         */ unsigned char c[10*1024];       /* 10k         */ /* Total = 70k */ void main(void) { }

Additional query words: 4.06 4.07 4.10 5.01.20 5.01.21 5.02 5.03 5.05 5.10 5.11 5.13 5.15 5.20 5.30 5.31.009 5.50 5.60

Keywords: kb16bitonly KB70360

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.