Update to the latest version of Native Client / PNaCl by running: gclient syncPre-built binaries for PNaCl are located in one of these directories, depending upon your architecture and operating system. toolchain/pnacl_linux_x86/newlib/toolchain/pnacl_mac_x86/newlib/toolchain/pnacl_win_x86/newlib/You must build and install the SDK libraries before using the toolchain outside of SCons: pnacl/build.sh sdk newlibSanity Check: Compiling a test programAt this point, you probably want to test if the pre-built toolchain works. Let's start by creating a "hello world" program: #include <stdio.h>int main(int argc, const char *argv[]) { printf("Hello World!\n"); return 0;}Add the PNaCl toolchain to your path for convenience: PATH=${PATH}:toolchain/pnacl_linux_x86/newlib/bin # Adjust the name for your system Now compile hello.c: pnacl-clang hello.c -o hello.pexe(NOTE: If you get an error about missing crt1.o or -lnacl, you must install the SDK. See the installation instructions in the previous section.) You have now produced a "pexe", a PNaCl bitcode application. To run this pexe, it must be first translated to native code. Let's translate it to X86-32, X86-64 and ARM. pnacl-translate -arch x86-32 hello.pexe -o hello_x86_32.nexepnacl-translate -arch x86-64 hello.pexe -o hello_x86_64.nexepnacl-translate -arch arm hello.pexe -o hello_arm.nexeNow you have 3 native executables, one for each architecture. To run them inside of sel_ldr, use the helper script, native_client/run.py:./run.py hello_x86_32.nexe./run.py hello_x86_64.nexe./run.py hello_arm.nexe # By default it will look for qemu to run the ARM nexe.Testing with the pre-built toolchain with SConsTo use the PNaCl toolchain with the native client scons tests, just specify "bitcode=1" on the command-line. Some sample command lines: ./scons platform=arm bitcode=1 # build everything./scons platform=arm bitcode=1 smoke_tests # run smoke_tests./scons platform=x86-32 bitcode=1 # build everything./scons platform=x86-32 bitcode=1 smoke_tests # run smoke_tests./scons platform=x86-64 bitcode=1 # build everything./scons platform=x86-64 bitcode=1 smoke_tests # run smoke_testsThe scons tests are more conveniently wrapped in a testing script: pnacl/test.sh test-x86-32 # Runs the smoke tests as above, plus nonpexe_testspnacl/test.sh test-x86-64pnacl/test.sh test-armpnacl/test.sh test-x86-32-sbtc # Runs the same tests, but with the sandboxed translatorpnacl/test.sh test-x86-64-sbtcpnacl/test.sh test-arm-sbtcOther Compiler TestsLLVM regression testsThese tests can be run directly by running 'make check' in the build directory (pnac/build/llvm_x86_64). There are currently a few known failures which are not marked as XFAIL in the usual LLVM way, so instead the regression tests can also be run in the following way, which will ignore the known failures. pnacl/scripts/llvm-test.sh llvm-regressionThe LLVM regression tests run quickly and should be run before every LLVM commit, along with the scons tests. The following tests take longer and are generally not run by the developers on every commit, but they should be run for large changes, and are run on the toolchain testing bots on every commit. GCC Torture testsTo run the gcc torture test suite against pnacl, do the following: tools/toolchain_tester/torture_test.sh install-tests # Only needs to be run oncetools/toolchain_tester/torture_test.sh pnacl-x86-64-torture --concurrency=12LLVM Test SuiteTo run the LLVM testsuite against pnacl, do pnacl/scripts/llvm-test.sh all x86-64This is equivalent to pnacl/scripts/llvm-test.sh testsuite-cleanpnacl/scripts/llvm-test.sh testsuite-configurepnacl/scripts/llvm-test.sh testsuite-run x86-64pnacl/scripts/llvm-test.sh testsuite-report x86-64The testsuite needs to be cleaned and re-configured each time you switch architectures, but the results files persist after cleaning, so testsuite-report will give the result from the last run for that architecture. Because there is no good way to filter the set of tests that are actually run and there are a lot of known failures (e.g. tests that have not been ported to use newlib), this testsuite takes a long time to run. Spec2kIf you have access to the spec2k benchmark suite you can use the harness in tests/spec2k/ to run some more extensive tests. If SPEC_DIR is the directory containing the benchmark code/data, run: pnacl/test.sh test-spec <SPEC_DIR> SetupPnaclX8664Opttest.sh is a convenience script and clobbers old results, etc. The actual steps are: pushd tests/spec2k./run_all.sh CleanBenchmarks./run_all.sh PopulateFromSpecHarness <SPEC_DIR>./run_all.sh TimedBuildAndRunBenchmarks SETUPpopdwhere SETUP is for example "SetupPnaclArmOpt". See "run_all.sh" for a full list of setups. Toolchain DevelopmentFrom the native_client/ directory: pnacl/build.sh clean pnacl/build.sh sync-sources # Pulls the PNaCl sources pnacl/build.sh build-all # Builds and installs PNaCl toolchainpnacl/build.sh translator-all # Builds the sandboxed translatorIf everything built correctly, run the scons tests with: Important ScriptsMost tasks related to the toolchains are focused in two scripts.
pnacl/build.shThis script checks out and builds the complete PNaCl toolchain. Important invocations:
pnacl/test.shThis script runs toolchain tests. It deletes old testing artifacts before running. The main invocation is test-all. This directory contains the compiler drivers, which are in Python. If you change them, run "pnacl/build.sh driver" to install them. Git Repositories Most of the code required to build the PNaCl toolchain lives in git repositories hosted on git.chromium.org. The build.sh script will automatically check out and update these repositories. The checked-out code is placed in native_client/pnacl/git. Relevant Directories
Process for making changes to the PNaCl toolchainIf you've made changes to PNaCl toolchain, either to the driver or git repositories, you can rebuild PNaCl by doing: pnacl/build.sh all # Incrementally syncs, builds and reinstalls pnacl/test.sh test-all # Run the scons testsHow to send out reviews for git reposTo send out reviews for the git repos, you must have depot tools. Code reviews are sent using the git cl script in depot_tools.If you are going to commit, you also need an account on gerrit.chromium.org and an SSH key setup for it. The first time you set up code review you'll need to let git cl do some setup: % cd pnacl/git/llvm% git cl configJust press Enter at the prompts. To do local development, create a new branch: % git checkout -b mybranch origin/masterThe last argument to git checkout (the start point) is important because if your local branch does not track the remote master branch, then git cl push will not work) Edit your code, and commit as many times as you want: % git commit -a -m “comment describing changes”Then use git-cl to upload to the code review site: % git cl uploadGit cl associates each branch with a review issue ID. So you if you type git cl upload again from the same branch, it will upload a new patch set to the same issue. When you get the LGTM, you can push the changes. % git cl pushWhen you push, you will need to have your gerrit SSH key to authenticate to the gerrit git server. If there have been changes on the master branch since you forked your local branch, git cl may complain, in which case you should rebase it against the new HEAD before you push: % git fetch origin% git rebase origin/masterUpdate stable revisions in the pnacl DEPS, test, review and submitAt this point the official toolchain builder is still not incorporating your changes as it builds off of specific commit IDs in the external repo. To fix this modify native_client/pnacl/DEPS to point at your new commit ID which look like "pnacl_llvm_rev": "efa7b3d5c85f0242787eb091dadedc2727215df4",Finally, to allow users to download the new revision built by the toolchain bulder, look in the native_client/TOOL_REVISIONS file for PNACL_VERSION=9476and update this to an svn revision number that is new enough to include your build.sh revision change. Now create a CL and test it with some try jobs (e.g., gcl try my_cl_name). NOTE: You will need to wait for a toolchain to be built (see the waterfall) before this change actually works (downloads a toolchain tarball). Misc NotesBuilding Validators In the case that you want to run the native client validators on your nexes, build the validators like so: ./scons targetplatform=arm sdl=none arm-ncval-core./scons platform=x86-32 sdl=none ncval./scons platform=x86-64 sdl=none ncvalThe validators will be placed in scons-out/{host}-{platform}/staging/. Upstream LLVM tests:If you are making upstream changes, be sure to run llvm unit tests: % make checkother tests: http://llvm.org/docs/TestingGuide.html. We are in the process of making the llvm unit tests work with NaCl. However, we do currently run the llvm-test nightly suite on our bots. See pnacl/scripts/llvm-test-suite.sh. LLVM Further ReadingIntroduction to td files and phases Description of LLVM Phases (Life of a bitcode) |
