From: Willy Tarreau <w@1wt.eu>
To: Adam Borowski <kilobyte@angband.pl>
Cc: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>,
nicolas.pitre@linaro.org, josh@joshtriplett.org,
linux-kernel@vger.kernel.org
Subject: Re: Kernel-only deployments?
Date: Thu, 23 Aug 2018 21:06:57 +0200 [thread overview]
Message-ID: <20180823190657.GA12057@1wt.eu> (raw)
In-Reply-To: <20180823185417.y3ung3b553f2d24a@angband.pl>
On Thu, Aug 23, 2018 at 08:54:17PM +0200, Adam Borowski wrote:
> .globl _start
> .data
> req: .8byte 999999999, 999999999
> .text
> _start:
> mov $35, %rax # syscall: nanosleep
> mov $req, %rdi
> xor %rsi, %rsi
> syscall
> jmp _start
>
>
> as sl.s -o sl.o
> ld sl.o -o init
>
> 'Ere you go, no libc needed. If your arch is not amd64, just say so.
>
> If you want to do anything more complex, though -- you really want musl
> or another lightweight libc instead. Glibc is utterly unfit for static
> linking.
Since there seems to be some interest about this, I'll repost this
here. I've developed a "nolibc" include file which implements most
common syscalls and string functions (those I use in early boot)
as static inlines so the resulting executable only contains the
code you really use :
http://git.formilux.org/?p=people/willy/nolibc.git;a=tree
Example :
$ echo "int main() { return sleep(3);}" | gcc -Os -nostdlib -include ../nolibc/nolibc.h -s -fno-exceptions -fno-asynchronous-unwind-tables -fno-unwind-tables -lgcc -o sleep -xc -
$ ls -l sleep
-rwxr-xr-x 1 willy users 664 Aug 23 20:37 sleep
It's actually used by my pre-init loader that is embedded into the
initramfs of all my kernels, to untar the modules and switch to the
initrd or rootfs. This way all my modules are contained into the
kernel image and I can easily use many different kernels with rootfs
without having to install modules.
Just in case someone curious would want to know more about it, the
(old and horrible) preinit is here :
http://git.formilux.org/?p=dist/src/flxutils.git;a=tree;f=init;h=9dc8fbae6383d9b4d56d34cc6c3d59585318bef8;hb=HEAD
And the (old and ugly) build script is here :
http://git.formilux.org/?p=dist/techno.git;a=tree;f=scripts/kernel;hb=HEAD
Yes it's aging a lot now but it's still very convenient ;-)
Willy
next prev parent reply other threads:[~2018-08-23 19:07 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-08-23 17:43 Kernel-only deployments? Paul E. McKenney
2018-08-23 18:16 ` Geert Uytterhoeven
2018-08-23 18:43 ` Paul E. McKenney
2018-08-23 18:42 ` Nicolas Pitre
2018-08-23 20:37 ` Paul E. McKenney
2018-08-23 18:54 ` Adam Borowski
2018-08-23 19:06 ` Willy Tarreau [this message]
2023-02-15 2:35 ` Zhangjin Wu
2023-02-15 9:47 ` Willy Tarreau
2023-02-16 13:09 ` Zhangjin Wu
2018-08-23 19:16 ` Josh Triplett
2018-08-23 20:39 ` Paul E. McKenney
2018-08-23 20:39 ` Paul E. McKenney
2018-08-23 19:12 ` Josh Triplett
2018-08-23 20:45 ` Paul E. McKenney
2018-08-23 19:22 ` Ray Clinton
2018-08-23 20:49 ` Paul E. McKenney
2018-08-23 19:52 ` Bernd Petrovitsch
2018-08-23 20:54 ` Paul E. McKenney
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180823190657.GA12057@1wt.eu \
--to=w@1wt.eu \
--cc=josh@joshtriplett.org \
--cc=kilobyte@angband.pl \
--cc=linux-kernel@vger.kernel.org \
--cc=nicolas.pitre@linaro.org \
--cc=paulmck@linux.vnet.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox