Skip to content

Commit

Permalink
[Hashing] get_execution_seed: use a non-vague linkage symbol
Browse files Browse the repository at this point in the history
Follow-up to llvm#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.
  • Loading branch information
MaskRay committed Jun 29, 2024
1 parent 2628a5f commit c00ada0
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions llvm/include/llvm/ADT/Hashing.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint64_t>(reinterpret_cast<uintptr_t>(&seed));
return static_cast<uint64_t>(
reinterpret_cast<uintptr_t>(&install_fatal_error_handler));
#else
return 0xff51afd7ed558ccdULL;
#endif
Expand Down

0 comments on commit c00ada0

Please sign in to comment.