Optimization auto-setting _FORTIFY_SOURCE ??
LIU Hao
lh_mouse@126.com
Mon Jan 30 04:57:35 GMT 2023
在 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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_signature
Type: application/pgp-signature
Size: 840 bytes
Desc: OpenPGP digital signature
URL: <https://gcc.gnu.org/pipermail/gcc-help/attachments/20230130/2ca8e8b0/attachment.sig>
More information about the Gcc-help
mailing list