6.1.19 P: Position Psect
Psects are linked together and assigned addresses based on information
supplied to the linker via -Pspec
options. The argument to the
-P
option consists of comma-separated sequences with the form:
-Ppsect=linkaddr+min/loadaddr+min,psect=linkaddr/loadaddr,...
All values can be omitted, in which case a default will apply, depending on previous values. The link address of a psect is the address at which it can be accessed at runtime. The load address is the address at which the psect starts within the output file (HEX or binary file etc.), but it is rarely used by 8-bit PIC devices. The addresses specified can be numerical addresses, the names of other psects, classes, or special tokens.
This argument to this option often contains a comma, so it you are passing this option to
the linker from either the MPLAB XC8 C compiler (xc8-cc) or the
MPLAB XC8 PIC Assembler (pic-as) drivers, you might need to use the
-Xlinker
driver option (see 3.4.40 Xlinker Option) rather than the
-Wl
option (see 3.4.36 Wl: Pass Option To The Linker,
Option) to avoid the comma
in the option argument causing unexpected results.
Examples of the basic and most common forms of this option are:
-Ptext10=02000h
which places (links) the starting address of psect
text10
at address 0x2000;
-PmyData=AUXRAM
which places the psect myData
anywhere in the range of
addresses specified by the linker class AUXRAM
(which would need to be
defined using the -A
option, see 6.1.1 A: Define Linker Class Option), and
-PstartCode=0200h,endCode
which places endCode
immediately after the end of
startCode
, which will start at address 0x200.
The additional variants of this option are rarely needed; but, are described below.
If a link or load address cannot be allowed to fall below a minimum
value, the +min
, suffix indicates the minimum address.
If the link address is a negative number, the psect is linked in reverse order with the top of the psect appearing at the specified address minus one. Psects following a negative address will be placed before the first psect in memory.
If the load address is omitted entirely, it defaults to the link
address. If the slash /
character is supplied with no address
following, the load address will concatenate with the load address of the previous
psect. For example, after processing the option:
-Ptext=0,data=0/,bss
the text
psect will have a link and load address of 0;
data will have a link address of 0 and a load address following that of text. The
bss
psect will concatenate with data in terms of both link and load
addresses.
A load address specified as a dot character, “.
” tells
the linker to set the load address to be the same as the link address.
The final link and load address of psects are shown in the map file (see 6.3.2.2 Psect Information Listed By Module).