[systemd-devel] [PATCH] Allow cross-compilation.

Lennart Poettering lennart at poettering.net
Tue Nov 23 06:05:17 PST 2010


On Tue, 23.11.10 09:15, Thierry Reding (thierry.reding at avionic-design.de) wrote:

> When cross-compiling systemd, the introspection XML files fail to be
> generated because the systemd host binary is not executable. This patch
> works around this by looking for the systemd binary in the path of the
> build host and run that instead of the host binary created during the
> build process.

Hmpf. The systemd version on the host and the one being build might
differ...

I think a much nicer solution would be to rely on binutils' objcopy tool
to achieve that.  The idea would be something like this:

Everywhere where we define interface introspection data find the
appropriate char array, and use the gcc __attribute__ ((section
"foobar")) to place it in a special ELF section, one section for each
interface string. Then, in the makefile use objcopy to extract the
string from the ELF file without having to run it:

     $ objcopy -O binary -j foobar ./systemd foobar.introspect

Then, with some minimal awk hackery to add a prefix and a suffix to
this you should have generated the interface files from the sources
without having to run the resulting binary. That solution should work
for both cross-compilation and native compilation.

If you prepare such a patch I'd be happy to merge that. 

If you do, please define a macro for the section attribute stuff and
place the macro in macro.h!

Example how this should look like:

In dbus-manager.c look for:

    const char bus_manager_interface[] = BUS_MANAGER_INTERFACE;

and turn it into this:

    const char bus_manager_interface[] _section_ ("dbus-manager-interface"))) = BUS_MANAGER_INTERFACE;

(With _section_() appropriately defined as macro).

Then you can easily extract this data from the ELF file with:
 
     $ objcopy -O binary -j dbus-manager-interface ./systemd dbus-manager.interface

And now repeat that for all interfaces.

Lennart

-- 
Lennart Poettering - Red Hat, Inc.


More information about the systemd-devel mailing list