elf2aout: import from FreeBSD

The sparc openboot implementation can run executables in the a.out
format. We used to generate these using objcopy, but this does not work
anymore as binutils is deprecating a.out format support.

- Import elf2aout from FreeBSD
- Add some missing bits to our elf.h and have a copy of it in the build
  headers so it can be used to build elf2aout for the host platform
  (tested for Linux)
- Use it to generate the sparc haiku_loader
- Adjust the bootloader linker script to have two "program headers": one
  that is not loadable and contains the ELF headers, and the second one
  that is loadable and contains the actual code and data. Unlike
  objcopy, elf2aout relies only on the program headers to know what to
  put in its output file (sections are ignored), so this is required
  otherwise we end up with the ELF header nested inside the a.out file,
  and everything offset from the expected load address as a result.

Confirmed that this allows to build the loader and run it as far as
before, so I'm back to needing to implement some MMU support now.

FreeBSD commit: 7551d83c353e040b32c6ac205e577dbc5f2c8955

Change-Id: I90b48e578fa7f148aeddd8c5998fdddc5cfa73fa
Reviewed-on: https://review.haiku-os.org/c/1557
Reviewed-by: Adrien Destugues <[email protected]>
This commit is contained in:
Adrien Destugues
2019-07-13 01:29:05 +00:00
committed by waddlesplash
parent 19d1cffe33
commit 076b19023f
6 changed files with 1127 additions and 13 deletions
+9
View File
@@ -93,6 +93,12 @@ typedef struct {
#define ELFMAG "\x7f""ELF"
#define SELFMAG 4
/* e_ident */
#define IS_ELF(ehdr) ((ehdr).e_ident[EI_MAG0] == ELFMAG0 && \
(ehdr).e_ident[EI_MAG1] == ELFMAG1 && \
(ehdr).e_ident[EI_MAG2] == ELFMAG2 && \
(ehdr).e_ident[EI_MAG3] == ELFMAG3)
/* e_type (Object file type) */
#define ET_NONE 0 /* No file type */
#define ET_REL 1 /* Relocatable file */
@@ -197,6 +203,9 @@ typedef struct {
#define EM_RISCV 243 /* RISC-V */
#define EM_BPF 247 /* Linux kernel bpf virtual machine */
#define EM_ALPHA 0x9026 /* Digital Alpha (nonstandard, but the value
everyone uses) */
/* architecture class (EI_CLASS) */
#define ELFCLASSNONE 0
#define ELFCLASS32 1