My favorites | Sign in
Google
                
Search
for
Updated Apr 02, 2009 by kat...@google.com
Labels: Featured
Porting  
Tips on porting to Native Client

This page describes how to port your code to Native Client. Although this page concentrates on porting projects that use Autoconf, most of the information is also relevant to non-Autoconf projects.

Contents:

Note: This page needs more examples and details. It also needs to point to a list of ports, with recommendations on where to start with various kinds of ports. If you have porting tips, please add them to this page as comments. For suggestions and discussions, please respond to this post.

Porting a project that uses Autoconf

This section shows one approach to porting projects that have Autoconf-produced configure files. The main idea is to generate an acceptable Makefile, hand-editing the configure file (but not the Makefile) if necessary.

Note: The "right" way to port a project that uses Autoconf is to edit configure.in or configure.ac, and then feed that file to autoconf to produce the configure file. Feel free to do that if you're familiar with Autoconf (or want to be).

  1. Find the config.sub and configure files. Both files are often in the topmost directory of a software project's hierarchy.
  2. Add Native Client to config.sub.

    1. Add the following to the end of the case $os section for recognizing "common machines as not being operating systems":

      -nacl*)
              basic_machine=i686-pc
              os=-nacl
              ;;

    2. Add nacl to the first group of "basic CPU types without the company name" -- just above nios, for example:

      | nacl \

  3. Use the standard configuration to generate the Makefile. Example:

    ./configure

  4. Looking at the Makefile, make a list of the things you'll probably have to change. Typically:
    • gcc -> nacl-gcc (except for any targets that use shared libraries; avoid those targets)
    • ar -> nacl-ar, ranlib -> nacl-ranlib, etc.
    • g++ -> nacl-g++
    • compile with -O3 optimization
    • consider using the -d compile flag (but remove it later!)
    • specify the paths to the Native Client SDK libraries and executables (such as by setting prefix)
    • remove all dependencies on shared libraries
    • if the resulting object file is executed (by means of ac_try, for example) use sel_ldr to execute it. Note that there is no sel_ldr under nacl_sdk; you'll need to copy it there or use the version in your Native Client download. Example: cp <install_dir>/nacl/googleclient/native_client/scons-out/opt-linux/staging/sel_ldr /usr/local/nacl-sdk/nacl/bin

  5. Figure out which command-line options you'll need to specify to configure. You might need to look at Makefile and configure, as well as your list of probable changes.

  6. If no configure option exists to make a change you need, edit the configure file. For example, you might need to change the ac_try line in the configure file so that it uses sel_ldr:

    -  if { ac_try='./$ac_file'
    +  if { ac_try='$EMULATOR_FOR_BUILD ./$ac_file'

  7. Generate your Makefile, using the command-line options you determined previously plus the following: --enable-static --enable-shared=no --host=nacl. Example:

    ./configure CC=/usr/local/nacl-sdk/bin/nacl-gcc \
      CXX=/usr/local/nacl-sdk/bin/nacl-g++ \
      EMULATOR_FOR_BUILD=/usr/local/nacl-sdk/nacl/bin/sel_ldr \
      --enable-static --enable-shared=no --host=nacl \
      CFLAGS="-O3" --prefix=/usr/local/nacl-sdk

  8. Try building, using the Makefile you just generated. Example:

    make

  9. If the build fails, note any compile errors. Try commenting out the offending code and rebuilding.
  10. Look at the config.log file to find more subtle errors and get information about the build.
  11. Once the build succeeds, try to run the example.

Tips

Eliminate file access

In particular, take out all code that refers to directories. We currently don't even have stubs for that.

Eventually, you need to remove all file access or substitute URLs for files.

Use libunimpl if necessary

The unimpl library defines some POSIX routines that aren't implemented by Native Client. It can help you successfully compile programs that have calls to these unimplemented routines. Of course, you should make sure that your module doesn't really depend on those calls.

See also


Comment by vincent.chenxs, Mar 22, 2009

As nacl-paper successfully enabled cpu2000, i also want to have a try. I have modify a config file for cpu2000(originally linux-x86-gcc.cfg). mainly change these things: CC = /home/chinimei/nacl/googleclient/third_party/nacl_sdk/linux/bin/nacl-gcc CXX = /home/chinimei/nacl/googleclient/third_party/nacl_sdk/linux/bin/nacl-g++

and build with -O3 but some of samples compiles and some not. For example. 254.gap faild when LINK: /home/chinimei/nacl/googleclient/third_party/nacl_sdk/linux/bin/nacl-gcc -O3 -funroll-all-loops -lm -o options I see that it is because system.c cannot find termio.h and doesn't compile. Others failed may have the same kind of problems.


Sign in to add a comment