Merge ~mitchdz/ubuntu/+source/python2.7:mitch/python2.7_flag_opt into ubuntu/+source/python2.7:ubuntu/jammy-devel

Proposed by Mitchell Dzurick
Status: Merged
Merged at revision: 641a314e2b271bc0b1f5ba10f3ef7d16017921c8
Proposed branch: ~mitchdz/ubuntu/+source/python2.7:mitch/python2.7_flag_opt
Merge into: ubuntu/+source/python2.7:ubuntu/jammy-devel
Diff against target: 88 lines (+66/-0)
3 files modified
debian/changelog (+7/-0)
debian/patches/lp2002043-add-optimization-flags-to-cflags.patch (+58/-0)
debian/patches/series.in (+1/-0)
Reviewer Review Type Date Requested Status
Lena Voytek (community) Approve
git-ubuntu import Pending
Review via email: mp+458533@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Mitchell Dzurick (mitchdz) wrote :

Test case is in the attached bug report.

I do plan to apply these changes to the Focal package too, but I would like feedback on the Jammy patch first before Focal is made.

Revision history for this message
Lena Voytek (lvoytek) wrote :

This patch looks great, and so do the tests. I just have 1 suggestion and a diff comment. Since this is a full patch and not just a simple diff from upstream, I recommend naming it lp2002043-add-optimization-flags-to-cflags.patch rather than lp2002043-add-optimization-flags-to-cflags.diff. That's just a nitpick though and not a necessary change. Overall LGTM, I can sponsor whenever you'd like.

Revision history for this message
Mitchell Dzurick (mitchdz) wrote :

Thanks Lena! I added your suggestions.

I think the print messages I made could be a little much, what do you think? I'd potentially like to shorten it, maybe something like this:

There is a workaround to now inherit optimization CFLAGS when compiling wheels.
To enable this, set APPLY_LP2002043_UBUNTU_CFLAGS_WORKAROUND in your
environment. See LP: https://launchpad.net/bugs/2002043 for further context.

Revision history for this message
Lena Voytek (lvoytek) wrote :

Yeah that looks good to me

Revision history for this message
Mitchell Dzurick (mitchdz) wrote :

Thanks, I'm rebuilding the changes in my PPA now. Will wait for it to finish then test again. Usually takes ~3hrs for a build+publish so I'll report back near EOD if things go well.

Revision history for this message
Mitchell Dzurick (mitchdz) wrote :

Tested the new package and it LGTM.

# dpkg -s python2.7 | grep Version:
Version: 2.7.18-13ubuntu1.2~jammy10
# rm -rf build/ test.so
# export APPLY_LP2002043_UBUNTU_CFLAGS_WORKAROUND=""
# python2 setup.py build_ext --inplace | head -n 5
running build_ext
There is a workaround to now inherit optimization CFLAGS when compiling wheels.
To enable this, set APPLY_LP2002043_UBUNTU_CFLAGS_WORKAROUND in your
environment. See LP: https://launchpad.net/bugs/2002043 for further context.
APPLY_LP2002043_UBUNTU_CFLAGS_WORKAROUND detected, using workaround.
# # strings build/lib.linux-x86_64-2.7/test.so | grep -- -O
GNU GIMPLE 11.4.0 -mtune=generic -march=x86-64 -g -g -g -g -O2 -O2 -fno-openmp -fno-openacc -fcf-protection=full -fno-strict-aliasing -fwrapv -fstack-protector-strong -ffat-lto-objects -fstack-protector-strong -fPIC -fltrans
GNU C17 11.4.0 -mtune=generic -march=x86-64 -g -g -O2 -fno-strict-aliasing -fwrapv -flto -flto -ffat-lto-objects -fstack-protector-strong -fPIC -fasynchronous-unwind-tables -fstack-protector-strong -fstack-clash-protection -fcf-protection

