Microchip Technology XC8 Standard Compiler (Workstation) SW006021-1 SW006021-1 ユーザーズマニュアル

製品コード
SW006021-1
ページ / 518
MPLAB
®
 XC8 C Compiler User’s Guide
DS52053B-page 230
 2012 Microchip Technology Inc.
Previously all uninitialized variables were placed in the bss0 section. Now the code 
generator first checks that there will actually be enough room in bank 0 memory before 
doing so. If not, it chooses the bss1 section that will ultimately be linked into bank 1 
memory. The code generator keeps track of any object allocated to RAM so it can main-
tain the amount of free memory in each RAM bank. For these variables, the linker allo-
cates the sections to memory, but it is the code generator that decides which section 
will be used by each variable. Thus, both applications play a part in the memory allo-
cation process.
In this example, we also consider const variables which are stored in flash, not RAM. 
Each byte of data is encapsulated in a RETLW instruction that return the byte in the W 
register. Code is needed to access each byte of a variable or array. One way of doing 
this is a “computed goto” which involves loading the W register with an offset into the 
block of data and adding this to the PC.(The Microchip application note AN556 has 
examples of how this can be done for several devices.) A computed goto requires that 
the destination address (the result of adding W and PC) must not cross over a 256 word 
boundary (i.e., the addresses 100h, 200h, 300h, etc.). This requirement can be met 
using sections and a class.
In this example a new class, called CONST, is created and defined as follows
-ACONST=0-0ffhx16
which is to say that CONST is a container 100h long, but there are 16 of them one after 
the other in memory, so 0-ffh is one container, 100-1ffh is another, etc. We have the 
compiler place all the RETLW instructions and the computed goto code into the const 
section, which are linked into this class. The section can be located in any of the 16 
containers, but must fit entirely within one.
In this example, the compiler only allows one block of const data. It could be made to 
allow many by having each block of const data in a unique numbered section as we 
did for the text sections (e.g., const1, const2, etc.). Thus each sections could remain 
independent and be allocated to any memory bin of the CONST class.
5.15.1.6
EXPLAINING COMMON LINKER ERRORS AND PROBLEMS
We can also use our knowledge to help explain some common linker problems and 
error messages.
5.15.1.6.1
Not Finding Space
A common linker error is, “can’t find x words for psect ’abc’ in class ’XYZ’,” which we 
can now think of as, “can’t find 3 cubic feet for the boxes ’paris’ in container ’FRANCE’.”
The most obvious reason for this error is that the containers have been steadily filling 
and have finally run out of free space, i.e., the total amount of code or data you need 
to store exceeds the amount of memory on the device. 
Another reason is that a box is larger than the container(s) in which it has to be placed. 
If this is the case, the section will never fit, even if the entire memory space is empty. 
This situation might occur when defining a very large C function, RAM or const array 
resulting in an abnormally large section. Other possible sources include large switch 
statements or even a switch with too many case labels.