rjmccall added a comment. Hmm. Preserving unused global variables in case a hot patch might use them doesn't seem very compelling to me — hot patches need to be able to introduce globals of their own anyway. What I find more convincing is related to the *other* meaning of `__attribute__((used))`, that the compiler needs to treat the global as potentially referenced and used in ways that it cannot analyze. Considered from that perspective, a hot patch is essentially extra code that can be loaded into any translation unit dynamically. If there are hot-patchable functions in a translation unit, the compiler needs to broadly avoid optimizing any globals referenceable from that translation unit as if it understood all their uses. So it's less that we need to preserve globals that are actually unused and more that we need to preserve the use-patterns of globals. For example, we can't decide that a mutable global variable is never reassigned and so forward its constant initializer to all the loads from it, because we need to treat that global as potentially reassigned by the code loaded in a hot patch.
I'm not sure if it's better to represent that by using `__attribute__((used))` on every global variable or by setting something more globally in the module. The latter seems more impervious to the LTO problem, at least. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D150221/new/ https://reviews.llvm.org/D150221 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits