Skip to content

Ada Annex E with PolyORB under QNX

Piotr Trojanek edited this page Aug 22, 2013 · 24 revisions

This mini-howto should guide you through the setup of an environment for cross compilation of Ada for QNX real-time platform. In particular, the setup for PolyORB, an implementation of a Distributed System Annex, is covered.

This document is based on an earlier HOWTO for setting up just the Ada cross compiler.

Prerequisites

This HOWTO explains how to setup the environment in Ubuntu Lucid Lynx (10.04 LTS) amd64 host; however, it should be straightforward to follow the steps with any Linux i386 or amd64 distribution. Before you start, the following should be already installed :

  • native development tools, i.e. make, svn, autoconf, etc.; this can be installed with apt-get install autotools-dev build-essential ...
  • cross development tools (QNX® Software Development Platform)
  • the QNX should have an access to the Linux filesystem with a NFS; see SettingUpNFSHowTo for setting the Linux server side and Working with Filesystems for a QNX client side
  • the RSH client should be installed on the Linux (the rsh-client package) and the RSH server on the QNX (see Running the Internet daemons for a details); note: the RSH is well-known to be insecure, but PolyORB still uses it by default.

The already working Ada compiler is required to bootstrap the build of the cross compiler. The most full-featured Ada compiler for Linux is from AdaCore. There is also an IDE and all the other neat tools you would need to develop Ada software.

It is recommended to use the latest (2010) x86 or x86_64 release, depending on your Linux host. You can install the package into preferred location, i.e.:

$ tar zxvf gnat-gpl-2010-i686-gnu-linux-libc2.3-bin.tar.gz -C /opt

I assume that all the source and build folders, together with patches and configuration scripts, are located in the user’s home directory.

Native and cross development

There are many reasons to setup the environment for a cross instead of a native QNX development:

  • there is no Ada IDE QNX and porting an existing IDE is not as easy as one would expect
  • QNX has dropped the support for a native QDE (Eclipse-based) IDE with system inspection tools
  • native compilation under QNX is noticeably slower than cross compilation (this is probably due to the performance of the QNX’s hard disc drivers)
  • QNX does not support the recent hardware; it is much easier to install a QNX for development on a virtual machine
  • QNX does not offer much of the software (MP3 players, chat clients, etc.), which makes your development a joy instead of hard work :)

Ada cross compiler

Get the sources

There are at least three ways to get the GNAT source code:

The “official” sources are not regularly tested with Ada nor QNX (i.e. the Ada part of the gcc-4.5-20091029 snapshot did not compile). AdaCore does not officially supports the QNX – e.g. the resulting binaries give an error message in the case of unhandled exception and also their debugging with gdb is broken.

In short – the preferred way is to use the sources from QNX. If you can solve the issues with other versions (with more features), then please let me know!

You can grab the source code from the repository:

$ svn checkout http://community.qnx.com/svn/repos/core-dev-tools/tools/gcc/trunk gcc

Then fix the sources with the following patch (for the 543 revision, which is the latest at the time of this writing). This patch solves the following issues:
  • provides specialization of the Ada runtime for the QNX platform
  • fixes static library support for the cross QNX build tools
  • fixes support for the GNAT.Sockets under QNX
  • fixes spawning of a child processes (in QNX the fork(2) can not be used in multi-threaded applications)
  • enables to run the ACATS tests in the cross environment
  • fixes the incompatibilities of the style and the source code with the latest (and the most restrictive) gnat-2010 from AdaCore

The known bugs are:

  • shared version of the GNAT library is not build
gcc $ patch -p0 < ../gnat-qnx-r543.diff

Build the cross compiler

Make sure that the native Ada compiler is on the $PATH environment variable (it is required to bootstrap the build of the cross compiler).
Fetch the configuration script, then create and execute the script from the build folder:

$ mkdir build-gcc-cross; cd build-gcc-cross
build-gcc-cross $ sh ../configure.gcc-cross

You can adjust the prefix location of the cross compiler (currently /opt/i486-pc-nto-qnx6.5.0-gnat-bin). It is recommended to create the destination folder (as root) and change its ownership to an non-priviledged user. This will ease the make install, since the root user’s $PATH environment may not include the folder with an Ada native compiler or the QNX® Software Development Platform tools.

If everything is OK, then build and install the cross compiler:

build-gcc-cross $ make && make install

You can safely strip the binaries from the debugging symbols:

