MyGit

1.0.0

jart/blink

版本发布时间: 2023-06-05 04:49:54

jart/blink最新发布版本:1.1.0(2024-01-21 14:45:06)

The Blink Team (short for Blinkenlights) is proud to announce its first milestone release, version 1.0. Blink is a brand-new unprivileged userspace virtual machine that can emulate x86-64-linux binaries on any POSIX platform. It's basically a 220kb dependency-free static binary that implements about 600 x86 instructions and 180 Linux system calls, which makes Blink pretty good at running simple command line programs.

./configure        # use `./configure --help | less` for help
make -j8           # build blink and blinkenlights
doas make install  # doas is modern sudo
blink program      # use `man blink` for help

image

Blink has a snappy JIT that in some cases goes 2x faster than Qemu for use-cases like ephemeral programs. That's because Blink has a baseline JIT that generates code fast using a printf-style DSL. That means Blink has an approachable codebase since we've only got 63,500 lines of ANSI C11 code. Blink currently doesn't even try to perform optimizations, which makes this project a total greenfield for algorithms. The only complicated things it does right now are (1) trapping segfaults to RWX memory fast, (2) managing a trie of semaphores for tracking memory pages, and (3) storing JIT hooks in a multithreaded lockless hashtable. Here's a screenshot of Blink vs. Qemu running GCC's CC1 command. You'll notice that Blink is able to compile Hello World at least 2x faster.

image

While the blink command is headless, Blink also has a TUI interface (called blinkenlights) which lets you debug and visualize programs in real time. Here's an example of it running a bare metal Game of Life demo, written in Rust, which boots from BIOS in i8086 mode, bootstraps to long mode, and then draws to Blinkenlight's text-based CGA display.

man blinkenlights
blinkenlights -jmr third_party/gameoflife/gameoflife.bin
# Press CTRL-T several times for Turbo mode

image

Blinkenlights supports running the dynamically-linked binaries shipped by your Linux distro. Here's a screenshot of Blink executing the ls program on an actual Alpine Linux install. Alpine is such a great distro for Blink, since Musl Libc only uses the sane POSIX subset of Linux system calls that are easy for Blink to support.

blinkenlights ls  # on alpine linux

image

The best feature offered by the Blinkenlights TUI is reverse debugging. All you need to do is scroll wheel over the assembly display. Blink also profiles your program functions in real time if you press the p key. You can also control-wheel the memory panels to zoom out memory using a lanczos kernel.

https://github.com/jart/blink/assets/49262/bc6cf740-a4a8-4fdf-a52b-bad19e76f50c

Blink works best for command line programs, although Blink has some support for emulating GUI applications too. Here's a screenshot of Blink running the Emacs GUI on Debian Linux.

image

Unlike qemu-user (which only runs on Linux) Blink is able to run on other operating systems. Here's what happens if you build Blink on Cygwin (Windows) and then run Bash inside an Alpine Linux chroot. Blink emulates the Linux userspace well enough to fool neofetch, despite Blink being only a 250kb dependency-free executable. See also alpine-minirootfs-3.17.2-x86_64.tar.gz and https://justine.lol/bash-static-x86_64.elf

./configure --enable-vfs
make -j8 m=tiny
cc -pthread -pie   o/tiny/blink/blink.o o/tiny/blink/blink.a  -lrt -lm  -o o/tiny/blink/blink -lntdll  # xxx
PATH='/bin:/usr/bin' PS1='$? > ' o/tiny/blink/blink -C alpine-minirootfs-3.17.2-x86_64 bash

image

Blink works great on Apple Silicon too! Here's Blink fooling neofetch into thinking MacOS M1 is Alpine x86_64.

image

Obtaining Blink

Blink is released under the permissive ISC license. You may download the source code blink-1.0.0.tar.gz and build it yourself on a POSIX with a C11 compiler. You can also download prebuilt binaries attached below, e.g. blink-1.0-linux-x86_64.elf.gz and blink-1.0-linux-aarch64.elf.gz. Finally, if you want to build the ultra tiny version of Blink that's been advertised, then all you need is the following, which will produce a deterministic binary for Linux x86_64 that's 221 kilobytes. Please note tiny mode omits some cool features, like system call logging.

