Raul_Silvera's Profile

  • Name: (Private)
  • Email: (Private)
  • Member Since: Nov 6, 2008
  • Last Logged In: Nov 4, 2009 10:26 AM
  • Status Level:  

Raul_Silvera's Latest Content

In a couple of previous posts ( TOC Overflow: what is it, and why should you care?, Dealing with TOC overflow: the traditional approach ) I have presented the issue of TOC overflow. Now I will discuss some features of the XL compilers that can help bypass TOC overflow while minimizing any negative effects on runtime performance.

1. Minimal TOC: The option -qminimaltoc makes the compiler generate code that uses a single entry in the TOC for each compilation unit (in C/C++ a compilation unit is a source file). In order to do this, a separate level of indirection must be follow in order to access TOC-based variables. This means that the program will be larger and slower than if it did not have TOC overflow, but it will still be faster than using the -bbigtoc option. This is similar to the -mminimal-toc from gcc.

Furthermore, -qminimaltoc does not need to be used on all compilation units, so you can minimize the performance impact by using this flag only on compilation units that are not relevant for performance.

2. IPA: IPA is short for inter-procedural analysis, a form of compiler optimization that looks at the whole program, not just a single compilation unit. For this, the optimizer is invoked during the linking phase of your application, to perform transformations that can affect multiple compilation units.

Applying this process significantly reduces TOC pressure, and in most cases completely eliminates TOC overflow. It does so by restructuring your program to reduce the number of global symbols. The result is similar to what could be achieved through source changes, but avoiding the widespread manual source changes.

In the XL compilers, IPA is implied at optimization levels -O4 and -O5, but those also include other complex optimizations which may not be as relevant to commercial application development. One good alternative is the option -qipa=level=0, which applies a minimal level of whole-program optimization. This is often sufficient to eliminate TOC overflow, but in very large applications you may need -qipa=level=1 instead, which will perform a more aggressive reduction of the TOC requirements, at the cost of a longer compilation process.

Note that for whole-program analysis to be performed, the -qipa option needs to be specified both at the compile and link command lines. This means that the linking of the program has to be done through the compiler driver (xlc, xlC or cc) instead of directly through the system linker (ld). For maximum effect, all source files should be compiled with -qipa, but it is possible to mix-and-match objects compiled with different options and have them interoperate.

If you try these options please add comments to this post describing your results.

7 Comments Permalink

In a previous posting (TOC Overflow: what is it, and why should you care?) I discussed the TOC overflow condition, which is common when developing large commercial applications on AIX.

These are some of the common solutions to this problem:

1. Change your application The most obvious solution to this problem is to change the application to reduce the number of global symbols being defined. One way to do this is by grouping some global variables into a global structure, or changing them from external to static. This can be time-consuming and error-prone, so it is not a realistic option on most large projects.

2. -bbigtoc The most frequently-used solution for TOC overflow is the bigtoc linker option. This instructs the linker to generate a TOC larger than 64K.

The problem with -bbigtoc is that TOC entries in the overflow area (outside the initial 64K) cannot be accessed with a single load based on the TOC pointer, which introduces a nontrivial performance penalty. Each access to the TOC overflow area requires a branch to offline code that adjusts the base pointer and then performs the load. Because this code is generated during link processing, it cannot be properly scheduled or optimized with the rest of the program.

To make matters worse, the programmer does not have control over which variables are located in the TOC overflow area, so there is no way to ensure that frequently accessed variables will stay out of the TOC overflow area.

On my next post on this series I'll describe some mechanisms the XLC compilers provide to deal with this issue.

PS: In order to experiment with TOC overflow, we need a program with many global variables. Attached is a shell script called TOCOverflowGenerator, which creates a such a program.

Try it with the value 16384 (or 8192 on 64-bit mode), and the program will reach TOC overflow and fail to link.

Do you find this topic interesting, or do you have additional questions? Please add comments to this post describing where you've seen TOC overflow and how do you currently deal with it.

6 Comments Permalink

When building large applications on AIX or pSeries Linux you may have experienced the dreaded TOC overflow. This is a situation reported the system linker that causes it to abort and fail to generate an executable.

What is this situation and what are the strategies for coping with it?

Basically, the TOC or table-of-contents is a table that the program uses to reference global symbols. Since these symbols can be referenced from multiple object files, their memory location is unknown until link time, so the code generated by the compiler to access them must look them up in this table.

The way this works is that the ABI reserves a register which always points to the TOC. The compiler generates an indirect reference off this pointer with a zero offset, which is updated by the linker with the actual offset it selected for each global symbol. The PowerPC architecture allows up to a 64K offset, thus creating a limit of 16K global symbols on 32-bit mode and 8K on 64-bit mode. If a program has a larger number of global symbols the linker cannot reserve TOC slots for all of them, and it aborts after reporting TOC overflow.

On my next post I'll discuss some strategies for addressing this problem, and their tradeoffs. Here's a link: Dealing with TOC overflow: the traditional approach

Permalink

Brainstorm with co-workers, get your questions answered, build status with your responses.

Write your own drafts, invite selected collaborators, or leave it open for all to pitch in.