nacl-and-pnacl.rst revision 1320f92c476a1ad9d19dba2a48c72b75566198e9
1.. _nacl-and-pnacl: 2 3############## 4NaCl and PNaCl 5############## 6 7This document describes the differences between **Native Client** and 8**Portable Native Client**, and provides recommendations for when to use each. 9 10.. contents:: 11 :local: 12 :backlinks: none 13 :depth: 2 14 15.. _native-client-nacl: 16 17Native Client (NaCl) 18==================== 19 20Native Client enables the execution of native code securely inside web 21applications through the use of advanced `Software Fault Isolation (SFI) 22techniques <http://research.google.com/pubs/pub35649.html>`_. Native Client 23allows you to harness a client machine's computational power to a fuller extent 24than traditional web technologies. It does this by running compiled C and C++ 25code at near-native speeds, and exposing a CPU's full capabilities, including 26SIMD vectors and multiple-core processing with shared memory. 27 28While Native Client provides operating system independence, it requires you to 29generate architecture-specific executables (**nexe**) for each hardware 30platform. This is neither portable nor convenient, making it ill-suited for the 31open web. 32 33The traditional method of application distribution on the web is through self- 34contained bundles of HTML, CSS, JavaScript, and other resources (images, etc.) 35that can be hosted on a server and run inside a web browser. With this type of 36distribution, a website created today should still work years later, on all 37platforms. Architecture-specific executables are clearly not a good fit for 38distribution on the web. Consequently, Native Client has been until recently 39restricted to applications and browser extensions that are installed through the 40Chrome Web Store. 41 42.. _portable-native-client-pnacl: 43 44Portable Native Client (PNaCl) 45============================== 46 47PNaCl solves the portability problem by splitting the compilation process 48into two parts: 49 50#. compiling the source code to a bitcode executable (pexe), and 51#. translating the bitcode to a host-specific executable as soon as the module 52 loads in the browser but before any code execution. 53 54This portability aligns Native Client with existing open web technologies such 55as JavaScript. You can distribute a pexe as part of an application (along with 56HTML, CSS, and JavaScript), and the user's machine is simply able to run it. 57 58With PNaCl, you'll generate a single pexe, rather than multiple platform- 59specific nexes. Since the pexe uses an abstract, architecture- and OS- 60independent format, it does not suffer from the portability problem described 61above. Although, PNaCl can be more efficient on some operating systems than on 62others. PNaCl boasts the same level of security as NaCl. Future versions of 63hosting environments should have no problem executing the pexe, even on new 64architectures. Moreover, if an existing architecture is enhanced, the pexe 65doesn't need to be recompiled. In some cases the client-side translation will 66automatically take advantage of new capabilities. A pexe can be part of any web 67application. It does not have to be distributed through the Chrome Web Store. In 68short, PNaCl combines the portability of existing web technologies with the 69performance and security benefits of Native Client. 70 71PNaCl is a new technology, and as such it still has a few limitations 72as compared to NaCl. These limitations are described below. 73 74.. _when-to-use-pnacl: 75 76When to use PNaCl 77================= 78 79PNaCl is the preferred toolchain for Native Client, and the only way to deploy 80Native Client modules without the Google Web Store. Unless your project is 81subject to one of the narrow limitations described under ":ref:`When to use 82NaCl<when-to-use-nacl>`", you should use PNaCl. 83 84Since version 31, Chrome supports translation of pexe 85modules and their use in web applications without requiring installation either 86of a browser plug-in or of the applications themselves. Native Client and PNaCl 87are open-source technologies, and our hope is that they will be added to other 88hosting platforms in the future. 89 90If controlled distribution through the Chrome Web Store is an important part of 91your product plan, the benefits of PNaCl are less critical for you. But you can 92still use the PNaCl toolchain and distribute your application through the Chrome 93Web Store, and thereby take advantage of the conveniences of PNaCl, such as not 94having to explicitly compile your application for all supported architectures. 95 96.. _when-to-use-nacl: 97 98When to use NaCl 99================ 100 101Use NaCl if any of the following apply to your application: 102 103* Your application requires architecture-specific instructions such as, for 104 example, inline assembly. PNaCl tries to offer high-performance portable 105 equivalents. One such example is PNaCl's :ref:`Portable SIMD Vectors 106 <portable_simd_vectors>`. 107* Your application uses dynamic linking. PNaCl only supports static linking 108 with a PNaCl port of the ``newlib`` C standard library. Dynamic linking and 109 ``glibc`` are not yet supported in PNaCl. Work is under way to enable dynamic 110 linking in future versions of PNaCl. 111* Your application uses certain GNU extensions not supported by PNaCl's LLVM 112 toolchain, like taking the address of a label for computed ``goto``, or nested 113 functions. 114