From: LIU Hao <lh_mouse@126.com>
To: Xi Ruoyao <xry111@xry111.site>, Patrick Herbst <paherbst@gmail.com>
Cc: gcc-help <gcc-help@gcc.gnu.org>
Subject: Re: Optimization auto-setting _FORTIFY_SOURCE ??
Date: Mon, 30 Jan 2023 12:57:35 +0800 [thread overview]
Message-ID: <f94d5764-99d6-a20d-d9cd-583d40d5618e@126.com> (raw)
In-Reply-To: <e847f769bee19ed447dd250dd3bd1a0bcd11d284.camel@xry111.site>
[-- Attachment #1.1: Type: text/plain, Size: 1230 bytes --]
在 2023/1/30 12:23, Xi Ruoyao via Gcc-help 写道:
> On Sun, 2023-01-29 at 18:05 -0500, Patrick Herbst via Gcc-help wrote:
>> Using GCC 9.4, I've noticed setting -O1 will set
>> _FORTIFY_SOURCE=2
>>
>> I'm able to see this by running
>> gcc -c -E -dM -O1 - < /dev/null | grep FORTIFY_SOURCE
>>
>> But running the same command without -O1 doesn't set it.
>>
>> Is this documented? is this expected behavior? I could not find any
>> reference to how optimization leads to setting this macro.
>>
>> Any tips on where I can look, or what i'm missing to see this
>> connection?
>
> It's because your distro hacked GCC code to define _FORTIFY_SOURCE when
> optimization is enabled. Vanilla GCC does not have this behavior.
>
>
For the record: Debian and Ubuntu are known distros that have `_FORTIFY_SOURCE` set when
optimization is enabled. The relevant patch is here
https://sources.debian.org/src/gcc-8/8.3.0-2/debian/patches/gcc-default-fortify-source.diff/
however the hunk against 'invoke.texi' is incorrect: It says `_FORTIFY_SOURCE` is enabled if
optimization level 'is set to 2 or higher', but it is actually defined for any optimization level > 0.
--
Best regards,
LIU Hao
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 840 bytes --]
prev parent reply other threads:[~2023-01-30 4:57 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-29 23:05 Patrick Herbst
2023-01-30 4:23 ` Xi Ruoyao
2023-01-30 4:57 ` LIU Hao [this message]
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=f94d5764-99d6-a20d-d9cd-583d40d5618e@126.com \
--to=lh_mouse@126.com \
--cc=gcc-help@gcc.gnu.org \
--cc=paherbst@gmail.com \
--cc=xry111@xry111.site \
/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).