Improving Cross compilation of Perl 5 - report for July/August

Jess Robinson writes:

(Report up to Aug 26th anyway, I'll add anything I do in the last few days of August to the next one)

After a bit of a slow start (and thus the reason to merge July/August reports), I've gotten started on the actual work, and managed to tick off one of my tasks.

I eliminated my earlier use of the tool "agcc" from the code base. This was an external (and with non-compatible licence) tool designed to make using the cross-compiled gcc similar to a normal gcc. In the end it turned out to be more of a hinderance. Getting rid of it and using Android's suggestion for "--sysroot" as a gcc option means upgrading the NDK to the latest one is now simple. The SDK is now not required at all.

The last 2 weeks (Weeks #6/#7) I was at the Perl Reunification Summit, and then YAPC::EU, which were inspirational. I got started on the second task I have identified. To enable me to merge (or better, re-port) my original changes to blead, I have started with a fresh copy of blead and will add a piece at a time.

Expanding Configure is my current target. It already has a small piece of code to support cross-compiling, using -Dusecrosscompile, however this mostly skips all the parts it can't do, like compiling and then running various pieces of code for testing sizes of integers and similar. In order to enable us to have as small a piece of "canned" as possible, I am adding support for these things.

Currently I have it using `nm` (or rather the copy in the cross-compiler bin-utils) to find the size of the variables declared in the 'try.c' binary. When cross-compiling, this now looks like:

  #include <stdio.h>
  #$i_stdlib I_STDLIB
  #ifdef I_STDLIB
  #include <stdlib.h>

     int PERL_INT_SIZE;
     long PERL_LONG_SIZE;
     short PERL_SHORT_SIZE;

  int main()

Running nm gets us:

  $ /usr/src/android/android-ndk-r8/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-nm -p -t d -S  UU/try
  00037740 d _DYNAMIC
  00037940 d _GLOBAL_OFFSET_TABLE_
  00033612 A __exidx_end
  00037996 A _bss_end__
  00037724 T __FINI_ARRAY__
  00037960 A __bss_start__
  00037968 00000004 B __dso_handle
  00033612 A __exidx_start
  00037984 00000004 B PERL_LONG_SIZE
  00037988 00000004 B PERL_INT_SIZE
           U __libc_init
  00037992 00000002 B PERL_SHORT_SIZE
  00037732 D __CTOR_LIST__
  00037996 A __bss_end__
  00033552 T _start
  00037716 T __INIT_ARRAY__
  00037960 A __bss_start
  00033600 00000012 T main
  00037996 A __end__
  00037708 D __PREINIT_ARRAY__
  00037960 A _edata
  00037996 A _end
           U exit
  00037960 D __data_start

And we extract the values for the PERL_* variables. The same process is repeated for long longs, long doubles, pointers etc. Assuming cross-compile environments all use gcc and contain the bin-utils, this ought to be fairly portable.

To ensure the correct 'nm' (and also later 'ar') is used, I've added support to Configure to allow the binaries to be named differently. The cross-compiler 'nm' for the NDK is, for example, 'arm-linux-androideabi-nm'. If "-Dusecrosscompile=arm-linux-androideabi-" is passed as a Configure argument, binaries will be discovered with that string as a prefix.

I've now started to add support for -Dsysroot. The name is taken from the gcc option mentioned earlier, and is similar to chroot, it specifies a logical root directory under which headers and libraries can be found. Various parts of the Configure script try to discover which libraries are available, and the location of the, using absolute paths. When cross-compiling, these are being found on the host system, instead of inside the toolchain for the cross-compiler. Adding sysroot support means the compiler's headers and libraries can now be located correctly. This is applicable to any system with its compiler located in its own chroot, or multiple toolchains / libraries installed.

[Hours] [Activity]

5.75     Admin - Tasks, Emails, Planning
6.50     Remove agcc from x-cross-compile branch
2.00     Update to latest Android NDK and verify working with x-cross-compile
10.50    Update Configure with better cross-compiling support

24.75 hours total

About TPF

The Perl Foundation - supporting the Perl community since 2000. Find out more at

About this Entry

This page contains a single entry by reneeb published on September 3, 2012 5:45 PM.

Improving Perl 5: Grant Report for Month 11 was the previous entry in this blog.

Adding tests to and refactoring the perl debugger - Grant Report #2 is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.


OpenID accepted here Learn more about OpenID
Powered by Movable Type 6.2.2