On Sun, Feb 23, 2025 at 11:34 PM Heinrich Schuchardt <heinrich.schucha...@canonical.com> wrote: > > > > Sam Edwards <cfswo...@gmail.com> schrieb am Mo., 24. Feb. 2025, 06:56: >> >> This was 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 seems that while GNU ld does not complain, LLVM's lld considers this >> an error. >> >> Signed-off-by: Sam Edwards <cfswo...@gmail.com> >> Cc: Heinrich Schuchardt <heinrich.schucha...@canonical.com> >> --- >> lib/efi_loader/elf_efi.ldsi | 6 +++--- >> 1 file changed, 3 insertions(+), 3 deletions(-) >> >> diff --git a/lib/efi_loader/elf_efi.ldsi b/lib/efi_loader/elf_efi.ldsi >> index dc4d1a3660e..acf02eba4d6 100644 >> --- a/lib/efi_loader/elf_efi.ldsi >> +++ b/lib/efi_loader/elf_efi.ldsi >> @@ -20,10 +20,10 @@ SECTIONS >> *(.gnu.linkonce.t.*) >> *(.srodata) >> *(.rodata*) >> - . = ALIGN(16); >> - *(.dynamic); >> - . = ALIGN(512); >> } >> + . = ALIGN(16); >> + .dynamic : { *(.dynamic) } > > > .dynamic is related to dynamic linking of libraries. > > Under which circumstances would we have content in .dynamic? Why would it be > needed for executing an EFI application?
Hey Heinrich, Apologies for the late response; I didn't have sufficient time/tuits to get to this until now. While EFI applications are indeed statically linked, they need to be relocatable. The .dynamic section contains the ELF dynamic table (exposed via the _DYNAMIC symbol), which is passed to _relocate by the crt0_[arch]_efi.S stubs. _relocate finds the relocations table by querying the DT_RELA/_RELASZ/_RELAENT entries in the dynamic table. Normally, the PE loader handles relocation of EFI applications before transferring control by applying the PE relocations in .reloc, but generating PE-format relocations would require some toolchain trickery. Hence the ELF dynamic information (and relocations) in a PE file. :) Happy Monday, Sam > > Best regards > > Heinrich > > >> + . = ALIGN(512); >> .rela.dyn : { *(.rela.dyn) } >> .rela.plt : { *(.rela.plt) } >> .rela.got : { *(.rela.got) } >> -- >> 2.45.2 >>