wget https://github.com/jart/blink/releases/download/1.0.0/blink-1.0.0.tar.gz
tar xvzf blink-1.0.0.tar.gz
cd blink-1.0.0
./configure MODE=tiny
make -j8 MODE=tiny o/tiny/x86_64/blink/blink
o/third_party/gcc/x86_64/bin/x86_64-linux-musl-strip o/tiny/x86_64/blink/blink
o/tiny/x86_64/blink/blink -v

If you want to build Blink as a 119kb binary, then run these commands:

./configure --disable-all MODE=tiny
make -j8 MODE=tiny o/tiny/x86_64/blink/blink
o//third_party/gcc/x86_64/bin/x86_64-linux-musl-strip o/tiny/x86_64/blink/blink
o/tiny/x86_64/blink/blink -v

Adopting Blink

One of the projects currently using Blink is Cosmopolitan Libc. Blink is more embeddable than qemu-x86_64 since Blink is 22x tinier in terms of binary footprint. So what Cosmo does is it vendors prebuilt Blink binaries inside each of the x86-64 executables it compiles. That way, whenever someone tries to run these programs on a different architecture like Arm, the Actually Portable Executable shell script wrapper will simple extract the appropriate blink binary and re-run itself.

Joining Blink

If you find Blink useful or interesting, then please join our Discord community https://discord.gg/HQNA9faw so you can say thanks and meet the team that built it, namely @jart, @trungnt2910, @tkchia, and @ghaerr. The Discord is called "Redbean" and Blink development happens in the #blink channel.

相关地址:原始地址 下载(tar) 下载(zip)

1、 blink-1.0-cygwin-x86_64.exe.gz 226.72KB

2、 blink-1.0-darwin-arm64.elf.gz 110.32KB

3、 blink-1.0-darwin-x86_64.elf.gz 252.03KB

4、 blink-1.0-freebsd-x86_64.elf.gz 872.92KB

5、 blink-1.0-linux-aarch64.elf.gz 1.13MB

6、 blink-1.0-linux-arm.elf.gz 1.03MB

7、 blink-1.0-linux-i486.elf.gz 956.01KB

8、 blink-1.0-linux-mips.elf.gz 1.13MB

9、 blink-1.0-linux-mips64.elf.gz 1.41MB

10、 blink-1.0-linux-mips64el.elf.gz 971.61KB

11、 blink-1.0-linux-mipsel.elf.gz 1.24MB

12、 blink-1.0-linux-powerpc.elf.gz 1.09MB

13、 blink-1.0-linux-powerpc64le.elf.gz 1.26MB

14、 blink-1.0-linux-s390x.elf.gz 1.09MB

15、 blink-1.0-linux-x86_64.elf.gz 1.09MB

16、 blink-1.0-openbsd-x86_64.elf.gz 912.81KB

17、 blink-1.0.0.tar.gz 2.85MB

18、 blink-1.0.bin.zip 31.51MB

19、 blink-1.0.pdf 41.18KB

20、 blink-1.0.ps 24.1KB

21、 blinkenlights-1.0-cygwin-x86_64.exe.gz 1.74MB

22、 blinkenlights-1.0-darwin-arm64.elf.gz 327.12KB

23、 blinkenlights-1.0-darwin-x86_64.elf.gz 307.97KB

24、 blinkenlights-1.0-freebsd-x86_64.elf.gz 1013.25KB

25、 blinkenlights-1.0-linux-aarch64.elf.gz 1.13MB

26、 blinkenlights-1.0-linux-arm.elf.gz 1.03MB

27、 blinkenlights-1.0-linux-i486.elf.gz 956.01KB

28、 blinkenlights-1.0-linux-mips.elf.gz 1.13MB

29、 blinkenlights-1.0-linux-mips64.elf.gz 1.41MB

30、 blinkenlights-1.0-linux-mips64el.elf.gz 971.62KB

31、 blinkenlights-1.0-linux-mipsel.elf.gz 1.24MB

32、 blinkenlights-1.0-linux-powerpc.elf.gz 1.09MB

33、 blinkenlights-1.0-linux-powerpc64le.elf.gz 1.26MB

34、 blinkenlights-1.0-linux-s390x.elf.gz 1.09MB

35、 blinkenlights-1.0-linux-x86_64.elf.gz 1.09MB

36、 blinkenlights-1.0-openbsd-x86_64.elf.gz 1.03MB

37、 blinkenlights-1.0.pdf 45.04KB

38、 blinkenlights-1.0.ps 32.57KB

查看:2023-06-05发行的版本