Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1987610imm; Thu, 23 Aug 2018 12:09:32 -0700 (PDT) X-Google-Smtp-Source: AA+uWPxDMNOvbcs/DegjIhr84DkD9b+rwDQuWx8HeZSMtQd+OlAt4t2fL1NpMWh7mR6NThHSgji5 X-Received: by 2002:a17:902:5501:: with SMTP id f1-v6mr59175538pli.219.1535051372039; Thu, 23 Aug 2018 12:09:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535051372; cv=none; d=google.com; s=arc-20160816; b=yentsrxpBMS6Ih4n12D6JJMF4V1H5NbgsY+gE/c+DnHXhj/4OtBhjJoGDF63TzKh3B t2Lk5B3OmYqUfaaT/rSI52zicbEeqjkuTOYadQ78d9KwW2Rrfef3U8b+6mJp+KwREHl4 FkDTeocqqpqrxUk7AV8AzpAVQ/K0Ntsspdd8ADKK4fan/NoSFqdvYO+bDR2olnmYKR/f btqWZ0TlmpbP/3PpVKvtZhB7a0y5gkxBgXompJN5GqciPJlvARZIbaWKchx6ZTwXqi4L 85tb5TFa3Uyqw26KM8/F2BoPE1zIzuF81EvkFPG5093khx3zlXVjuofDgUZAAufx9ZQm TcUA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=RFtbuMdVwkmi68M9+mYVfHntLWozJlPImPa3KqVKPqc=; b=qTkpFGFNTakNmDwL9KaadkNzev1IUKHCJVX98cxZbM/zQDqxXP1joSEXlAiIwDLteB eI8P0BdE1c+c8w+HuMtKYESnljQDVd9US08cwJPktgx8eEHX8wz/focslb988RYc5RcF 0RHgEX9RC11IYIGWlLqOZzJ7XqhFyolyNIIfXULOaPs4905t4amHYBeplcv1SON6dmsF dz2hij4mRjS7AXtAx0lcvuwtCgyVX0s3lpQ6AAtQSD6xwF3F0yrXmvI4TWOa66+p933b gTTg6YVIPeID8hftvTk4KsoEbPZGFPCotzNtQpNu7k4ZVN4mSVDXGPAG+mYayivMv9Hx 1yZg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e125-v6si5006034pgc.424.2018.08.23.12.09.16; Thu, 23 Aug 2018 12:09:32 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727427AbeHWWiM (ORCPT + 99 others); Thu, 23 Aug 2018 18:38:12 -0400 Received: from wtarreau.pck.nerim.net ([62.212.114.60]:32904 "EHLO 1wt.eu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726081AbeHWWiM (ORCPT ); Thu, 23 Aug 2018 18:38:12 -0400 Received: (from willy@localhost) by pcw.home.local (8.15.2/8.15.2/Submit) id w7NJ6vIk012063; Thu, 23 Aug 2018 21:06:57 +0200 Date: Thu, 23 Aug 2018 21:06:57 +0200 From: Willy Tarreau To: Adam Borowski Cc: "Paul E. McKenney" , nicolas.pitre@linaro.org, josh@joshtriplett.org, linux-kernel@vger.kernel.org Subject: Re: Kernel-only deployments? Message-ID: <20180823190657.GA12057@1wt.eu> References: <20180823174359.GA13033@linux.vnet.ibm.com> <20180823185417.y3ung3b553f2d24a@angband.pl> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180823185417.y3ung3b553f2d24a@angband.pl> User-Agent: Mutt/1.6.1 (2016-04-27) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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