C/C++ and Fortran

How to handle table of contents overflow (1)

By Archive User posted Thu March 14, 2013 03:19 AM

  

Originally posted by: AliceYing


Do you have experience of encountering table of contents (TOC) overflow? If you do, how do you deal with the problem? The IBM XL C compiler provides solutions to solve the problem since version 12. There is also a developerWorks article written by Kit Barton and Yang Lu to explain how the TOC overflow occurs and how to tackle the overflow problem on AIX (Please see http://www.ibm.com/developerworks/rational/library/overview-toc-aix/index.html). Here I'd like to summarize the contents in the article and provide more options to present a package of solutions.

Why does TOC overflow occur?
The addresses of global symbols in programs are stored in a data structure called TOC. To access a global symbol, the address of the global symbol must be retrieved from the TOC. The default TOC data structure has a fixed size that can store a fixed number of global symbols. For example, the IBM® PowerPC® architecture uses an instruction with a signed 16-bit offset for indirect address calculations, and limits the size of the TOC to 64 KB. A maximum of 16 K entries can be stored in the TOC in 32-bit mode and 8 K entries in 64-bit mode.

Sometimes there are more entries needed than the maximum of entries, and hence the overflow occurs, especially when it happens to some large applications. Now it is time for you to choose the right methods to address this problem.

To reduce TOC needs or to enlarge TOC?
Which option would you choose? Let me show you an example first that is used as an analogy. Suppose you are the operation manager of a certain site, and one of your job responsibilities is to provide work seats to meet the needs of new employees the number of which is keep increasing. For now the building contains 1000 seats for 1000 people, when you finish the job to allocate the 1000th seat to the 1000th employee, you must be obsessed with the question that how to provide a seat for the next new comer? Surely there are multiple choices to make. If you have enough budget, probably you will consider to rent or buy a second building. More space is created to allow more new comers and you won't be worried about the capacity problem for a while. However, the decision could be made depending on whether you can afford the high expense. If you are a prudent manager, you will try to find more space in the building by making use of some meeting rooms, or add some seats along the corridor.

What decision will you make? The truth is that it is difficult to give an instant answer, because you need to do some investigation and measure the possible impact and results. The same thing happens when you are facing TOC overflow. There are multiple methods provided, but it is up to you choose your best way after taking compilation performance into consideration. I will just list the approaches to solve overflow and the performance impact they will bring to you in this blog. You can be the decision maker to take one or more options to solve your problem with little impact on the compilation performance.

An overview of solutions
To simply put it, there two general options - to reduce the number of global symples in programs and to enlarge the TOC access range. See the following for how to implement the general ideas:

  • Reduce the number of global symbols in programs
    • Change the source code. It is the best approach to reduce the number of global symbols.
    • Specify the -qminimaltoc option.
    • Apply the interprocedural analysis by specifying the -qipa option. For more information about the option, see Using interprocedural analysis and Getting the most from -qipa.
  • Enlarge the TOC access range by specifying the following options:
    • bbigtoc (a linker option)
    • -qpic=large
In my next blog, I will describe these compiler option behaviors and detail the pros and cons of each option.
0 comments
0 views

Permalink