From nobody Fri Aug 18 06:23:24 2023 X-Original-To: emulation@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4RRsJL2sycz4qlyH; Fri, 18 Aug 2023 06:23:30 +0000 (UTC) (envelope-from felix@palmen-it.de) Received: from stef.palmen-it.de (stef.palmen-it.de [IPv6:2001:470:1f0b:bbb:1::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4RRsJK0TzWz4VFP; Fri, 18 Aug 2023 06:23:28 +0000 (UTC) (envelope-from felix@palmen-it.de) Authentication-Results: mx1.freebsd.org; dkim=pass header.d=palmen-it.de header.s=20200414 header.b=evTUD0+u; spf=pass (mx1.freebsd.org: domain of felix@palmen-it.de designates 2001:470:1f0b:bbb:1::1 as permitted sender) smtp.mailfrom=felix@palmen-it.de; dmarc=none DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=palmen-it.de; s=20200414; h=Content-Type:MIME-Version:Message-ID:Subject:Cc :To:From:Date:Sender:Reply-To:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=nwT9FkF5Qi34k+pnA8Y39ayvdFFOgl+X6YFOeZF8giQ=; b=evTUD0+uve/HR85n4ljoO9r971 KZ+IKYjyVkiq2zh8I8aDnsTqzdTA2BiEyuvexoybEZGOyxFDtHIFxG4jHLtU/cC6g5YHzt0WHz4EU uChB/uJb8s8h1vxT7y+PjiAgMCjQZNiCS0jzei343DKsZH66805t7ZMFK/w0Hi0bTEI8Sj2tQ7vDj YRgw+OFLsfdbTtCVVSJs8OIzIr8S4Jfpyhl8LkYKuGqgatf/dPb9pbumEO+HPsg8UqQLcLcakkBRM 71Cz+AT7gkOVeNojfkAnSVjUx5pBine2qZOex2PzcVQo4cozDHgmj6O8dGkarlug5/3BfOh6+/+Ib Bb8XI/0A==; Received: from [192.168.71.101] (helo=mail.home.palmen-it.de) by stef.palmen-it.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qWstJ-00A2RW-Ie; Fri, 18 Aug 2023 08:23:25 +0200 Received: from nexus.home.palmen-it.de ([192.168.99.2]) by mail.home.palmen-it.de with esmtpsa (TLS1.3) tls TLS_CHACHA20_POLY1305_SHA256 (Exim 4.96 (FreeBSD)) (envelope-from ) id 1qWstJ-0004iN-12; Fri, 18 Aug 2023 06:23:25 +0000 Date: Fri, 18 Aug 2023 08:23:24 +0200 From: Felix Palmen To: ports@freebsd.org Cc: emulation@freebsd.org Subject: Building a Linuxulator userland from source Message-ID: Mail-Followup-To: ports@freebsd.org, emulation@freebsd.org X-Face: /1K@t"h.}e~pR@]c7HorQ!T`F^RJCa'BCr#e>IKA{>C/9OTGB4|xh"y2{?1Z5M i2w"AH^pN_LlHR^{+f',_Np~;.B;!M/bL}*qk]p5*r7F5vW};{:@4u5S?T&f0$7BJ-71Q5SV]:v$`5 A0[DZ:=?S52x8HJ~5@^P_\T@MsjG{R( Organization: FreeBSD.org List-Id: Development of Emulators of other operating systems List-Archive: https://lists.freebsd.org/archives/freebsd-emulation List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-emulation@freebsd.org MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="4dabomp7b6hwux6v" Content-Disposition: inline User-Agent: NeoMutt/20230517 X-Spamd-Result: default: False [-7.50 / 15.00]; SIGNED_PGP(-2.00)[]; DWL_DNSWL_MED(-2.00)[palmen-it.de:dkim]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_MEDIUM(-1.00)[-1.000]; NEURAL_HAM_SHORT(-1.00)[-0.999]; MID_RHS_NOT_FQDN(0.50)[]; RCVD_DKIM_ARC_DNSWL_MED(-0.50)[]; FORGED_SENDER(0.30)[zirias@freebsd.org,felix@palmen-it.de]; R_DKIM_ALLOW(-0.20)[palmen-it.de:s=20200414]; R_SPF_ALLOW(-0.20)[+ip6:2001:470:1f0b:bbb:1::1]; RCVD_IN_DNSWL_MED(-0.20)[2001:470:1f0b:bbb:1::1:from]; MIME_GOOD(-0.20)[multipart/signed,text/plain]; FROM_HAS_DN(0.00)[]; DMARC_NA(0.00)[freebsd.org]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MLMMJ_DEST(0.00)[ports@freebsd.org,emulation@freebsd.org]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_NEQ_ENVFROM(0.00)[zirias@freebsd.org,felix@palmen-it.de]; RCVD_COUNT_TWO(0.00)[2]; HAS_ORG_HEADER(0.00)[]; TO_DN_NONE(0.00)[]; ARC_NA(0.00)[]; RCPT_COUNT_TWO(0.00)[2]; MIME_TRACE(0.00)[0:+,1:+,2:~]; DKIM_TRACE(0.00)[palmen-it.de:+]; ASN(0.00)[asn:6939, ipnet:2001:470::/32, country:US]; RCVD_TLS_ALL(0.00)[] X-Spamd-Bar: ------- X-Rspamd-Queue-Id: 4RRsJK0TzWz4VFP --4dabomp7b6hwux6v Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hi all, for the last two weeks, I've been working on a spike in ports which now reached a state where I want to show it to and discuss it with fellow ports hackers. First, a link to my feature branch (warning, will be rebased every now and then): The goal is to create a replacement for the now antiquated linux-c7 userland. While the classic approach would be to find another Linux distribution that's not too much of a moving target and start "repackaging" that, I want to try something different: Build the required packages from source. ** Why It will be quite some work to do this, I'm not really sure about it yet (and how it would compare to the repackaging approach), so feasibility is yet to be decided. But I hope to get at least these two advantages: - Provide the newest GNU libs (glibc, libstdc++, ...) built against exactly the Linux version emulated by the FreeBSD version this will run on. This should make it possible to run a lot more Linux binaries without relying on e.g. Linux jails. - When binaries don't work for missing Linux libraries, make it somewhat easy to add them, maybe based on already existing FreeBSD ports. ** State I just reached a state where I can build a working Linux-native GNU toolchain (binutils, glibc, gcc) for C and C++ on aarch64, amd64 and i386. From here on, it should be simpler, there are already two ports in my branch (archivers/linux-bzip2 and archivers/linux-xz) using that native toolchain for building. ** How The native toolchain is built by a cross toolchain, the packages for this cross-toolchain are prefixed "lxcross-". For building this cross toolchain, bootstrapping versions of binutils and gcc are needed to build the initial glibc, these versions are suffixed "-bootstrap". lxcross ports set PREFIX to ${LXCROSSBASE}, which defaults to ${LOCALBASE}/linux-cross. lxcross-*-bootstrap ports set PREFIX to ${LXBOOTSTRAP}, this one defaults to ${LXCROSSBASE}/bootstrap. ** Open issues This is an unordered list off my head, so most likely incomplete. - Some trickery with PREFIX is currently needed. The ports framework expects PREFIX to be used as is by the upstream build system. This won't hold for building Linux packages, PREFIX must be /compat/linux for that, but passed to the upstream build system in DESTDIR. - LIB_DEPENDS don't work, which could probably be solved in the framework. Right now, I'm using a hacky workaround to define LINLIB_DEPENDS and add it to both RUN_ and BUILD_DEPENDS. - A lot of smaller things that *should* be provided by the framework, some of them probably by USES=3Dlinux, are currently copy&pasted to every port needing them. I wanted to keep it simple while first trying to get it to work, so the framework isn't touched yet at all. - Some stage-qa checks get confused, some (e.g. checking that everything is stripped) don't work. - In my tests, "poudriere testport" failed at least on i386, because it mounts linprocfs on /compat/linux/proc and then tries to remove /compat/linux (remove pre-existing PREFIX). To test the ports, I had to slightly modify the testport script for now. - For the Linux headers, there should be a metaport picking the Linux version based on ${OSVERSION}. This doesn't exist yet, Linux 4.4.x is always used. - Building the final linux-gcc ports, I get weird error messages directly to poudriere's terminal (they do NOT appear in the build log!) like this: ELF interpreter /usr/lib/ld-linux.so.2 not found, error 2 I have no idea where this comes from, so far I couldn't identify any negative effect though. Acknowledgement: I found quite some useful info for doing this in the "Linux from Scratch" book. Of course you can't just follow the book (very different scenario, it assumes building on Linux and not doing any staging/packaging), but it *does* have some helpful hints. Cheers, Felix --=20 Felix Palmen {private} felix@palmen-it.de -- ports committer -- {web} http://palmen-it.de {pgp public key} http://palmen-it.de/pub.txt {pgp fingerprint} 6936 13D5 5BBF 4837 B212 3ACC 54AD E006 9879 F231 --4dabomp7b6hwux6v Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iNUEABYKAH0WIQRpNhPVW79IN7ISOsxUreAGmHnyMQUCZN8OU18UgAAAAAAuAChp c3N1ZXItZnByQG5vdGF0aW9ucy5vcGVucGdwLmZpZnRoaG9yc2VtYW4ubmV0Njkz NjEzRDU1QkJGNDgzN0IyMTIzQUNDNTRBREUwMDY5ODc5RjIzMQAKCRBUreAGmHny Mfb1AQDJMy04uNjEmDdeyGb09tR9H5ml2dfag+8QS1gGO15v+QD+Kk76UPeIAism I13Zq+Eag2MRCbSDKKBFwNg9RlsrTww= =ZxmZ -----END PGP SIGNATURE----- --4dabomp7b6hwux6v--