[PATCH] D127259: [CodeGen] guarantee templated static variables are initialized in the reverse instantiation order

Yuanfang Chen via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jun 16 15:18:14 PDT 2022


ychen added a comment.

In D127259#3590127 <https://reviews.llvm.org/D127259#3590127>, @rnk wrote:

> I think Richard had some concerns in the other review that this may not be enough to really guarantee initialization order within the TU. I couldn't say either way, I shouldn't review this code. Conceptually, this change seems small enough to me. Can we ask @aaron.ballman to take a look?

@rnk, thanks. @rsmith, please correct me if I'm wrong. I think the current approach is relying on two things: partial ordering in `llvm.global_ctors` entries (this is also needed to fix https://github.com/llvm/llvm-project/issues/55804, D127233 <https://reviews.llvm.org/D127233>, I could submit a follow-up patch to either make IR verifier check the order is not unexpected changed or simply check the order is maintained by GlobalOpt) and a linker that picks the *first* COMDAT consistently (this is not guaranteed but generally true for major linkers for a long time). The alternative is to coalesce `llvm.global_ctors` entries with order requirements into a single dynamic initialization function, however, as already being discussed, this has code size and startup time overhead. We could discuss the partial ordering in `llvm.global_ctors` entries in D127233 <https://reviews.llvm.org/D127233>.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D127259/new/

https://reviews.llvm.org/D127259



More information about the cfe-commits mailing list