# unset APPLY_LP2002043_UBUNTU_CFLAGS_WORKAROUND
# python2 setup.py build_ext --inplace
running build_ext
There is a workaround to now inherit optimization CFLAGS when compiling wheels.
To enable this, set APPLY_LP2002043_UBUNTU_CFLAGS_WORKAROUND in your
environment. See LP: https://launchpad.net/bugs/2002043 for further context.
APPLY_LP2002043_UBUNTU_CFLAGS_WORKAROUND not detected.
# strings build/lib.linux-x86_64-2.7/test.so | grep -- -O
GNU GIMPLE 11.4.0 -mtune=generic -march=x86-64 -g -g -g -g -O2 -fno-openmp -fno-openacc -fcf-protection=full -fno-strict-aliasing -fwrapv -fstack-protector-strong -ffat-lto-objects -fstack-protector-strong -fPIC -fltrans

Revision history for this message
Lena Voytek (lvoytek) wrote :

Thanks! uploaded:

dput ubuntu ../python2.7_2.7.18-13ubuntu1.2_source.changes
D: Setting host argument.
Checking signature on .changes
gpg: ../python2.7_2.7.18-13ubuntu1.2_source.changes: Valid signature from 34B8AD7D9529E793
Checking signature on .dsc
gpg: ../python2.7_2.7.18-13ubuntu1.2.dsc: Valid signature from 34B8AD7D9529E793
Uploading to ubuntu (via ftp to upload.ubuntu.com):
  Uploading python2.7_2.7.18-13ubuntu1.2.dsc: done.
  Uploading python2.7_2.7.18-13ubuntu1.2.diff.gz: done.
  Uploading python2.7_2.7.18-13ubuntu1.2_source.buildinfo: done.
  Uploading python2.7_2.7.18-13ubuntu1.2_source.changes: done.
