public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/103453] New: ASAN detection with clang
@ 2021-11-27 19:03 glisse at gcc dot gnu.org
  2021-11-27 23:33 ` [Bug libstdc++/103453] " redi at gcc dot gnu.org
                   ` (14 more replies)
  0 siblings, 15 replies; 16+ messages in thread
From: glisse at gcc dot gnu.org @ 2021-11-27 19:03 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 103453
           Summary: ASAN detection with clang
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: glisse at gcc dot gnu.org
  Target Milestone: ---

Libstdc++ uses __SANITIZE_ADDRESS__ to detect if ASAN is enabled, but with
clang that should be __has_feature(address_sanitizer). This means that
_GLIBCXX_SANITIZE_STD_ALLOCATOR is not automatically defined, and thus defining
_GLIBCXX_SANITIZE_VECTOR has no effect.

(noticed in https://stackoverflow.com/q/70117470/1918193 )

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug libstdc++/103453] ASAN detection with clang
  2021-11-27 19:03 [Bug libstdc++/103453] New: ASAN detection with clang glisse at gcc dot gnu.org
@ 2021-11-27 23:33 ` redi at gcc dot gnu.org
  2021-11-30  0:21 ` pinskia at gcc dot gnu.org
                   ` (13 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: redi at gcc dot gnu.org @ 2021-11-27 23:33 UTC (permalink / raw)
  To: gcc-bugs

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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2021-11-27
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug libstdc++/103453] ASAN detection with clang
  2021-11-27 19:03 [Bug libstdc++/103453] New: ASAN detection with clang glisse at gcc dot gnu.org
  2021-11-27 23:33 ` [Bug libstdc++/103453] " redi at gcc dot gnu.org
@ 2021-11-30  0:21 ` pinskia at gcc dot gnu.org
  2021-11-30 13:52 ` redi at gcc dot gnu.org
                   ` (12 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-11-30  0:21 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |unlvsur at live dot com

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
*** Bug 103481 has been marked as a duplicate of this bug. ***

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug libstdc++/103453] ASAN detection with clang
  2021-11-27 19:03 [Bug libstdc++/103453] New: ASAN detection with clang glisse at gcc dot gnu.org
  2021-11-27 23:33 ` [Bug libstdc++/103453] " redi at gcc dot gnu.org
  2021-11-30  0:21 ` pinskia at gcc dot gnu.org
@ 2021-11-30 13:52 ` redi at gcc dot gnu.org
  2021-11-30 20:11 ` cvs-commit at gcc dot gnu.org
                   ` (11 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: redi at gcc dot gnu.org @ 2021-11-30 13:52 UTC (permalink / raw)
  To: gcc-bugs

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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |12.0
           Assignee|unassigned at gcc dot gnu.org      |redi at gcc dot gnu.org
             Status|NEW                         |ASSIGNED

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug libstdc++/103453] ASAN detection with clang
  2021-11-27 19:03 [Bug libstdc++/103453] New: ASAN detection with clang glisse at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2021-11-30 13:52 ` redi at gcc dot gnu.org
@ 2021-11-30 20:11 ` cvs-commit at gcc dot gnu.org
  2021-11-30 20:18 ` redi at gcc dot gnu.org
                   ` (10 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-11-30 20:11 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jonathan Wakely <redi@gcc.gnu.org>:

https://gcc.gnu.org/g:cca6090b13ab503bef1cfa327e2d107789d6bd30

commit r12-5636-gcca6090b13ab503bef1cfa327e2d107789d6bd30
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Tue Nov 30 13:14:38 2021 +0000

    libstdc++: Make Asan detection work for Clang [PR103453]

    Clang doesn't define __SANITIZE_ADDRESS__ so use its __has_feature check
    to detect Asan instead.

    libstdc++-v3/ChangeLog:

            PR libstdc++/103453
            * config/allocator/malloc_allocator_base.h
            (_GLIBCXX_SANITIZE_STD_ALLOCATOR): Define for Clang.
            * config/allocator/new_allocator_base.h
            (_GLIBCXX_SANITIZE_STD_ALLOCATOR): Likewise.

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug libstdc++/103453] ASAN detection with clang
  2021-11-27 19:03 [Bug libstdc++/103453] New: ASAN detection with clang glisse at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2021-11-30 20:11 ` cvs-commit at gcc dot gnu.org
@ 2021-11-30 20:18 ` redi at gcc dot gnu.org
  2021-12-01  1:01 ` unlvsur at live dot com
                   ` (9 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: redi at gcc dot gnu.org @ 2021-11-30 20:18 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Fixed on trunk so far, but this is backportable.

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug libstdc++/103453] ASAN detection with clang
  2021-11-27 19:03 [Bug libstdc++/103453] New: ASAN detection with clang glisse at gcc dot gnu.org
                   ` (4 preceding siblings ...)
  2021-11-30 20:18 ` redi at gcc dot gnu.org
