seL4_tools icon indicating copy to clipboard operation
seL4_tools copied to clipboard

Changes to enable linking with LLVM/lld

Open heshamelmatary opened this issue 1 year ago • 5 comments

heshamelmatary avatar Jul 26 '23 10:07 heshamelmatary

The rv32imac,gcc failure is likely due to old Binutils installed on the test machines. This could either be fixed by upgrading Binutils there, or maybe use "-z nostart-stop-gc" (as per the commit message) to the linker flags.

heshamelmatary avatar Jul 26 '23 11:07 heshamelmatary

Err, I may be mixing up the meaning of (NOLOAD) in the linker script and the meaning of the ALLOC and LOAD flags in the section table, and what they mean about whether contents are allocated in the ELF file data, allocated in the program image and initialized by the loader (or zeroed). And then what the implicit rules are with .bss, .tbss and other special named sections in the GCC toolchains. Would you be able to add a summary @heshamelmatary ?

kent-mcleod avatar Jul 27 '23 01:07 kent-mcleod

Err, I may be mixing up the meaning of (NOLOAD) in the linker script and the meaning of the ALLOC and LOAD flags in the section table, and what they mean about whether contents are allocated in the ELF file data, allocated in the program image and initialized by the loader (or zeroed). And then what the implicit rules are with .bss, .tbss and other special named sections in the GCC toolchains. Would you be able to add a summary @heshamelmatary ?

Most linkers heuristically recognise common section names and apply the proper flags to them. .[t]bss sections for example should be recognised and linkers mark them ALLOC, NOLOAD, which means that they don't occupy space in the ELF image and shouldn't be loaded at run-time, but they should be allocated space at run-time in the process image when loaded.

Adding NOLOAD (similar to the seL4's kernel) is good for intentionality, and for linkers that might not automatically flag .[t]bss at NOLOAD. I've come across a bug in lld that actually allocated space in the ELF before, but I believe that got fixed.

I will add that explanation to the commit message.

heshamelmatary avatar Jul 27 '23 13:07 heshamelmatary

I dropped custom Arm's linker handling for sections and directives and rather added a new commit that unifies the linker script between Arm and RISC-V to include fixes for both and to make it more portable to build with lld and ld

heshamelmatary avatar Jan 15 '24 16:01 heshamelmatary

Also I modified the "retain" attribute to check if the toolchain supports it or not as this may fail on older GCC versions

heshamelmatary avatar Jan 15 '24 16:01 heshamelmatary