Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(433)

Side by Side Diff: native_client_sdk/doc_generated/reference/pnacl-undefined-behavior.html

Issue 438403003: [NaCl SDK Docs] Only generate one top-level <section> element. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 {{+bindTo:partials.standard_nacl_article}} 1 {{+bindTo:partials.standard_nacl_article}}
2 2
3 <section id="pnacl-undefined-behavior"> 3 <section id="pnacl-undefined-behavior">
4 <h1 id="pnacl-undefined-behavior">PNaCl Undefined Behavior</h1> 4 <h1 id="pnacl-undefined-behavior">PNaCl Undefined Behavior</h1>
5 <div class="contents local" id="contents" style="display: none"> 5 <div class="contents local" id="contents" style="display: none">
6 <ul class="small-gap"> 6 <ul class="small-gap">
7 <li><a class="reference internal" href="#overview" id="id2">Overview</a></li> 7 <li><a class="reference internal" href="#overview" id="id2">Overview</a></li>
8 <li><a class="reference internal" href="#specification" id="id3">Specification</ a></li> 8 <li><a class="reference internal" href="#specification" id="id3">Specification</ a></li>
9 <li><p class="first"><a class="reference internal" href="#behavior-in-pnacl-bitc ode" id="id4">Behavior in PNaCl Bitcode</a></p> 9 <li><p class="first"><a class="reference internal" href="#behavior-in-pnacl-bitc ode" id="id4">Behavior in PNaCl Bitcode</a></p>
10 <ul class="small-gap"> 10 <ul class="small-gap">
11 <li><a class="reference internal" href="#well-defined" id="id5">Well-Defined</a> </li> 11 <li><a class="reference internal" href="#well-defined" id="id5">Well-Defined</a> </li>
12 <li><p class="first"><a class="reference internal" href="#not-well-defined" id=" id6">Not Well-Defined</a></p> 12 <li><p class="first"><a class="reference internal" href="#not-well-defined" id=" id6">Not Well-Defined</a></p>
13 <ul class="small-gap"> 13 <ul class="small-gap">
14 <li><a class="reference internal" href="#potentially-fixable" id="id7">Potential ly Fixable</a></li> 14 <li><a class="reference internal" href="#potentially-fixable" id="id7">Potential ly Fixable</a></li>
15 <li><a class="reference internal" href="#floating-point" id="id8">Floating-Point </a></li> 15 <li><a class="reference internal" href="#floating-point" id="id8">Floating-Point </a></li>
16 <li><a class="reference internal" href="#simd-vectors" id="id9">SIMD Vectors</a> </li> 16 <li><a class="reference internal" href="#simd-vectors" id="id9">SIMD Vectors</a> </li>
17 <li><a class="reference internal" href="#hard-to-fix" id="id10">Hard to Fix</a>< /li> 17 <li><a class="reference internal" href="#hard-to-fix" id="id10">Hard to Fix</a>< /li>
18 </ul> 18 </ul>
19 </li> 19 </li>
20 </ul> 20 </ul>
21 </li> 21 </li>
22 </ul> 22 </ul>
23 23
24 </div><section id="overview"> 24 </div><h2 id="overview"><span id="undefined-behavior"></span>Overview</h2>
25 <span id="undefined-behavior"></span><h2 id="overview"><span id="undefined-behav ior"></span>Overview</h2>
26 <p>C and C++ undefined behavior allows efficient mapping of the source 25 <p>C and C++ undefined behavior allows efficient mapping of the source
27 language onto hardware, but leads to different behavior on different 26 language onto hardware, but leads to different behavior on different
28 platforms.</p> 27 platforms.</p>
29 <p>PNaCl exposes undefined behavior in the following ways:</p> 28 <p>PNaCl exposes undefined behavior in the following ways:</p>
30 <ul class="small-gap"> 29 <ul class="small-gap">
31 <li><p class="first">The Clang frontend and optimizations that occur on the deve loper&#8217;s 30 <li><p class="first">The Clang frontend and optimizations that occur on the deve loper&#8217;s
32 machine determine what behavior will occur, and it will be specified 31 machine determine what behavior will occur, and it will be specified
33 deterministically in the <em>pexe</em>. All targets will observe the same 32 deterministically in the <em>pexe</em>. All targets will observe the same
34 behavior. In some cases, recompiling with a newer PNaCl SDK version 33 behavior. In some cases, recompiling with a newer PNaCl SDK version
35 will either:</p> 34 will either:</p>
(...skipping 14 matching lines...) Expand all
50 (i.e. after a Chrome update) will compile the code differently and 49 (i.e. after a Chrome update) will compile the code differently and
51 cause different behavior.</li> 50 cause different behavior.</li>
52 <li>In some cases, the same versions of the PNaCl translator, on the 51 <li>In some cases, the same versions of the PNaCl translator, on the
53 same architecture, will generate a different <em>nexe</em> for 52 same architecture, will generate a different <em>nexe</em> for
54 defense-in-depth purposes, but may cause code that reads invalid 53 defense-in-depth purposes, but may cause code that reads invalid
55 stack values or code sections on the heap to observe these 54 stack values or code sections on the heap to observe these
56 randomizations.</li> 55 randomizations.</li>
57 </ul> 56 </ul>
58 </li> 57 </li>
59 </ul> 58 </ul>
60 </section><section id="specification">
61 <h2 id="specification">Specification</h2> 59 <h2 id="specification">Specification</h2>
62 <p>PNaCl&#8217;s goal is that a single <em>pexe</em> should work reliably in the same 60 <p>PNaCl&#8217;s goal is that a single <em>pexe</em> should work reliably in the same
63 manner on all architectures, irrespective of runtime parameters and 61 manner on all architectures, irrespective of runtime parameters and
64 through Chrome updates. This goal is unfortunately not attainable; PNaCl 62 through Chrome updates. This goal is unfortunately not attainable; PNaCl
65 therefore specifies as much as it can and outlines areas for 63 therefore specifies as much as it can and outlines areas for
66 improvement.</p> 64 improvement.</p>
67 <p>One interesting solution is to offer good support for LLVM&#8217;s sanitizer 65 <p>One interesting solution is to offer good support for LLVM&#8217;s sanitizer
68 tools (including <a class="reference external" href="http://clang.llvm.org/docs/ UsersManual.html#controlling-code-generation">UBSan</a>) 66 tools (including <a class="reference external" href="http://clang.llvm.org/docs/ UsersManual.html#controlling-code-generation">UBSan</a>)
69 at development time, so that developers can test their code against 67 at development time, so that developers can test their code against
70 undefined behavior. Shipping code would then still get good performance, 68 undefined behavior. Shipping code would then still get good performance,
71 and diverging behavior would be rare.</p> 69 and diverging behavior would be rare.</p>
72 <p>Note that none of these issues are vulnerabilities in PNaCl and Chrome: 70 <p>Note that none of these issues are vulnerabilities in PNaCl and Chrome:
73 the NaCl sandboxing still constrains the code through Software Fault 71 the NaCl sandboxing still constrains the code through Software Fault
74 Isolation.</p> 72 Isolation.</p>
75 </section><section id="behavior-in-pnacl-bitcode">
76 <h2 id="behavior-in-pnacl-bitcode">Behavior in PNaCl Bitcode</h2> 73 <h2 id="behavior-in-pnacl-bitcode">Behavior in PNaCl Bitcode</h2>
77 <section id="well-defined">
78 <h3 id="well-defined">Well-Defined</h3> 74 <h3 id="well-defined">Well-Defined</h3>
79 <p>The following are traditionally undefined behavior in C/C++ but are well 75 <p>The following are traditionally undefined behavior in C/C++ but are well
80 defined at the <em>pexe</em> level:</p> 76 defined at the <em>pexe</em> level:</p>
81 <ul class="small-gap"> 77 <ul class="small-gap">
82 <li>Dynamic initialization order dependencies: the order is deterministic 78 <li>Dynamic initialization order dependencies: the order is deterministic
83 in the <em>pexe</em>.</li> 79 in the <em>pexe</em>.</li>
84 <li>Bool which isn&#8217;t <code>0</code>/<code>1</code>: the bitcode instructio n sequence is 80 <li>Bool which isn&#8217;t <code>0</code>/<code>1</code>: the bitcode instructio n sequence is
85 deterministic in the <em>pexe</em>.</li> 81 deterministic in the <em>pexe</em>.</li>
86 <li>Out-of-range <code>enum</code> value: the backing integer type and bitcode 82 <li>Out-of-range <code>enum</code> value: the backing integer type and bitcode
87 instruction sequence is deterministic in the <em>pexe</em>.</li> 83 instruction sequence is deterministic in the <em>pexe</em>.</li>
88 <li>Aggressive optimizations based on type-based alias analysis: TBAA 84 <li>Aggressive optimizations based on type-based alias analysis: TBAA
89 optimizations are done before stable bitcode is generated and their 85 optimizations are done before stable bitcode is generated and their
90 metadata is stripped from the <em>pexe</em>; behavior is therefore 86 metadata is stripped from the <em>pexe</em>; behavior is therefore
91 deterministic in the <em>pexe</em>.</li> 87 deterministic in the <em>pexe</em>.</li>
92 <li>Operator and subexpression evaluation order in the same expression 88 <li>Operator and subexpression evaluation order in the same expression
93 (e.g. function parameter passing, or pre-increment): the order is 89 (e.g. function parameter passing, or pre-increment): the order is
94 defined in the <em>pexe</em>.</li> 90 defined in the <em>pexe</em>.</li>
95 <li>Signed integer overflow: two&#8217;s complement integer arithmetic is 91 <li>Signed integer overflow: two&#8217;s complement integer arithmetic is
96 assumed.</li> 92 assumed.</li>
97 <li>Atomic access to a non-atomic memory location (not declared as 93 <li>Atomic access to a non-atomic memory location (not declared as
98 <code>std::atomic</code>): atomics and <code>volatile</code> variables all lower to the 94 <code>std::atomic</code>): atomics and <code>volatile</code> variables all lower to the
99 same compatible intrinsics or external functions; the behavior is 95 same compatible intrinsics or external functions; the behavior is
100 therefore deterministic in the <em>pexe</em> (see <a class="reference internal" href="/native-client/reference/pnacl-c-cpp-language-support.html#memory-model-an d-atomics"><em>Memory Model and 96 therefore deterministic in the <em>pexe</em> (see <a class="reference internal" href="/native-client/reference/pnacl-c-cpp-language-support.html#memory-model-an d-atomics"><em>Memory Model and
101 Atomics</em></a>).</li> 97 Atomics</em></a>).</li>
102 <li>Integer divide by zero: always raises a fault (through hardware on 98 <li>Integer divide by zero: always raises a fault (through hardware on
103 x86, and through integer divide emulation routine or explicit checks 99 x86, and through integer divide emulation routine or explicit checks
104 on ARM).</li> 100 on ARM).</li>
105 </ul> 101 </ul>
106 </section><section id="not-well-defined">
107 <h3 id="not-well-defined">Not Well-Defined</h3> 102 <h3 id="not-well-defined">Not Well-Defined</h3>
108 <p>The following are traditionally undefined behavior in C/C++ which also 103 <p>The following are traditionally undefined behavior in C/C++ which also
109 exhibit undefined behavior at the <em>pexe</em> level. Some are easier to fix 104 exhibit undefined behavior at the <em>pexe</em> level. Some are easier to fix
110 than others.</p> 105 than others.</p>
111 <section id="potentially-fixable">
112 <h4 id="potentially-fixable">Potentially Fixable</h4> 106 <h4 id="potentially-fixable">Potentially Fixable</h4>
113 <ul class="small-gap"> 107 <ul class="small-gap">
114 <li><p class="first">Shift by greater-than-or-equal to left-hand-side&#8217;s bi t-width or 108 <li><p class="first">Shift by greater-than-or-equal to left-hand-side&#8217;s bi t-width or
115 negative (see <a class="reference external" href="https://code.google.com/p/nati veclient/issues/detail?id=3604">bug 3604</a>).</p> 109 negative (see <a class="reference external" href="https://code.google.com/p/nati veclient/issues/detail?id=3604">bug 3604</a>).</p>
116 <ul class="small-gap"> 110 <ul class="small-gap">
117 <li>Some of the behavior will be specified in the <em>pexe</em> depending on 111 <li>Some of the behavior will be specified in the <em>pexe</em> depending on
118 constant propagation and integer type of variables.</li> 112 constant propagation and integer type of variables.</li>
119 <li>There is still some architecture-specific behavior.</li> 113 <li>There is still some architecture-specific behavior.</li>
120 <li>PNaCl could force-mask the right-hand-side to <cite>bitwidth-1</cite>, which 114 <li>PNaCl could force-mask the right-hand-side to <cite>bitwidth-1</cite>, which
121 could become a no-op on some architectures while ensuring all 115 could become a no-op on some architectures while ensuring all
(...skipping 26 matching lines...) Expand all
148 <ul class="small-gap"> 142 <ul class="small-gap">
149 <li>LLVM provides an IR instruction called “unreachable” whose effect 143 <li>LLVM provides an IR instruction called “unreachable” whose effect
150 will be undefined. PNaCl could change this to always trap, as the 144 will be undefined. PNaCl could change this to always trap, as the
151 <code>llvm.trap</code> intrinsic does.</li> 145 <code>llvm.trap</code> intrinsic does.</li>
152 </ul> 146 </ul>
153 </li> 147 </li>
154 <li>Zero or negative-sized variable-length array (and <code>alloca</code>) aren& #8217;t 148 <li>Zero or negative-sized variable-length array (and <code>alloca</code>) aren& #8217;t
155 defined behavior. PNaCl&#8217;s frontend or the translator could insert 149 defined behavior. PNaCl&#8217;s frontend or the translator could insert
156 checks with <code>-fsanitize=vla-bound</code>.</li> 150 checks with <code>-fsanitize=vla-bound</code>.</li>
157 </ul> 151 </ul>
158 </section><section id="floating-point"> 152 <h4 id="floating-point"><span id="undefined-behavior-fp"></span>Floating-Point</ h4>
159 <span id="undefined-behavior-fp"></span><h4 id="floating-point"><span id="undefi ned-behavior-fp"></span>Floating-Point</h4>
160 <p>PNaCl offers a IEEE-754 implementation which is as correct as the 153 <p>PNaCl offers a IEEE-754 implementation which is as correct as the
161 underlying hardware allows, with a few limitations. These are a few 154 underlying hardware allows, with a few limitations. These are a few
162 sources of undefined behavior which are believed to be fixable:</p> 155 sources of undefined behavior which are believed to be fixable:</p>
163 <ul class="small-gap"> 156 <ul class="small-gap">
164 <li>Float cast overflow is currently undefined.</li> 157 <li>Float cast overflow is currently undefined.</li>
165 <li>Float divide by zero is currently undefined.</li> 158 <li>Float divide by zero is currently undefined.</li>
166 <li>The default denormal behavior is currently unspecified, which isn&#8217;t 159 <li>The default denormal behavior is currently unspecified, which isn&#8217;t
167 IEEE-754 compliant (denormals must be supported in IEEE-754). PNaCl 160 IEEE-754 compliant (denormals must be supported in IEEE-754). PNaCl
168 could mandate flush-to-zero, and may give an API to enable denormals 161 could mandate flush-to-zero, and may give an API to enable denormals
169 in a future release. The latter is problematic for SIMD and 162 in a future release. The latter is problematic for SIMD and
170 vectorization support, where some platforms do not support denormal 163 vectorization support, where some platforms do not support denormal
171 SIMD operations.</li> 164 SIMD operations.</li>
172 <li><code>NaN</code> values are currently not guaranteed to be canonical; see <a class="reference external" href="https://code.google.com/p/nativeclient/issues/ detail?id=3536">bug 165 <li><code>NaN</code> values are currently not guaranteed to be canonical; see <a class="reference external" href="https://code.google.com/p/nativeclient/issues/ detail?id=3536">bug
173 3536</a>.</li> 166 3536</a>.</li>
174 <li>Passing <code>NaN</code> to STL functions (the math is defined, but the 167 <li>Passing <code>NaN</code> to STL functions (the math is defined, but the
175 function implementation isn&#8217;t, e.g. <code>std::min</code> and <code>std::m ax</code>), is 168 function implementation isn&#8217;t, e.g. <code>std::min</code> and <code>std::m ax</code>), is
176 well-defined in the <em>pexe</em>.</li> 169 well-defined in the <em>pexe</em>.</li>
177 </ul> 170 </ul>
178 </section><section id="simd-vectors">
179 <h4 id="simd-vectors">SIMD Vectors</h4> 171 <h4 id="simd-vectors">SIMD Vectors</h4>
180 <p>SIMD vector instructions aren&#8217;t part of the C/C++ standards and as such 172 <p>SIMD vector instructions aren&#8217;t part of the C/C++ standards and as such
181 their behavior isn&#8217;t specified at all in C/C++; it is usually left up to 173 their behavior isn&#8217;t specified at all in C/C++; it is usually left up to
182 the target architecture to specify behavior. Portable Native Client 174 the target architecture to specify behavior. Portable Native Client
183 instead exposed <a class="reference internal" href="/native-client/reference/pna cl-c-cpp-language-support.html#portable-simd-vectors"><em>Portable SIMD Vectors< /em></a> and 175 instead exposed <a class="reference internal" href="/native-client/reference/pna cl-c-cpp-language-support.html#portable-simd-vectors"><em>Portable SIMD Vectors< /em></a> and
184 offers the same guarantees on these vectors as the guarantees offered by 176 offers the same guarantees on these vectors as the guarantees offered by
185 the contained elements. Of notable interest amongst these guarantees are 177 the contained elements. Of notable interest amongst these guarantees are
186 those of alignment for load/store instructions on vectors: they have the 178 those of alignment for load/store instructions on vectors: they have the
187 same alignment restriction as the contained elements.</p> 179 same alignment restriction as the contained elements.</p>
188 </section><section id="hard-to-fix">
189 <h4 id="hard-to-fix">Hard to Fix</h4> 180 <h4 id="hard-to-fix">Hard to Fix</h4>
190 <ul class="small-gap"> 181 <ul class="small-gap">
191 <li><p class="first">Null pointer/reference has behavior determined by the NaCl sandbox:</p> 182 <li><p class="first">Null pointer/reference has behavior determined by the NaCl sandbox:</p>
192 <ul class="small-gap"> 183 <ul class="small-gap">
193 <li>Raises a segmentation fault in the bottom <code>64KiB</code> bytes on all 184 <li>Raises a segmentation fault in the bottom <code>64KiB</code> bytes on all
194 platforms, and on some sandboxes there are further non-writable 185 platforms, and on some sandboxes there are further non-writable
195 pages after the initial <code>64KiB</code>.</li> 186 pages after the initial <code>64KiB</code>.</li>
196 <li>Negative offsets aren&#8217;t handled consistently on all platforms: 187 <li>Negative offsets aren&#8217;t handled consistently on all platforms:
197 x86-64 and ARM will wrap around to the stack (because they mask the 188 x86-64 and ARM will wrap around to the stack (because they mask the
198 address), whereas x86-32 will fault (because of segmentation).</li> 189 address), whereas x86-32 will fault (because of segmentation).</li>
(...skipping 25 matching lines...) Expand all
224 </ul> 215 </ul>
225 </li> 216 </li>
226 <li>Out-of-scope variable usage: will produce unknown data, mostly 217 <li>Out-of-scope variable usage: will produce unknown data, mostly
227 dependent on stack and memory allocation.</li> 218 dependent on stack and memory allocation.</li>
228 <li>Data races: any two operations that conflict (target overlapping 219 <li>Data races: any two operations that conflict (target overlapping
229 memory), at least one of which is a store or atomic read-modify-write, 220 memory), at least one of which is a store or atomic read-modify-write,
230 and at least one of which is not atomic: this will be very dependent 221 and at least one of which is not atomic: this will be very dependent
231 on processor and execution sequence, see <a class="reference internal" href="/na tive-client/reference/pnacl-c-cpp-language-support.html#memory-model-and-atomics "><em>Memory Model and 222 on processor and execution sequence, see <a class="reference internal" href="/na tive-client/reference/pnacl-c-cpp-language-support.html#memory-model-and-atomics "><em>Memory Model and
232 Atomics</em></a>.</li> 223 Atomics</em></a>.</li>
233 </ul> 224 </ul>
234 </section></section></section></section> 225 </section>
235 226
236 {{/partials.standard_nacl_article}} 227 {{/partials.standard_nacl_article}}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698