d7d21d
From 6d9d949fb4962e32636aee48a948081d8936d318 Mon Sep 17 00:00:00 2001
d7d21d
From: Jitka Plesnikova <jplesnik@redhat.com>
d7d21d
Date: Wed, 11 Jan 2023 09:12:18 +0100
d7d21d
Subject: [PATCH] Add definition of OPTIMIZE to .ph files
d7d21d
d7d21d
The fortify.h header includes a test to ensure that -O is used when
d7d21d
compiling with _FORTIFY_SOURCE, and the header looks for OPTIMIZE, which
d7d21d
is set by the compiler whenever -O is used.  Perl translates this test
d7d21d
to the .ph file, but nothing ever sets OPTIMIZE. This causes a warning
d7d21d
for anything that uses features.ph.
d7d21d
d7d21d
_FORTIFY_SOURCE is defined in /usr/lib64/perl5/_h2ph_pre.ph which is
d7d21d
generated by h2ph. It uses value of @Config{'ccsymbols', 'cppsymbols',
d7d21d
'cppccsymbols'} which does not contain definition for OPTIMIZE.
d7d21d
d7d21d
The patch updated h2ph to add OPTIMIZE if -O is used.
d7d21d
---
d7d21d
 utils/h2ph.PL | 5 +++++
d7d21d
 1 file changed, 5 insertions(+)
d7d21d
d7d21d
diff --git a/utils/h2ph.PL b/utils/h2ph.PL
d7d21d
index afa53c2..3950d11 100644
d7d21d
--- a/utils/h2ph.PL
d7d21d
+++ b/utils/h2ph.PL
d7d21d
@@ -865,6 +865,11 @@ sub _extract_cc_defines
d7d21d
     my $allsymbols  = join " ",
d7d21d
 	@Config{'ccsymbols', 'cppsymbols', 'cppccsymbols'};
d7d21d
 
d7d21d
+    # If optimizing -O2 is used, add the definition
d7d21d
+    if ($Config{'ccflags'} =~ /(?:\s+|^)-O([\d]+)(?:\s+|$)/) {
d7d21d
+	$allsymbols .= " __OPTIMIZE__=$1";
d7d21d
+    }
d7d21d
+
d7d21d
     # Split compiler pre-definitions into 'key=value' pairs:
d7d21d
     while ($allsymbols =~ /([^\s]+)=((\\\s|[^\s])+)/g) {
d7d21d
 	$define{$1} = $2;
d7d21d
-- 
d7d21d
2.39.0
d7d21d