https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111736

--- Comment #19 from Uroš Bizjak <ubizjak at gmail dot com> ---
(In reply to Uroš Bizjak from comment #16)
> (In reply to Richard Biener from comment #13)
> > The original testcase is fixed, appearantly slapping 'extern' on the int
> > makes it not effective.
> > 
> > Possibly better amend the
> > 
> >   if (VAR_P (inner) && DECL_HARD_REGISTER (inner))
> >     return;
> > 
> > check though.  As indicated my fix fixed only VAR_DECL cases, there's
> > still pointer-based accesses (MEM_REF) to consider.  So possibly even
> > the following is necessary
> 
> I must admit that to create the patch from Comment #11 I just mindlessly
> searched for DECL_THREAD_LOCAL_P in asan.cc and amended the location with
> ADDR_SPACE_GENERIC_P check.
> 
> However, ASAN should back off from annotating *any* gs: prefixed address. 
> 
> I'll test your patch from Comment #13 ASAP.

Weee, it works!

Decompressing Linux... Parsing ELF... Performing relocations... done.
Booting the kernel (entry_offset: 0x0000000000000000).
[    0.000000] Linux version 6.8.0-11485-ge1826833c3a9 (uros@localhost) (xgcc
(GCC) 14.0.1 20240321 (experimental) [master r14-9588-g415091f0909], GNU ld
version 2.40-14.fc39) #1 SMP PREEMPT_DYNAMIC Thu Mar 21 09:44:30 CET 2024
...

I have used slightly different patch:

--cut here--
diff --git a/gcc/asan.cc b/gcc/asan.cc
index cfe83106460..026d079a4a1 100644
--- a/gcc/asan.cc
+++ b/gcc/asan.cc
@@ -2755,6 +2755,9 @@ instrument_derefs (gimple_stmt_iterator *iter, tree t,
   if (VAR_P (inner) && DECL_HARD_REGISTER (inner))
     return;

+  if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (TREE_TYPE (inner))))
+    return;
+
   poly_int64 decl_size;
   if ((VAR_P (inner)
        || (TREE_CODE (inner) == RESULT_DECL
--cut here--

Hard registers and named address spaces really have nothing in common.

IMO, the fixes here should be applied to all release branches. Running KASAN
sanitized kernel with the named AS is the ultimate test for this PR.

Reply via email to