jart / blink

tiniest x86-64-linux emulator
ISC License
7k stars 225 forks source link

Building cosmo under blink fails (aarch64-linux) #68

Closed ingenieroariel closed 1 year ago

ingenieroariel commented 1 year ago

Blink version:

 ./c/blink/o/blink/blink -m ./blinkroot/bin/busybox uname -a
Linux m1n1n0 4.5.0-blink-0.9.0 #414 DEFAULT Sat Feb 18 00:15:38 UTC 2023 x86_64 GNU/Linux

Steps done to trigger the problem:

nix build nixpkgs#pkgsStatic.pkgsCross.musl64.busybox
cp result/bin/* ~/blinkroot
export BLINK_OVERLAYS=$HOME/blinkroot
 ./c/blink/o/blink/blink -m ./blinkroot/bin/busybox sh
./build/bootstrap/make.com
( snip )

   314,364⏰    312,622⏳  58,640k     608iop o/third_party/gcc/bin/x86_64-linux-musl-gcc -msse3 -fno-math-errno -fno-trapping-math -fno-fp-int-builtin-inexact -fno-ident -fno-common -fno-gnu-unique -fstrict-aliasing -fstrict-overflow -fno-semantic-interposition -mno-tls-direct-seg-refs -Wall -Werror -fdebug-prefix-map=/cosmopolitan= -frecord-gcc-switches -fno-schedule-insns2 -fno-optimize-sibling-calls -mno-omit-leaf-frame-pointer -O2 -fno-code-hoisting -g -gdwarf-4 -gdescribe-dies -DCOSMO -DMODE="" -DIMAGE_BASE_VIRTUAL=0x400000 -nostdinc -iquote . -DSYSDEBUG -include libc/integral/normalize.inc -Wa,-W -Wa,-I. -Wa,--noexecstack -Wa,--nocompress-debug-sections -c -o /cosmopolitan/o/tmp/o__ape_ape_o.pk6pju/o__ape_ape.o ape/ape.S -fdiagnostics-color=always -pg -D__PG__ -mno-red-zone -D__MNO_RED_ZONE__ -fno-omit-frame-pointer -D__FNO_OMIT_FRAME_POINTER__
   369,387⏰    368,056⏳  58,560k     320iop o/third_party/gcc/bin/x86_64-linux-musl-gcc -D__LINKER__ -E -msse3 -fno-math-errno -fno-trapping-math -fno-fp-int-builtin-inexact -fno-ident -fno-common -fno-gnu-unique -fstrict-aliasing -fstrict-overflow -fno-semantic-interposition -mno-tls-direct-seg-refs -Wall -Werror -fdebug-prefix-map=/cosmopolitan= -frecord-gcc-switches -fno-schedule-insns2 -fno-optimize-sibling-calls -mno-omit-leaf-frame-pointer -O2 -fno-code-hoisting -DCOSMO -DMODE="" -DIMAGE_BASE_VIRTUAL=0x400000 -nostdinc -iquote . -DSYSDEBUG -include libc/integral/normalize.inc -P -xc -o /cosmopolitan/o/tmp/o__ape_ape_lds.mjplio/o__ape_ape.lds ape/ape.lds -fdiagnostics-color=always -pg -D__PG__ -mno-red-zone -D__MNO_RED_ZONE__ -fno-omit-frame-pointer -D__FNO_OMIT_FRAME_POINTER__
   372,451⏰    371,064⏳  58,528k     320iop o/third_party/gcc/bin/x86_64-linux-musl-gcc -D__LINKER__ -E -msse3 -fno-math-errno -fno-trapping-math -fno-fp-int-builtin-inexact -fno-ident -fno-common -fno-gnu-unique -fstrict-aliasing -fstrict-overflow -fno-semantic-interposition -mno-tls-direct-seg-refs -Wall -Werror -fdebug-prefix-map=/cosmopolitan= -frecord-gcc-switches -fno-schedule-insns2 -fno-optimize-sibling-calls -mno-omit-leaf-frame-pointer -O2 -fno-code-hoisting -DCOSMO -DMODE="" -DIMAGE_BASE_VIRTUAL=0x400000 -nostdinc -iquote . -DSYSDEBUG -UCOSMO -include libc/integral/normalize.inc -P -xc -o /cosmopolitan/o/tmp/o__ape_public_ape_lds.kogijv/o__ape_public_ape.lds ape/public/ape.lds -fdiagnostics-color=always -pg -D__PG__ -mno-red-zone -D__MNO_RED_ZONE__ -fno-omit-frame-pointer -D__FNO_OMIT_FRAME_POINTER__
ape/loader.c: In function 'Utoa':
ape/loader.c:237:16: warning: division by zero [-Wdiv-by-zero]
  237 |     p[i++] = x % 10 + '0';
      |                ^
ape/loader.c:238:11: warning: division by zero [-Wdiv-by-zero]
  238 |     x = x / 10;
      |           ^
E2023-02-17T20:10:58.261366:blink/throw.c:96:71500 SEGMENTATION FAULT AT ADDRESS 300000001
    PC b7e9b3 movzwl (%rdi),%eax 0f b7 07 83 3c 85 c0 80
    AX 000020000004ec90  CX 0000000000000003  DX 0000000000000000  BX 0000000000000000
    SP 00004fffffffe860  BP 00002000000701c8  SI 0000000000000000  DI 0000000300000001
    R8 0000000000000001  R9 0000000000000009 R10 0000000000000042 R11 0000000000000000
    R12 00002000001524b0 R13 0000000000000000 R14 0000000000000000 R15 0000000000000000
    FS 00002000000003a0  GS 0000000000000000 OPS 230095           JIT 0               
    o/third_party/gcc/bin/../libexec/gcc/x86_64-linux-musl/9.2.0/cc1
    2000000701c8 000000b7e9b3 UNKNOWN [STRAY]
    010000000022 200000067690 UNKNOWN [STRAY] [MISALIGN] [CORRUPT FRAME POINTER]
000000400000-000001a2ffff   22m  19% rx  o/third_party/gcc/bin/../libexec/gcc/x86_64-linux-musl/9.2.0/cc1
000001c2f000-000001d94fff 1432k  26% rw  
110001000000-11000101ffff  128k  25% rwx 
200000000000-200000000fff  4096 100% rw  
200000004000-200000004fff  4096 100% rw  
200000008000-200000008fff  4096 100% rw  
20000000c000-20000000dfff  8192 100% rw  
200000010000-200000011fff  8192 100% rw  
200000014000-200000018fff   20k 100% rw  
20000001c000-20000003cfff  132k 100% rw  
200000040000-200000048fff   36k 100% rw  
20000004c000-200000265fff 2152k  55% rw  
200000268000-200000269fff  8192 100% rw  
20000026c000-20000026dfff  8192 100% rw  
200000270000-2000002a5fff  216k  73% rw  
2000002a8000-2000002a9fff  8192 100% rw  
2000002ac000-20000030dfff  392k  25% rw  
4fffff800000-4fffffffffff 8192k   1% rw  [stack]
ape/loader.c: In function 'Exit':
ape/loader.c:280:3: internal compiler error: Segmentation fault
  280 |   __builtin_unreachable();
      |   ^~~~~~~~~~~~~~~~~~~~~
Please submit a full bug report,
with preprocessed source if appropriate.
See <https://gcc.gnu.org/bugs/> for instructions.

`make MODE= -j8 o//ape/loader.o` exited with 1:
o/third_party/gcc/bin/x86_64-linux-musl-gcc -DSUPPORT_VECTOR=0b01111001 -g -DNDEBUG -iquote. -Wall -Wextra -fpie -Os -fno-code-hoisting -ffreestanding -mgeneral-regs-only -fno-ident -fno-gnu-unique -c -o /cosmopolitan/o/tmp/o__ape_loader_o.3bihje/o__ape_loader.o ape/loader.c -fdiagnostics-color=always -mno-red-zone -D__MNO_RED_ZONE__ -fomit-frame-pointer
consumed 159,626µs wall time
ballooned to 69,616kb in size
needed 158,779us cpu (16% kernel)
caused 3,055 page faults (99% memcpy)
18 context switches (27% consensual)
performed 0 read and 32 write i/o operations

make.com: *** [ape/ape.mk:181: o//ape/loader.o] Error 1
make.com: *** Deleting file 'o//ape/loader.o'
jart commented 1 year ago

Building cosmo under blink on x86 produces a lot of interesting gcc errors too. I'm going to look into this. It's possible there's some kind of opcode bug.

jart commented 1 year ago

So far the minimum steps to reproduce are:

  1. You need the GCC 9.2.0 cc1 binary
  2. Use it to build a file containing either of the following codes:
// reproduce no. 1
struct hi {
  int there : 1;
};

// reproduce no. 2
unsigned long strtoul(const char *, char **, int)
    __attribute__((__nonnull__(1)));

Under Blink, GCC 9.2.0 (specifically) reads the 1's above as 0. Then prints errors accordingly.

I'm currently building GCC 9.2.0 with more debug symbols to see if I can narrow down where things are going wrong.