How to handle table of contents overflow (1)
AliceYing 27000649CQ Visits (5620)
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: