[Skiboot] [PATCH] Align TOC to 256 bytes

Alan Modra amodra at au1.ibm.com
Sun May 17 00:20:10 AEST 2015

Patrick Williams III/Rochester/IBM wrote on 15/05/2015 07:39:51:

> My understanding is that the TOC base points somewhere "in the
> middle" of the GOT, so that both positive and negative load offsets
> can be used.  It isn't immediately obvious how aligning the GOT to
> 256 bytes also aligns the TOC base itself.
> I guess this works because the TOC base is actually a constant from the
> #define TOC_BASE_OFF   0x8000

The linker change aligns the TOC base regardless of whether your script
aligns the .got section.  Which means that if you don't align .got, then
the TOC base is *not* .got + 0x8000.  (It's rounded down to a 256 byte
boundary.)  So that anyone using a linker script symbol to guess the TOC
base, rather than using .TOC. (for example because you need to be
compatible with older linkers that don't define .TOC), is in trouble.

One backwards compatible solution is to align .got to 256 bytes.

Another is to use something like the following to define your symbol
guessing the TOC base.
  .got          : ALIGN(at_least_8)
    __toc_base = DEFINED (.TOC.) ? .TOC. : . + 0x8000 ;
    *(.got .toc)
With a new linker you won't be guessing, but actually using the linker
defined TOC base.  And Alan Modra won't be breaking things for you if
the .got layout changes..  Sorry about that.

> I see the linker script change Alan made is basically the same
> proposed here, so I trust it is right and I'll make correspondingly
> similar changes to Hostboot.

More information about the Skiboot mailing list