5.15.5 Signature Checking
A signature is a 16-bit value computed from a combination of the function’s return type, the number of its parameters and other information affecting how the function is called. This signature is automatically generated and placed the output whenever a C function is referenced or defined. The linker will report any mismatch of signatures, which will indicate a discrepancy between how the function is defined and how it is called.
If it is necessary to write an assembly language routine, it is desirable
to include a signature with that routine that is compatible with its equivalent C
prototype. The simplest method of determining the correct signature for a function is to
write a dummy C function with the same prototype and check the assembly list file using the
-Wa,-a
option.
For example, suppose you have an assembly language routine called
_widget
whose equivalent C prototype takes a char
argument and returns a char
. To find the correct signature for such a
function, write a test function, such as the following, and check the assembly list file
after building this function as part of a test program.
char myTestFunction(char arg1) {
}
The resultant assembler code seen in the assembly list file includes the following line, indicating that the signature value is 4217:
SIGNAT _myTestFunction,4217
Include a similar SIGNAT
directive in your assembly
source code that contains _widget
.
If you mistakenly declare this assembly routine in a C source file as:
extern char widget(long);
then the signature generated by this declaration will differ to that specified in your assembly routine and trigger an error.