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 18 Native Client enables the execution of native code 19 securely inside web applications through the use of advanced 20 `Software Fault Isolation (SFI) techniques <https://developers.google.com/native-client/community/talks#research>`_. 21 Since its launch in 2011, Native Client has provided 22 developers with the ability to harness a client machine's computational power 23 to a much fuller extent than traditional web technologies, by running compiled C 24 and C++ code at near-native speeds and taking advantage of multiple cores with 25 shared memory. 26 27 While Native Client provides operating system independence, it requires 28 developers to generate architecture-specific executable modules 29 (**nexe** modules) for each hardware platform. This is not only inconvenient 30 for developers, but architecture-specific machine code is not portable and thus 31 not well-suited for the open web. The traditional method of application 32 distribution on the web is through a self-contained bundle of HTML, CSS, 33 JavaScript, and other resources (images, etc.) that can be hosted on a server 34 and run inside a web browser. With this type of distribution, a website 35 created today should still work years later, on all platforms. 36 Architecture-specific executables are clearly not a good fit for distribution 37 on the web. As a consequence, Native Client has been restricted to 38 applications and browser extensions that are installed through the 39 Chrome Web Store. 40 41 Portable Native Client (PNaCl) 42 ============================== 43 44 PNaCl solves the portability problem by splitting the compilation process 45 into two parts: 46 47 #. compiling the source code to a portable bitcode format, and 48 #. translating the bitcode to a host-specific executable. 49 50 PNaCl enables developers 51 to distribute **portable executables** (**pexe** modules) that the hosting 52 environment (e.g., the Chrome browser) can translate to native code before 53 executing. This portability aligns Native Client with existing open web 54 technologies such as JavaScript: A developer can distribute a **pexe** 55 as part of an application (along with HTML, CSS, and JavaScript), 56 and the user's machine is simply able to run it. 57 58 With PNaCl, a developer generates a single **pexe** from source code, 59 rather than multiple platform-specific nexes. The **pexe** provides both 60 architecture- and OS-independence. Since the **pexe** uses an abstract, 61 architecture-independent format, it does not suffer from the portability 62 problem described above. Future versions of hosting environments should 63 have no problem executing the **pexe**, even on new architectures. 64 Moreover, if an existing architecture is subsequently enhanced, the 65 **pexe** doesn't even have to be recompiled---in some cases the 66 client-side translation will automatically be able to take advantage of 67 the new capabilities. 68 69 **In short, PNaCl combines the portability of existing web technologies with 70 the performance and security benefits of Native Client.** 71 72 With the advent of PNaCl, the distribution restriction of Native Client 73 can be lifted. Specifically, a **pexe** module can be part of any web 74 application---it does not have to be distributed through the Chrome Web 75 Store. 76 77 PNaCl is a new technology, and as such it still has a few limitations 78 as compared to NaCl. These limitations are described below. 79 80 When to use PNaCl 81 ================= 82 83 PNaCl is the preferred toolchain for Native Client, and the only way to deploy 84 Native Client modules on the open web. Unless your project is subject to one 85 of the narrow limitations described below 86 (see :ref:`When to use NaCl<when-to-use-nacl>`), you should use PNaCl. 87 88 Beginning with version 31, the Chrome browser supports translation of 89 **pexe** modules and their use in web applications, without requiring 90 any installation (either of a browser plugin or of the applications 91 themselves). Native Client and PNaCl are open-source technologies, and 92 our hope is that they will be added to other hosting platforms in the 93 future. 94 95 If controlled distribution through the Chrome Web Store is an important part 96 of your product plan, the benefits of PNaCl are less critical for you. But 97 you can still use the PNaCl toolchain and distribute your application 98 through the Chrome Web Store, and thereby take advantage of the 99 conveniences of PNaCl, such as not having to explicitly compile your application 100 for all supported architectures. 101 102 .. _when-to-use-nacl: 103 104 When to use NaCl 105 ================ 106 107 The limitations below apply to the current release of PNaCl. If any of 108 these limitations are critical for your application, you should use 109 non-portable NaCl: 110 111 * By its nature, PNaCl does not support architecture-specific instructions in 112 an application (i.e., inline assembly). Future editions of PNaCl will 113 attempt to mitigate this problem by introducing portable intrinsics for vector 114 operations. 115 * Currently PNaCl only supports static linking with the ``newlib`` 116 C standard library (the Native Client SDK provides a PNaCl port of 117 ``newlib``). Dynamic linking and ``glibc`` are not yet supported. 118 Work is under way to enable dynamic linking in future versions of PNaCl. 119 * In the initial release, PNaCl does not support vector types and SIMD. 120 * In the initial release, PNaCl does not support some GNU extensions 121 like taking the address of a label for computed ``goto``, or nested 122 functions. 123