Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BOLT] Fix data race in MCPlusBuilder::getOrCreateAnnotationIndex #67004

Merged
merged 3 commits into from
Sep 21, 2023

Conversation

kbeyls
Copy link
Collaborator

@kbeyls kbeyls commented Sep 21, 2023

MCPlusBuilder::getOrCreateAnnotationIndex(Name) can be called from different threads, for example when making use of
ParallelUtilities::runOnEachFunctionWithUniqueAllocId.

The race occurs when an Index for a particular annotation Name needs to be created for the first time.

For example, this can easily happen when multiple "copies" of an analysis pass run on different BinaryFunctions, and the analysis pass creates a new Annotation Index to be able to store analysis results as annotations.

This was found by using the ThreadSanitizer.

No regression test was added; I don't think there is good way to write regression tests that verify the absence of data races?

MCPlusBuilder::getAnnotationIndex(Name) can be called from different
threads, for example when making use of
ParallelUtilities::runOnEachFunctionWithUniqueAllocId.

The race occurs when an Index for a particular annotation Name needs to
be created for the first time.

For example, this can easily happen when multiple "copies" of an
analysis pass run on different BinaryFunctions, and the analysis pass
creates a new Annotation Index to be able to store analysis results as
annotations.

This was found by using the ThreadSanitizer.

No regression test was added; I don't think there is good way to write
regression tests that verify the absence of data races?
@kbeyls kbeyls requested a review from aaupov September 21, 2023 11:43
Copy link
Contributor

@aaupov aaupov left a comment

Choose a reason for hiding this comment

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

Thank you for the fix! LGTM with a minor nit.

@kbeyls kbeyls merged commit 8fb28e4 into llvm:main Sep 21, 2023
2 checks passed
@kbeyls
Copy link
Collaborator Author

kbeyls commented Sep 21, 2023

Thanks for the quick review!

@kbeyls kbeyls deleted the bolt-fix-data-race branch September 21, 2023 17:55
Guzhu-AMD pushed a commit to GPUOpen-Drivers/llvm-project that referenced this pull request Sep 28, 2023
Local branch amd-gfx 345ce9d Merged main:7fcbb64fca5e into amd-gfx:b56d6b265611
Remote branch main 8fb28e4 [BOLT] Fix data race in MCPlusBuilder::getOrCreateAnnotationIndex (llvm#67004)
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.

None yet

2 participants