mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-01-31 03:27:39 +00:00
Remove feature for embedding blink in ape scripts
Embedding Blink builds in Cosmo executables was a failed experiment. It turned out to be easier than expected to let the mono repo have support for multiple architectures. Blink still works great; it's supported and recommended; just please use it as a separate program. For example, you can use Blink to run Cosmo binaries on architectures like i486 / s390x.
This commit is contained in:
parent
2719080986
commit
f27808c4d2
8 changed files with 4 additions and 188 deletions
10
ape/BUILD.mk
10
ape/BUILD.mk
|
@ -173,8 +173,6 @@ o/$(MODE)/ape/ape-no-modify-self.o: \
|
||||||
libc/runtime/mman.internal.h \
|
libc/runtime/mman.internal.h \
|
||||||
libc/runtime/pc.internal.h \
|
libc/runtime/pc.internal.h \
|
||||||
libc/sysv/consts/prot.h \
|
libc/sysv/consts/prot.h \
|
||||||
ape/blink-linux-aarch64.gz \
|
|
||||||
ape/blink-xnu-aarch64.gz \
|
|
||||||
o/$(MODE)/ape/ape.elf
|
o/$(MODE)/ape/ape.elf
|
||||||
@$(COMPILE) \
|
@$(COMPILE) \
|
||||||
-AOBJECTIFY.S \
|
-AOBJECTIFY.S \
|
||||||
|
@ -202,9 +200,7 @@ o/$(MODE)/ape/ape-copy-self.o: \
|
||||||
libc/runtime/e820.internal.h \
|
libc/runtime/e820.internal.h \
|
||||||
libc/runtime/mman.internal.h \
|
libc/runtime/mman.internal.h \
|
||||||
libc/runtime/pc.internal.h \
|
libc/runtime/pc.internal.h \
|
||||||
libc/sysv/consts/prot.h \
|
libc/sysv/consts/prot.h
|
||||||
ape/blink-linux-aarch64.gz \
|
|
||||||
ape/blink-xnu-aarch64.gz
|
|
||||||
@$(COMPILE) \
|
@$(COMPILE) \
|
||||||
-AOBJECTIFY.S \
|
-AOBJECTIFY.S \
|
||||||
$(OBJECTIFY.S) \
|
$(OBJECTIFY.S) \
|
||||||
|
@ -263,10 +259,6 @@ endif
|
||||||
o/$(MODE)/ape/ape.o: ape/ape.S
|
o/$(MODE)/ape/ape.o: ape/ape.S
|
||||||
@$(COMPILE) -AOBJECTIFY.S $(OBJECTIFY.S) $(OUTPUT_OPTION) -c $<
|
@$(COMPILE) -AOBJECTIFY.S $(OBJECTIFY.S) $(OUTPUT_OPTION) -c $<
|
||||||
|
|
||||||
o/$(MODE)/ape/ape.o: \
|
|
||||||
ape/blink-linux-aarch64.gz \
|
|
||||||
ape/blink-xnu-aarch64.gz
|
|
||||||
|
|
||||||
o/$(MODE)/ape/ape.lds: \
|
o/$(MODE)/ape/ape.lds: \
|
||||||
ape/ape.lds \
|
ape/ape.lds \
|
||||||
ape/macros.internal.h \
|
ape/macros.internal.h \
|
||||||
|
|
31
ape/ape.S
31
ape/ape.S
|
@ -700,36 +700,9 @@ apesh: .ascii "\n@\n#'\"\n" // sixth edition shebang
|
||||||
#endif /* APE_NO_MODIFY_SELF */
|
#endif /* APE_NO_MODIFY_SELF */
|
||||||
.ascii "exit $?\n"
|
.ascii "exit $?\n"
|
||||||
.ascii "fi\n" // x86_64
|
.ascii "fi\n" // x86_64
|
||||||
// ...
|
.ascii "echo error: this ape binary only supports x86_64 >&2\n"
|
||||||
// decentralized section (.apesh)
|
|
||||||
// ...
|
|
||||||
.ascii "PHDRS='' <<'@'\n"
|
|
||||||
.endobj apesh
|
|
||||||
|
|
||||||
// elf program headers get inserted here
|
|
||||||
// because they need to be in the first 4096 bytes
|
|
||||||
.section .emushprologue,"a",@progbits
|
|
||||||
emush: .ascii "\n@\n#'\"\n"
|
|
||||||
.ascii "s=$(uname -s 2>/dev/null) || s=Darwin\n"
|
|
||||||
// our script is running on a non-x86_64 architecture
|
|
||||||
// 1. `dd` out the appropriate blink vm blob
|
|
||||||
// 2. gunzip the blink virtual machine executable
|
|
||||||
// 3. relaunch this program inside the blink vm
|
|
||||||
.ascii "o=\"$(command -v \"$0\")\"\n"
|
|
||||||
.ascii "e=\"${TMPDIR:-${HOME:-.}}/.ape-blink-1.0.0\"\n"
|
|
||||||
.previous
|
|
||||||
// ...
|
|
||||||
// decentralized section (.emush)
|
|
||||||
// - __static_yoink("blink_linux_aarch64"); // for raspberry pi
|
|
||||||
// - __static_yoink("blink_xnu_aarch64"); // is apple silicon
|
|
||||||
// ...
|
|
||||||
.section .emushepilogue,"a",@progbits
|
|
||||||
.ascii "echo \"$0: this ape binary lacks $m support\" >&2\n"
|
|
||||||
.rept 16
|
|
||||||
.ascii "exit 127\n"
|
|
||||||
.endr
|
|
||||||
.ascii "exit 1\n"
|
.ascii "exit 1\n"
|
||||||
.previous
|
.endobj apesh
|
||||||
|
|
||||||
#ifdef APE_LOADER
|
#ifdef APE_LOADER
|
||||||
.section .ape.loader,"a",@progbits
|
.section .ape.loader,"a",@progbits
|
||||||
|
|
29
ape/ape.lds
29
ape/ape.lds
|
@ -229,7 +229,6 @@ SECTIONS {
|
||||||
|
|
||||||
/* Real Mode */
|
/* Real Mode */
|
||||||
KEEP(*(.head))
|
KEEP(*(.head))
|
||||||
KEEP(*(.apesh))
|
|
||||||
KEEP(*(.text.head))
|
KEEP(*(.text.head))
|
||||||
|
|
||||||
/* Executable & Linkable Format */
|
/* Executable & Linkable Format */
|
||||||
|
@ -238,10 +237,6 @@ SECTIONS {
|
||||||
KEEP(*(.elf.phdrs))
|
KEEP(*(.elf.phdrs))
|
||||||
ape_phdrs_end = .;
|
ape_phdrs_end = .;
|
||||||
|
|
||||||
KEEP(*(.emushprologue))
|
|
||||||
KEEP(*(.emush))
|
|
||||||
KEEP(*(.emushepilogue))
|
|
||||||
|
|
||||||
/* OpenBSD */
|
/* OpenBSD */
|
||||||
. = ALIGN(. != 0 ? __SIZEOF_POINTER__ : 0);
|
. = ALIGN(. != 0 ? __SIZEOF_POINTER__ : 0);
|
||||||
ape_note = .;
|
ape_note = .;
|
||||||
|
@ -301,7 +296,6 @@ SECTIONS {
|
||||||
KEEP(*(.textwindowsprologue))
|
KEEP(*(.textwindowsprologue))
|
||||||
*(.text.windows)
|
*(.text.windows)
|
||||||
KEEP(*(.textwindowsepilogue))
|
KEEP(*(.textwindowsepilogue))
|
||||||
KEEP(*(.blink))
|
|
||||||
*(SORT_BY_ALIGNMENT(.text.modernity))
|
*(SORT_BY_ALIGNMENT(.text.modernity))
|
||||||
*(SORT_BY_ALIGNMENT(.text.modernity.*))
|
*(SORT_BY_ALIGNMENT(.text.modernity.*))
|
||||||
*(SORT_BY_ALIGNMENT(.text.hot))
|
*(SORT_BY_ALIGNMENT(.text.hot))
|
||||||
|
@ -613,29 +607,6 @@ SHSTUB2(ape_loader_dd_count,
|
||||||
? ROUNDUP(ape_loader_end - ape_loader, CONSTANT(COMMONPAGESIZE)) / 64
|
? ROUNDUP(ape_loader_end - ape_loader, CONSTANT(COMMONPAGESIZE)) / 64
|
||||||
: 0);
|
: 0);
|
||||||
|
|
||||||
#if defined(APE_IS_SHELL_SCRIPT) && !IsTiny()
|
|
||||||
|
|
||||||
#define IDENTITY(X) X
|
|
||||||
|
|
||||||
#define APE_DECLARE_FIXED_DECIMAL(F, X) \
|
|
||||||
X##_quad = DEFINED(X) ? ((F(X) < 1000000000 ? 32 : F(X) / 1000000000 % 10 + 48) << 000 | \
|
|
||||||
(F(X) < 100000000 ? 32 : F(X) / 100000000 % 10 + 48) << 010 | \
|
|
||||||
(F(X) < 10000000 ? 32 : F(X) / 10000000 % 10 + 48) << 020 | \
|
|
||||||
(F(X) < 1000000 ? 32 : F(X) / 1000000 % 10 + 48) << 030 | \
|
|
||||||
(F(X) < 100000 ? 32 : F(X) / 100000 % 10 + 48) << 040 | \
|
|
||||||
(F(X) < 10000 ? 32 : F(X) / 10000 % 10 + 48) << 050 | \
|
|
||||||
(F(X) < 1000 ? 32 : F(X) / 1000 % 10 + 48) << 060 | \
|
|
||||||
(F(X) < 100 ? 32 : F(X) / 100 % 10 + 48) << 070) : 0; \
|
|
||||||
X##_short = DEFINED(X) ? ((F(X) < 10 ? 32 : F(X) / 10 % 10 + 48) << 000 | \
|
|
||||||
(F(X) % 10 + 48) << 010) : 0
|
|
||||||
|
|
||||||
APE_DECLARE_FIXED_DECIMAL(RVA, blink_linux_aarch64);
|
|
||||||
APE_DECLARE_FIXED_DECIMAL(IDENTITY, blink_linux_aarch64_size);
|
|
||||||
APE_DECLARE_FIXED_DECIMAL(RVA, blink_xnu_aarch64);
|
|
||||||
APE_DECLARE_FIXED_DECIMAL(IDENTITY, blink_xnu_aarch64_size);
|
|
||||||
|
|
||||||
#endif /* APE_IS_SHELL_SCRIPT */
|
|
||||||
|
|
||||||
#if SupportsMetal()
|
#if SupportsMetal()
|
||||||
v_ape_realsectors = MIN(0x70000 - IMAGE_BASE_REAL, ROUNDUP(RVA(_ezip), 512)) / 512;
|
v_ape_realsectors = MIN(0x70000 - IMAGE_BASE_REAL, ROUNDUP(RVA(_ezip), 512)) / 512;
|
||||||
v_ape_realbytes = v_ape_realsectors * 512;
|
v_ape_realbytes = v_ape_realsectors * 512;
|
||||||
|
|
|
@ -59,9 +59,7 @@ for x in .ape \
|
||||||
.ape-1.7 \
|
.ape-1.7 \
|
||||||
.ape-1.8 \
|
.ape-1.8 \
|
||||||
.ape-1.9 \
|
.ape-1.9 \
|
||||||
.ape-1.10 \
|
.ape-1.10; do
|
||||||
.ape-blink-0.9.2 \
|
|
||||||
.ape-blink-1.0.0; do
|
|
||||||
rm -f \
|
rm -f \
|
||||||
~/$x \
|
~/$x \
|
||||||
/tmp/$x \
|
/tmp/$x \
|
||||||
|
|
Binary file not shown.
Binary file not shown.
|
@ -1,60 +0,0 @@
|
||||||
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
|
|
||||||
│ vi: set noet ft=asm ts=8 sw=8 fenc=utf-8 :vi │
|
|
||||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
|
||||||
│ 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 │
|
|
||||||
│ above copyright notice and this permission notice appear in all copies. │
|
|
||||||
│ │
|
|
||||||
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
|
|
||||||
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
|
|
||||||
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
|
|
||||||
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
|
|
||||||
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
|
|
||||||
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
|
|
||||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
|
||||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
|
||||||
#include "libc/macros.internal.h"
|
|
||||||
|
|
||||||
// Blink Virtual Machine for Linux Arm64
|
|
||||||
//
|
|
||||||
// If you want to support Raspberry Pi by embedding an emulator
|
|
||||||
// in your APE binary that runs automatically, then put this:
|
|
||||||
//
|
|
||||||
// __static_yoink("blink_linux_aarch64");
|
|
||||||
//
|
|
||||||
// In your main.c file, to pull it into linkage from the static
|
|
||||||
// archive. Alternatively, you may simply add blink_linux_aarch64.o
|
|
||||||
// as an explicit linker argument.
|
|
||||||
|
|
||||||
.section .blink,"a",@progbits
|
|
||||||
.globl blink_linux_aarch64_size
|
|
||||||
blink_linux_aarch64:
|
|
||||||
.incbin "ape/blink-linux-aarch64.gz"
|
|
||||||
.endobj blink_linux_aarch64,globl
|
|
||||||
blink_linux_aarch64_size = . - blink_linux_aarch64
|
|
||||||
|
|
||||||
.section .emush,"a",@progbits
|
|
||||||
.ascii "if [ \"$s\" = Linux ]; then\n"
|
|
||||||
.ascii "if [ \"$m\" = aarch64 ] || [ \"$m\" = arm64 ]; then\n"
|
|
||||||
.ascii "if ! [ -x \"$e\" ]; then\n"
|
|
||||||
.ascii "echo \"extracting blink-linux-aarch64 to ${e}\" >&2\n"
|
|
||||||
.ascii "dd if=\"$o\" bs=1 skip=$(("
|
|
||||||
.weak blink_linux_aarch64_quad
|
|
||||||
.quad blink_linux_aarch64_quad
|
|
||||||
.weak blink_linux_aarch64_short
|
|
||||||
.short blink_linux_aarch64_short
|
|
||||||
.ascii ")) count=$(("
|
|
||||||
.weak blink_linux_aarch64_size_quad
|
|
||||||
.quad blink_linux_aarch64_size_quad
|
|
||||||
.weak blink_linux_aarch64_size_short
|
|
||||||
.short blink_linux_aarch64_size_short
|
|
||||||
.ascii ")) conv=notrunc 2>/dev/null | gunzip >\"$e.$$\"\n"
|
|
||||||
.ascii "mv -f \"$e.$$\" \"$e\"\n"
|
|
||||||
.ascii "chmod +x \"$e\"\n"
|
|
||||||
.ascii "fi\n"
|
|
||||||
.ascii "exec \"$e\" \"$o\" \"$@\"\n"
|
|
||||||
.ascii "fi\n"
|
|
||||||
.ascii "fi\n"
|
|
|
@ -1,58 +0,0 @@
|
||||||
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
|
|
||||||
│ vi: set noet ft=asm ts=8 sw=8 fenc=utf-8 :vi │
|
|
||||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
|
||||||
│ 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 │
|
|
||||||
│ above copyright notice and this permission notice appear in all copies. │
|
|
||||||
│ │
|
|
||||||
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
|
|
||||||
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
|
|
||||||
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
|
|
||||||
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
|
|
||||||
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
|
|
||||||
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
|
|
||||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
|
||||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
|
||||||
#include "libc/macros.internal.h"
|
|
||||||
|
|
||||||
// Blink Virtual Machine for Apple Silicon
|
|
||||||
//
|
|
||||||
// If you want to support Apple M1 by embedding an emulator in
|
|
||||||
// your APE binary that runs automatically, then put this:
|
|
||||||
//
|
|
||||||
// __static_yoink("blink_xnu_aarch64");
|
|
||||||
//
|
|
||||||
// In your main.c file, to pull it into linkage from the static
|
|
||||||
// archive. Alternatively, you may simply add blink_xnu_aarch64.o
|
|
||||||
// as an explicit linker argument.
|
|
||||||
|
|
||||||
.section .blink,"a",@progbits
|
|
||||||
.globl blink_xnu_aarch64_size
|
|
||||||
blink_xnu_aarch64:
|
|
||||||
.incbin "ape/blink-xnu-aarch64.gz"
|
|
||||||
.endobj blink_xnu_aarch64,globl
|
|
||||||
blink_xnu_aarch64_size = . - blink_xnu_aarch64
|
|
||||||
|
|
||||||
.section .emush,"a",@progbits
|
|
||||||
.ascii "if [ \"$s\" = Darwin ] && [ \"$m\" = arm64 ]; then\n"
|
|
||||||
.ascii "if ! [ -x \"$e\" ]; then\n"
|
|
||||||
.ascii "echo \"extracting blink-darwin-aarch64 to ${e}\" >&2\n"
|
|
||||||
.ascii "dd if=\"$o\" bs=1 skip=$(("
|
|
||||||
.weak blink_xnu_aarch64_quad
|
|
||||||
.quad blink_xnu_aarch64_quad
|
|
||||||
.weak blink_xnu_aarch64_short
|
|
||||||
.short blink_xnu_aarch64_short
|
|
||||||
.ascii ")) count=$(("
|
|
||||||
.weak blink_xnu_aarch64_size_quad
|
|
||||||
.quad blink_xnu_aarch64_size_quad
|
|
||||||
.weak blink_xnu_aarch64_size_short
|
|
||||||
.short blink_xnu_aarch64_size_short
|
|
||||||
.ascii ")) conv=notrunc 2>/dev/null | gunzip >\"$e.$$\"\n"
|
|
||||||
.ascii "mv -f \"$e.$$\" \"$e\"\n"
|
|
||||||
.ascii "chmod +x \"$e\"\n"
|
|
||||||
.ascii "fi\n"
|
|
||||||
.ascii "exec \"$e\" \"$o\" \"$@\"\n"
|
|
||||||
.ascii "fi\n"
|
|
Loading…
Reference in a new issue