From c45ebef05edcb217be8f9bf1d7649763132727cc Mon Sep 17 00:00:00 2001 From: Michael Pratt Date: Mon, 17 Oct 2022 15:57:48 -0400 Subject: runtime: avoid unsafe.{Slice,String} in debuglog CL 428157 and CL 428759 switched debuglog to using unsafe.String and unsafe.Slice, which broke the build with -tags=debuglog because this is a no write barrier context, but runtime.unsafeString and unsafeSlice can panic, which includes write barriers. We could add a panicCheck1 path to these functions to reallow write barriers, but it is a big mess to pass around the caller PC, particularly since the compiler generates calls. It is much simpler to just avoid unsafe.String and Slice. Also add a basic test to build the runtime with -tags=debuglog to help avoid future regressions. For #54854. Change-Id: I702418b986fbf189664e9aa4f40bc7de4d9e7781 Reviewed-on: https://go-review.googlesource.com/c/go/+/443380 Run-TryBot: Michael Pratt Auto-Submit: Michael Pratt TryBot-Result: Gopher Robot Reviewed-by: Michael Knyszek --- src/runtime/debuglog_test.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/runtime/debuglog_test.go') diff --git a/src/runtime/debuglog_test.go b/src/runtime/debuglog_test.go index 10dc72cf51..18c54a81b9 100644 --- a/src/runtime/debuglog_test.go +++ b/src/runtime/debuglog_test.go @@ -24,6 +24,7 @@ package runtime_test import ( "fmt" + "internal/testenv" "regexp" "runtime" "strings" @@ -155,3 +156,14 @@ func TestDebugLogLongString(t *testing.T) { t.Fatalf("want %q, got %q", want, got) } } + +// TestDebugLogBuild verifies that the runtime builds with -tags=debuglog. +func TestDebugLogBuild(t *testing.T) { + testenv.MustHaveGoBuild(t) + + // It doesn't matter which program we build, anything will rebuild the + // runtime. + if _, err := buildTestProg(t, "testprog", "-tags=debuglog"); err != nil { + t.Fatal(err) + } +} -- cgit v1.3-5-g9baa