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