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