diff options
author | Greg Ungerer <gerg@kernel.org> | 2023-11-28 23:29:43 +1000 |
---|---|---|
committer | Waldemar Brodkorb <wbx@openadk.org> | 2023-12-12 05:51:34 +0100 |
commit | 74d5b684253ce61404c1b72f2726599f00eb0a14 (patch) | |
tree | 6aab797e63c89b3c9575c2df35440499a35f5b00 /ldso | |
parent | 75a5fc9e5033f47e955406e300a070004c14b8ae (diff) |
elf: support ELF binaries in noMMU
The Linux kernels ELF-FDPIC binfmt program loader can support loading and
running conventional ELF format binaries on noMMU kernels when compiled
appropriately. That is when they are constant displacement binaries such
as generated using the -pie compile option.
Add a configure option to allow selecting ELF binary support in noMMU
mode configurations on architectures that support this. The main
requirement is to generate the ldso run-time loader to perform relocation
at load time. These configurations do not support shared libraries, so
there is no need to generate a full shared library, only the static
version is required.
The use of ELF format binaries does mean a slightly simpler toolchain
generation (does not require a -uclinux- for some architectures) and does
not require an extra tool like elf2flt.
This initial support targets M68K, ARM and RISC-V architectures. No kernel
changes are required, the required support for this is already in mainline
kernels (certainly as of linux-6.6).
Note that for the M68K and ARM architectures that the initialized
registers and stack layout at process startup is slightly different for
the flat format loader and the ELF/ELF-FDPIC loaders. So we need some
changes to the startup code (crt1.S) for them.
I have not done extensive testing outside of M68K, ARM and RISC-V.
I had to make changes to a couple of the dl-startup.h architecture files
to get them to build for this noMMU case. I did not dig down too deep on
the reasons, but they still seem ok for the MMU case as well.
Signed-off-by: Greg Ungerer <gerg@linux-m68k.org>
Diffstat (limited to 'ldso')
-rw-r--r-- | ldso/include/dl-defs.h | 2 | ||||
-rwxr-xr-x | ldso/include/ldso.h | 2 | ||||
-rw-r--r-- | ldso/ldso/arm/dl-startup.h | 2 | ||||
-rw-r--r-- | ldso/ldso/m68k/dl-startup.h | 3 | ||||
-rw-r--r-- | ldso/ldso/m68k/dl-sysdep.h | 2 | ||||
-rw-r--r-- | ldso/ldso/riscv64/dl-startup.h | 2 |
6 files changed, 11 insertions, 2 deletions
diff --git a/ldso/include/dl-defs.h b/ldso/include/dl-defs.h index daa6685cb..839239f4c 100644 --- a/ldso/include/dl-defs.h +++ b/ldso/include/dl-defs.h @@ -72,7 +72,7 @@ typedef struct { #endif #ifdef _LIBC -#ifndef __ARCH_HAS_NO_SHARED__ +#ifndef __ARCH_HAS_NO_LDSO__ /* arch specific defines */ #include <dl-sysdep.h> #endif diff --git a/ldso/include/ldso.h b/ldso/include/ldso.h index 8d9d057a0..80d5d5dd5 100755 --- a/ldso/include/ldso.h +++ b/ldso/include/ldso.h @@ -48,7 +48,7 @@ /* Pull in the MIN macro */ #include <sys/param.h> /* Pull in the ldso syscalls and string functions */ -#ifndef __ARCH_HAS_NO_SHARED__ +#if !defined(__ARCH_HAS_NO_SHARED__) || !defined(__ARCH_HAS_NO_LDSO__) #include <dl-syscall.h> #include <dl-string.h> /* Now the ldso specific headers */ diff --git a/ldso/ldso/arm/dl-startup.h b/ldso/ldso/arm/dl-startup.h index cacd461e1..d00e7b053 100644 --- a/ldso/ldso/arm/dl-startup.h +++ b/ldso/ldso/arm/dl-startup.h @@ -301,3 +301,5 @@ int raise(int sig) _dl_exit(1); } #endif /* __FDPIC__ */ + +#define DL_UPDATE_LOADADDR_HDR(LOADADDR, ADDR, PHDR) diff --git a/ldso/ldso/m68k/dl-startup.h b/ldso/ldso/m68k/dl-startup.h index dfece443f..9c3285e27 100644 --- a/ldso/ldso/m68k/dl-startup.h +++ b/ldso/ldso/m68k/dl-startup.h @@ -55,6 +55,9 @@ _dl_start_user:\n\ * do something a little more subtle here. */ #define GET_ARGV(ARGVP, ARGS) ARGVP = (((unsigned long *) ARGS) + 1) +/* We can't call functions earlier in the dl startup process */ +#define NO_FUNCS_BEFORE_BOOTSTRAP + /* Handle relocation of the symbols in the dynamic loader. */ static __always_inline void PERFORM_BOOTSTRAP_RELOC(ELF_RELOC *rpnt, unsigned long *reloc_addr, diff --git a/ldso/ldso/m68k/dl-sysdep.h b/ldso/ldso/m68k/dl-sysdep.h index 21937b259..5d2d7a097 100644 --- a/ldso/ldso/m68k/dl-sysdep.h +++ b/ldso/ldso/m68k/dl-sysdep.h @@ -83,3 +83,5 @@ elf_machine_relative (Elf32_Addr load_off, const Elf32_Addr rel_addr, *reloc_addr = load_off + rpnt->r_addend; } while (--relative_count); } + +#define DL_UPDATE_LOADADDR_HDR(LOADADDR, ADDR, PHDR) diff --git a/ldso/ldso/riscv64/dl-startup.h b/ldso/ldso/riscv64/dl-startup.h index dabe1bebd..82e525e66 100644 --- a/ldso/ldso/riscv64/dl-startup.h +++ b/ldso/ldso/riscv64/dl-startup.h @@ -88,3 +88,5 @@ void PERFORM_BOOTSTRAP_RELOC(ELF_RELOC *rpnt, ElfW(Addr) *reloc_addr, _dl_exit(1); } } + +#define DL_UPDATE_LOADADDR_HDR(LOADADDR, ADDR, PHDR) |