nanovms / nanos

A kernel designed to run one and only one application in a virtualized environment
https://nanos.org
Apache License 2.0
2.58k stars 133 forks source link

Build Problems: Stage 2 exceeds 64KB #2010

Closed ls-1801 closed 5 months ago

ls-1801 commented 5 months ago

I am running in issues when building nanos make run-noaccel on a different machine.

My local machine (Works here): GLIBC 2.36-9+deb12u4 GCC 12.2

STRIP   /home/ls/nanos/output/platform/pc/boot/stage2.strip
OBJCOPY /home/ls/nanos/output/platform/pc/boot/stage2.bin
DD  /home/ls/nanos/output/platform/pc/boot/stage2.pad
122+1 records in
123+0 records out
62976 bytes (63 kB, 62 KiB) copied, 0.000161789 s, 389 MB/s

On the server (does not work): GLIBC 2.31-0ubuntu9.9 GCC 9.4

STRIP   /data-ssd/ls/nanos/output/platform/pc/boot/stage2.strip
OBJCOPY /data-ssd/ls/nanos/output/platform/pc/boot/stage2.bin
DD  /data-ssd/lukas/dima/nanos/output/platform/pc/boot/stage2.pad
128+1 records in
129+0 records out
66048 bytes (66 kB, 64 KiB) copied, 0.000546148 s, 121 MB/s

stage2 exceeds 64KB

Is there anything i can do to reduce the stage2 size? Or have i just picked a bad version of compiler and libc, that does not generate the smaller binary?

francescolavra commented 5 months ago

One thing you could do is disabling the assertion checks in the bootloader code, by adding -DNO_ASSERT to the bootloader compiler flags at https://github.com/nanovms/nanos/blob/8a66481fd4f1d657122fc37998e13ee452b1768b/platform/pc/boot/Makefile#L34. Alternatively, since the 64KB size limit only applies to non-Nitro AWS instances, if you are not running your workloads on non-Nitro AWS instances you could just remove the binary size check at https://github.com/nanovms/nanos/blob/8a66481fd4f1d657122fc37998e13ee452b1768b/platform/pc/boot/Makefile#L120.

ls-1801 commented 5 months ago

Alright cool, stage2 is down to 44KiB. How likely is it to hit any of the asserts?

francescolavra commented 5 months ago

Most asserts are there to detect bugs in the code, and most are in code shared between the bootloader and the kernel. Given that the bootloader is relatively simple and executes in a fixed sequence of steps, I would say the likelihood of any of the asserts to be hit is very low.

francescolavra commented 5 months ago

https://github.com/nanovms/nanos/pull/2012 decreases the bootloader size and allows building with gcc-9.