public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/114276] New: Trapping on aligned operations when using vector builtins + `-std=gnu++23 -fsanitize=address -fstack-protector-strong`
@ 2024-03-08  4:10 elrodc at gmail dot com
  2024-03-08  4:11 ` [Bug target/114276] " elrodc at gmail dot com
  2024-03-08  4:13 ` pinskia at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: elrodc at gmail dot com @ 2024-03-08  4:10 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 114276
           Summary: Trapping on aligned operations when using vector
                    builtins + `-std=gnu++23 -fsanitize=address
                    -fstack-protector-strong`
           Product: gcc
           Version: 13.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: elrodc at gmail dot com
  Target Milestone: ---

Created attachment 57651
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=57651&action=edit
test file

I'm not sure how to categorize the issue, so I picked "target" as it occurs for
x86_64 when using aligned moves on 64-byte avx512 vectors.

`-std=c++23` also reproduces the problem.
I am using:

> g++ --version
> g++ (GCC) 13.2.1 20231205 (Red Hat 13.2.1-6)
> Copyright (C) 2023 Free Software Foundation, Inc.
> This is free software; see the source for copying conditions.  There is NO
> warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

The attached file is:

> #include <cstddef>
> #include <cstdint>
> 
> template <ptrdiff_t W, typename T>
> using Vec [[gnu::vector_size(W * sizeof(T))]] = T;
> 
> auto foo() {
>   Vec<8, int64_t> ret{};
>   return ret;
> }
> 
> int main() {
>   foo();
>   return 0;
> }

I have attached this file.

On a skylake-avx512 CPU, I get

> g++ -std=gnu++23 -march=skylake-avx512 -fstack-protector-strong -O0 -g -mprefer-vector-width=512 -fsanitize=address,undefined -fsanitize-trap=all simdvecalign.cpp && ./a.out
AddressSanitizer:DEADLYSIGNAL
=================================================================
==36238==ERROR: AddressSanitizer: SEGV on unknown address (pc 0x00000040125c bp
0x7ffdf88a1cb0 sp 0x7ffdf88a1bc0 T0)
==36238==The signal is caused by a READ memory access.
==36238==Hint: this fault was caused by a dereference of a high value address
(see register values below).  Disassemble the provided pc to learn which
register was used.
    #0 0x40125c in foo()
/home/chriselrod/Documents/progwork/cxx/experiments/simdvecalign.cpp:8
    #1 0x4012d1 in main
/home/chriselrod/Documents/progwork/cxx/experiments/simdvecalign.cpp:13
    #2 0x7f296b846149 in __libc_start_call_main (/lib64/libc.so.6+0x28149)
(BuildId: 7ea8d85df0e89b90c63ac7ed2b3578b2e7728756)
    #3 0x7f296b84620a in __libc_start_main_impl (/lib64/libc.so.6+0x2820a)
(BuildId: 7ea8d85df0e89b90c63ac7ed2b3578b2e7728756)
    #4 0x4010a4 in _start
(/home/chriselrod/Documents/progwork/cxx/experiments/a.out+0x4010a4) (BuildId:
765272b0173968b14f4306c8d4a37fcb18733889)

AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV
/home/chriselrod/Documents/progwork/cxx/experiments/simdvecalign.cpp:8 in foo()
==36238==ABORTING
fish: Job 1, './a.out' terminated by signal SIGABRT (Abort)

However, if I remove any of `-std=gnu++23`, `-fsantize=address`, or
`-fstack-protector-strong`, the code runs without a problem.

Using 32 byte vectors instead of 64 byte also allows it to work.

I also used `-S` to look at the assembly.

When I edit the two lines:
> 	vmovdqa64	%zmm0, -128(%rdx)
> 	.loc 1 9 10
> 	vmovdqa64	-128(%rdx), %zmm0

swapping `vmovdqa64` for `vmovdqu64`, the code runs as intended.

> g++ -fsanitize=address simdvecalign.s # using vmovdqu64
> ./a.out
> g++ -fsanitize=address simdvecalign.s # reverted back to vmovdqa64
> ./a.out
AddressSanitizer:DEADLYSIGNAL
=================================================================
==40364==ERROR: AddressSanitizer: SEGV on unknown address (pc 0x00000040125c bp
0x7ffd2e2dc240 sp 0x7ffd2e2dc140 T0)

so I am inclined to think that something isn't guaranteeing that `%rdx` is
actually 64-byte aligned (but it may be 32-byte aligned, given that I can't
reproduce with 32 byte vectors).

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

* [Bug target/114276] Trapping on aligned operations when using vector builtins + `-std=gnu++23 -fsanitize=address -fstack-protector-strong`
  2024-03-08  4:10 [Bug target/114276] New: Trapping on aligned operations when using vector builtins + `-std=gnu++23 -fsanitize=address -fstack-protector-strong` elrodc at gmail dot com
@ 2024-03-08  4:11 ` elrodc at gmail dot com
  2024-03-08  4:13 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: elrodc at gmail dot com @ 2024-03-08  4:11 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Chris Elrod <elrodc at gmail dot com> ---
Created attachment 57652
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=57652&action=edit
assembly from adding `-S`

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

* [Bug target/114276] Trapping on aligned operations when using vector builtins + `-std=gnu++23 -fsanitize=address -fstack-protector-strong`
  2024-03-08  4:10 [Bug target/114276] New: Trapping on aligned operations when using vector builtins + `-std=gnu++23 -fsanitize=address -fstack-protector-strong` elrodc at gmail dot com
  2024-03-08  4:11 ` [Bug target/114276] " elrodc at gmail dot com
@ 2024-03-08  4:13 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-03-08  4:13 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |DUPLICATE
             Status|UNCONFIRMED                 |RESOLVED

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Dup.

*** This bug has been marked as a duplicate of bug 110027 ***

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

end of thread, other threads:[~2024-03-08  4:13 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-08  4:10 [Bug target/114276] New: Trapping on aligned operations when using vector builtins + `-std=gnu++23 -fsanitize=address -fstack-protector-strong` elrodc at gmail dot com
2024-03-08  4:11 ` [Bug target/114276] " elrodc at gmail dot com
2024-03-08  4:13 ` pinskia 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).