@ 2021-12-01  1:01 ` unlvsur at live dot com
  2021-12-01  1:02 ` unlvsur at live dot com
                   ` (8 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: unlvsur at live dot com @ 2021-12-01  1:01 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from cqwrteur <unlvsur at live dot com> ---
(In reply to Jonathan Wakely from comment #3)
> Fixed on trunk so far, but this is backportable.

Still Does not work on x86_64-w64-mingw32 on windows by default,
-D_GLIBCXX_SANITIZE_STD_ALLOCATOR -D_GLIBCXX_SANITIZE_VECTOR works but the
default option does not.

Why?

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug libstdc++/103453] ASAN detection with clang
  2021-11-27 19:03 [Bug libstdc++/103453] New: ASAN detection with clang glisse at gcc dot gnu.org
                   ` (5 preceding siblings ...)
  2021-12-01  1:01 ` unlvsur at live dot com
@ 2021-12-01  1:02 ` unlvsur at live dot com
  2021-12-01  1:06 ` unlvsur at live dot com
                   ` (7 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: unlvsur at live dot com @ 2021-12-01  1:02 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from cqwrteur <unlvsur at live dot com> ---
(In reply to Jonathan Wakely from comment #3)
> Fixed on trunk so far, but this is backportable.

#include<vector>

int main()
{
        std::vector<std::size_t> vec;
        vec.reserve(20);
        vec[3]=40;
}

clang++ -o vec vec.cc -Ofast -std=c++2b -fuse-ld=lld
-fsanitize=address,undefined

Nothing.

clang++ -o vec vec.cc -Ofast -std=c++2b -I../../include -fuse-ld=lld
-fsanitize=address,undefined -D_GLIBCXX_SANITIZE_STD_ALLOCATOR
-D_GLIBCXX_SANITIZE_VECTOR

=================================================================
==15804==ERROR: AddressSanitizer: container-overflow on address 0x01e922536bd8
at pc 0x7ff6596d16df bp 0x0001000ff700 sp 0x0001000ff748
WRITE of size 8 at 0x01e922536bd8 thread T0
    #0 0x7ff6596d16de in main
(D:\hg\fast_io\examples\0007.legacy\vec.exe+0x1400016de)
    #1 0x7ff6596d13b0 in __tmainCRTStartup
/home/cqwrteur/myhome/gcc_build/canadian/x86_64-w64-mingw32/mingw-w64/mingw-w64-crt/../../../../../mingw-w64/mingw-w64-crt/crt/crtexe.c:321:15
    #2 0x7ff6596d14e5 in mainCRTStartup
/home/cqwrteur/myhome/gcc_build/canadian/x86_64-w64-mingw32/mingw-w64/mingw-w64-crt/../../../../../mingw-w64/mingw-w64-crt/crt/crtexe.c:202:9
    #3 0x7ffc57577033  (C:\WINDOWS\System32\KERNEL32.DLL+0x180017033)
    #4 0x7ffc58fe2650  (C:\WINDOWS\SYSTEM32\ntdll.dll+0x180052650)

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug libstdc++/103453] ASAN detection with clang
  2021-11-27 19:03 [Bug libstdc++/103453] New: ASAN detection with clang glisse at gcc dot gnu.org
                   ` (6 preceding siblings ...)
  2021-12-01  1:02 ` unlvsur at live dot com
@ 2021-12-01  1:06 ` unlvsur at live dot com
  2021-12-01  1:22 ` unlvsur at live dot com
                   ` (6 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: unlvsur at live dot com @ 2021-12-01  1:06 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from cqwrteur <unlvsur at live dot com> ---
(In reply to Jonathan Wakely from comment #3)
> Fixed on trunk so far, but this is backportable.

Turns out _GLIBCXX_SANITIZE_VECTOR is not defined if libsanitizer is not built
with GCC. But GCC does not support sanitizers on windows.

Can we just remove this macro and only use _GLIBCXX_SANITIZE_STD_ALLOCATOR?

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug libstdc++/103453] ASAN detection with clang
  2021-11-27 19:03 [Bug libstdc++/103453] New: ASAN detection with clang glisse at gcc dot gnu.org
                   ` (7 preceding siblings ...)
  2021-12-01  1:06 ` unlvsur at live dot com
@ 2021-12-01  1:22 ` unlvsur at live dot com
  2021-12-01  4:51 ` unlvsur at live dot com
                   ` (5 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: unlvsur at live dot com @ 2021-12-01  1:22 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from cqwrteur <unlvsur at live dot com> ---
(In reply to cqwrteur from comment #6)
> (In reply to Jonathan Wakely from comment #3)
> > Fixed on trunk so far, but this is backportable.
> 
> Turns out _GLIBCXX_SANITIZE_VECTOR is not defined if libsanitizer is not
> built with GCC. But GCC does not support sanitizers on windows.
> 
> Can we just remove this macro and only use _GLIBCXX_SANITIZE_STD_ALLOCATOR?

clang++ -o vec vec.cc -Ofast -std=c++2b -fuse-ld=lld
-fsanitize=address,undefined -D_GLIBCXX_SANITIZE_VECTOR

D:\hg\fast_io\examples\0007.legacy>vec
=================================================================
==10284==ERROR: AddressSanitizer: container-overflow on address 0x021fa68f6bd8
at pc 0x7ff7dae516df bp 0x00347beff840 sp 0x00347beff888
WRITE of size 8 at 0x021fa68f6bd8 thread T0

Also works

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug libstdc++/103453] ASAN detection with clang
  2021-11-27 19:03 [Bug libstdc++/103453] New: ASAN detection with clang glisse at gcc dot gnu.org
                   ` (8 preceding siblings ...)
  2021-12-01  1:22 ` unlvsur at live dot com
@ 2021-12-01  4:51 ` unlvsur at live dot com
  2021-12-01  8:29 ` redi at gcc dot gnu.org
                   ` (4 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: unlvsur at live dot com @ 2021-12-01  4:51 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from cqwrteur <unlvsur at live dot com> ---
(In reply to cqwrteur from comment #7)
> (In reply to cqwrteur from comment #6)
> > (In reply to Jonathan Wakely from comment #3)
> > > Fixed on trunk so far, but this is backportable.
> > 
> > Turns out _GLIBCXX_SANITIZE_VECTOR is not defined if libsanitizer is not
> > built with GCC. But GCC does not support sanitizers on windows.
> > 
> > Can we just remove this macro and only use _GLIBCXX_SANITIZE_STD_ALLOCATOR?
> 
> clang++ -o vec vec.cc -Ofast -std=c++2b -fuse-ld=lld
> -fsanitize=address,undefined -D_GLIBCXX_SANITIZE_VECTOR
> 
> D:\hg\fast_io\examples\0007.legacy>vec
> =================================================================
> ==10284==ERROR: AddressSanitizer: container-overflow on address
> 0x021fa68f6bd8 at pc 0x7ff7dae516df bp 0x00347beff840 sp 0x00347beff888
> WRITE of size 8 at 0x021fa68f6bd8 thread T0
> 
> Also works

Does this toggle need to turn on manually for std::vector?

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug libstdc++/103453] ASAN detection with clang
  2021-11-27 19:03 [Bug libstdc++/103453] New: ASAN detection with clang glisse at gcc dot gnu.org
                   ` (9 preceding siblings ...)
  2021-12-01  4:51 ` unlvsur at live dot com
@ 2021-12-01  8:29 ` redi at gcc dot gnu.org
  2021-12-01  8:37 ` redi at gcc dot gnu.org
                   ` (3 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: redi at gcc dot gnu.org @ 2021-12-01  8:29 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #9 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Yes. This is working as intended.

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug libstdc++/103453] ASAN detection with clang
  2021-11-27 19:03 [Bug libstdc++/103453] New: ASAN detection with clang glisse at gcc dot gnu.org
                   ` (10 preceding siblings ...)
  2021-12-01  8:29 ` redi at gcc dot gnu.org
@ 2021-12-01  8:37 ` redi at gcc dot gnu.org
  2022-01-05 22:06 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  14 siblings, 0 replies; 16+ messages in thread
From: redi at gcc dot gnu.org @ 2021-12-01  8:37 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #10 from Jonathan Wakely <redi at gcc dot gnu.org> ---
And as documented:
https://gcc.gnu.org/onlinedocs/gcc-11.2.0/libstdc++/manual/manual/using_macros.html

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug libstdc++/103453] ASAN detection with clang
  2021-11-27 19:03 [Bug libstdc++/103453] New: ASAN detection with clang glisse at gcc dot gnu.org
                   ` (11 preceding siblings ...)
  2021-12-01  8:37 ` redi at gcc dot gnu.org
@ 2022-01-05 22:06 ` cvs-commit at gcc dot gnu.org
  2022-01-05 22:06 ` cvs-commit at gcc dot gnu.org
  2022-01-05 22:10 ` redi at gcc dot gnu.org
  14 siblings, 0 replies; 16+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-01-05 22:06 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #11 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-11 branch has been updated by Jonathan Wakely
<redi@gcc.gnu.org>:

https://gcc.gnu.org/g:ad54d3fb8f09babc43ea46a93cc73cd623fe822f

commit r11-9436-gad54d3fb8f09babc43ea46a93cc73cd623fe822f
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Tue Nov 30 13:14:38 2021 +0000

    libstdc++: Make Asan detection work for Clang [PR103453]

    Clang doesn't define __SANITIZE_ADDRESS__ so use its __has_feature check
    to detect Asan instead.

    libstdc++-v3/ChangeLog:

            PR libstdc++/103453
            * config/allocator/malloc_allocator_base.h
            (_GLIBCXX_SANITIZE_STD_ALLOCATOR): Define for Clang.
            * config/allocator/new_allocator_base.h
            (_GLIBCXX_SANITIZE_STD_ALLOCATOR): Likewise.

    (cherry picked from commit cca6090b13ab503bef1cfa327e2d107789d6bd30)

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug libstdc++/103453] ASAN detection with clang
  2021-11-27 19:03 [Bug libstdc++/103453] New: ASAN detection with clang glisse at gcc dot gnu.org
                   ` (12 preceding siblings ...)
  2022-01-05 22:06 ` cvs-commit at gcc dot gnu.org
@ 2022-01-05 22:06 ` cvs-commit at gcc dot gnu.org
  2022-01-05 22:10 ` redi at gcc dot gnu.org
  14 siblings, 0 replies; 16+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-01-05 22:06 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #12 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-10 branch has been updated by Jonathan Wakely
<redi@gcc.gnu.org>:

https://gcc.gnu.org/g:37fec1c1b0c942d861dd51b31d099084826a485b

commit r10-10378-g37fec1c1b0c942d861dd51b31d099084826a485b
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Tue Nov 30 13:14:38 2021 +0000

    libstdc++: Make Asan detection work for Clang [PR103453]

    Clang doesn't define __SANITIZE_ADDRESS__ so use its __has_feature check
    to detect Asan instead.

    libstdc++-v3/ChangeLog:

            PR libstdc++/103453
            * config/allocator/malloc_allocator_base.h
            (_GLIBCXX_SANITIZE_STD_ALLOCATOR): Define for Clang.
            * config/allocator/new_allocator_base.h
            (_GLIBCXX_SANITIZE_STD_ALLOCATOR): Likewise.

    (cherry picked from commit cca6090b13ab503bef1cfa327e2d107789d6bd30)

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [Bug libstdc++/103453] ASAN detection with clang
  2021-11-27 19:03 [Bug libstdc++/103453] New: ASAN detection with clang glisse at gcc dot gnu.org
                   ` (13 preceding siblings ...)
  2022-01-05 22:06 ` cvs-commit at gcc dot gnu.org
@ 2022-01-05 22:10 ` redi at gcc dot gnu.org
  14 siblings, 0 replies; 16+ messages in thread
From: redi at gcc dot gnu.org @ 2022-01-05 22:10 UTC (permalink / raw)
  To: gcc-bugs

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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|ASSIGNED                    |RESOLVED
   Target Milestone|12.0                        |10.4

--- Comment #13 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Fixed for 11.3 and 10.4

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2022-01-05 22:10 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-27 19:03 [Bug libstdc++/103453] New: ASAN detection with clang glisse at gcc dot gnu.org
2021-11-27 23:33 ` [Bug libstdc++/103453] " redi at gcc dot gnu.org
2021-11-30  0:21 ` pinskia at gcc dot gnu.org
2021-11-30 13:52 ` redi at gcc dot gnu.org
2021-11-30 20:11 ` cvs-commit at gcc dot gnu.org
2021-11-30 20:18 ` redi at gcc dot gnu.org
2021-12-01  1:01 ` unlvsur at live dot com
2021-12-01  1:02 ` unlvsur at live dot com
2021-12-01  1:06 ` unlvsur at live dot com
2021-12-01  1:22 ` unlvsur at live dot com
2021-12-01  4:51 ` unlvsur at live dot com
2021-12-01  8:29 ` redi at gcc dot gnu.org
2021-12-01  8:37 ` redi at gcc dot gnu.org
2022-01-05 22:06 ` cvs-commit at gcc dot gnu.org
2022-01-05 22:06 ` cvs-commit at gcc dot gnu.org
2022-01-05 22:10 ` redi at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).