Understanding Code Layout and Multi-Object IPO

One of the optimizations performed during an IPO compilation is code layout.

IPO analysis determines a layout order for all of the routines for which it has IR. If a single object is being generated, the compiler generates the layout simply by compiling the routines in the desired order.

For a multi-object IPO compilation, the compiler must tell the linker about the desired order. The compiler first puts each routine in a named text section that varies depending on the platform.

Linux*:

Windows*:

However, the linker script must be taken into account if you use either -ipo-c or -ipo-S (Linux*) or /Qipo-c or /Qipo-S (Windows*).

With these options, the IPO compilation and actual linking are done by different invocations of the compiler. When this occurs, the compiler issues a message indicating that it is generating an explicit linker script, ipo_layout.script.

When ipo_layout.script is generated, the typical response is to modify your link command to use this script:

Example

--script=ipo_layout.script

If your application already requires a custom linker script, you can place the necessary contents of ipo_layout.script in your script.

The layout-specific content of ipo_layout.script is at the beginning of the description of the .text section. For example, to describe the layout order for 12 routines:

Example output

.text     :
{
*(.text00001) *(.text00002) *(.text00003) *(.text00004) *(.text00005)
*(.text00006) *(.text00007) *(.text00008) *(.text00009) *(.text00010)
*(.text00011) *(.text00012)
...

For applications that already require a linker script, you can add this section of the .text section description to the customized linker script. If you add these lines to your linker script, it is desirable to add additional entries to account for future development. The addition is harmless, since the “*(…)” syntax makes these contributions optional.

If you choose to not use the linker script your application will still build, but the layout order will be random. This may have an adverse affect on application performance, particularly for large applications.