Re: Rust: kernel vs user-space

From: Jacques Fourie <jacques.fourie_at_gmail.com>
Date: Thu, 05 Sep 2024 01:10:06 UTC
On Wed, Sep 4, 2024 at 5:13 PM Konstantin Belousov <kostikbel@gmail.com>
wrote:

> On Wed, Sep 04, 2024 at 04:43:31PM -0700, Jacques Fourie wrote:
> > On Wed, Sep 4, 2024 at 3:41 PM Konstantin Belousov <kostikbel@gmail.com>
> > wrote:
> >
> > > On Wed, Sep 04, 2024 at 03:15:22PM -0700, Cy Schubert wrote:
> > > > In message <78BC157F-6E30-49C4-931D-9EB539BD0322@digitaldaemon.com>,
> > > Jan
> > > > Kneppe
> > > > r writes:
> > > > > D
> > > > >
> > > > > www.dlang.org
> > > >
> > > > The problem with D is data structure definitions need to also be
> > > mirrored
> > > > (duplicated) in D. For example, when 64-bit inodes were implemented D
> > > > failed to build and generate any code. The reason for this was
> > > > ufs/ufs/inode.h now defined 64-bit inodes while the D representation
> as
> > > > provided by the D language were still 32-bit. I had opened an issue
> with
> > > > upstream regarding this. To this day they still haven't figured out
> how
> > > to
> > > > implement 64-bit inodes on newer FreeBSD systems while maintaining
> > > 32-bit
> > > > inode backward compatibility on older FreeBSD systems (as FreeBSD
> > > > implemented this using ifunc).
> > >
> > > Rust is same.  It still uses pre-ino64 bindings for both stdlib and
> libc.
> > >
> >
> > Looking at the Rust libc bindings I see the following:
> >
> https://github.com/rust-lang/libc/blob/72c40004a3568849055c0bab5c92c9975b4eb132/src/unix/bsd/freebsdlike/freebsd/freebsd11/mod.rs#L8
> >
> https://github.com/rust-lang/libc/blob/72c40004a3568849055c0bab5c92c9975b4eb132/src/unix/bsd/freebsdlike/freebsd/freebsd12/mod.rs#L5
> >
> > Seems to have changed to 64 bit for FreeBSD 12 and up?
>
> Rust libc seems to make some strange things to follow FreeBSD ABI
> evolution, which is not done e.g. for glibc.  But anyway, the relevant
> place
> to look seems to be a comment and decision code at
>
> https://github.com/rust-lang/libc/blob/72c40004a3568849055c0bab5c92c9975b4eb132/build.rs#L44
>
> By default they seems to use FreeBSD 11 ABI from freebsd11 module still.
> I do not know what is CARGO_FEATURE_RUSTC_DEP_OF_STD.
>
> CARGO_FEATURE_RUSTC_DEP_OF_STD is an environment variable set by cargo
when libc is built with the rustc-dep-of-std feature, as is done when
building the std library. What this means is that the std library uses a
libc ABI that is backwards compatible with FreeBSD 12. When using a
standalone libc from crates.io you will get libc bindings that are
backwards compatible with FreeBSD 11. Definitely not entirely clear to me.
I made a small sample app that prints the size of libc::ino_t. Building
this app without any environment variables defined results in a size of 4.
Building with `LIBC_CI=1` results in a size of 8, as does building with
`CARGO_FEATURE_RUSTC_DEP_OF_STD=1`. These tests were done on a host running
FreeBSD 15.