The Subrecord Format is: 1 byte 1 or 2 bytes 1 or 2 bytes ÚÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ ³ A8 ³ Weak extern ³ Default resolution ³ ³ ³ EXTDEF Index ³ EXTDEF Index ³ ÀÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
The Weak EXTDEF Index field is the 1 or 2 byte index to the EXTDEF of the extern which is weak.
The Default Resolution EXTDEF Index is the 1 or 2 byte index to the EXTDEF
of the extern that will be used to resolve the extern if no "stronger" link
is found to resolve it.
Notes:
There are two ways to cancel the "weakness" of a weak extern: both result in the extern becoming a "strong" extern (the same as an EXTDEF). They are:
o
If a weak extern becomes strong, them it must be resolved with a matching PUBDEF, just like a regular EXTDEF. If a weak extern has not become strong by the end of the linking process, then the default resolution is used.
If two weak externs for the same symbol in different modules have differing default resolutions, the linker will emit a warning.
Weak externs do not query libraries for resolution: if an extern is still weak when libraries are searched, it stays weak and gets the default resolution. However, if a library module is linked in for other reasons (eg. to resolve a strong extern) and there are EXTDEF's for symbols that were weak, the symbols become strong.
For example, suppose there is a weak extern for "foo" with a default resolution name of "bar". If there is a PUBDEF for "foo" in some library nodule which would not otherwise be linked in, then the library module is not linked in, and any references to "foo" are resolved to "bar". However, if a library module is linked in for other reasons, for example to resolve references to a strong extern named "bletch", then "foo" will be resolved by the PUBDEF from the library, not to the default resolution "bar".
WKEXT's are best understood by explaining why they were added in the first place. The run time library for a programming language is generally very large and has a significant amount of code that need not be linked in for the smaller programs. Much of the code is not called directly by the user, but was called indirectly from other routines in the library, so it is linked in to resolve the external references.
For instance, the floating point library is linked in even when the user program does not require floating point, because the PRINT library routine has calls to the floating point library to support printing floating point numbers.
The solution is to make the function calls between the library routines into weak externals, with the default resolution to dummy symbols. If the user doesn't require floating point then the compiler will not generate a strong external for floating point routines. The weak extern's in the PRINT library routine that call floating point will be resolved to dummy symbols (or stub routines) and the unnecessary floating point library routines are not included in the executable module. This requires that the compiler know a lot about the run time library routines to sort this out correctly, but it results in a much smaller executable module.