diff mbox series

[RFC,08/10] arm: efi_loader: move .dynamic out of .text in EFI

Message ID 20230520205547.1009254-9-CFSworks@gmail.com
State RFC
Delegated to: Tom Rini
Headers show
Series Improve ARM target's support for LLVM toolchain | expand

Commit Message

Sam Edwards May 20, 2023, 8:55 p.m. UTC
This is not proper: A .text section is SHT_PROGBITS,
while the .dynamic section is SHT_DYNAMIC. Attempting to
combine them like this creates a section type mismatch.

It does seem that GNU ld does not complain, but LLVM's lld
considers this an error.

Signed-off-by: Sam Edwards <CFSworks@gmail.com>
Cc: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
---

 arch/arm/lib/elf_aarch64_efi.lds | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

Comments

Ilias Apalodimas May 22, 2023, 7:30 a.m. UTC | #1
Hi Sam,

On Sat, 20 May 2023 at 23:56, Sam Edwards <cfsworks@gmail.com> wrote:
>
> This is not proper: A .text section is SHT_PROGBITS,
> while the .dynamic section is SHT_DYNAMIC. Attempting to
> combine them like this creates a section type mismatch.
>
> It does seem that GNU ld does not complain, but LLVM's lld
> considers this an error.
>
> Signed-off-by: Sam Edwards <CFSworks@gmail.com>
> Cc: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
> ---
>
>  arch/arm/lib/elf_aarch64_efi.lds | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/arch/arm/lib/elf_aarch64_efi.lds b/arch/arm/lib/elf_aarch64_efi.lds
> index 5dd9809169..986f13936d 100644
> --- a/arch/arm/lib/elf_aarch64_efi.lds
> +++ b/arch/arm/lib/elf_aarch64_efi.lds
> @@ -24,10 +24,9 @@ SECTIONS
>                 *(.gnu.linkonce.t.*)
>                 *(.srodata)
>                 *(.rodata*)
> -               . = ALIGN(16);
> -               *(.dynamic);
>                 . = ALIGN(512);
>         }
> +       .dynamic : { *(.dynamic) }
This looks correct.  However, this changed recently on commit
d7ddeb66a6ce ("efi_loader: fix building aarch64 EFI binaries").

Heinrich any chance you can repeat your tests?

Thanks
/Ilias
>         .rela.dyn : { *(.rela.dyn) }
>         .rela.plt : { *(.rela.plt) }
>         .rela.got : { *(.rela.got) }
> --
> 2.39.2
>
Heinrich Schuchardt May 22, 2023, 8:10 a.m. UTC | #2
On 5/20/23 22:55, Sam Edwards wrote:
> This is not proper: A .text section is SHT_PROGBITS,
> while the .dynamic section is SHT_DYNAMIC. Attempting to
> combine them like this creates a section type mismatch.
>
> It does seem that GNU ld does not complain, but LLVM's lld
> considers this an error.
>
> Signed-off-by: Sam Edwards <CFSworks@gmail.com>
> Cc: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
> ---
>
>   arch/arm/lib/elf_aarch64_efi.lds | 3 +--
>   1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/arch/arm/lib/elf_aarch64_efi.lds b/arch/arm/lib/elf_aarch64_efi.lds
> index 5dd9809169..986f13936d 100644
> --- a/arch/arm/lib/elf_aarch64_efi.lds
> +++ b/arch/arm/lib/elf_aarch64_efi.lds
> @@ -24,10 +24,9 @@ SECTIONS
>   		*(.gnu.linkonce.t.*)
>   		*(.srodata)
>   		*(.rodata*)
> -		. = ALIGN(16);

.dynamic should be aligned. Structure Elf64_Dyn requires at least 8 byte
alignment.

> -		*(.dynamic);
>   		. = ALIGN(512);

The symbol _etext below should be 512 aligned as in
arch/arm/lib/crt0_aarch64_efi.S we have set FileAlignment = 0x200.

Best regards

Heinrich

>   	}
> +	.dynamic : { *(.dynamic) }
>   	.rela.dyn : { *(.rela.dyn) }
>   	.rela.plt : { *(.rela.plt) }
>   	.rela.got : { *(.rela.got) }
Sam Edwards May 22, 2023, 5:13 p.m. UTC | #3
On 5/22/23 02:10, Heinrich Schuchardt wrote:

Hi Heinrich,

> .dynamic should be aligned. Structure Elf64_Dyn requires at least 8 byte
> alignment.

As best as I can tell, linkers (certainly lld[1], apparently also GNU ld 
judging by its default linker scripts) themselves set the proper word 
alignment on the .dynamic section that they synthesize for their 
internal input object. That alignment requirement bubbles up to the 
output section, so explicit alignment here should not be necessary.

> The symbol _etext below should be 512 aligned as in
> arch/arm/lib/crt0_aarch64_efi.S we have set FileAlignment = 0x200.

Ah, that definitely needs to be fixed since the .rela.* sections might 
not have the 512 alignment. I've updated my local branch, though this 
also needs to be addressed in the current master branch.

Cheers,
Sam

[1]: 
https://github.com/llvm/llvm-project/blob/acce2a315945e386a7be6f014ebe90c2a28f38d9/lld/ELF/SyntheticSections.cpp#L1246
diff mbox series

Patch

diff --git a/arch/arm/lib/elf_aarch64_efi.lds b/arch/arm/lib/elf_aarch64_efi.lds
index 5dd9809169..986f13936d 100644
--- a/arch/arm/lib/elf_aarch64_efi.lds
+++ b/arch/arm/lib/elf_aarch64_efi.lds
@@ -24,10 +24,9 @@  SECTIONS
 		*(.gnu.linkonce.t.*)
 		*(.srodata)
 		*(.rodata*)
-		. = ALIGN(16);
-		*(.dynamic);
 		. = ALIGN(512);
 	}
+	.dynamic : { *(.dynamic) }
 	.rela.dyn : { *(.rela.dyn) }
 	.rela.plt : { *(.rela.plt) }
 	.rela.got : { *(.rela.got) }