Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 7 Jan 2013 19:24:33 +0200
From:      Konstantin Belousov <kostikbel@gmail.com>
To:        John Baldwin <jhb@freebsd.org>
Cc:        freebsd-toolchain@freebsd.org, freebsd-arch@freebsd.org
Subject:   Re: LLVM Image Activator
Message-ID:  <20130107172433.GX82219@kib.kiev.ua>
In-Reply-To: <201301070936.39052.jhb@freebsd.org>
References:  <50E9BC2D.7000302@freebsd.org> <201301070936.39052.jhb@freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help

--oDFa8iZvINJ+yMtC
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Mon, Jan 07, 2013 at 09:36:38AM -0500, John Baldwin wrote:
> On Sunday, January 06, 2013 01:02:21 PM Nathan Whitehorn wrote:
> > Having LLVM/clang in the base system lets us do some interesting things
> > that we couldn't do with GCC. One is that LLVM ships with a JIT for LLVM
> > IR as well as components of a toolchain for it (this is what Google's
> > pNACL uses) and that you can end up producing binary files that are in
> > IR instead of native code. The IR isn't really cross-platform, but does
> > let you do CPU-specific optimizations when executed by the JIT, etc.
> >=20
> > The attached patch causes the LLVM JIT (lli) to be built by default
> > (adding ~20 seconds to buildworld on my five-year-old laptop) and adds a
> > kernel image activator that invokes it when passed LLVM bitcode files.
> > It's not completely finished (see the XXX comment in the middle), but it
> > does work, as follows:
> >=20
> > $ clang -emit-llvm -c -o hw.ll hw.c
> > $ file hw.ll
> > hw.ll: LLVM bitcode
> > $ lli hw.ll
> > Hello world!
> > $ chmod a+x hw.ll
> > $ ./hw.ll
> > Hello world!
> > $
> >=20
> > Is there any interest in having features like this? It seems like this
> > could provides some interesting possibilities for us and nice
> > integration from having imported clang into base.
> > -Nathan
>=20
> This sounds neat indeed.  Does the IR format provide any sort of notation=
 for=20
> encoding the path to the interpreter (similar to ELF)?  If not, you might=
 want=20
> to at least make the path to 'lli' be configurable via a tunable and/or s=
ysctl=20
> (e.g. if using a newer version of clang in /usr/local).

I do not like one-purpose write-once never-used image activators.
I still do remember the buzz about the binary format 0xCAFEBABE, which
AFAIR gained image activator support on several OSes, to be garbage
collected.

For one thing, such hacks are very system-specific and thus are never
used, causing quick bit rot. Second, more important, is that parsing
of yet another format opens an attack vector on kernel, and due to the
nature of the activators, on the user space.

Look at the PE image activator history, including at least one SA, to
see what I mean. And PE is real image format instead of hack. Even for
ELF, there were recent panic-level bugs.

Note that several language runtimes are happy to use the shebang for
bytecode. For examples, look at the ocaml and lisps.

If adding despite these arguments, please do not make the thing 'standard'.
Provide the option to compile it in, and may be make it a module.

--oDFa8iZvINJ+yMtC
Content-Type: application/pgp-signature

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.19 (FreeBSD)

iQIcBAEBAgAGBQJQ6wTQAAoJEJDCuSvBvK1BM4sP/1zs6BH/0cXbfHukn+M0TOLz
S5+Dn+FTd9K4FmXS2CQpQdcZDCE1uBTQ8j6pIyUCO4rOSaGmdYTCOij2TRnEs+Rf
v1wdr49/H7iO1uDAG2l32WPSmvd2K6tFilDRiLvSsBaH63uI2+xGhq0jPfSXPbv+
jnsBDOGSoex2+rIaDvoV9TZ/2ShWEDp2SBnPPBYTa515JmO0ypw2FBZd5+9wbW7v
oaLNhQQz7eB1nrlxCs2MlQB4PR94DH9xAmkdRp+Q/AJ58icOiZOBiEH2L9ESYF+n
UFP32ESKJrABTvzoS+nusRtmQwWZrymFUpb1AxqXVbi8fm2/9dOf1aLqbH9dO2vT
IiuzC/C14yvp01DSs66ryD7ODogEaTEIMbBx9CHOkmcka4vxxPhqhX3is7xMnnVs
ipcb0DeKiv7FIYwinTkJzrXhS4gi5N6nR+1RqEsq2LZW6BywERhVR3S4wNgWJWJH
VisAiQUrUlwxpEwm6OJaA+PQ1OKlx80ZRYVJwC9Wr6gml9TRqjlOvO7VLXx4+K1v
3T2u8ha0qPEApKvIM5s2Ws2Npj4qkAbjHl8hxfTOYe++HQgjbNYVnJnAZ+7nm0CN
u9YsM61C+u9W5X3ROmXiKcqsZf2VSekJhQNXXebgqs5BB+rG+tiIWijuzst9IF5S
3gpSF0hDaZf3X4suEe6w
=i6JE
-----END PGP SIGNATURE-----

--oDFa8iZvINJ+yMtC--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20130107172433.GX82219>