[kvm-unit-tests PATCH v5 16/29] powerpc: Set .got section alignment to 256 bytes

Nicholas Piggin npiggin at gmail.com
Sun Dec 17 00:42:43 AEDT 2023

Modern powerpc64 toolchains require the .got section have alignment of
256 bytes. Incorrect alignment ends up causing the .data section ELF
load address to move by 8 bytes from its file offset, relative to
previous sections. This is not a problem for the QEMU bios loader used
by the pseries machine, but it is a problem for the powernv machine
using skiboot as the bios and the test programs as a kernel, because the
skiboot ELF loader is crippled:

  * Note that we execute the kernel in-place, we don't actually
  * obey the load informations in the headers. This is expected
  * to work for the Linux Kernel because it's a fairly dumb ELF
  * but it will not work for any ELF binary.

This causes all references to data to be incorrect. Aligning the .got
to 256 bytes prevents this offset skew and allows the skiboot "flat"
loader to work. [I don't know why the .got alignment can cause this
difference in linking.]

Signed-off-by: Nicholas Piggin <npiggin at gmail.com>
 powerpc/flat.lds | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/powerpc/flat.lds b/powerpc/flat.lds
index 5eed368d..e07b91c1 100644
--- a/powerpc/flat.lds
+++ b/powerpc/flat.lds
@@ -41,8 +41,7 @@ SECTIONS
      * tocptr is tocbase + 32K, allowing toc offsets to be +-32K
-    tocptr = . + 32K;
-    .got : { *(.toc) *(.got) }
+    .got : ALIGN(256) { tocptr = . + 32K; *(.toc .got) }
     . = ALIGN(64K);
     edata = .;
     . += 64K;

More information about the Linuxppc-dev mailing list