Microchip Technology XC8 Standard Compiler (Workstation) SW006021-1 SW006021-1 User Manual

Product codes
SW006021-1
Page of 518
C Language Features
 2012 Microchip Technology Inc.
DS52053B-page 227
This process continues until all the program has been generated. The output is passed 
to the linker (via the assembler) which then looks for the sections it contains.
The linker sorts each section as it is encountered. All text sections are collated, as 
well as the bss0, data0 and idata sections. The order in which they will be assem-
bled will match the order in which they are passed to the linker, which in turn will be the 
order in which they were produced by the code generator. There is now one collated 
text
, bss0, data0 and idata section.
These sections are now located in memory. The linker is passed options (from the com-
piler driver) which define the linker classes and the memory ranges they represent, see 
Section 7.2.1 “-Aclass =low-high,...”
1
. For our device, the linker options might look 
like this.
-ACODE=0-7ffh
-ABANK0=20h-6fh
So for example, the BANK0 class covers memory from 20h to 6fh. You can see all the 
options passed to the linker in the map file, see Section 7.4 “Map Files”.
The linker “fits” each section into the memory associated with the class it is associated 
with. It might, for example, place the text section at address 0 in the CODE class, then 
immediately follow it with the idata section at address 374h, for example. The bss0 
and data0 sections will similarly be placed in the BANK0 class.
All the sections are now allocated an address within a class. The addresses of symbols 
can now be determined and ultimately a hex file is produced. The compiler’s job is over.
5.15.1.4
MORE ADVANCED TOPICS
Let’s look at more complex issues with linking now that we understand the basics.
5.15.1.4.1
Allocation at Specific Locations
We have seen in the preceding analogy that the linker places sections in their corre-
sponding class when it comes time to determine where they will live in memory. This is 
how most sections are linked, but there are some exceptions. Code to be executed on 
Reset or an interrupt are examples. They cannot just be placed anywhere in a class; 
they must be located at specific addresses. So how are these positioned by the linker?
Any code that is to be linked at a particular address is placed in a section in the usual 
way. These sections will even have a class associated with them, but allocation any-
where in this class can be overridden by a special linker option which tells the linker to 
place the section at a specific address. In terms of our previous analogy, think of the 
special linker options as being explicit instructions given to the packing machine as to 
where in a container to place the box. We will see in the next example the linker options 
to place a section explicitly.
-preset_vec=0h
-pint_text=04h
Note that if a section is linked in this way, the linker will follow these instructions strictly. 
It will warn if it is asked to place a section over the top of another, but since there is no 
container, which essentially represents a memory range, the linker cannot check for 
sections extending past the device’s memory limits.
5.15.1.4.2
Where Classes and Containers Differ
Containers and linker classes differ in one important aspect: Linker classes are con-
ceptual and merely represent the memory of a device; they are not physical storage.
1.Remember these are linker options and you cannot pass these straight to the compiler driver. You
can, however, encapsulate these options in the driver’s -L- options, see Section 4.8.7 “-L-: Adjust
Linker Options Directly”
.