public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "hedayat.fwd at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug middle-end/103537] Using -fstack-protector-strong "without" optimization cause segmentation fault
Date: Sat, 04 Dec 2021 23:04:36 +0000	[thread overview]
Message-ID: <bug-103537-4-OdjvK4UgcC@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-103537-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #4 from Hedayat Vatankhah <hedayat.fwd at gmail dot com> ---
Well, sorry if I should gave more logs to make it more clear.

Note that the crash happens here:
https://github.com/hedayat/powerfake/blob/a4c80d6628816656796d2e85b4422218da05ce00/powerfake.h#L257

And the problematic code doesn't use any of the parts of the code you
mentioned. 

To make the scope of the problem much less, I replaced main() function as
follows and commented out all other unrelated code:

int main()
{
    SampleClass2 sc2;
    SamplePrivate::Call(sc2);
}

This code certainly doesn't use any of the code you mentioned. It only uses
TAG_PRIVATE_MEMBER macro, which in turn uses TagBase and
PrivateFunctionExtractor structs, and no other code. 

The behavior is as follows:

* without -fstack-protector-strong, with or without any of the sanitize options
the code runs normally. No crash, and not any messages from any of the
sanitizers.

* with -fstack-protector-strong, with or without -fsanitize=undefined, you got
a segmentation fault. Logs when running with -fsanitize=undefined:

/home/hedayat/Projects/powerfake/powerfake.h:257:40: runtime error: load of
misaligned address 0x7f64004083fc for type '<unknown> *', which requires 8 byte
alignment
0x7f64004083fc: note: pointer points here
<memory cannot be printed>
zsh: segmentation fault (core dumped)  ./sample/samples

* with -fstack-protector-strong and with -fsanitize=address, you don't get a
crash, so -fsanitizer=address somehow fixes the problem caused with
-fstack-protector-strong. (Using address sanitizer only causes a crash when I
use OverloadedPrivateFloat::Call(sc2, 5);, which I will investigate. But that
issue seems completely unrelated to this bug. address sanitizer causes a crash
with that function even when -fstack-protector-strong is not used).

  parent reply	other threads:[~2021-12-04 23:04 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-03  9:11 [Bug c++/103537] New: " hedayat.fwd at gmail dot com
2021-12-03  9:16 ` [Bug middle-end/103537] " pinskia at gcc dot gnu.org
2021-12-03 20:15 ` hedayat.fwd at gmail dot com
2021-12-03 20:30 ` pinskia at gcc dot gnu.org
2021-12-04 23:04 ` hedayat.fwd at gmail dot com [this message]
2021-12-04 23:17 ` hedayat.fwd at gmail dot com
2021-12-04 23:37 ` hedayat.fwd at gmail dot com
2021-12-05  0:19 ` hedayat.fwd at gmail dot com

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-103537-4-OdjvK4UgcC@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).