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