TOC Overflow: what is it, and why should you care?
rauls 1200005VCY Comment (1) Visits (12773)
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