Open stellaraccident opened 4 years ago
Correct; this has nothing to do with MLIR static dialect registration and is specifically about LLVM's CommandLineParser::registerCategory
(which is using static initialization).
Obsolete, since MLIR doesn't use static initialization anymore.
It's not an MLIR bug though (wasn't to begin with, I don't think) the claim seems to be that it's a general bug with the way LLVM's command line parsing/handling works.
Could/should we reopen this?
Obsolete, since MLIR doesn't use static initialization anymore.
Extended Description
When attempting to add an OptionCategory to https://github.com/google/iree (which uses MLIR and LLVM), we encountered an ASAN initialization-order-fiasco error on the assert in registerCategory(OptionCategory*). Our temporary fix was to remove the category, and I have not yet rolled any kind of repro.
The failure point is in the registerCategory function here: https://llvm.org/doxygen/CommandLine_8cpp_source.html
Looking at this code, I think the assert is not legal to be doing in a static initializer in this way, and it suffers from the initialization order issue when option categories are declared in multiple modules. It looks like other functions (like registerSubCommand()) could have a similar issue. Due to the specific way that StringRef equality is implemented, it seems like, while this is accessing uninitialized memory sometimes, that is just being interpreted as a false negative (versus a crash). It seems odd that ASAN hasn't triggered on this before, and I can't explain that. Also, since this is an assert, it only affects debug builds.
I think that a more appropriate way to do this would be to do the duplicate check on option parse (or equiv) versus static init, although I am not an expert on LLVM option initialization logic.
================================================================= ==7911==ERROR: AddressSanitizer: initialization-order-fiasco on address 0x55d4407a2920 at pc 0x55d43e64a6b5 bp 0x7ffd24ae1c90 sp 0x7ffd24ae1c88 READ of size 8 at 0x55d4407a2920 thread T0
0 0x55d43e64a6b4 in llvm::cl::OptionCategory::getName() const third_party/llvm/llvm-project/llvm/include/llvm/Support/CommandLine.h:202:38
0x55d4407a2920 is located 0 bytes inside of global variable 'mlir::iree_compiler::IREE::HAL::halTargetOptionsCategory' defined in 'third_party/iree/iree/compiler/Dialect/HAL/Target/ExecutableTarget.cpp:24:33' (0x55d4407a2920) of size 32 registered at:
0 0x55d437e47ebd in __asan_register_globals third_party/llvm/llvm-project/compiler-rt/lib/asan/asan_globals.cpp:360:3
SUMMARY: AddressSanitizer: initialization-order-fiasco third_party/llvm/llvm-project/llvm/include/llvm/Support/CommandLine.h:202:38 in llvm::cl::OptionCategory::getName() const