Some Questions with Watcom compiler.

Hello, everyone.

Here are my questions with Watcom compiler( Watcom 10.6 ):

  1. What’s the meaning of the argument “-g”? In one of my object given by BroadCom Co., “-g” is used in some important target files, such as startup.o, mac.o, and so on. But they specify “-g1” to other files, such as snmp.o, print.o, and so on.
    Is it correct that the group ( consist of startup.o, mac.o, and so on )would be loaded firstly when the program performed?

  2. At the end of compiling, i was told that “offset=12K, st=32K”, would you tell me the meaning of it?
    When i compiled, i can specify the size of the stack by “-N”. But would compiler calculate the total size of the stack without “-N”?
    My main process has three child threads, and the size of stack of each of them is 4096, 4 * 4096, 8 * 4096, respectively. I want to specify 16KB as the size of the main process, is it OK?

    Thanks in advance.

  1. -g tells the compiler to include debugging information in the object file and later if given when linking into the executable. The number following -g specifies the level of information to be included. This option has no effect on the ordering of object file.

Object files (startup.o, mac.o …) are all linked into one executable. Location of these object file within the executable are specify by the order in which they where given to the linker. However when the program starts all of the executable (hence all object files within) are loaded at once.

  1. st=32k which is the default stack size. As you were told in some other post I beleive, stack size is NEVER calculated. 32k it’s just the default value if you don’t specify -N yourself. As for offset I don’t really know what it means (and I wouldn’t dare play with it). If you want to specify 16K for main thread yes you can do it with -N16K. Are you so memory limited as to worry about saving 16K?

Offset is used to change the starting virtual address of the executable code. This is used primarily when dealing with shared libraries. Assuming I remember this correctly, the explaination is as follows.

QNX4 does not have generalised shared library support. In particular, when using a shared library, the addresses of the functions are known at link time, not runtime as a normal shared library would use.

So QNX4 achieves something like shared lib support by a few “tricks”. When a “shared” lib is created, it is given a particular address range for it’s location. Let’s say that the photon shared library is given address range from 1M-1.8M in virtual address - this is close to true, but I don’t want to go figure it out right now. When you link against this library, the linker knows that this address range is reserved and passes an offset=1828k to make sure your code starts beyond this.

You can actually use this trick to create your own “shared” libs. You need to figure out which address ranges are already reserved (in particular the socket and photon libs) and then use the mkshlib command (which is part of a archive somewhere on quics - or it used to be). Then when you link your programs, you will see that the offset is now larger to make room for all possible shared libs (photon, socket, yours).

The offset is harmless if you are not doing this as it is just the starting virtual address you are fooling with. On the other hand, if you are not interesting in creating your own “shared” libs in QNX4, then just ignore it and let cc figure it out for you.


Thanks for your answers.

But the total size of all of my child threads have reached 52KB(that is, 4096+44096+84096=52KB).
The child thread would get it’s own stack from the stack of it’s parent process( or thread ). Then my question is, if i did not specify the stack size of the main process, 32K would be the default value, but the total size of all the main process’s childs is more than 50K, what would happen? The stack of the main process would grow up automaticlly?

In my program, the child threads get their stacks by defining some strings( like ‘char MacStack[ 4096 ]’ ) and specifying the strings to the threads respectively as the stacks.Is it OK? Are there any other methods?

An Intel Pentium 3 processor is in my machine. But the Watcom Compiler would compile my object files in 386 mode. How can i use the Pentium mode? And is it useful to increase the performance of my program?


I think Mario mentioned this in a different forum thread, but we both strongly recommend you do not try to use threading (via vfork() or something I presume) in QNX4. Most of the clib is not thread safe and you are just waiting for a problem to happen.

To answer your question, where do you declare the threads stack? If it is a global, then the thread stack doesn’t use part of your processes stack. If you declare the ‘char MacStack[4096]’ in your main (or other) functions, then they are certainly on your main stack and it has to be big enough.

Trying adding ‘-5 and -Oneatx’ to your compile options and that will probably be about as good as it gets for optimization.