diff mbox series

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

Message ID 20231216134257.1743345-17-npiggin@gmail.com (mailing list archive)
State Not Applicable
Headers show
Series powerpc: updates, P10, PNV support | expand

Commit Message

Nicholas Piggin Dec. 16, 2023, 1:42 p.m. UTC
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@gmail.com>
---
 powerpc/flat.lds | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

Comments

Thomas Huth Dec. 19, 2023, 12:01 p.m. UTC | #1
On 16/12/2023 14.42, Nicholas Piggin wrote:
> 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@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;

Acked-by: Thomas Huth <thuth@redhat.com>
diff mbox series

Patch

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;