
Boot-to-Guile - zoowar
https://lists.gnu.org/archive/html/guile-user/2013-02/msg00131.html
======
justincormack
I see they say they can't use the ffi [1] as libc is not in the initrd which
is kind of unfortunate as it makes it a lot more work. Issue is that glibc is
insanely big for an initrd. For my similar project based on LuaJIT [2] I use
the ffi and Musl libc [3] which is a sane sub 600k shared library (all in one
file). Will put up a bootable system soon.

[1]
[http://git.savannah.gnu.org/cgit/guix.git/tree/gnu/packages/...](http://git.savannah.gnu.org/cgit/guix.git/tree/gnu/packages/patches/guile-
linux-syscalls.patch)

[2] <https://github.com/justincormack/ljsyscall>

[3] <http://www.musl-libc.org/>

~~~
wingo
AFAIUI libc is in the initrd, but it's a statically linked libc. Guile's
dynamic FFI uses dlopen/dlsym to get its function pointers, so it can't do
that in a statically linked libc. (Or could it? I suppose there's no reason
why a statically linked library wouldn't expose symbol tables, whether via
dlsym or some other means.)

Your point about size is well-taken though. Besides libc in this case, Guile's
build products are much larger (and slower) than LuaJIT's images because we've
been trying to write the compiler in Scheme from the very beginning. We can't
even think about doing a nice JIT until we have a good AOT compiler, because
otherwise the JIT written in Scheme would be too slow.

~~~
justincormack
I believe that LuaJIT's ffi can use symbols that are statically linked in, but
I haven't tested it myself so I could be wrong. You can't use dlsym though in
a static binary, so it might need some work. My plan to port ljsyscall to
straight Lua without ffi though is to generate C bindings rather than writing
them by hand. But I have done all the ioctl stuff in Lua not C so all I need
is all the syscalls and structs defined and then all the ffi code for ioctls,
netlink etc will just work; all the constants and so on are define on the Lua
side (that has other issues like dealing with the ABI directly in Lua).

I might be tempted in your case just to use a huge initrd for now, it will be
freed after boot anyway.

~~~
lukego
LuaJIT's "running" page <http://luajit.org/running.html> suggests linking with
-E (gcc -Wl,-E) to make all your global symbols visible to dlsym() even when
you statically link.

That's what we're doing in Snabb Switch <http://snabb.co/snabbswitch/> to
create a statically linked executable that heavily uses FFI. (Currently don't
statically link libc though so I don't know if there is a particular gotcha
there.)

~~~
justincormack
I think it won't work if you statically link LuaJIT too. I think it still uses
dlopen, which with glibc still needs the dynamic libc available at run time,
and might not work with other libcs. But you could fake it all with a
statically linked table of function pointers quite easily I guess.

------
natfriedman
This brings back great memories of embedding guile into practically every
piece of software I wrote from 1997 to 2000. At the time Guile sported a very
simple-to-use embedding API and it was lovely to use Scheme for scripting my
web server, for building the logic for Braitenberg vehicles, etc.

~~~
agumonkey
Any chance you wrote about it somewhere ?

------
klrr
Bmote: This is part of the Guix project and will bring a official bootable
system from GNU, one with Linux-libre and one with HURD.

~~~
AlexanderDhoore
I had to google "linux-libre". So they actually rip out all the proprietary
code? Must have horrible driver support. Every piece of hardware on the market
is proprietary... Where do you draw the line then. I'd rather draw the line
above the kernel, so at least you get to run your free software!

~~~
klrr
Well, I don't actually know since I don't probably gonna use it. But it's
still nice to see that GNU is getting their own distribution.

------
kragen
Disappointingly, they're still booting Linux — this is not a standalone Guile
running on bare metal (even emulated), but rather Guile running on top of the
Linux kernel, loaded from an initrd.

~~~
agumonkey
Not sure if kidding or not, but it's still an interesting step. Maybe someone
will be inspired to write a scheme os after that.

~~~
Armbrs
You may find this interesting.

<http://www.stripedgazelle.org/joey/dreamos.html>

~~~
agumonkey
Thank you very much, despite all my digging I don't think I've ever even heard
of this.

