From c00ada070207979f092be9046a02fcfff8b9f9ce Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Sat, 29 Jun 2024 12:55:57 -0700 Subject: [PATCH] [Hashing] get_execution_seed: use a non-vague linkage symbol Follow-up to #96282. Since llvm/lib/Target files are compiled with -fvisibility=hidden, the seed variable in libLLVM.so is hidden in a -DLLVM_BUILD_LLVM_DYLIB=on build. This would cause `hash_value(std::string()), hash_value(StringRef())` to fail since the former (might be part of the main executable) and the latter (llvm/lib/Support/StringRef.cpp in libLLVM.so) use copies in different components. --- llvm/include/llvm/ADT/Hashing.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/llvm/include/llvm/ADT/Hashing.h b/llvm/include/llvm/ADT/Hashing.h index 177fb0318bf80d..109966257b51c0 100644 --- a/llvm/include/llvm/ADT/Hashing.h +++ b/llvm/include/llvm/ADT/Hashing.h @@ -307,16 +307,16 @@ struct hash_state { }; /// In LLVM_ENABLE_ABI_BREAKING_CHECKS builds, the seed is non-deterministic -/// (address of a variable) to prevent having users depend on the particular -/// hash values. On platforms without ASLR, this is still likely -/// non-deterministic per build. +/// per process (address of a function in LLVMSupport) to prevent having users +/// depend on the particular hash values. On platforms without ASLR, this is +/// still likely non-deterministic per build. inline uint64_t get_execution_seed() { // Work around x86-64 negative offset folding for old Clang -fno-pic // https://reviews.llvm.org/D93931 #if LLVM_ENABLE_ABI_BREAKING_CHECKS && \ (!defined(__clang__) || __clang_major__ > 11) - static const char seed = 0; - return static_cast(reinterpret_cast(&seed)); + return static_cast( + reinterpret_cast(&install_fatal_error_handler)); #else return 0xff51afd7ed558ccdULL; #endif