Repository navigation
fix(global-read-before-write): identify a global across files as the linker does - #197
Merged
Merged
Conversation
… linker does Two static globals with the same name in two files, or a static and an external one, share one cross-TU entry: a write to one counts as a write to the other (#166). Cover both collisions, a static global written in another function of its own file, and an external global written in another file.
…linker does The cross-TU summary keyed each global by its raw IR name, whatever its linkage. Two static globals with the same name in two files, or a static and an external one, shared one entry, so a write to one counted as a write to the other. Key an external global by its linker symbol, as the cross-TU function facts do (#157). Key a static global by its module too: it stays in the index, so a write in another function of its own file still counts, but no other file finds it. Fixes #166
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #166
Problem
The cross-TU summary of
GlobalReadBeforeWritekeyed each global by its raw IR name, whatever its linkage. Twostaticglobals with the same name in two files, or a static and an external one, shared one entry: a write to one counted as a write to the other. Reproduced onmainfaf1050:read_table(reads the statictableofa.c)a.ca.c b.c(statictablewritten inb.c)a.c ext_table.c(externaltablewritten)Fix
A
summaryKeyfunction now gives the key at the 3 places that read or write the index:linkerSymbolName, as the cross-TU function facts are (Cross-TU: rules that follow calls within a file lose them across files #157), so a declaration finds the definition of another file;LLVM module identifiers are not unique here (every module is
cached_irorin_memory_ll), so the key uses the address of thellvm::Module. The index is only built in shared loading, from the modules that are then analyzed, so the address is stable for the lifetime of the index. The header documents the key.Tests
check_global_read_before_write_identity_across_filescovers both collisions, a static global written in another function of its own file, and an external global written in another file.mainbinary: the 2 collisions fail, the 2 guards pass. GREEN: 4/4.Before / after (
mainfaf1050 vs this branch, Linux x86_64)defaultandz3: 846 runs, 0 differ, 1287 = 1287 diagnostics.Limits
GlobalReadBeforeWriteresult. The two comparisons show no regression elsewhere; the new check is what covers the fix.linkerSymbolNameinstead of the raw name only matters for a renamed symbol (__asm__). No case covers that here.Code scanning
CI is green on 4c64dd4: 13 checks pass, the release attach step is skipped.
main: none new, none gone.github-advanced-securitycomment on this PR. No newcoretrace-concurrency-analyzeralert.