Skip to content

Fix inlining failures when using bazel#12

Merged
yuzefovich merged 1 commit intojordanlewis:masterfrom
healthy-pod:actually-support-bazel
Jun 7, 2023
Merged

Fix inlining failures when using bazel#12
yuzefovich merged 1 commit intojordanlewis:masterfrom
healthy-pod:actually-support-bazel

Conversation

@healthy-pod
Copy link
Copy Markdown
Contributor

Some of the inline statements do not appear in the compiler output when the go compiler is invoked through bazel.

This code change makes gcassert inspect the object files directly to check if a function call that must always be inlined was ever not inlined (when using bazel).

@healthy-pod
Copy link
Copy Markdown
Contributor Author

@yuzefovich @jordanlewis please take a look

Copy link
Copy Markdown
Collaborator

@yuzefovich yuzefovich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some of the inline statements do not appear in the compiler output when the go compiler is invoked through bazel.

Can you say a bit more about this? Does it mean that direct go invocation produces lines like was inlined for some functions whereas bazel invocation doesn't?

gcassert_test.go Outdated
func TestGCAssert(t *testing.T) {
var w strings.Builder
err := GCAssert(&w, false /* useBazel */, "./testdata", "./testdata/otherpkg")
err := GCAssert(&w, false /* useBazel */, false /* debug*/, "./testdata", "./testdata/otherpkg")
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: add a space after debug.
nit: also update README.md with the new arg.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

bazel_utils.go Outdated
return exec.Command("bazel", args...)
}

func getBazelBin() (string, error) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: getBazelBin and getWorkspacePath are almost the same, maybe extract a helper.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

bazel_utils.go Outdated
mvcc.go:1135 0x66928a 94000000 CALL 0(PC) [0:4]R_CALLARM64:github.com/cockroachdb/cockroach/pkg/storage.(*MVCCGetOptions).validate

*/
callRegex, err := regexp.Compile(`\s*(\S+)\s*\S*\s*\S*\s*(CALL)\s*\S*\s*(\S+)`)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: we could remove the capturing group for (i.e. the parenthesis around) CALL characters since we don't actually need to capture it, up to you though.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

bazel_utils.go Outdated
if fnIdentifierMatch != nil {
// See example call above for details on why this manipulation works.
currentFn := fnIdentifierMatch[3][strings.LastIndex(fnIdentifierMatch[3], ":")+1:]
for _, inlineFn := range bazelInlineSites {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: not sure if this is important, but we could make bazelInlineSites a map to speed up this search.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@healthy-pod healthy-pod force-pushed the actually-support-bazel branch 4 times, most recently from 5d97194 to ecab5e4 Compare June 7, 2023 00:30
@healthy-pod
Copy link
Copy Markdown
Contributor Author

Can you say a bit more about this? Does it mean that direct go invocation produces lines like was inlined for some functions whereas bazel invocation doesn't?

Exactly, for some function calls we do not get inlining call to ... in the compiler output even though the call is inlined according to the object code (which ofcourse is the most trusted way to check if a call is inlined).

@healthy-pod healthy-pod requested a review from yuzefovich June 7, 2023 00:31
bazel_utils.go Outdated

if !atleastMatchedOnce {
errorMsg := `callRegex did not match any line in the disassembled object code.
This means it did not find any non-inlined function calls in the inspected object files. Ensure that the regex is still correct if this
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: we're not in crdb repo (where this is mandated in the style guide), but there are a few lines and comments (as well as in the other file) that are too long, consider wrapping them.

@yuzefovich
Copy link
Copy Markdown
Collaborator

Oops, just realized that a couple of comments that I had in response to your previous comments are now removed because I marked them as "resolved" (I'm not used to using the github review modal :/). (Trying to reproduce those.)

  1. I like your change for the error / warning when no non-inlined function were found, thanks!
  2. I'm satisfied with the warning / error in terms of change to the compiler output when Go is upgraded. Including a step in the runbook sounds good to me, but I'll defer to you whether it's worth doing so.

Some of the inline statements do not appear in the compiler output
when the go compiler is invoked through bazel.

This code change makes gcassert inspect the object files directly to check if a
function call that must always be inlined was ever not inlined (when
using bazel).
@healthy-pod healthy-pod force-pushed the actually-support-bazel branch from ecab5e4 to 819f79a Compare June 7, 2023 03:19
@healthy-pod
Copy link
Copy Markdown
Contributor Author

I wrapped a few long lines and addressed the other nits. I will add the new runbook step in cockroachdb/cockroach#103471. Thanks for the quick review!

@healthy-pod healthy-pod requested a review from yuzefovich June 7, 2023 03:34
@jordanlewis
Copy link
Copy Markdown
Owner

Will defer to Yahor for the review, please keep in mind that this tool should remain usable outside of Bazel as well.

@yuzefovich
Copy link
Copy Markdown
Collaborator

Ahmad effectively implemented a parallel path for bazel builds, so the existing non-bazel one should continue working.

@yuzefovich yuzefovich merged commit 9012d8e into jordanlewis:master Jun 7, 2023
healthy-pod pushed a commit to healthy-pod/gcassert that referenced this pull request Jun 7, 2023
…azel

Fix inlining failures when using bazel
healthy-pod pushed a commit to healthy-pod/gcassert that referenced this pull request Jun 7, 2023
…azel

Fix inlining failures when using bazel
healthy-pod pushed a commit to healthy-pod/gcassert that referenced this pull request Jun 7, 2023
…azel

Fix inlining failures when using bazel
healthy-pod pushed a commit to healthy-pod/gcassert that referenced this pull request Jun 7, 2023
…azel

Fix inlining failures when using bazel
healthy-pod pushed a commit to healthy-pod/gcassert that referenced this pull request Jun 7, 2023
…azel

Fix inlining failures when using bazel
healthy-pod pushed a commit to healthy-pod/cockroach that referenced this pull request Jun 8, 2023
This code change pulls changes from jordanlewis/gcassert#11
and jordanlewis/gcassert#12 to let gcassert use bazel to build
if the `--use-bazel` flag is set.

It now checks if inline directives passed by inspecting object
files because the compiler output is missing some inline statements
when invoked through `bazel`.

Release note: None
Epic: CRDB-8349

Closes cockroachdb#65485
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants