Reputation: 12700
Google NaCL comes with at least two C++ compilers: a very old gcc version, and a very recent clang version. The gcc version does not support C++ 11, so I would rather not use it. The very new clang compiler generates intermediate code, and then either is compiled in the browser, or ones compiles it to native. I tried the first approach: having Chrome compile it in the browser. The problem: exceptions didn't work, and I need them. I checked this, but I really can't understand the fine print of this ticket. That leaves the second approach: compile the code to native before deploying... question: would I be able to use exceptions then? Or should I surrender any hope?
(... After Go and this, I'm under the impression that Google engineers really hate exceptions...)
Upvotes: 3
Views: 1212
Reputation: 1462
In the latest versions of the PNaCl toolchain, you can enable C++ exception handling by passing the option --pnacl-exceptions=sjlj
at link time. The resulting pexe will work in any version of Chrome that supports PNaCl (Chrome 31 onwards).
This option converts try/catch blocks to using setjmp() internally. The performance might not be great. We plan on adding ABI-stable support for zero-cost exception handling later to improve the performance.
This option should eventually be available in the NaCl SDK for Chrome 33. Until then, it's available in Canary versions of the NaCl SDK.
Upvotes: 7
Reputation: 634
The essence of the ticket you link to is that
you can't use C++ exceptions in PNaCl, that is, you can't use C++ exceptions if you plan to deploy as a .pexe
file (LLVM bitcode), but
you can use C++ exceptions with the Clang-based toolchain if you provide the flag --pnacl-allow-exceptions
(to both pnacl-clang and pnacl-translate) and compile and translate all the way to a set of .nexe
binaries before deployment.
In C++, as well as in pretty much any other language, exceptions should be used sparingly, and as you can see above some style guides suggest not using them at all.
Upvotes: 4
Reputation: 1462
You can use C++ exceptions with the PNaCl toolchain if you plan to deploy a .nexe.
You'll need to pass --pnacl-allow-exceptions
to pnacl-clang when linking the .pexe and to pnacl-translate when translating the .pexe to a .nexe.
If you don't pass this option to pnacl-translate, you'll get errors about _Unwind_*
symbols being unresolved. If you don't pass this option when linking the .pexe, throwing an exception will cause the program to exit.
C++ exceptions won't be supported when the .pexe is translated by the browser in the first release of PNaCl. As above, throwing an exception will cause the program to exit. But a later release will support C++ exceptions.
Upvotes: 4