What is the purpose of the PHDRS section of a linker script? When do I need it?
The PHDRS section is used in a user-defined linker script to generate program header information in the executable. The linker creates reasonable program headers by default. The following is a brief explanation of PHDRS, including when and how to use them.
Program headers are read by the system loader (for Xilinx, data2bram) and describe how the program should be loaded into memory. Program headers define the start address of a memory location and the size that is loadable. If a memory that contains a loadable section (.text, .data...) => followed by an uninitialized section (.bss, .sbss - these do not need to be loaded into memory) => followed by another loadable section (.sdata, .sdata2..), the memory region needs two headers (one for each of the loadable memory chunks). The linker does not generate two headers in this case; consequently, you should use PHDRS.
Note that when the PHDRS command is used, the linker does not generate any program headers.
When and How to Use PHDRS
Linker generates the necessary program headers even if the linker script has multiple memory regions. It is only in the scenario described above that it cannot generate the right headers. To make the linker work correctly for each of the memory regions, define the loadable sections first in the linker script followed by the uninitialized ones. This ensures that the generated header is correct and that the loader functions properly. Use PHDRS only when the mix and match of initialized and uninitialized data for a memory is impossible to avoid.