Small Mem. Mod. 64K Boundaries and Watcom C

Hello,

I am using Watcom C 10.6 and QNX 4.25 to compile/link a C program using
the small memory model, e.g.,

wpp386 -ms -ze -4s -sg -bt=QNX program.c
wlink na exename f program op offset=4K op st=16K op map=mapfile form QNX

(note that the default cc chooses a stack of 32K and this crashes the code).

My question is does the small memory model mean that separate 64K spaces
are used for the code and data, or must both the code and data must fit in the
one 64K space ?

The map file indicates that the data follows directly on from the code in
memory, data starting at address 0x0000EA97 in the following part of the
map file (best viewed with a fixed width font),



WATCOM Linker Version 10.6
Copyright by WATCOM International Corp. 1985, 1996. All rights reserved.
Created on: 01/01/01 15:24:06
Executable Image: Snav
creating a QNX 386 executable


±-----------+
| Groups |
±-----------+

Group Address Size
===== ======= ====

DGROUP 0000f000 0000c210



±-------------+
| Segments |
±-------------+

Segment Class Group Address Size
======= ===== ===== ======= ====

BEGTEXT CODE 00001000 00000006
_TEXT CODE 00001010 0000da87
printf11_DATA FAR_DATA 0000ea97 00000000
sprintf11_DATA FAR_DATA 0000ea97 00000000
fprintf11_DATA FAR_DATA 0000ea97 00000000
fprtf11_DATA FAR_DATA 0000ea97 00000000
efgfmt11_DATA FAR_DATA 0000ea97 00000000
_NULL BEGDATA DGROUP 0000f000 00000020
_AFTERNULL BEGDATA DGROUP 0000f020 00000002
CONST DATA DGROUP 0000f024 00002628
CONST2 DATA DGROUP 0001164c 000001d4
_DATA DATA DGROUP 00011820 00000674
XIB DATA DGROUP 00011e94 00000000
XI DATA DGROUP 00011e94 00000030
XIE DATA DGROUP 00011ec4 00000000
YIB DATA DGROUP 00011ec4 00000000
YI DATA DGROUP 00011ec4 0000000c
YIE DATA DGROUP 00011ed0 00000000
DATA DATA DGROUP 00011ed0 00000000
DATA32 DATA DGROUP 00011ed0 0000011c
CONST32 CONST DGROUP 00011fec 00000000
_BSS BSS DGROUP 00011ff0 00005218
BSS32 BSS DGROUP 00017208 00000000
STACK STACK DGROUP 00017210 00004000

etc…

Note that 2^16 = 64K => 0x00010000 < 0x00017210+0x00004000.

Thank you,

Amit Sanyal
asanyal@tamu.edu

Amit K Sanyal <asanyal@tamu.edu> wrote:

Hello,

Don’t invoke wpp386 or wlink directly yourself – you will often give
them invalid instructions that will cause them to generate output that
is not a valid QNX executable. ALWAYS use cc to invoke them.

Again, ALWAYS use cc to invoke the QNX4 compiler/linker toolchain. If
you need to pass specific option to a particular stage, use the cc pass
through option -W to pass it to the appropriate step.

I am using Watcom C 10.6 and QNX 4.25 to compile/link a C program using
the small memory model, e.g.,

wpp386 -ms -ze -4s -sg -bt=QNX program.c
wlink na exename f program op offset=4K op st=16K op map=mapfile form QNX

That wlink line above is broken – you have an invalid combination of
option on it, and this will bread your executable.

(note that the default cc chooses a stack of 32K and this crashes the code).

Do you get a stack overflow error? Or do you sigsegv? If 32K is not
enough, you should probably go larger.

Or, are you trying to make _CA_PCI calls? These are restricted. You
might want to move them to a different server – there is sample code
available that does this, try searching at qdn.qnx.com for pci.

My question is does the small memory model mean that separate 64K spaces
are used for the code and data, or must both the code and data must fit in the
one 64K space ?

You are compiling -4s (which is also a bit odd – that says compile for
486 optimized code in stack calling conventions), which means that in
small model you have a 4G segment for your code and a 4G segment for
your data.

The map file indicates that the data follows directly on from the code in
memory, data starting at address 0x0000EA97 in the following part of the
map file (best viewed with a fixed width font),

Yes, constant data is part of the CODE segment of your program. This is
normal. (BTW, you shouldn’t really have to worry about any of this.)

Note that 2^16 = 64K => 0x00010000 < 0x00017210+0x00004000.

Yes, of course… you are compiling a 32bit program… in 32-bit, small
model means one segment for code and one for data – but they are 32-bit
segments.

-David

QNX Training Services
dagibbs@qnx.com