xref: /aosp_15_r20/external/toolchain-utils/compiler_wrapper/kernel_bug.go (revision 760c253c1ed00ce9abd48f8546f08516e57485fe)
1*760c253cSXin Li// Copyright 2021 The ChromiumOS Authors
2*760c253cSXin Li// Use of this source code is governed by a BSD-style license that can be
3*760c253cSXin Li// found in the LICENSE file.
4*760c253cSXin Lipackage main
5*760c253cSXin Li
6*760c253cSXin Liimport (
7*760c253cSXin Li	"bytes"
8*760c253cSXin Li	"strings"
9*760c253cSXin Li)
10*760c253cSXin Li
11*760c253cSXin Li// crbug.com/1166017
12*760c253cSXin Li
13*760c253cSXin Liconst kernelBugRetryLimit = 25
14*760c253cSXin Li
15*760c253cSXin Li// GCC will sometimes fail to wait on subprocesses due to this kernel bug. It always fails the
16*760c253cSXin Li// compilation and prints "Unknown error 512" in that case.
17*760c253cSXin Lifunc containsTracesOfKernelBug(buf []byte) bool {
18*760c253cSXin Li	return bytes.Contains(buf, []byte("Unknown error 512"))
19*760c253cSXin Li}
20*760c253cSXin Li
21*760c253cSXin Lifunc errorContainsTracesOfKernelBug(err error) bool {
22*760c253cSXin Li	// We'll get errors that look like "waitid: errno 512." Presumably, this isn't specific to
23*760c253cSXin Li	// waitid, so just try to match the "errno 512" ending.
24*760c253cSXin Li	return err != nil && strings.HasSuffix(err.Error(), "errno 512")
25*760c253cSXin Li}
26