The Watcom Linker is a linkage editor (linker) that takes object and library files as input and produces executable files as output. The QNX executable file format only runs under the QNX operating system.
Most of the time you'll likely use the cc command instead of invoking the Watcom C/C++ Linker directly. See the description of the cc command in the Watcom Utilities Reference for more information. |
This chapter includes the following sections:
The following object module formats (OMF) are supported by the Watcom Linker:
The Watcom Linker can produce executable files for QNX as well as the following formats:
The Watcom Linker runs under a variety of operating systems:
This guide describes only the QNX executable file format. |
Input to the Watcom Linker is specified on the command line. The following notation is used to describe the syntax of Watcom Linker commands:
Certain characters have special meaning to the linker. When a special character must appear in a name, you can imbed the string that makes up the name inside apostrophes (for example, 'name@8'). This prevents the linker from interpreting the special character in its usual manner. The special characters are listed below:
Character | Name of Character |
---|---|
Blank | |
= | Equals |
( | Left Parenthesis |
) | Right Parenthesis |
, | Comma |
. | Period |
{ | Left Brace |
} | Right Brace |
@ | At Sign |
# | Hash Mark |
% | Percentage Symbol |
The Watcom Linker command-line format is as follows:
wlink {directive}
The directive is any of the following:
where db_list is a list of one or more debugging options, separated by commas. The debugging options are as follows:
where obj_spec is defined as
obj_file[(obj_module)] | library_file[(obj_module)]
where option is one of the following:
where seg_desc is a seg_id followed by one or more seg_attrs, and
where
When a library file is specified in a FILE directive, and obj_module is specified, the object module identified by obj_module is extracted from the library file and included in the executable file. If obj_module isn't specified (that is, only the library file is specified), all object modules in the library are included in the executable file.
Object files may contain multiple object modules. A simple way of creating such an object file is to concatenate a number of object files into a single object file. Each of the original object files is now an object module in the resulting object file. Also, some language processors may generate object files that contain multiple object modules. Specifying obj_module allows you to select a particular object module from an object file.
[0x]d{d}[k|m]
d represents a decimal digit. If 0x is specified, the string of digits represents a hexadecimal number. If k is specified, the value is multiplied by 1024. If m is specified, the value is multiplied by 1024*1024.
You can view all the directives specific to QNX executable files by simply typing the following:
wlink ? qnx
The question mark (?) is used for filename expansion by the shell. You should put a backslash (\) before it to make sure that the shell doesn't replace it with any one-character filenames in your current directory. |
If the directive information won't all fit on the command line, type the following:
wlink
The prompt WLINK> appears on the next line. You can enter as many lines of directive information as required. Press Ctrl-D to terminate the input of directive information.
Directives tell the Watcom Linker how to create your program. For example, using directives you can tell the Watcom Linker which object files are to be included in the program, which library files to search to resolve undefined references, and the name of the executable file.
The file wlink.lnk is a special linker directive file that's automatically processed by the Watcom Linker before processing any other directives.
There isn't a default version of this file for QNX. For other operating systems, you'll find the default version in:
Note that the file wlink.lnk includes the file wlsystem.lnk, which is located in the \watcom\binw directory on DOS, OS/2, Windows 95 and Windows NT-hosted systems
The files wlink.lnk and wlsystem.lnk reference the WATCOM environment variable, which must be set to the directory in which you installed your software.
It's also possible to use environment variables when specifying a directive. For example, if the LIBDIR environment variable is defined as follows,
export libdir=/test
then the linker directive
library $libdir/mylib
is equivalent to the following linker directive:
library /test/mylib
A space must precede a reference to an environment variable. |
Many directives can take a list of one or more arguments separated by commas. Instead of a comma-delimited list, you can specify a space-separated list provided the list is enclosed in braces (for example, { space-delimited list }). For example, the FILE directive can take a list of object file names as an argument:
file first,second,third,fourth
The alternate way of specifying this is as follows:
file {first second third fourth}
Where this comes in handy is in make files, where a list of dependents is usually a space-delimited list:
OBJS = first second third fourth . . . wlink file {$(objs)}
The following sections describe the Watcom Linker directives that are used to generate QNX executable files:
The ALIAS directive is used to specify an equivalent name for a symbol name. The format of the ALIAS directive (short form A) is as follows:
ALIAS alias_name=symbol_name{, alias_name=symbol_name}
Consider the following example:
alias sine=mysine
When the linker tries to resolve the reference to sine, it immediately substitutes the name mysine for sine, and begins searching for the symbol mysine.
The DEBUG directive is used to tell the Watcom Linker to generate debugging information in the executable file. This extra information in the executable file is used by the Watcom Debugger, wd. The format of the DEBUG directive (short form D) is as follows:
DEBUG [[WATCOM] db_list | CODEVIEW | DWARF]
where db_list is a list of one or more options, separated by commas. The options are:
The format for a NetWare executable file differs slightly. The format is as follows:
DEBUG [[WATCOM] db_list | CODEVIEW | DWARF]
or
DEBUG NOVELL [ONLYEXPORTS] [REFERENCED]
where db_list is a list of one or more options, separated by commas. The options are:
The Watcom Linker supports three types of debugging information, WATCOM, CODEVIEW and DWARF:
It's necessary to run the Microsoft Debugging Information Compactor, CVPACK, on the executable that it has created. See the ``CVPACK option'' for information on requesting the linker to automatically run CVPACK. Alternatively, you can run CVPACK from the command line.
For the WATCOM debugging information format, we can be selective about the types of debugging information that we include with the executable file. We can categorize the types of debugging information as follows:
The following options can be used with the DEBUG WATCOM directive to control which of the above classes of debugging information are included in the executable file:
The position of the DEBUG directive is important. The level of debugging information specified in a DEBUG directive only applies to object files and libraries that appear in subsequent FILE or LIBRARY directives. For example, if DEBUG ALL were the only DEBUG directive specified, and it was also the last linker directive, no debugging information would appear in the executable file. |
Only global and static symbol information is actually produced by the Watcom Linker; the other three classes of debugging information are extracted from object modules and copied to the executable file. Therefore, at compile time, you must instruct the compiler to generate local symbol, line numbering and typing information in the object file so that the information can be transferred to the executable file.
If you've asked the Watcom Linker to produce a particular class of debugging information and it appears that none is present, one of the following conditions may exist:
The sections that follow describe the classes of debugging information, as well as:
The DEBUG LINES option controls the processing of line numbering information. Line numbering information is the line number and address of the generated code for each line of source code in a particular module. This allows the Watcom Debugger to perform source-level debugging.
When the Watcom Linker encounters a DEBUG directive with a LINES or ALL option, line number information for each subsequent object module is placed in the executable file. This includes all object modules extracted from object files specified in subsequent FILE directives and object modules extracted from libraries specified in subsequent LIBRARY or FILE directives.
All modules for which line numbering information is requested must have been compiled with the d1 or d2 option. |
A subsequent DEBUG directive without a LINES or ALL option terminates the processing of line numbering information.
The DEBUG LOCALS option controls the processing of local symbol information. Local symbol information is the name and address of all symbols local to a particular module. This allows Watcom Debugger to locate these symbols so that you can reference local data and routines by name.
When the Watcom Linker encounters a DEBUG directive with a LOCALS or ALL option, local symbol information for each subsequent object module is placed in the executable file. This includes all object modules extracted from object files specified in subsequent FILE directives and object modules extracted from libraries specified in subsequent LIBRARY or FILE directives.
All modules for which local symbol information is requested must have been compiled with the d2 option. |
A subsequent DEBUG directive without a LOCALS or ALL option terminates the processing of local symbol information.
The DEBUG TYPES option controls the processing of typing information. Typing information includes a description of all types, structures and arrays that are defined in a module. This allows Watcom Debugger to display variables according to their type.
When the Watcom Linker encounters a DEBUG directive with a TYPES or ALL option, typing information for each subsequent object module is placed in the executable file. This includes all object modules extracted from object files specified in subsequent FILE directives and object modules extracted from libraries specified in subsequent LIBRARY or FILE directives.
All modules for which typing information is requested must have been compiled with the d2 option. |
A subsequent DEBUG directive without a TYPES or ALL option terminates the processing of typing information.
The DEBUG STATIC option controls the processing of static symbol information. Static symbol information consists of all static symbols in your program and their addresses. This allows Watcom Debugger to locate these symbols so that you can reference static data in the modules you're debugging.
When the Watcom Linker encounters a DEBUG directive with a STATIC or ALL option, static symbol information for each subsequent object module is placed in the executable file. This includes all object modules extracted from object files specified in subsequent FILE directives and object modules extracted from libraries specified in subsequent LIBRARY or FILE directives.
Static symbol information is a subset of local symbol information. The major difference is that static symbol information is always available from the object file much like global symbol information, whereas local symbol information requires source to be compiled with the d2 option. |
A subsequent DEBUG directive without a STATIC or ALL option terminates the processing of static symbol information.
The DEBUG ALL option is a quick way to request the LINES,LOCALS, TYPES and STATIC options.
Each of these options is described in its own section. A subsequent DEBUG directive without an ALL option discontinues the options that aren't specified in the list of debug options.
Global symbol information consists of all the global symbols in your program and their addresses. This allows Watcom Debugger to locate these symbols so that you can reference global data and routines by name. When the Watcom Linker encounters a DEBUG directive, global symbol information for all the global symbols appearing in your program is placed in the executable file.
The NetWare 386 operating system has a built-in debugger that can be used to debug programs. When DEBUG NOVELL is specified, the Watcom Linker generates global symbol information that can be used by the NetWare 386 debugger.
Any line numbering, local symbol, and typing information generated in the executable file won't be recognized by the NetWare 386 debugger. Also, wstrip can't be used to remove this form of global symbol information from the executable file. |
The ONLYEXPORTS option (short form ONL) restricts the generation of global symbol information to exported symbols (symbols appearing in an EXPORT directive). If DEBUG ONLYEXPORTS is specified, Watcom Debugger global symbol information is generated only for exported symbols. If DEBUG NOVELL ONLYEXPORTS is specified, NetWare 386 global symbol information is generated only for exported symbols.
Consider the following directive file:
debug all file module1 debug lines file module2, module3 debug library mylib
It specifies that the following debugging information is to be generated in the executable file:
Note that if the DEBUG directive before the LIBRARY directive isn't specified, line numbering information for all object modules extracted from the library mylib.lib is generated in the executable file, provided the object modules extracted from the library have line numbering information present.
A DEBUG directive with no option suppresses the processing of line numbering, local symbol and typing information for all subsequent object modules. |
Debugging information can use a significant amount of disk space. As shown in the above example, you can select only the class of debugging information you want and for those modules you wish to debug. In this way, the amount of debugging information in the executable file is minimized, and hence the amount of disk space used by the executable file is kept to a minimum.
As you can see from the above example, the position of the DEBUG directive is important when describing the debugging information that's to appear in the executable file.
If you want all classes of debugging information for all files to appear in the executable file you must specify DEBUG ALL before any FILE and LIBRARY directives. |
A utility called wstrip has been provided that takes as input an executable file and removes the debugging information placed in it by the Watcom Linker. Note that wstrip can't remove global symbol information generated using the DEBUG NOVELL directive.
For more information on this utility, see the Strip Utility chapter.
The DISABLE directive is used to disable the display of linker messages.
The Watcom Linker issues three classes of messages. Each message has a 4-digit number associated with it:
It's possible for a message to be issued as a warning or an error.
If a fatal error occurs, the linker terminates immediately, and no executable file is generated.
If an error occurs, the linker continues to execute so that all possible errors are issued. However, no executable file is generated, since these errors don't permit it.
If a warning occurs, the linker continues to execute. A warning message is usually informational, and doesn't prevent the creation of a proper executable file. However, you should eventually correct all warnings.
The behaviour of the linker doesn't change when a message is disabled. For example, if a message that normally terminates the linker is disabled, the linker still terminates, but the message describing the reason for the termination isn't displayed. For this reason, you should only disable warnings. |
The linker ignores the severity of the message number. For example, some messages can be displayed as errors or warnings. It isn't possible to disable the message when it's issued as a warning, and display the message when it's issued as an error. In general, don't specify the severity of the message when specifying a message number.
The format of the DISABLE directive (short form DISA) is as follows:
DISABLE msg_num{, msg_num}
where
The following DISABLE directive disables message 28 (an undefined symbol has been referenced):
disable 28
The FILE directive is used to specify the object files and library modules that the Watcom Linker is to process. The format of the FILE directive (short form F) is as follows:
FILE obj_spec{,obj_spec}
where obj_spec is defined as
obj_file[(obj_module)] | library_file[(obj_module)]
and
Consider the following example:
wlink file /math/sin, mycos
The Watcom Linker is instructed to process the following object files:
The object file mycos.o is located in the current directory, since no path was specified.
More than one FILE directive may be used. The following example is equivalent to the one above:
wlink file /math/sin file mycos
Thus, other directives may be placed between lists of object files.
The FILE directive can also specify object modules from a library file or object file. Consider the following example:
wlink file /math/math.lib(sin)
The Watcom Linker is instructed to process the object module sin contained in the library file math.lib in the directory /math.
In the following example, the Watcom Linker processes the object module sin contained in the object file math.o in the directory /math:
wlink file /math/math(sin)
In the following example, the Watcom Linker includes all object modules contained in the library file math.lib in the directory /math:
wlink file /math/math.lib
The FORMAT directive is used to specify the format of the executable file that the Watcom Linker is to generate. The format of the FORMAT directive (short form FORM) is as follows:
FORMAT form
The form argument is one of the following:
where
The formats are as follows:
No file extension is added to the executable file name.
If no FORMAT directive is specified, the executable file format is selected for each of the following host systems, based on the type of object files encountered:
Host system | Object file format | Executable file format |
---|---|---|
DOS | 16-bit | 16-bit DOS |
32-bit | 32-bit DOS/4G | |
OS/2 | 16-bit | 16-bit OS/2 |
32-bit object | 32-bit OS/2 | |
QNX | 16-bit | 16-bit QNX |
32-bit | 32-bit QNX | |
Windows NT | 16-bit | 16-bit Windows |
32-bit | 32-bit Win32 | |
Windows 95 | 16-bit | 16-bit Windows |
32-bit | 32-bit Win32 |
The LANGUAGE directive is used to specify the language in which strings in the Watcom Linker directives are specified. The format of the LANGUAGE directive (short form LANG) is as follows:
LANGUAGE JAPANESE | CHINESE | KOREAN
where
The LIBRARY directive is used to specify the library files to be searched when unresolved symbols remain after processing all specified input object files. The format of the LIBRARY directive (short form L) is as follows:
LIBRARY library_file{,library_file}
where
Consider the following example:
wlink file trig lib /math/trig, /cmplx/trig
The Watcom Linker is instructed to process the trig.o object file. If any unresolved symbol references remain after all object files have been processed, the following library files are searched:
More than one LIBRARY directive may be used. The following example is equivalent to the one above:
wlink file trig lib /math/trig lib /cmplx/trig
Thus other directives may be placed between lists of library files.
The LIB environment variable can be used to specify a list of paths to be searched for library files. It can be set using the export command, as follows:
export LIB=/graphics/lib:/utility
Consider the following LIBRARY directive and the above definition of the LIB environment variable:
library /mylibs/util, graph
If undefined symbols remain after processing all object files specified in all FILE directives, the Watcom Linker resolves these references by searching the following libraries in the specified order:
Note the following:
Phar Lap's librarian, 386|LIB, creates libraries whose dictionary is in a different format from the one used by other librarians. For this reason, linking an application using the Watcom Linker with libraries created using 386|LIB won't work. Library files created using 386|LIB must be converted to the form recognized by the Watcom Linker. This is achieved by issuing the following wlib command:
wlib newlib +pharlib.lib
The library file pharlib.lib is a library created using 386|LIB. The library file newlib.lib is created so that the Watcom Linker can now process it.
The LIBFILE directive is used to specify the object files that the Watcom Linker is to process. The format of the LIBFILE directive (short form LIBF) is as follows:
LIBFILE obj_spec{,obj_spec}
where obj_spec is defined as
obj_file | library_file
and
The differences between the LIBFILE directive and the FILE directive are as follows:
Essentially, object files that appear in LIBFILE directives are viewed as components of a library that haven't been explicitly placed in a library file.
Consider the following linker directive file:
libpath /libs libfile mystart path /objs file file1, file2
The Watcom Linker is instructed to process the following object files:
Note that the executable file has the file name file1, and not mystart.
The LIBPATH directive is used to specify the directories that are to be searched for library files appearing in subsequent LIBRARY directives, and object files appearing in subsequent LIBFILE directives. The format of the LIBPATH directive (short form LIBP) is as follows:
LIBPATH [path_name{:path_name}]
where
Consider a directive file containing the following linker directives:
file test libpath /math library trig libfile newsin
First, the Watcom Linker processes the object file test.o from the current working directory. The object file newsin.o is then processed, searching the current working directory first. If newsin.o isn't in the current working directory, the /math directory is searched. If any unresolved references remain after processing the object files, the library file trig.lib is searched. If the file trig.lib doesn't exist in the current working directory, the /math directory is searched.
It's also possible to specify a list of paths in a LIBPATH directive. Consider the following example.
libpath /newmath:/math library trig
When processing undefined references, the Watcom Linker attempts to process the library file trig.lib in the current working directory. If trig.lib doesn't exist in the current working directory, the /newmath directory is searched. If trig.lib doesn't exist in the /newmath directory, the /math directory is searched.
If the name of a library file appearing in a LIBRARY directive or the the name of an object file appearing in a LIBFILE directive contains a path specification, only the specified path is searched.
Note that
libpath path1 libpath path2 is equivalent to the following: libpath path2:path1 |
The MODTRACE directive instructs the Watcom Linker to print a list of all modules that reference the symbols defined in the specified modules. The format of the MODTRACE directive (short form MODT) is as follows:
MODTRACE module_name{,module_name}
where
The information is displayed in the map file. Consider the following example:
wlink op map file test lib math modt trig
If the module trig defines the symbols sin and cos, the Watcom Linker lists, in the map file, all modules that reference the symbols sin and cos.
The MODTRACE directive can't be used in conjunction with the VERBOSE option. |
The NAME directive is used to provide a name for the executable file generated by the Watcom Linker.. The format of the NAME directive (short form N) is as follows:
NAME exe_file
where
Consider the following example:
wlink name myprog file test, test2, test3
An executable file called myprog is generated.
Note the following:
This directive is intended for 16-bit segmented applications. By default, the Watcom Linker automatically groups logical code segments into physical segments. By default, these segments are 64K bytes in size. However, the PACKCODE option can be used to specify a maximum size for all physical segments that's smaller than 64K bytes.
The NEWSEGMENT directive provides an alternate method of grouping code segments into physical segments. By placing this directive after a sequence of FILE directives, all code segments appearing in object modules specified by the sequence of FILE directives are packed into a physical segment. Note that the size of a physical segment may vary in size. The format of the NEWSEGMENT directive (short form NEW) is as follows:
NEWSEGMENT
Consider the following example:
file file1, file2, file3 newsegment file file4 file file5
Code segments from file1, file2 and file3 are grouped into one physical segment. Code segments from file4 and file5 are grouped into another physical segment.
Note that code segments extracted from library files are grouped into physical segments as well. The size of these physical segments is determined by the PACKCODE option, and is 64k by default.
The OPTION directive is used to specify options to the Watcom Linker. The format of the OPTION directive (short form OP) is as follows:
OPTION option{,option}
Each option must be one of the following:
where
[0x]d{d}[k|m]
d represents a decimal digit. If 0x is specified, the string of digits represents a hexadecimal number. If k is specified, the value is multiplied by 1024. If m is specified, the value is multiplied by 1024*1024.
The following sections describe the Watcom Linker options for this executable format.
The ARTIFICIAL option should only be used if you're developing a Watcom C++ application. A Watcom C++ application contains many compiler-generated symbols. By default, the linker doesn't include these symbols in the map file. The ARTIFICIAL option can be used if you wish to include these compiler-generated symbols in the map file.
The format of the ARTIFICIAL option (short form ART) is as follows:
OPTION ARTIFICIAL
The CACHE and NOCACHE options can be used to control caching of object and library files in memory by the linker. When neither the CACHE nor NOCACHE option is specified, the linker only caches small libraries. Object files and large libraries aren't cached. The CACHE and NOCACHE options can be used to alter this default behaviour. The CACHE option enables the caching of object files and large library files, while the NOCACHE option disables all caching.
The format of the CACHE option (short form CAC) is as follows:
OPTION CACHE
The format of the NOCACHE option (short form NOCAC) is as follows:
OPTION NOCACHE
When linking large applications with many object files, caching object files causes extensive use of memory by the linker. On virtual memory systems such as OS/2 and Windows NT, this can cause extensive page file activity when real memory resources have been exhausted. This can degrade the performance of other tasks on your system. For this reason, the OS/2 and Windows NT-hosted versions of the linker do not perform object file caching by default. This doesn't imply that object file caching isn't beneficial. If your system has lots of real memory, or the linker is running as the only task on the machine, object file caching can certainly improve the performance of the linker.
On single-tasking environments such as DOS, the benefits of improved linker performance outweighs the memory demands associated with object file caching. For this reason, object file caching is performed by default on these systems. If the memory requirements of the linker exceed the amount of memory on your system, the NOCACHE option can be specified.
The QNX operating system is a multi-tasking real-time operating system. However, it isn't a virtual memory system. Caching object files can consume large amounts of memory. This may prevent other tasks on the system from running, a problem that may be solved by using the NOCACHE option. |
The CASEEXACT option tells the Watcom Linker to respect case when resolving references to global symbols. That is, ``ScanName'' and ``SCANNAME'' represent two different symbols. By default, the Watcom Linker is case-insensitive; ``ScanName'' and ``SCANNAME'' represent the same symbol. The format of the CASEEXACT option (short form C) is as follows:
OPTION CASEEXACT
If you have specified the CASEEXACT option in the default directive files wlink.lnk or wlsystem.lnk, it's possible to override this option by using the NOCASEEXACT option. The NOCASEEXACT option turns off case-sensitive linking. The format of the NOCASEEXACT option (short form NOCASE) is as follows:
OPTION NOCASEEXACT
This option is only meaningful when generating Microsoft Codeview debugging information. This option causes the linker to automatically run the Microsoft Debugging Information Compactor, CVPACK, on the executable that it has created. This is necessary to get the Codeview debugging information into a state where the Microsoft Codeview debugger will accept it. The linker doesn't run CVPACK by default since CVPACK isn't available for the OS/2 or QNX operating systems.
The format of the CVPACK option (short form CVP) is as follows:
OPTION CVPACK
For more information on generating Codeview debugging information in the executable, see the ``DEBUG directive.''
The DOSSEG option tells the Watcom Linker to order segments in a special way. The format of the DOSSEG option (short form D) is as follows:
OPTION DOSSEG
When the DOSSEG option is specified, segments are ordered in the following way:
A special segment belonging to class BEGDATA is defined when linking with Watcom runtime libraries. This segment is initialized with the hexadecimal byte pattern 01, and is the first segment in group DGROUP so that storing data at location 0 can be detected.
Segments belonging to class BSS contain uninitialized data. Note that this only includes uninitialized data in segments belonging to group DGROUP. Segments belonging to class STACK are used to define the size of the stack used for your application. Segments belonging to the classes BSS and STACK are last in the segment ordering so that uninitialized data need not take space in the executable file.
When using Watcom runtime libraries, it isn't necessary to specify the DOSSEG option. One of the object files in the Watcom runtime libraries contains a special record that specifies the DOSSEG option.
If no DOSSEG option is specified, segments are ordered in the order they are encountered by the Watcom Linker.
When the DOSSEG option is specified, the Watcom Linker defines two special variables:
Your program must not redefine these symbols.
The ELIMINATE option can be used to enable the elimination of dead code. Dead code elimination is a process the linker uses to remove unreferenced segments from the application. The linker only removes segments that contain code; unreferenced data segments aren't removed.
The format of the ELIMINATE option (short form EL) is as follows:
OPTION ELIMINATE
Typically, a module of C/C++ code contains a number of functions. When this module is compiled, all functions are placed in the same code segment. It's unlikely that all the functions in a module are unreferenced, so the ELIMINATE option isn't very useful.
In order to maximize the effect of the ELIMINATE option, the zm compiler option is available to tell the Watcom C/C++ compiler to place each function in its own code segment. This allows the linker to remove unreferenced functions from modules that contain many functions.
Note that if a function is referenced by data, as in a jump table, the linker won't be able to eliminate the code for the function even if the data that references it's unreferenced.
The Watcom FORTRAN 77 compiler always places each function and subroutine in its own code segment, even if they're contained in the same module. Therefore when linking with the ELIMINATE option the linker is able to eliminate code on a function/subroutine basis.
The HEAPSIZE option specifies the size of the heap required by the application. The format of the HEAPSIZE option (short form H) is as follows:
OPTION HEAPSIZE=n
where
[0x]d{d}[k|m]
d represents a decimal digit. If 0x is specified, the string of digits represents a hexadecimal number. If k is specified, the value is multiplied by 1024. If m is specified, the value is multiplied by 1024*1024.
n specifies the size of the heap. The default heap size is 0 bytes. The maximum value of n is 65536 (64K) for 16-bit applications, and 4G for 32-bit applications, which is the maximum size of a physical segment. Actually, for a particular application, the maximum value of n is 64K or 4G less the size of group DGROUP.
The LINEARRELOCS option instructs the linker to generate offset fixups in addition to the normal segment fixups. The offset fixups allow the system to move pieces of code and data that were loaded at a particular offset within a segment to another offset within the same segment.
The format of the LINEARRELOCS option (short form LI) is as follows:
OPTION LINEARRELOCS
Use this option only with Neutrino. |
The LONGLIVED option specifies that the application being linked will reside in memory, or be active, for a long period of time (for example, background tasks). The memory manager, knowing an application is LONGLIVED, allocates memory for the application so as to reduce fragmentation.
The format of the LONGLIVED option (short form LO) is as follows:
OPTION LONGLIVED
The MANGLEDNAMES option should only be used if you're developing a Watcom C++ application. Due to the nature of C++, the Watcom C++ compiler generates mangled names for symbols. A mangled name for a symbol includes the following:
This information is stored in a cryptic form with the symbol. When the linker encounters a mangled name in an object file, it formats the above information and produces this name in the map file.
If you would like the linker to produce the mangled name as it appears in the object file, specify the MANGLEDNAMES option.
The format of the MANGLEDNAMES option (short form MANG) is as follows:
OPTION MANGLEDNAMES
The MAP option controls the generation of a map file. The format of the MAP option (short form M) is as follows:
OPTION MAP[=map_file]
By default, no map file is generated. Specifying this option causes the Watcom Linker to generate a map file. The map file is simply a memory map of your program. That is, it specifies the relative location of all global symbols in your program. The map file also contains the size of your program.
If no file name is specified, the map file has a default file extension of .map, and the same file name as the executable file. Note that the map file is created in the current directory even if the executable file name specified in the NAME directive contains a path specification.
Alternatively, a file name can be specified. The following directive instructs the Watcom Linker to generate a map file and call it myprog.map, regardless of the name of the executable file:
option map=myprog
You can also specify a path and/or file extension when using the MAP= form of the MAP option.
The MAXERRORS option can be used to set a limit on the number of error messages generated by the linker. Note that this doesn't include warning messages. When this limit is reached, the linker issues a fatal error and terminate.
The format of the MAXERRORS option (short form MAXE) is as follows:
OPTION MAXERRORS=n
The NAMELEN option tells the Watcom Linker that all symbols must be uniquely identified in the number of characters specified or less. If any symbol fails to satisfy this condition, a warning message is issued. The warning message states that a symbol has been defined more than once.
The format of the NAMELEN option (short form NAMEL) is as follows:
OPTION NAMELEN=n
where
[0x]d{d}[k|m]
d represents a decimal digit. If 0x is specified, the string of digits represents a hexadecimal number. If k is specified, the value is multiplied by 1024. If m is specified, the value is multiplied by 1024*1024.
Some computer systems, for example, require that all global symbols be uniquely identified in 8 characters. By specifying an appropriate value for the NAMELEN option, you can ease the task of porting your application to other computer systems.
Special object module records that specify default libraries are placed in object files generated by Watcom compilers. These libraries reflect the memory and floating-point model that a source file was compiled for and are automatically searched by the Watcom Linker when unresolved symbols are detected. These libraries can exist in the current directory, in one of the paths specified in LIBPATH directives, or in one of the paths specified in the LIB environment variable.
Note that all library files that appear in a LIBRARY directive are searched before default libraries. The NODEFAULTLIBS option instructs the Watcom Linker to ignore default libraries. That is, only libraries appearing in a LIBRARY directive are searched.
The format of the NODefaultlibs option (short form NOD) is as follows:
OPTION NODEFAULTLIBS
The NORELOCS option specifies that no relocation information is to be written to the executable file. When the NORELOCS option is specified, the executable file can only be run in protected mode and won't run in real mode. In real mode, the relocation information is required; in protected mode, the relocation information isn't required unless your application is running at privilege level 0.
The format of the NORELOCS option (short form NOR) is as follows:
OPTION NORELOCS
The OFFSET option specifies the offset in the program's segment in which the first byte of code or data is loaded. This option applies to 32-bit QNX applications only. The format of the OFFSET option (short form OFF) is as follows:
OPTION OFFSET=n
where
[0x]d{d}[k|m]
d represents a decimal digit. If 0x is specified, the string of digits represents a hexadecimal number. If k is specified, the value is multiplied by 1024. If m is specified, the value is multiplied by 1024*1024.
n specifies the offset (in bytes) at which the program is loaded, and must be a multiple of 4K. The Watcom Linker rounds the value up to a multiple of 4K if it isn't already a multiple of 4K.
It's possible to detect NULL pointer references by linking the
program at an offset that's a multiple of 4K (usually an offset of 4K is
sufficient).
option offset=4k When the program is loaded, the pages skipped by the OFFSET option aren't mapped. Any reference to an unmapped area (such as a NULL pointer) causes a page fault, preventing the NULL reference from corrupting the program. |
The OSNAME option can be used to set the name of the target operating system of the executable file generated by the linker. The format of the OSNAME option (short form OSN) is as follows:
OPTION OSNAME='string'
where
The information specified by the OSNAME option is displayed in the creating a ? executable message. This is the last line of output produced by the linker, provided the QUIET option isn't specified. Consider the following example:
option osname='SuperOS'
The last line of output produced by the linker is as follows:
creating a SuperOS executable
This option is intended for 16-bit segmented applications. By default, the Watcom Linker automatically groups logical code segments into physical segments. The PACKCODE option is used to specify the size of the physical segment. The format of the PACKCODE option (short form PACKC) is as follows:
OPTION PACKCODE=n
where
[0x]d{d}[k|m]
d represents a decimal digit. If 0x is specified, the string of digits represents a hexadecimal number. If k is specified, the value is multiplied by 1024. If m is specified, the value is multiplied by 1024*1024.
n specifies the size of the physical segments into which code segments are packed. The default value of n is 64K for 16-bit applications. Note that this is also the maximum size of a physical segment. To suppress automatic grouping of code segments, specify a value of 0 for n.
Note the following:
This option is intended for 16-bit segmented applications. By default, the Watcom Linker automatically groups logical far data segments into physical segments. The PACKDATA option is used to specify the size of the physical segment. The format of the PACKDATA option (short form PACKD) is as follows:
OPTION PACKDATA=n
where
[0x]d{d}[k|m]
d represents a decimal digit. If 0x is specified, the string of digits represents a hexadecimal number. If k is specified, the value is multiplied by 1024. If m is specified, the value is multiplied by 1024*1024.
n specifies the size of the physical segments into which far data segments are packed. The default value of n is 64K for 16-bit applications. Note that this is also the maximum size of a physical segment. To suppress automatic grouping of far data segments, specify a value of 0 for n.
Note the following:
The PRIVILEGE option specifies the privilege level (0, 1, 2 or 3) at which the application runs. The format of the PRIVILEGE option (short form PRIV) is as follows:
OPTION PRIVILEGE=n
where
[0x]d{d}[k|m]
d represents a decimal digit. If 0x is specified, the string of digits represents a hexadecimal number. If k is specified, the value is multiplied by 1024. If m is specified, the value is multiplied by 1024*1024.
The default privilege level is 0.
The QUIET option tells the Watcom Linker to suppress all informational messages. Only warning, error and fatal messages are issued. By default, the Watcom Linker issues informational messages. The format of the QUIET option (short form Q) is as follows:
OPTION QUIET
The REDEFSOK option tells the Watcom Linker to ignore redefined symbols, and to generate an executable file anyway. By default, warning messages are displayed, and an executable file is generated if redefined symbols are present.
The format of the REDEFSOK option (short form RED) is as follows:
OPTION REDEFSOK
The NOREDEFSOK option tells the Watcom Linker to treat redefined symbols as an error, and not to generate an executable file. By default, warning messages are displayed, and an executable file is generated if redefined symbols are present.
The format of the NOREDEFSOK option (short form NORED) is as follows:
OPTION NOREDEFSOK
The RESOURCE option specifies the contents of the resource record in QNX executable files. The format of the RESOURCE option (short form RES) is as follows:
OPTION RESOURCE 'string' | =resource_file
where
If a resource file is specified, the contents of the resource file are included in the resource record.
The resource record contains, for example, help information, and is displayed when the following command is executed.
use <executable>
QNX also provides the usemsg utility to manipulate the resource record of an executable file. Its use is recommended. This utility is described in the QNX Utilities Reference manual.
The STACK option can be used to increase the size of the stack. The format of the STACK option (short form ST) is as follows:
OPTION STACK=n
where
[0x]d{d}[k|m]
d represents a decimal digit. If 0x is specified, the string of digits represents a hexadecimal number. If k is specified, the value is multiplied by 1024. If m is specified, the value is multiplied by 1024*1024.
The default stack size varies for both 16-bit and protected-mode 32-bit applications depending on the executable format. You can determine the default stack size by looking at the map file that can be generated when an application is linked (OPTION MAP). During execution of your program, you may get an error message indicating your stack has overflowed. If you encounter such an error, you must link your application again, this time specifying a larger stack size using the STACK option. For example,
option stack=8192
The STATICS option should only be used if you're developing a Watcom C or C++ application. The Watcom C and C++ compilers produce definitions for static symbols in the object file. By default, these static symbols don't appear in the map file. If you want static symbols to be displayed in the map file, use the STATICS option.
The format of the STATICS option (short form STAT) is as follows:
OPTION STATICS
The SYMFILE option provides a method for specifying an alternate file for debugging information. The format of the SYMFILE option (short form SYMF) is as follows:
OPTION SYMFILE[=symbol_file]
where
By default, no symbol file is generated; debugging information is appended at the end of the executable file. Specifying this option causes the Watcom Linker to generate a symbol file, which contains the debugging information generated by the Watcom Linker when the DEBUG directive is used. The symbol file can then be used by Watcom Debugger, wd. If no debugging information is requested, no symbol file is created, regardless of the presence of the SYMFILE option.
If no file name is specified, the symbol file has a default file extension of .sym and the same path and file name as the executable file. Note that the symbol file is placed in the same directory as the executable file.
Alternatively, a file name can be specified. The following directive instructs the Watcom Linker to generate a symbol file and call it myprog.sym, regardless of the name of the executable file.
option symf=myprog
You can also specify a path and/or file extension when using the SYMFILE= form of the SYMFILE option.
Note the following:
The UNDEFSOK option tells the Watcom Linker to generate an executable file even if undefined symbols are present. By default, no executable file is generated if undefined symbols are present.
The format of the UNDEFSOK option (short form U) is as follows:
OPTION UNDEFSOK
The VERBOSE option controls the amount of information produced by the Watcom Linker in the map file. The format of the VERBOSE option (short form V) is as follows:
OPTION VERBOSE
If the VERBOSE option is specified, the Watcom Linker lists, for each object file, all segments it defines and their sizes. By default, this information isn't produced in the map file.
The VERBOSE option can't be used in conjunction with the MODTRACE or SYMTRACE directives. |
The PATH directive is used to specify the directories that are to be searched for object files appearing in subsequent FILE directives. When the PATH directive is specified, the current directory is no longer searched unless it appears in the PATH directive. The format of the PATH directive (short form P) is as follows:
PATH path_name{:path_name}
where
Consider a directive file containing the following linker directives:
path /math file sin path /stats file mean, variance
It instructs the Watcom Linker to process the following object files:
It's also possible to specify a list of paths in a PATH directive. Consider the following example:
path /math:/stats file sin
First, the Watcom Linker attempts to load the file /math/sin.o. If unsuccessful, the Watcom Linker attempts to load the file /stats/sin.o.
It's possible to override the path specified in a PATH directive by preceding the object file name in a FILE directive with an absolute path specification. An absolute path specification is one that begins with the ``/'' character. For example,
path /math file sin path /stats file mean, /mydir/variance
The above directive file instructs the Watcom Linker to process the following object files:
The REFERENCE directive is used to explicitly reference a symbol that isn't referenced by any object file processed by the linker. If any symbol appearing in a REFERENCE directive isn't resolved by the linker, an error message is issued for that symbol specifying that the symbol is undefined.
The REFERENCE directive can be used to force object files from libraries to be linked with the application. Also note that a symbol appearing in a REFERENCE directive isn't eliminated by dead code elimination. For more information on dead code elimination, see the section ``ELIMINATE option.''
The format of the REFERENCE directive (short form REF) is as follows:
REFERENCE symbol_name{, symbol_name}
Consider the following example:
reference domino
The symbol domino is searched for. The object module that defines this symbol is linked with the application. Note that the linker also attempts to resolve symbols referenced by this module.
The SEGMENT directive is used to describe the attributes of code and data segments. The format of the SEGMENT directive (short form SEG) is as follows:
SEGMENT seg_desc{,seg_desc}
where each seg_desc consists of a segment ID,
'seg_name' | CLASS 'class_name' | TYPE [CODE | DATA]
followed by one or more segment attributes:
EXECUTEONLY | EXECUTEREAD | READONLY | READWRITE
where
The SORT directive is used to sort the symbols in the ``Memory Map'' section of the map file. By default, symbols are listed on a per module basis in the order the modules were encountered by the linker. That is, a module header is displayed followed by the symbols defined by the module.
The format of the SORT directive (short form SO) is as follows:
SORT [GLOBAL] [ALPHABETICAL]
If the SORT directive is specified without any options, as in the following example, the module headers are displayed each followed by the list of symbols it defines, sorted by address.
sort
If only the GLOBAL sort option (short form GL) is specified, as in the following example, the module headers won't be displayed, and all symbols are sorted by address.
sort global
If only the ALPHABETICAL sort option (short form ALP) is specified, as in the following example, the module headers are displayed, each followed by the list of symbols it defines sorted alphabetically.
sort alphabetical
If both the GLOBAL and ALPHABETICAL sort options are specified, as in the following example, the module headers won't be displayed, and all symbols are sorted alphabetically.
sort global alphabetical
If you're linking a Watcom C++ application, mangled names are sorted by using the base name. The base name is the name of the symbol as it appeared in the source file. See the section ``MANGLEDNAMES option'' for more information on mangled names.
The SYMTRACE directive instructs the Watcom Linker to print a list of all modules that reference the specified symbols. The format of the SYMTRACE directive (short form SYMT) is as follows:
SYMTRACE symbol_name{,symbol_name}
where
The information is displayed in the map file. Consider the following example:
wlink system op map file test lib math symt sin, cos
The Watcom Linker lists, in the map file, all modules that reference the symbols sin and cos.
The SYMTRACE directive can't be used in conjunction with the VERBOSE option. |
There are three forms of the SYSTEM directive (short form SYS):
The first form of the SYSTEM directive is called a system definition directive. It allows you to associate a set of linker directives with a specified name called the system name. This set of linker directives is called a system definition block. The format of a system definition directive is as follows:
SYSTEM BEGIN system_name {directive} END
where
A system definition directive can't be specified within another system definition directive.
The second form of the SYSTEM directive is called a system deletion directive. It allows you to remove the association of a set of linker directives with a system name. The format of a system deletion directive is as follows:
SYSTEM DELETE system_name
where
The third form of the SYSTEM directive is as follows:
SYSTEM system_name
where
When this form of the SYSTEM directive is encountered, all directives specified in the system definition block identified by system_name are processed.
Let's consider an example that demonstrates the use of the SYSTEM directive. The following linker directives define a system called statistics:
system begin statistics form qnx libpath /libs library stats, graphics option stack=8k end
They specify that a statistics application is to be created by using the libraries stats.lib and graphics.lib. These library files are located in the directory /libs. The application requires a stack size of 8K, and a QNX executable is generated.
Suppose the linker directives in the above example are contained in the file stats.lnk. If we wish to create a statistics application, we can issue the following command:
wlink @stats system statistics file myappl
As demonstrated by the above example, the SYSTEM directive can be used to localize the common attributes that describe a class of applications.
The system deletion directive can be used to redefine a previously defined system. Consider the following example:
system begin at_dos libpath %WATCOM%\lib286 libpath %WATCOM%\lib286\dos format dos ^ end system begin n98_dos sys at_dos ^ libpath %WATCOM%\lib286\dos\n98 end system begin dos sys at_dos ^ end
If you wish to redefine the definition of the dos system, you can specify the following set of directives:
system delete dos system begin dos sys n98_dos ^ end
This effectively redefines a dos system to be equivalent to a n98_dos system (NEC PC-9800 DOS), rather than the previously defined at_dos system (AT-compatible DOS).
There are two special system names. When the linker has processed all object files and the executable file format hasn't been determined, and a system definition block hasn't been processed, the directives specified in the 286 or 386 system definition block are processed. The 386 system definition block is processed if a 32-bit object file has been processed. Furthermore, only a restricted set of linker directives is allowed in a 286 and 386 system definition block. They are as follows:
The # directive is used to mark the start of a comment. All text from the # character to the end of the line is considered a comment. The format of the # directive is as follows:
# comment
where
The following directive file illustrates the use of comments:
file main, trigtest # Use my own version of "sin" instead of the # library version. file mysin library /math/trig
The @ directive instructs the Watcom Linker to process directives from an alternate source. The format of the @ directive is as follows:
@directive_var
or
@directive_file
where
The environment variable approach to specifying linker directives allows you to specify commonly used directives without having to specify them each time you invoke the Watcom Linker. If the environment variable WLINK is set as in the following example,
export WLINK=debug all option map, verbose library math wlink @WLINK
each time the Watcom Linker is invoked, full debugging information is generated, a verbose map file is created, and the library file math.lib is searched for undefined references.
A linker directive file is useful, for example, when the linker input consists of a large number of object files, and you don't want to type their names on the command line each time you link your program. Note that a linker directive file can also include other linker directive files.
Let the file memos.lnk be a directive file containing the following lines:
system qnx386 name memos file memos file actions file read file msg file prompt file memmgr library /termio/screen library /termio/keyboard
Consider the following example:
wlink @memos
The Watcom Linker is instructed to process the contents of the directive file memos.lnk. The executable image file is called memos.qnx. The following object files are loaded from the current directory:
If any unresolved symbol references remain after all object files have been processed, the library files screen.lib and keyboard.lib in the directory /termio are searched (in the order listed).
Note the following:
system qnx386 name memos file memos,actions,read,msg,prompt,memmgr library /termio/screen,/termio/keyboard
However, if you want to selectively specify what debugging information should be included, the first style of directive file is easier to use. This is illustrated in the following sample directive file:
system qnx386 name memos debug lines file memos debug all file actions debug lines file read file msg file prompt file memmgr debug library /termio/screen library /termio/keyboard
system qnx386 file memos, actions, read, msg, prompt, memmgr file @dbgfiles library /termio/screen library /termio/keyboard
The directive file dbgfiles.lnk contains, for example, those object files that are used for debugging purposes.
The Watcom Linker uses all available memory when linking an application. It's possible for the size of the image being linked to exceed the amount of memory available in your machine, particularly if the image file is to contain debugging information. For this reason, a temporary disk file is used when all available memory is used by the Watcom Linker.
Normally, the temporary file is created in the current working directory. However, by defining the TMPDIR environment variable to be a directory, you can tell the Watcom Linker where to create the temporary file. This can be particularly useful if you have a RAM disk. Consider the following definition of the TMPDIR environment variable:
export TMPDIR=/tmp
The Watcom Linker creates the temporary file in the directory /tmp.