6.1.8 Program Sections

Program sections, or psects, are simply a section of code or data. They are a way of grouping together parts of a program (via the psect’s name) even though the source code cannot be physically adjacent in the source file, or even where spread over several modules.

A psect is identified by a name and has several attributes. The PSECT assembler directive is used to define a psect. It requires a name argument, which may be followed an comma-separated list of flags which define its attributes. Linker options that can be used to control psect placement in memory are described in Linker. These options can be accessed from the driver using the -Wl driver option (see 4.6.11.8 Wl: Pass Option To The Linker, Option), negating the need for you to run the linker explicitly.

See Compiler-Generated Psects for a list of all psects that the code generator defines.

Unless defined as abs (absolute), psects are relocatable.

Code or data that is not explicitly placed into a psect using the PSECT directive will become part of the default (unnamed) psect. As you have no control over where this psect is linked, it recommended that a PSECT directive always be placed before the code and objects.

When writing assembly code, you can use the existing compiler-generated psects or create your own. You will not need to adjust the linker options if you are using compiler-generated psects.

If you create your own psects, try to associate them with an existing linker class (see 5.15.2 Default Linker Classes and 7.1.2 C: Associate Linker Class To Psect) otherwise you can need to specify linker options for them to be allocated correctly.

Note, that the length and placement of psects is important. It is easier to write code if all executable code is located in psects that do not cross any device pages boundaries; so, too, if data psects do not cross bank boundaries. The location of psects (where they are linked) must match the assembly code that accesses the psect contents.