Skip to content

Commit 54c9404

Browse files
committed
[asan] Avoid global ~DenseMap()
Follow up to #100923
1 parent 7b0f143 commit 54c9404

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

compiler-rt/lib/asan/asan_globals.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,9 @@ struct GlobalListNode {
3737
GlobalListNode *next = nullptr;
3838
};
3939
typedef IntrusiveList<GlobalListNode> ListOfGlobals;
40-
typedef DenseMap<uptr, ListOfGlobals> MapOfGlobals;
4140

4241
static Mutex mu_for_globals;
4342
static ListOfGlobals list_of_all_globals;
44-
static MapOfGlobals map_of_globals_by_indicator;
4543

4644
static const int kDynamicInitGlobalsInitialCapacity = 512;
4745
struct DynInitGlobal {
@@ -60,6 +58,19 @@ struct GlobalRegistrationSite {
6058
typedef InternalMmapVector<GlobalRegistrationSite> GlobalRegistrationSiteVector;
6159
static GlobalRegistrationSiteVector *global_registration_site_vector;
6260

61+
static ListOfGlobals &GlobalsByIndicator(uptr odr_indicator) {
62+
using MapOfGlobals = DenseMap<uptr, ListOfGlobals>;
63+
64+
static MapOfGlobals *globals_by_indicator = nullptr;
65+
if (!globals_by_indicator) {
66+
alignas(
67+
alignof(MapOfGlobals)) static char placeholder[sizeof(MapOfGlobals)];
68+
globals_by_indicator = new (placeholder) MapOfGlobals();
69+
}
70+
71+
return (*globals_by_indicator)[odr_indicator];
72+
}
73+
6374
ALWAYS_INLINE void PoisonShadowForGlobal(const Global *g, u8 value) {
6475
FastPoisonShadow(g->beg, g->size_with_redzone, value);
6576
}
@@ -152,8 +163,7 @@ static void CheckODRViolationViaIndicator(const Global *g) {
152163
if (g->odr_indicator == UINTPTR_MAX)
153164
return;
154165

155-
ListOfGlobals &relevant_globals =
156-
map_of_globals_by_indicator[g->odr_indicator];
166+
ListOfGlobals &relevant_globals = GlobalsByIndicator(g->odr_indicator);
157167

158168
u8 *odr_indicator = reinterpret_cast<u8 *>(g->odr_indicator);
159169
if (*odr_indicator == REGISTERED) {

0 commit comments

Comments
 (0)