7.1.18 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 in the form:
-Ppsect=linkaddr+min/loadaddr+min,psect=linkaddr/loadaddr,...

All values can be omitted, in which case defaults will apply, depending on previous values. The link address of a psect is the address at which it can be accessed during 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.

Should the argument to this option contain a comma, you must pass this option to the linker from either the MPLAB XC8 C compiler (xc8-cc) or the MPLAB XC8 PIC Assembler (pic-as) drivers using the -Xlinker driver option (see Xlinker Option) rather than the -Wl option to avoid the comma being misinterpreted.

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 A: Define Linker Class Option); and
-PstartCode=0200h,middleCode,endCode
which places endCode immediately after the end of middleCode, which in turn is placed immediately after the end of startCode, which will start at address 0x200. Note that if you were to specify a linker class instead of an absolute address in the above example, the psects listed after the class will also be placed anywhere in the address range specified by that class. If the link order of the psects is important but the link address is flexible, use two options. For example, the options
-PstartCode=SEQCODE  -PmiddleCode=startCode,endCode
will place startCode anywhere in the range of addresses specified by the linker class SEQCODE (which would need to be defined using the -A option), and the endCode psect will be placed immediately after the end of middleCode, which in turn will be placed immediately after the end of startCode.

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 Psect Information Listed By Module).