${PREFIX}/bin $ strip i486-pc-nto-qnx6.5.0-*
${PREFIX}/lib/gcc/i486-pc-nto-qnx6.5.0/4.4.2 $ strip cc1 collect2 gnat1

Test the cross compiler

You should now be able to test the cross compiler with a simple “Hello world!” application.
Just add the ${PREFIX}/bin to your $PATH environment variable or build the binary directly specifying a path to the cross compiler:

$ /opt/i486-pc-nto-qnx6.5.0-gnat-bin/bin/i486-pc-nto-qnx6.5.0-gnatmake hello.adb 
i486-pc-nto-qnx6.5.0-gcc -c hello.adb
i486-pc-nto-qnx6.5.0-gnatbind -x hello.ali
i486-pc-nto-qnx6.5.0-gnatlink hello.ali

Note: to check the cross compiler with ACATS follow the Running cross-target ACATS check section in the previous HOWTO.

PolyORB cross tools

Get the sources

The PolyORB uses the Ada compiler to generate stubs of remote objects (partition communication subsystem, PCS). For this reason the versions of the PolyORB and GNAT must have a matching interfaces. PCS versions in different GNAT and PolyORB releases are summarized here.

The latest PolyORB compatible with the GCC sources released by the QNX can be fetched from AdaCore:

$ svn checkout -r 139901 http://svn.eu.adacore.com/anonsvn/Dev/trunk/polyorb/

These SVN release does not contain the latest PolyORB features, but it seems to be fully functional in respect with the DSA personality.

You have to fix some style errors, which triggers errors and warnings in the more recent Ada compilers, with this patch.

polyorb $ patch -p0 < ../polyorb-r139901-qnx.diff

The configure script and another autoconf utilities are not included in the SVN repository. Instead they have to be regenerated on the build machine:

polyorb $ autoreconf -I support/
polyorb $ automake --add-missing
polyorb $ libtoolize

Build the PolyORB cross

Make sure, that both the native and cross Ada compilers are on the $PATH environment variable, i.e.

export PATH=/opt/gnat-2010-i686-gnu-linux-libc2.3-bin/bin:/opt/i486-pc-nto-qnx6.5.0-gnat-bin/bin:${PATH}

It is required, because both native (i.e. po_gnatdist) and target (i.e. po_names) tools will be build.
Fetch the configuration script, then create and execute the script from the build folder:
$ mkdir build-polyorb-cross; cd build-polyorb-cross
build-polyorb-cross $ sh ../configure.polyorb-cross

You can adjust the prefix location of the PolyORB installation (currently setup to include the SVN revision number). Once again – it is recommended to create the destination folder (as root) and change its ownership to an non-priviledged user.

If everything is OK, then build and install the PolyORB:

build-polyorb-cross $ make && make install

Test the PolyORB cross

Make sure, that both the cross Ada compiler and PolyORB tools are on the $PATH environment variable, i.e.

export PATH=/opt/polyorb-gpl-r139901-i486-pc-nto-qnx6.5.0-bin/bin:/opt/i486-pc-nto-qnx6.5.0-gnat-bin:${PATH}

The po_gnatdist executes the cross toolchain without the i486-pc-nto-qnx6.5.0-... prefix (see this post). This is why you have to create symbolic links in the cross compiler installation bin/ folder:

/opt/i486-pc-nto-qnx6.5.0-gnat-bin/bin $ for i in i486-pc-nto-qnx6.5.0-*; do
> ln -s $i `echo $i|sed 's/i486-pc-nto-qnx6.5.0-//'`
> done

Note: be careful with the $PATH environment variable setting, since now both the native and cross Ada tools can be called with the same names!

Now you should be able to build the PolyORB example DSA echo application with po_gnatdist echo.cfg as usual. Make sure, that the name resolution (/etc/hosts.conf file or the DNS resolver) is configured on your QNX machine.

It is convenient to provide the QNX machine with an NFS access to both the folders – with a PolyORB utilities (po_names) and application (echo). Start the po_names in one console and the client binary in another.

Note: it is also possible to run a heterogeneous DSA application, i.e. client_partition on QNX and server_partition on Linux. This setup has been tested with po_names running both on Linux and QNX.
However, you have to use the very same versions of the native and the cross GNAT and PolyORB. It has been tested with a vanilla gcc-4.4.2 release with the patch, which allows to bootstrap the build with a gnat-2010 from AdaCore using this configuration script.