Lines Matching +full:odr +full:- +full:value
1 //===-- asan_globals.cpp --------------------------------------------------===//
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
12 //===----------------------------------------------------------------------===//
47 // Lazy-initialized and never deleted.
58 ALWAYS_INLINE void PoisonShadowForGlobal(const Global *g, u8 value) { in PoisonShadowForGlobal() argument
59 FastPoisonShadow(g->beg, g->size_with_redzone, value); in PoisonShadowForGlobal()
64 FastPoisonShadow(g.beg + aligned_size, g.size_with_redzone - aligned_size, in PoisonRedZones()
77 if (addr <= g.beg - kMinimalDistanceFromAnotherGlobal) return false; in IsAddressNearGlobal()
84 bool symbolized = Symbolizer::GetOrInit()->SymbolizeData(g.beg, &info); in ReportGlobal()
97 Report(" location: name=%s, %d\n", g.gcc_location->filename, g.gcc_location->line_no); in ReportGlobal()
104 for (uptr i = 0, n = global_registration_site_vector->size(); i < n; i++) { in FindRegistrationSite()
114 if (!flags()->report_globals) return 0; in GetGlobalsForAddress()
117 for (ListOfGlobals *l = list_of_all_globals; l; l = l->next) { in GetGlobalsForAddress()
118 const Global &g = *l->g; in GetGlobalsForAddress()
119 if (flags()->report_globals >= 2) in GetGlobalsForAddress()
138 // Check ODR violation for given global G via special ODR indicator. We use
142 // Instrumentation requests to skip ODR check. in CheckODRViolationViaIndicator()
143 if (g->odr_indicator == UINTPTR_MAX) in CheckODRViolationViaIndicator()
145 u8 *odr_indicator = reinterpret_cast<u8 *>(g->odr_indicator); in CheckODRViolationViaIndicator()
151 // externally visible symbol with the same name. This is an ODR violation. in CheckODRViolationViaIndicator()
152 for (ListOfGlobals *l = list_of_all_globals; l; l = l->next) { in CheckODRViolationViaIndicator()
153 if (g->odr_indicator == l->g->odr_indicator && in CheckODRViolationViaIndicator()
154 (flags()->detect_odr_violation >= 2 || g->size != l->g->size) && in CheckODRViolationViaIndicator()
155 !IsODRViolationSuppressed(g->name)) in CheckODRViolationViaIndicator()
157 l->g, FindRegistrationSite(l->g)); in CheckODRViolationViaIndicator()
161 // Check ODR violation for given global G by checking if it's already poisoned.
165 if (__asan_region_is_poisoned(g->beg, g->size_with_redzone)) { in CheckODRViolationViaPoisoning()
168 for (ListOfGlobals *l = list_of_all_globals; l; l = l->next) { in CheckODRViolationViaPoisoning()
169 if (g->beg == l->g->beg && in CheckODRViolationViaPoisoning()
170 (flags()->detect_odr_violation >= 2 || g->size != l->g->size) && in CheckODRViolationViaPoisoning()
171 !IsODRViolationSuppressed(g->name)) in CheckODRViolationViaPoisoning()
173 l->g, FindRegistrationSite(l->g)); in CheckODRViolationViaPoisoning()
181 // cheaply detect ODR violation: if we try to poison an already poisoned
182 // global, we have ODR violation error.
187 // 1) Non-zero value. In this case, odr_indicator is an address of
190 // and can freely check ODR violation with the first method.
192 // This routine chooses between two different methods of ODR violation
195 return g->odr_indicator > 0; in UseODRIndicator()
203 if (flags()->report_globals >= 2) in RegisterGlobal()
205 CHECK(flags()->report_globals); in RegisterGlobal()
206 CHECK(AddrIsInMem(g->beg)); in RegisterGlobal()
207 if (!AddrIsAlignedByGranularity(g->beg)) { in RegisterGlobal()
210 Report("resides in another non-instrumented module.\n"); in RegisterGlobal()
211 Report("Or the global comes from a C file built w/o -fno-common.\n"); in RegisterGlobal()
212 Report("In either case this is likely an ODR violation bug,\n"); in RegisterGlobal()
215 CHECK(AddrIsAlignedByGranularity(g->beg)); in RegisterGlobal()
217 CHECK(AddrIsAlignedByGranularity(g->size_with_redzone)); in RegisterGlobal()
218 if (flags()->detect_odr_violation) { in RegisterGlobal()
219 // Try detecting ODR (One Definition Rule) violation, i.e. the situation in RegisterGlobal()
229 l->g = g; in RegisterGlobal()
230 l->next = list_of_all_globals; in RegisterGlobal()
232 if (g->has_dynamic_init) { in RegisterGlobal()
235 dynamic_init_globals->reserve(kDynamicInitGlobalsInitialCapacity); in RegisterGlobal()
238 dynamic_init_globals->push_back(dyn_global); in RegisterGlobal()
244 if (flags()->report_globals >= 2) in UnregisterGlobal()
246 CHECK(flags()->report_globals); in UnregisterGlobal()
247 CHECK(AddrIsInMem(g->beg)); in UnregisterGlobal()
248 CHECK(AddrIsAlignedByGranularity(g->beg)); in UnregisterGlobal()
249 CHECK(AddrIsAlignedByGranularity(g->size_with_redzone)); in UnregisterGlobal()
256 // Release ODR indicator. in UnregisterGlobal()
257 if (UseODRIndicator(g) && g->odr_indicator != UINTPTR_MAX) { in UnregisterGlobal()
258 u8 *odr_indicator = reinterpret_cast<u8 *>(g->odr_indicator); in UnregisterGlobal()
265 if (!flags()->check_initialization_order || !dynamic_init_globals) in StopInitOrderChecking()
267 flags()->check_initialization_order = false; in StopInitOrderChecking()
268 for (uptr i = 0, n = dynamic_init_globals->size(); i < n; ++i) { in StopInitOrderChecking()
289 return should_demangle ? Symbolizer::GetOrInit()->Demangle(name) : name; in MaybeDemangleGlobalName()
292 // Check if the global is a zero-terminated ASCII string. If so, print it.
294 for (uptr p = g.beg; p < g.beg + g.size - 1; p++) { in PrintGlobalNameIfASCII()
298 if (*(char *)(g.beg + g.size - 1) != '\0') return; in PrintGlobalNameIfASCII()
299 str->AppendF(" '%s' is ascii string '%s'\n", MaybeDemangleGlobalName(g.name), in PrintGlobalNameIfASCII()
306 if (Symbolizer::GetOrInit()->SymbolizeData(g.beg, &info) && info.line != 0) { in PrintGlobalLocation()
307 str->AppendF("%s:%d", info.file, static_cast<int>(info.line)); in PrintGlobalLocation()
310 str->AppendF("%s", g.gcc_location->filename ? g.gcc_location->filename in PrintGlobalLocation()
312 if (g.gcc_location->line_no) in PrintGlobalLocation()
313 str->AppendF(":%d", g.gcc_location->line_no); in PrintGlobalLocation()
314 if (g.gcc_location->column_no) in PrintGlobalLocation()
315 str->AppendF(":%d", g.gcc_location->column_no); in PrintGlobalLocation()
317 str->AppendF("%s", g.module_name); in PrintGlobalLocation()
320 str->AppendF(" in %s", info.module); in PrintGlobalLocation()
325 // ---------------------- Interface ---------------- {{{1
349 CHECK_EQ(0, ((uptr)stop - (uptr)start) % sizeof(__asan_global)); in __asan_register_elf_globals()
352 __asan_register_globals(globals_start, globals_stop - globals_start); in __asan_register_elf_globals()
359 CHECK_EQ(0, ((uptr)stop - (uptr)start) % sizeof(__asan_global)); in __asan_unregister_elf_globals()
362 __asan_unregister_globals(globals_start, globals_stop - globals_start); in __asan_unregister_elf_globals()
368 if (!flags()->report_globals) return; in __asan_register_globals()
375 global_registration_site_vector->reserve(128); in __asan_register_globals()
377 GlobalRegistrationSite site = {stack_id, &globals[0], &globals[n - 1]}; in __asan_register_globals()
378 global_registration_site_vector->push_back(site); in __asan_register_globals()
379 if (flags()->report_globals >= 2) { in __asan_register_globals()
382 (void *)&globals[n - 1]); in __asan_register_globals()
391 (sizeof(__asan_global) & (sizeof(__asan_global) - 1)) == 0, in __asan_register_globals()
410 if (!flags()->report_globals) return; in __asan_unregister_globals()
430 if (!flags()->check_initialization_order || in __asan_before_dynamic_init()
434 bool strict_init_order = flags()->strict_init_order; in __asan_before_dynamic_init()
438 if (flags()->report_globals >= 3) in __asan_before_dynamic_init()
440 for (uptr i = 0, n = dynamic_init_globals->size(); i < n; ++i) { in __asan_before_dynamic_init()
445 if (g->module_name != module_name) in __asan_before_dynamic_init()
456 if (!flags()->check_initialization_order || in __asan_after_dynamic_init()
463 for (uptr i = 0, n = dynamic_init_globals->size(); i < n; ++i) { in __asan_after_dynamic_init()