Справочник Пользователя для Microchip Technology SW006021-2N
MPLAB
®
XC8 C Compiler User’s Guide
DS52053B-page 238
2012 Microchip Technology Inc.
All library source code is written in C, and the p-code library files that contain these
library routines are actually passed to the code generator, not the linker, but both these
applications work in the way described above in resolving library symbols.
library routines are actually passed to the code generator, not the linker, but both these
applications work in the way described above in resolving library symbols.
You cannot replace a C library function with an equivalent written in assembly code
using the above method. If this is required, you will need to use the librarian to edit or
create a new library file.
using the above method. If this is required, you will need to use the librarian to edit or
create a new library file.
5.15.5
Signature Checking
The compiler automatically produces signatures for all functions. A signature is a 16-bit
value computed from a combination of the function’s return data type, the number of its
parameters and other information affecting the calling sequence for the function. This
signature is generated and placed the object code whenever a function is referenced
or defined.
value computed from a combination of the function’s return data type, the number of its
parameters and other information affecting the calling sequence for the function. This
signature is generated and placed the object code whenever a function is referenced
or defined.
At link time, the linker will report any mismatch of signatures, which will indicate a dis-
crepancy between how the function is defined. MPLAB XC8 is only likely to issue a mis-
match error from the linker when the routine is either a precompiled object file or an
assembly routine. Other function mismatches are reported by the code generator.
crepancy between how the function is defined. MPLAB XC8 is only likely to issue a mis-
match error from the linker when the routine is either a precompiled object file or an
assembly routine. Other function mismatches are reported by the code generator.
It is sometimes necessary to write assembly language routines which are called from
C using an extern declaration. Such assembly language functions should include a
signature which is compatible with the C prototype used to call them. The simplest
method of determining the correct signature for a function is to write a dummy C func-
tion with the same prototype and check the assembly list file using the --ASMLIST
option (see Section 4.8.16 “--ADDRQUAL: Set Compiler Response to Memory
Qualifiers”).
C using an extern declaration. Such assembly language functions should include a
signature which is compatible with the C prototype used to call them. The simplest
method of determining the correct signature for a function is to write a dummy C func-
tion with the same prototype and check the assembly list file using the --ASMLIST
option (see Section 4.8.16 “--ADDRQUAL: Set Compiler Response to Memory
Qualifiers”).
For example, suppose you have an assembly language routine called _widget which
takes a char argument and returns a char. The prototype used to call this function
from C would be:
takes a char argument and returns a char. The prototype used to call this function
from C would be:
extern char widget(char);
Where a call to _widget is made in the C code, the signature for a function with one
char
char
argument and a char return value would be generated. In order to match the
correct signature, the source code for widget needs to contain an assembler SIGNAT
directive which defines the same signature value. To determine the correct value, you
would write the following code into a dummy file:
directive which defines the same signature value. To determine the correct value, you
would write the following code into a dummy file:
char widget(char arg1)
{
}
The resultant assembler code seen in the assembly list file includes the following line:
SIGNAT _widget,4217
The SIGNAT directive tells the assembler to include a record in the .obj file which
associates the signature value 4217 with symbol _widget. The value 4217 is the
correct signature for a function with one char argument and a char return value.
associates the signature value 4217 with symbol _widget. The value 4217 is the
correct signature for a function with one char argument and a char return value.
If this directive is copied into the assembly source file which contains the _widget
code, it will associate the correct signature with the function and the linker will be able
to check for correct argument passing.
code, it will associate the correct signature with the function and the linker will be able
to check for correct argument passing.
If a C source file contains the declaration:
extern char widget(long);
then a different signature will be generated and the linker will report a signature
mis-match which will alert you to the possible existence of incompatible calling
conventions.
mis-match which will alert you to the possible existence of incompatible calling
conventions.