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