GCC Newspaper
OCTOBER 6, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
c++

c++: hash TYPENAME_TYPEs on TYPE_UID instead of pointers

Fixes compiler to correctly handle precompiled headers with TYPENAME_TYPEs by hashing TYPE_UID.

This commit resolves an issue where hashing TYPENAME_TYPEs in precompiled headers was unreliable due to hashing pointer addresses. These addresses change between compile runs, leading to duplicate type creations and incorrect debug information. The fix changes the hashing mechanism to use TYPE_UID, which is preserved across precompiled header reads, ensuring consistent compilation results.

In Details

The typename_htab in GCC's C++ frontend uses a hash table for TYPENAME_TYPEs, which is streamed to precompiled headers (PCH). The previous hashing of scope and fullname addresses, which are subject to ASLR, caused lookups to fail after PCH loading. This commit modifies typename_hasher::hash to use TYPE_UID for the context and iterative_hash_template_arg for the fullname, ensuring stable hashing across PCH loads and fixing PR124811.

For Context
TYPENAME_TYPE
An internal GCC type representing a type name found in C++ code, often used in templates or with decltype.
Precompiled Header (PCH)
A compiler optimization that pre-compiles a common set of header files to speed up subsequent compilations. GCC can stream internal data structures like hash tables to PCH files.
ASLR
Address Space Layout Randomization is a security technique that randomizes the memory addresses of processes to make it harder for attackers to exploit vulnerabilities.
TYPE_UID
A unique identifier assigned to each type within a GCC compilation. This identifier is stable across PCH loads.
Filed Under: c++precompiled headersdebuggingbugfix