diff --git a/llvm/include/llvm/ADT/Any.h b/llvm/include/llvm/ADT/Any.h index acb7101a5145f0..7486491914ef75 100644 --- a/llvm/include/llvm/ADT/Any.h +++ b/llvm/include/llvm/ADT/Any.h @@ -124,7 +124,16 @@ class LLVM_EXTERNAL_VISIBILITY Any { std::unique_ptr Storage; }; -template char Any::TypeId::Id = 0; +// Define the type id and initialize with a non-zero value. +// Initializing with a zero value means the variable can end up in either the +// .data or the .bss section. This can lead to multiple definition linker errors +// when some object files are compiled with a compiler that puts the variable +// into .data but they are linked to object files from a different compiler that +// put the variable into .bss. To prevent this issue from happening, initialize +// the variable with a non-zero value, which forces it to land in .data (because +// .bss is zero-initialized). +// See also https://github.com/llvm/llvm-project/issues/62270 +template char Any::TypeId::Id = 1; template LLVM_DEPRECATED("Use any_cast(Any*) != nullptr instead", "any_cast")