Introduce new linker for fat ape binaries

This commit is contained in:
Justine Tunney 2023-08-11 04:37:23 -07:00
parent e3c456d23a
commit 0105e3e2b6
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
44 changed files with 3140 additions and 867 deletions

View file

@ -1044,7 +1044,8 @@ DLLEXE = DLLSTD
// 6:Contains Initialized Data
// o 5:Contains Code
// rrrr oororrorrr
PETEXT = 0b01100000000000000000000001100000
PETEXT = 0b01100000000000000000000000100000
PERDAT = 0b01000000000000000000000001000000
PEDATA = 0b11000000000000000000000011000000
PEIMPS = 0b11000000000000000000000001000000
@ -1106,6 +1107,19 @@ ape_pe: .ascin "PE",4
.long PETEXT // Flags
.previous
.section .pe.sections,"a",@progbits
.ascin ".rdata",8 // Section Name
.long ape_rom_memsz // Virtual Size or Physical Address
.long ape_rom_rva // Relative Virtual Address
.long ape_rom_filesz // Physical Size
.long ape_rom_offset // Physical Offset
.long 0 // Relocation Table Offset
.long 0 // Line Number Table Offset
.short 0 // Relocation Count
.short 0 // Line Number Count
.long PERDAT // Flags
.previous
.section .pe.sections,"a",@progbits
.ascin ".data",8 // Section Name
.long ape_ram_memsz // Virtual Size or Physical Address
@ -1128,6 +1142,7 @@ ape_pe: .ascin "PE",4
.type ape_idata_idt,@object
.globl ape_idata_idt,ape_idata_idtend
.hidden ape_idata_idt,ape_idata_idtend
.balign 4
ape_idata_idt:
.previous/*
...
@ -1136,6 +1151,7 @@ ape_idata_idt:
*/.section .idata.ro.idt.3,"a",@progbits
.long 0,0,0,0,0
ape_idata_idtend:
.byte 0
.previous
.section .piro.data.sort.iat.1,"aw",@progbits
@ -1143,13 +1159,16 @@ ape_idata_idtend:
.type ape_idata_iat,@object
.globl ape_idata_iat,ape_idata_iatend
.hidden ape_idata_iat,ape_idata_iatend
.balign 8
ape_idata_iat:
.previous/*
...
decentralized content
...
*/.section .piro.data.sort.iat.3,"aw",@progbits
.quad 0
ape_idata_iatend:
.byte 0
.previous
#endif /* SupportsWindows() */
@ -1259,8 +1278,6 @@ realmodeloader:
call lhinit
call rlinit
call sinit4
.optfn _start16
call _start16
call longmodeloader
.endfn realmodeloader

View file

