The python "open" function will use the default encoding for the locale (the result of "locale.getpreferredencoding()"). Explicitly set the locale to utf-8 when opening the crashlog for writing, as there may be non-ascii symbols in there (for example, Swift uses "τ" to indicate generic parameters). rdar://101402755 Differential Revision: https://reviews.llvm.org/D136798