Modular Reasoning about Global Variables and Their Initialization
Open Access
- 9 October 2025
- journal article
- Published by Association for Computing Machinery (ACM) in Proceedings of the ACM on Programming Languages
- Vol. 9 (OOPSLA2) , 2310-2337
Abstract
Many imperative programming languages offer global variables to implement common functionality such as global caches and counters. Global variables are typically initialized by module initializers (e.g., static initializers in Java), code blocks that are executed automatically by the runtime system. When or in what order these initializers run is typically not known statically and modularly. For instance in Java, initialization is triggered dynamically upon the first use of a class, while in Go, the order depends on all packages of a program. As a result, reasoning modularly about global variables and their initialization is difficult, especially because module initializers may perform arbitrary side effects and may have cyclic dependencies. Consequently, existing modular verification techniques either do not support global state or impose drastic restrictions that are not satisfied by mainstream languages and programs. In this paper, we present the first practical verification technique to reason formally and modularly about global state and its initialization. Our technique is based on separation logic and uses module invariants to specify ownership and values of global variables. A partial order on modules and methods allows us to reason modularly about when a module invariant may be soundly assumed to hold, irrespective of when exactly the module initializer establishing it runs. Our technique supports both thread-local and shared global state. We formalize it as a program logic in Iris and prove its soundness in Rocq. We make only minimal assumptions about the initialization semantics, making our technique applicable to a wide range of programming languages. We implemented our technique in existing verifiers for Java and Go and demonstrate its effectiveness on typical uses cases of global state as well as a substantial codebase implementing an Internet router.Keywords
This publication has 39 references indexed in Scilit:
- Gobra: Modular Specification and Verification of Go Programs2021
- SCION: A Secure Internet Architecture2017
- Deductive Software Verification – The KeY Book2016
- The Spirit of Ghost CodeLecture Notes in Computer Science, 2014
- The VerCors Tool for Verification of Concurrent Programs2014
- Boogie: A Modular Reusable Verifier for Object-Oriented Programs2006
- Modular Verification of Static Class InvariantsLecture Notes in Computer Science, 2005
- Object Invariants in Dynamic Contexts2004
- Resources, Concurrency and Local Reasoning2004
- Checking Interference with Fractional Permissions2003