@ -229,7 +229,7 @@ SECTIONS {
KEEP(*(.text.head))
/* Executable & Linkable Format */
. = ALIGN(__SIZEOF_POINTER__);
. = ALIGN(. != 0 ? __SIZEOF_POINTER__ : 0);
ape_phdrs = .;
KEEP(*(.elf.phdrs))
ape_phdrs_end = .;
@ -239,7 +239,7 @@ SECTIONS {
KEEP(*(.emushepilogue))
/* OpenBSD */
. = ALIGN(__SIZEOF_POINTER__);
. = ALIGN(. != 0 ? __SIZEOF_POINTER__ : 0);
ape_note = .;
KEEP(*(.note.openbsd.ident))
KEEP(*(.note.netbsd.ident))
@ -253,15 +253,15 @@ SECTIONS {
/* Mach-O */
KEEP(*(.macho))
. = ALIGN(__SIZEOF_POINTER__);
. = ALIGN(. != 0 ? __SIZEOF_POINTER__ : 0);
ape_macho_end = .;
/* APE loader */
KEEP(*(.ape.loader))
. = ALIGN(CODE_GRANULE);
. = ALIGN(. != 0 ? CODE_GRANULE : 0);
KEEP(*(.ape.pad.head))
. = ALIGN(SupportsWindows() || SupportsMetal() ? CONSTANT(MAXPAGESIZE) : 16);
. = ALIGN(. != 0 ? (SupportsWindows() || SupportsMetal() ? CONSTANT(MAXPAGESIZE) : 16) : 0);
_ehead = .;
} :Head
@ -312,14 +312,14 @@ SECTIONS {
/* Privileged code invulnerable to magic */
KEEP(*(.ape.pad.privileged));
. = ALIGN(__privileged_end > __privileged_start ? CONSTANT(MAXPAGESIZE) : 1);
. = ALIGN(__privileged_end > __privileged_start ? CONSTANT(MAXPAGESIZE) : 0);
/*END: morphable code */
__privileged_start = .;
*(.privileged)
__privileged_end = .;
KEEP(*(.ape.pad.text))
. = ALIGN(CONSTANT(MAXPAGESIZE));
. = ALIGN(. != 0 ? CONSTANT(MAXPAGESIZE) : 0);
/*END: Read Only Data (only needed for initialization) */
} :Cod
@ -354,7 +354,7 @@ SECTIONS {
KEEP(*(SORT_BY_NAME(.initro.*)))
KEEP(*(.initroepilogue))
KEEP(*(SORT_BY_NAME(.sort.rodata.*)))
. = ALIGN(CONSTANT(MAXPAGESIZE));
. = ALIGN(. != 0 ? CONSTANT(MAXPAGESIZE) : 0); /* don't delete this line :o */
/*END: read-only data that's only needed for initialization */
@ -368,14 +368,13 @@ SECTIONS {
*(SORT_BY_ALIGNMENT(.tdata.*))
_tdata_end = .;
KEEP(*(.ape.pad.rodata))
. = ALIGN(CONSTANT(MAXPAGESIZE));
. = ALIGN(. != 0 ? CONSTANT(MAXPAGESIZE) : 0);
_etext = .;
PROVIDE(etext = .);
} :Tls :Rom
/*END: Read Only Data */
. = DATA_SEGMENT_ALIGN(CONSTANT(MAXPAGESIZE), CONSTANT(MAXPAGESIZE));
. = DATA_SEGMENT_RELRO_END(0, .);
. = ALIGN(CONSTANT(MAXPAGESIZE));
/* this only tells the linker about the layout of uninitialized */
/* TLS data, and does not advance the linker's location counter */
@ -409,7 +408,7 @@ SECTIONS {
*(.got.plt)
KEEP(*(.gotpltepilogue))
. = ALIGN(__SIZEOF_POINTER__);
. = ALIGN(. != 0 ? __SIZEOF_POINTER__ : 0);
__init_array_start = .;
KEEP(*(SORT_BY_INIT_PRIORITY(.init_array.*)
SORT_BY_INIT_PRIORITY(.ctors.*)))
@ -418,7 +417,7 @@ SECTIONS {
KEEP(*(.preinit_array))
__init_array_end = .;
. = ALIGN(__SIZEOF_POINTER__);
. = ALIGN(. != 0 ? __SIZEOF_POINTER__ : 0);
__fini_array_start = .;
KEEP(*(SORT_BY_INIT_PRIORITY(.fini_array.*)
SORT_BY_INIT_PRIORITY(.dtors.*)))
@ -427,19 +426,21 @@ SECTIONS {
__fini_array_end = .;
/*BEGIN: Post-Initialization Read-Only */
. = ALIGN(__SIZEOF_POINTER__);
. = ALIGN(. != 0 ? __SIZEOF_POINTER__ : 0);
KEEP(*(SORT_BY_NAME(.piro.relo.sort.*)))
. = ALIGN(__SIZEOF_POINTER__);
. = ALIGN(. != 0 ? __SIZEOF_POINTER__ : 0);
KEEP(*(SORT_BY_NAME(.piro.data.sort.*)))
KEEP(*(.piro.pad.data))
KEEP(*(.dataepilogue))
. = ALIGN(CONSTANT(MAXPAGESIZE));
. = ALIGN(. != 0 ? CONSTANT(MAXPAGESIZE) : 0);
/*END: NT FORK COPYING */
_edata = .;
PROVIDE(edata = .);
_ezip = .; /* <-- very deprecated */
} :Ram
. = ALIGN(CONSTANT(MAXPAGESIZE));
/*END: file content that's loaded by o/s */
/*END: file content */
/*BEGIN: bss memory that's addressable */
@ -463,14 +464,14 @@ SECTIONS {
KEEP(*(.bssepilogue))
. = ALIGN(CONSTANT(MAXPAGESIZE));
. = ALIGN(. != 0 ? CONSTANT(MAXPAGESIZE) : 0);
/*END: NT FORK COPYING */
_end = .;
PROVIDE(end = .);
} :Ram
. = DATA_SEGMENT_END(.);
. = ALIGN(CONSTANT(MAXPAGESIZE));
_end = .;
PROVIDE(end = .);
/*END: nt addressability guarantee */
/*END: bsd addressability guarantee */
@ -556,24 +557,24 @@ _tls_align = 1;
ape_cod_offset = 0;
ape_cod_vaddr = ADDR(.head);
ape_cod_paddr = LOADADDR(.head);
ape_cod_filesz = SIZEOF(.head) + SIZEOF(.text);
ape_cod_filesz = ADDR(.rodata) - ADDR(.head);
ape_cod_memsz = ape_cod_filesz;
ape_cod_align = CONSTANT(MAXPAGESIZE);
ape_cod_rva = RVA(ape_cod_vaddr);
ape_rom_offset = ape_cod_offset + ape_cod_filesz;
ape_rom_vaddr = ADDR(.rodata);
ape_rom_offset = ape_rom_vaddr - __executable_start;
ape_rom_paddr = LOADADDR(.rodata);
ape_rom_filesz = SIZEOF(.rodata) + SIZEOF(.tdata);
ape_rom_filesz = ADDR(.tbss) - ADDR(.rodata);
ape_rom_memsz = ape_rom_filesz;
ape_rom_align = CONSTANT(MAXPAGESIZE);
ape_rom_rva = RVA(ape_rom_vaddr);
ape_ram_offset = ape_rom_offset + ape_rom_filesz;
ape_ram_vaddr = ADDR(.data);
ape_ram_offset = ape_ram_vaddr - __executable_start;
ape_ram_paddr = LOADADDR(.data);
ape_ram_filesz = SIZEOF(.data);
ape_ram_memsz = SIZEOF(.data) + SIZEOF(.bss);
ape_ram_filesz = ADDR(.bss) - ADDR(.data);
ape_ram_memsz = _end - ADDR(.data);
ape_ram_align = CONSTANT(MAXPAGESIZE);
ape_ram_rva = RVA(ape_ram_vaddr);
@ -591,10 +592,10 @@ ape_note_offset = ape_cod_offset + (ape_note - ape_cod_vaddr);
ape_note_filesz = ape_note_end - ape_note;
ape_note_memsz = ape_note_filesz;
ape_text_offset = ape_cod_offset + LOADADDR(.text) - ape_cod_paddr;
ape_text_paddr = LOADADDR(.text);
ape_text_vaddr = ADDR(.text);
ape_text_filesz = SIZEOF(.text) + SIZEOF(.rodata) + SIZEOF(.tdata);
ape_text_offset = ape_text_vaddr - __executable_start;
ape_text_paddr = LOADADDR(.text);
ape_text_filesz = ADDR(.rodata) - ADDR(.text);
ape_text_memsz = ape_text_filesz;
ape_text_align = CONSTANT(MAXPAGESIZE);
ape_text_rva = RVA(ape_text_vaddr);
@ -760,12 +761,6 @@ ASSERT(((DEFINED(__init_rodata_end) ? __init_rodata_end : 0) %
ASSERT((!DEFINED(ape_grub) ? 1 : RVA(ape_grub) < 8192),
"grub stub needs to be in first 8kb of image");
ASSERT(DEFINED(_start) || DEFINED(_start16),
"please link a _start() or _start16() entrypoint");
ASSERT(!DEFINED(_start16) || REAL(_end) < 65536,
"ape won't support non-tiny real mode programs");
ASSERT(IS2POW(ape_stack_memsz),
"ape_stack_memsz must be a two power");

View file

@ -43,10 +43,10 @@
.hidden \fn
.previous
.section ".idata.ro.ilt.\dll\().2.\actual","a",@progbits
".Lidata.ilt.\dll\().\actual":
"idata.ilt.\dll\().\actual":
.quad RVA("\dll\().\actual")
.type ".Lidata.ilt.\dll\().\actual",@object
.size ".Lidata.ilt.\dll\().\actual",.-".Lidata.ilt.\dll\().\actual"
.type "idata.ilt.\dll\().\actual",@object
.size "idata.ilt.\dll\().\actual",.-"idata.ilt.\dll\().\actual"
.previous
.section ".idata.ro.hnt.\dll\().2.\actual","a",@progbits
"\dll\().\actual":