mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-06 03:08:31 +00:00
Mint APE Loader v1.3
This version has better error messages and safety checks. It supports loading static position-independent executables. It correctly handles more kinds of weird ELF program header layouts. A force flag has been added to avoid system execve(). Finally the longstanding misalignment with our ELF PT_NOTE section has been addressed.
This commit is contained in:
parent
82b1e61443
commit
3d172c99fe
19 changed files with 1001 additions and 470 deletions
|
@ -1,7 +1,7 @@
|
|||
/*-*- mode: ld-script; indent-tabs-mode: nil; tab-width: 2; coding: utf-8 -*-│
|
||||
│vi: set et sts=2 tw=2 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2021 Justine Alexandra Roberts Tunney │
|
||||
│ Copyright 2023 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ Permission to use, copy, modify, and/or distribute this software for │
|
||||
│ any purpose with or without fee is hereby granted, provided that the │
|
||||
|
@ -16,26 +16,80 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
ENTRY(_start)
|
||||
|
||||
ENTRY(ElfEntrypoint)
|
||||
|
||||
PHDRS {
|
||||
text PT_LOAD FLAGS(1) FILEHDR PHDRS; /* PF_X */
|
||||
rodata PT_LOAD FLAGS(4); /* PF_R */
|
||||
stack PT_GNU_STACK FLAGS(6); /* PF_W|PF_R */
|
||||
note PT_NOTE FLAGS(4); /* PF_R */
|
||||
}
|
||||
|
||||
SECTIONS {
|
||||
. = 0x7fff0000;
|
||||
|
||||
. = SEGMENT_START("text-segment", 0x7f000000);
|
||||
__executable_start = .;
|
||||
.rodata : {
|
||||
KEEP(*(.head))
|
||||
*(.rodata .rodata.*)
|
||||
. = ALIGN(4096);
|
||||
}
|
||||
. += SIZEOF_HEADERS;
|
||||
|
||||
.macho : {
|
||||
KEEP(*(.macho))
|
||||
} :text
|
||||
|
||||
.note : {
|
||||
KEEP(*(.note))
|
||||
} :text :note
|
||||
|
||||
.text : {
|
||||
text = .;
|
||||
*(.text)
|
||||
}
|
||||
*(.text .text.* .gnu.linkonce.t.*)
|
||||
} :text
|
||||
|
||||
.rodata ALIGN(CONSTANT(COMMONPAGESIZE)) : {
|
||||
*(.rodata .rodata.* .gnu.linkonce.r.*)
|
||||
} :rodata
|
||||
|
||||
.stack : {
|
||||
*(.stack)
|
||||
} :stack
|
||||
|
||||
_end = .;
|
||||
|
||||
.stab 0 : { *(.stab) }
|
||||
.stabstr 0 : { *(.stabstr) }
|
||||
.stab.excl 0 : { *(.stab.excl) }
|
||||
.stab.exclstr 0 : { *(.stab.exclstr) }
|
||||
.stab.index 0 : { *(.stab.index) }
|
||||
.stab.indexstr 0 : { *(.stab.indexstr) }
|
||||
.gnu.build.attributes : { *(.gnu.build.attributes .gnu.build.attributes.*) }
|
||||
.debug 0 : { *(.debug) }
|
||||
.line 0 : { *(.line) }
|
||||
.debug_srcinfo 0 : { *(.debug_srcinfo) }
|
||||
.debug_sfnames 0 : { *(.debug_sfnames) }
|
||||
.debug_aranges 0 : { *(.debug_aranges) }
|
||||
.debug_pubnames 0 : { *(.debug_pubnames) }
|
||||
.debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) }
|
||||
.debug_abbrev 0 : { *(.debug_abbrev) }
|
||||
.debug_line 0 : { *(.debug_line .debug_line.* .debug_line_end) }
|
||||
.debug_frame 0 : { *(.debug_frame) }
|
||||
.debug_str 0 : { *(.debug_str) }
|
||||
.debug_loc 0 : { *(.debug_loc) }
|
||||
.debug_macinfo 0 : { *(.debug_macinfo) }
|
||||
.debug_weaknames 0 : { *(.debug_weaknames) }
|
||||
.debug_funcnames 0 : { *(.debug_funcnames) }
|
||||
.debug_typenames 0 : { *(.debug_typenames) }
|
||||
.debug_varnames 0 : { *(.debug_varnames) }
|
||||
.debug_pubtypes 0 : { *(.debug_pubtypes) }
|
||||
.debug_ranges 0 : { *(.debug_ranges) }
|
||||
.debug_macro 0 : { *(.debug_macro) }
|
||||
.debug_addr 0 : { *(.debug_addr) }
|
||||
.debug_loclists 0 : { *(.debug_loclists) }
|
||||
.debug_rnglists 0 : { *(.debug_rnglists) }
|
||||
.debug_line_str 0 : { *(.debug_line_str) }
|
||||
.debug_extra 0 : { *(.debug_line_str) }
|
||||
.debug_pubtypes 0 : { *(.debug_pubtypes) }
|
||||
.gnu.attributes 0 : { KEEP(*(.gnu.attributes)) }
|
||||
|
||||
/DISCARD/ : {
|
||||
*(.*)
|
||||
}
|
||||
}
|
||||
|
||||
textsz = SIZEOF(.text);
|
||||
rosize = SIZEOF(.rodata);
|
||||
filesz = SIZEOF(.rodata) + SIZEOF(.text);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue