Index: compiler-rt/lib/sanitizer_common/sanitizer_fuchsia.cc =================================================================== --- compiler-rt/lib/sanitizer_common/sanitizer_fuchsia.cc +++ compiler-rt/lib/sanitizer_common/sanitizer_fuchsia.cc @@ -407,7 +407,32 @@ } void RawWrite(const char *buffer) { - __sanitizer_log_write(buffer, internal_strlen(buffer)); + constexpr size_t size = 128; + static _Thread_local char line[size]; + static _Thread_local char *lastNewline = nullptr; + static _Thread_local size_t cur = 0; + + while (*buffer) { + if (cur >= size) { + if (lastNewline == nullptr) + lastNewline = line; + __sanitizer_log_write(line, lastNewline - line); + internal_memmove(line, lastNewline, line + size - lastNewline); + cur = 0; + lastNewline = nullptr; + } + if (*buffer == '\n') + lastNewline = line + cur; + line[cur++] = *buffer++; + } + // Flush if there's a newline in the buffer but the buffer isn't full. + // This prevents the last few lines from not being flushed. + if (lastNewline != nullptr) { + __sanitizer_log_write(line, lastNewline - line); + internal_memmove(line, lastNewline, line + cur - lastNewline); + cur = 0; + lastNewline = nullptr; + } } void CatastrophicErrorWrite(const char *buffer, uptr length) {