- IAR Embedded Workbench for RL78 5.20
- IAR C/C++ Development
- Linking your application
- Checking module consistency
Checking module consistency
This section introduces the concept of runtime model attributes, a mechanism used by the tools provided by IAR to ensure that modules that are linked into an application are compatible, in other words, are built using compatible settings. The tools use a set of predefined runtime model attributes. In addition to these, you can define your own that you can use to ensure that incompatible modules are not used together.
Note
In addition to the predefined attributes, compatibility is also checked against the RL78 ABI runtime attributes. These attributes deal mainly with object code compatibility, etc. They reflect compilation settings and are not user-configurable.
For example, in the compiler, it is possible to specify the size of the double floating-point type. If you write a routine that only works for 64-bit doubles, it is possible to check that the routine is not used in an application built using 32-bit doubles.
Runtime model attributes
A runtime attribute is a pair constituted of a named key and its corresponding value. In general, two modules can only be linked together if they have the same value for each key that they both define.
There is one exception—if the value of an attribute is *, then that attribute matches any value. The reason for this is that you can specify this in a module to show that you have considered a consistency property, and this ensures that the module does not rely on that property.
Note
For IAR predefined runtime model attributes, the linker checks them in several ways.
Example
In this table, the object files could (but do not have to) define the two runtime attributes color and taste:
Object file | Color | Taste |
|---|---|---|
|
| not defined |
|
| not defined |
|
|
|
|
|
|
|
|
|
In this case, file1 cannot be linked with any of the other files, because the runtime attribute color does not match. Also, file4 and file5 cannot be linked together, because the taste runtime attribute does not match.
On the other hand, file2 and file3 can be linked with each other, and with either file4 or file5, but not with both.
Using runtime model attributes
To ensure module consistency with other object files, use the #pragmartmodel directive to specify runtime model attributes in your C/C++ source code. For example, if you have a UART that can run in two modes, you can specify a runtime model attribute, for example uart. For each mode, specify a value, for example mode1 and mode2. Declare this in each module that assumes that the UART is in a particular mode. This is what it could look like in one of the modules:
#pragma rtmodel="uart", "mode1"Alternatively, you can also use theRTMODEL assembler directive to specify runtime model attributes in your assembler source code. For example:
rtmodel "uart", "mode1"Note
Key names that start with two underscores are reserved by the compiler. For more information about specifying runtime model attributes, see rtmodel and the reference documentation for the assembler directive RTMODEL in Module control directives .
At link time, the linker checks module consistency by ensuring that modules with conflicting runtime attributes will not be used together. If conflicts are detected, an error is issued.