[compiler-rt] [asan] Speed up ASan ODR indicator-based checking (PR #100923)

Artem Pianykh via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 31 15:32:17 PDT 2024


================
@@ -147,14 +163,21 @@ static void CheckODRViolationViaIndicator(const Global *g) {
     *odr_indicator = REGISTERED;
     return;
   }
+
+  // Fetch globals with the same ODR indicator.
+  auto *relevant_globals_lookup =
+      map_of_globals_by_indicator.find(g->odr_indicator);
+  if (!relevant_globals_lookup)
+    return;
+
+  ListOfGlobals *relevant_globals = relevant_globals_lookup->second;
   // If *odr_indicator is DEFINED, some module have already registered
   // externally visible symbol with the same name. This is an ODR violation.
-  for (ListOfGlobals *l = list_of_all_globals; l; l = l->next) {
-    if (g->odr_indicator == l->g->odr_indicator &&
----------------
artempyanykh wrote:

> Instead of removal checking that indicators still match is enough

@vitalybuka could you expand on what you mean by 'indicators still match'?

Looking at the code for `UnregisterGlobal`, we update the value of whatever the indicator points to to `UNREGISTERED` (which affects all instances that share the same indicator) but the indicator address is unchanged.
https://github.com/llvm/llvm-project/blob/99b2444c7742b2c3a955660c75a95e063c03fc74/compiler-rt/lib/asan/asan_globals.cpp#L283-L284

I didn't find any tests around 'unregistering' so I added one in https://github.com/llvm/llvm-project/pull/100923/commits/01847d1dd72fb078d26f38973391f37d2815ec3c to demonstrate the behavior (it's the same on main and in this branch).

https://github.com/llvm/llvm-project/pull/100923


More information about the llvm-commits mailing list