[Toybox] llvm regression test.

Rob Landley rob at landley.net
Mon May 4 22:06:22 PDT 2020


On 5/4/20 5:03 PM, Rob Landley wrote:
> $ root/x86_64/fs/bin/toybox echo hello
> hello
> $ sudo chroot root/x86_64/fs /init
> Segmentation fault
> 
> Looks like I've still got some work to do before the release...

No, I don't. I can't fix this.

A) Statically linked bionic is almost as big as glibc?

$
~/android/android-ndk-r21b/toolchains/llvm/prebuilt/linux-x86_64/bin/x86_64-linux-android-cc
hello.c --static
$ ls -l a.out
-rwxr-xr-x 1 landley landley 3955552 May  4 23:52 a.out
$ file a.out
a.out: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked,
not stripped
$ strip a.out
$ ls -l a.out
-rwxr-xr-x 1 landley landley 676904 May  4 23:52 a.out
$ ./a.out
hello

(glibc static hello world strips to 738384 bytes, With musl, 5240 bytes.)

B) the problem is if /dev/null isn't there, bionic's startup code segfaults
before reaching main().

$ mkdir empty
$ mv a.out empty
$ sudo chroot empty ./a.out
Segmentation fault
$ sudo strace chroot empty ./a.out
...
mprotect(0x4a7000, 4096, PROT_READ)     = 0
mprotect(0x4a7000, 4096, PROT_READ|PROT_WRITE) = 0
mprotect(0x4a7000, 4096, PROT_READ)     = 0
openat(AT_FDCWD, "/dev/null", O_RDWR)   = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/sys/fs/selinux/null", O_RDWR) = -1 ENOENT (No such file or
directory)
--- SIGSEGV {si_signo=SIGSEGV, si_code=SEGV_MAPERR, si_addr=0x80} ---
+++ killed by SIGSEGV +++
Segmentation fault
$ mknod empty/dev
$ sudo mknod empty/dev/null c 1 3
$ sudo chroot empty ./a.out
hello

Needless to say, this makes performing initramfs setup with a bionic binary
kinda awkward, since /dev isn't populated yet when PID 1 runs. (I sent a patch!
Three times! The kernel guys ignored it. https://lkml.org/lkml/2017/9/13/651 .)

Rob



More information about the Toybox mailing list