Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 22 May 2013 17:17:29 -0500
From:      Stacey Son <sson@FreeBSD.org>
To:        freebsd-arch@freebsd.org
Subject:   binmiscctl(8) (and imgact_binmisc kernel module)
Message-ID:  <CD3A8F5A-7AF9-4190-8B01-67D13B3121F9@FreeBSD.org>

next in thread | raw e-mail | index | archive | help
Hi all:

I added a command-line utility called 'binmiscctl' for the =
imgact_binmisc kernel module that I previously proposed on this list.  =
As you may recall, imgact_binmisc is an image activator for =
miscellaneous binary file types that are executed with the help of a =
user-level interpreter or emulator.  It has been proposed that =
imgact_binmisc be added to the kernel as a module.  The main reason I =
created this is to support cross building packages using qemu user mode =
(see my dev summit slides at =
http://people.freebsd.org/~sson/imgact_binmisc/20130515-bsdcan-xbuild-port=
s.pdf) but there are a lot of other applications for this module as =
well.  For example, Nathan Whitehorn previously proposed on this list a =
similar code change (but much less general) to support transparently =
execute  LLVM bitcode using the 'lli' JIT compiler.  This kernel module =
if flexible enough that it supports that as well.

Baptiste has also added support in poudri=E8re for cross-building mips64 =
packages in a "cross jail" using qemu user mode.  See his slides from =
BSDCan 2013 (pg. 7):

	http://people.freebsd.org/~bapt/modern-package-management.pdf

Bapt mentioned that he built over 10,000 mips64 packages in about 30 =
hours.  Of course, this is before adding imgact_binmisc which greatly =
improves the cross build speed by allowing both native (amd64) cross =
build tools to be used along with emulated mips64 binaries in a hybrid =
fashion.  With my limited testing of cross building a handful of ports =
the overhead compared to building the port natively on a commodity amd64 =
host is 2x to 4x using this kernel module.  Without the module the =
overhead is 10x or much more.

The recently added 'binmiscctl' command-line utility allows for easy =
configuration and management of the image activators in this =
imgact_binmisc kernel module.   For example, to add an image activator =
for qemu-mips64 (the qemu user mode emulator for mips64):

	# binmiscctl add mips64elf --interpreter =
"/usr/local/bin/qemu-mips64" --magic \ =
"\x7f\x45\x4c\x46\x02\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\=
x00\x08" \
--mask =
"\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\=
xff\xff" --size 20 --set-enabled

To disable the above without removing it from the module's activator =
list:

	# binmiscctl disable mips64elf

To enable:

	# binmiscctl enable mips64elf

To remove from the module's activator list:

	# binmiscctl remove mips64elf

To lookup and print out the activator entry:

	# binmiscctl lookup mips64elf

	name: mips64elf
	interpreter: /usr/local/bin/qemu-mips64
	flags: ENABLED USE_MASK=20
	magic size: 20
	magic offset: 0=09
	magic: 0x7f 0x45 0x4c 0x46  0x02 0x02 0x01 0x00  0x00 0x00 0x00 =
0x00=20
                   0x00 0x00 0x00 0x00  0x00 0x02 0x00 0x08=20
	mask:  0xff 0xff 0xff 0xff  0xff 0xff 0xff 0x00  0xff 0xff 0xff =
0xff=20
	           0xff 0xff 0xff 0xff  0xff 0xfe 0xff 0xff=20

To take a snapshot and list all the activators=20

	# binmiscctl list

	name: mips64elf
	[...]

To add an image activator for LLVM bitcode JIT lli(1) compiler:

	# binmiscctl add llvmbc --interpreter ''/usr/bin/lli =
--fake-argv0=3D#a'' \
     --magic ''BC\xc0\xde'' --size 4 --set-enabled

Note the "#a", in the above example, is replaced with the old argv0 =
value so lli(1) can use it to fake the argv0 as described in the lli(1) =
man page.

The source code, man page, and diff to add it to the source tree can be =
found at:

	http://people.freebsd.org/~sson/imgact_binmisc/

Of course, comments, suggestions, concerns, detailed code reviews, etc. =
are welcome.

Best Regards,

-stacey.=



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CD3A8F5A-7AF9-4190-8B01-67D13B3121F9>