Successfully uploaded packages.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/debian/changelog b/debian/changelog
2index 55885af..2f4435b 100644
3--- a/debian/changelog
4+++ b/debian/changelog
5@@ -1,3 +1,10 @@
6+python2.7 (2.7.18-13ubuntu1.2) jammy; urgency=medium
7+
8+ * Add d/p/add-optimization-flags-to-cflags.diff: Add optimization flags to
9+ cflags when compiling C modules. (LP: #2002043)
10+
11+ -- Mitchell Dzurick <mitchell.dzurick@canonical.com> Sun, 15 Oct 2023 12:43:11 -0400
12+
13 python2.7 (2.7.18-13ubuntu1.1) jammy-security; urgency=medium
14
15 * SECURITY UPDATE: Injection Attack
16diff --git a/debian/patches/lp2002043-add-optimization-flags-to-cflags.patch b/debian/patches/lp2002043-add-optimization-flags-to-cflags.patch
17new file mode 100644
18index 0000000..198ba0b
19--- /dev/null
20+++ b/debian/patches/lp2002043-add-optimization-flags-to-cflags.patch
21@@ -0,0 +1,58 @@
22+Subject: Add optimization to cflags in sysconfig.py when building C modules.
23+
24+When compiling C code using python, the resulting binary is not being optimized
25+properly. Currently this is caused by the 'OPT' variable never being imported or
26+used in distutils/sysconfig.py and not being appended to the cflags variable.
27+This patch fixes the issue by importing 'OPT' and appending it to 'cflags'.
28+
29+Author: Mitchell Dzurick <mitchell.dzurick@canonical.com>
30+Date: Sun, 15 Oct 2023 17:50:49 +0300
31+Bug-Ubuntu: https://bugs.launchpad.net/bugs/2002043
32+--- a/Lib/distutils/sysconfig.py
33++++ b/Lib/distutils/sysconfig.py
34+@@ -190,12 +190,22 @@
35+ _osx_support.customize_compiler(_config_vars)
36+ _config_vars['CUSTOMIZED_OSX_COMPILER'] = 'True'
37+
38+- (cc, cxx, cflags, extra_cflags, basecflags,
39+- ccshared, ldshared, so_ext, ar, ar_flags,
40+- configure_cppflags, configure_cflags, configure_ldflags) = \
41+- get_config_vars('CC', 'CXX', 'CFLAGS', 'EXTRA_CFLAGS', 'BASECFLAGS',
42+- 'CCSHARED', 'LDSHARED', 'SO', 'AR', 'ARFLAGS',
43+- 'CONFIGURE_CPPFLAGS', 'CONFIGURE_CFLAGS', 'CONFIGURE_LDFLAGS')
44++ lp2002043_ubuntu_cflags_workaround = 'APPLY_LP2002043_UBUNTU_CFLAGS_WORKAROUND' in os.environ
45++
46++ if (lp2002043_ubuntu_cflags_workaround):
47++ (cc, cxx, cflags, extra_cflags, basecflags, opt,
48++ ccshared, ldshared, so_ext, ar, ar_flags,
49++ configure_cppflags, configure_cflags, configure_ldflags) = \
50++ get_config_vars('CC', 'CXX', 'CFLAGS', 'EXTRA_CFLAGS', 'BASECFLAGS', 'OPT',
51++ 'CCSHARED', 'LDSHARED', 'SO', 'AR', 'ARFLAGS',
52++ 'CONFIGURE_CPPFLAGS', 'CONFIGURE_CFLAGS', 'CONFIGURE_LDFLAGS')
53++ else:
54++ (cc, cxx, cflags, extra_cflags, basecflags,
55++ ccshared, ldshared, so_ext, ar, ar_flags,
56++ configure_cppflags, configure_cflags, configure_ldflags) = \
57++ get_config_vars('CC', 'CXX', 'CFLAGS', 'EXTRA_CFLAGS', 'BASECFLAGS',
58++ 'CCSHARED', 'LDSHARED', 'SO', 'AR', 'ARFLAGS',
59++ 'CONFIGURE_CPPFLAGS', 'CONFIGURE_CFLAGS', 'CONFIGURE_LDFLAGS')
60+
61+ if 'CC' in os.environ:
62+ newcc = os.environ['CC']
63+@@ -228,7 +238,15 @@
64+ cflags = ' '.join(str(x) for x in (basecflags, os.environ['CFLAGS'], extra_cflags) if x)
65+ ldshared = ldshared + ' ' + os.environ['CFLAGS']
66+ elif configure_cflags:
67+- cflags = ' '.join(str(x) for x in (basecflags, configure_cflags, extra_cflags) if x)
68++ print("There is a workaround to now inherit optimization CFLAGS when compiling wheels.")
69++ print("To enable this, set APPLY_LP2002043_UBUNTU_CFLAGS_WORKAROUND in your")
70++ print("environment. See LP: https://launchpad.net/bugs/2002043 for further context.")
71++ if (lp2002043_ubuntu_cflags_workaround):
72++ print("APPLY_LP2002043_UBUNTU_CFLAGS_WORKAROUND detected, using workaround.")
73++ cflags = ' '.join(str(x) for x in (basecflags, opt, configure_cflags, extra_cflags) if x)
74++ else:
75++ print("APPLY_LP2002043_UBUNTU_CFLAGS_WORKAROUND not detected.")
76++ cflags = ' '.join(str(x) for x in (basecflags, configure_cflags, extra_cflags) if x)
77+ ldshared = ldshared + ' ' + configure_cflags
78+ if 'CPPFLAGS' in os.environ:
79+ cpp = cpp + ' ' + os.environ['CPPFLAGS']
80diff --git a/debian/patches/series.in b/debian/patches/series.in
81index f8a4532..c968800 100644
82--- a/debian/patches/series.in
83+++ b/debian/patches/series.in
84@@ -85,3 +85,4 @@ sphinx4.diff
85 skip-tls1.2-tests.diff
86 issue46811.diff
87 CVE-2015-20107.patch
88+lp2002043-add-optimization-flags-to-cflags.patch

Subscribers

People subscribed via source and target branches