Python extension modules get built using wrong compiler flags with python2
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
python2.7 (Ubuntu) |
Invalid
|
Undecided
|
Unassigned | ||
Bionic |
Won't Fix
|
High
|
Unassigned | ||
Focal |
Fix Released
|
High
|
Mitchell Dzurick | ||
Jammy |
Fix Released
|
High
|
Mitchell Dzurick | ||
Kinetic |
Invalid
|
High
|
Unassigned | ||
Lunar |
Invalid
|
Undecided
|
Unassigned | ||
Mantic |
Invalid
|
Undecided
|
Unassigned |
Bug Description
[ Impact ]
When compiling Python extensions using Python2, CFLAGS optimization flags are dropped.
This behavior has been caused by our update in this patch http://
The fix modifies the portion of code in Lib/distutils/
[ Test Plan ]
There will be 2 separate tests for this bug:
* Ensuring no-change rebuilds are not changed
* Ensuring local builds are not changed unless environment variable is set
Test 1) No-change rebuilds
To test that no-change rebuilds are not changed, the package python-
Test 2) Functional test
1. Create test container
$ lxc launch ubuntu:jammy jammy-2002043
$ lxc shell jammy-2002043
2. Install required packages
For Jammy
# apt update -y && apt install -y python2 python-pip
For Focal
# apt update -y && apt install -y python2 python-setuptools gcc
3. Create test files
# mkdir testprog
# cd testprog
# cat >setup.py <<EOL
from setuptools import setup, Extension
setup(
name="test",
ext_
zip_safe=False
)
EOL
# cat >testmodule.c <<EOL
#include <stdio.h>
int main(void)
{
return 0;
}
EOL
4. Compile a test program
# python2 setup.py build_ext --inplace
5. Check CFLAGS
# python2 -c "import sysconfig; print(sysconfig
-fno-strict-
6. Check the flags used to compile the test wheel
# strings build/lib.
GNU GIMPLE 11.4.0 -mtune=generic -march=x86-64 -g -g -g -g -O2 -fno-openmp -fno-openacc -fcf-protection
7. Install fixed python
Once updated, this will simply be an apt update && apt upgrade
# add-apt-repository ppa:mitchdz/
# apt install -y python2.7
# dpkg -s python2.7 | grep Version:
Version: 2.7.18-
8. Clean build
# rm -rf build/ test.so
9. Enable opt-in environment variable
# export APPLY_LP2002043
9. Rebuild with new python2.7 installed
# python2 setup.py build_ext --inplace
10. Check build flags
# strings build/lib.
GNU GIMPLE 11.4.0 -mtune=generic -march=x86-64 -g -g -g -g -O2 -O2 -fno-openmp -fno-openacc -fcf-protection
GNU C17 11.4.0 -mtune=generic -march=x86-64 -g -g -O2 -fno-strict-
[ Where problems could occur ]
* Changing optimization flags can cause a myriad of unattended side effects, but the change being opt-in means the users should be aware a change is being made
* The change is opt-in, so an informative message is printed to the console to spread awareness of the issue and how to use the workaround. A questionably made CI/CD system might see the new console output and flag it as a failure, so it is important to choose wording carefully.
Related branches
- Lena Voytek (community): Approve
- git-ubuntu import: Pending requested
-
Diff: 88 lines (+66/-0)3 files modifieddebian/changelog (+7/-0)
debian/patches/lp2002043-add-optimization-flags-to-cflags.patch (+58/-0)
debian/patches/series.in (+1/-0)
- Lena Voytek (community): Approve
- git-ubuntu import: Pending requested
-
Diff: 88 lines (+66/-0)3 files modifieddebian/changelog (+7/-0)
debian/patches/lp2002043-add-optimization-flags-to-cflags.patch (+58/-0)
debian/patches/series.in (+1/-0)
summary: |
- Python extension modules get build using wrong compiler flags with + Python extension modules get built using wrong compiler flags with python2 |
Changed in python2.7 (Ubuntu Bionic): | |
status: | New → In Progress |
Changed in python2.7 (Ubuntu Focal): | |
status: | New → In Progress |
Changed in python2.7 (Ubuntu Jammy): | |
status: | New → In Progress |
Changed in python2.7 (Ubuntu Kinetic): | |
status: | New → In Progress |
Changed in python2.7 (Ubuntu Bionic): | |
assignee: | nobody → Ghadi Rahme (ghadi-rahme) |
Changed in python2.7 (Ubuntu Focal): | |
assignee: | nobody → Ghadi Rahme (ghadi-rahme) |
Changed in python2.7 (Ubuntu Jammy): | |
assignee: | nobody → Ghadi Rahme (ghadi-rahme) |
Changed in python2.7 (Ubuntu Kinetic): | |
assignee: | nobody → Ghadi Rahme (ghadi-rahme) |
tags: | added: se-sponsor-halves |
Changed in python2.7 (Ubuntu Jammy): | |
assignee: | Ghadi Rahme (ghadi-rahme) → Mitchell Dzurick (mitchdz) |
Changed in python2.7 (Ubuntu Focal): | |
assignee: | Ghadi Rahme (ghadi-rahme) → Mitchell Dzurick (mitchdz) |
Changed in python2.7 (Ubuntu Lunar): | |
assignee: | Ghadi Rahme (ghadi-rahme) → nobody |
Changed in python2.7 (Ubuntu Mantic): | |
assignee: | Ghadi Rahme (ghadi-rahme) → nobody |
Changed in python2.7 (Ubuntu Kinetic): | |
assignee: | Ghadi Rahme (ghadi-rahme) → nobody |
Changed in python2.7 (Ubuntu Bionic): | |
assignee: | Ghadi Rahme (ghadi-rahme) → nobody |
Changed in python2.7 (Ubuntu): | |
assignee: | Ghadi Rahme (ghadi-rahme) → nobody |
Changed in python2.7 (Ubuntu Focal): | |
status: | Won't Fix → In Progress |
Changed in python2.7 (Ubuntu Jammy): | |
status: | Won't Fix → In Progress |
Changed in python2.7 (Ubuntu): | |
status: | In Progress → Invalid |
Changed in python2.7 (Ubuntu Kinetic): | |
status: | Won't Fix → Invalid |
Changed in python2.7 (Ubuntu Lunar): | |
status: | Won't Fix → Invalid |
Changed in python2.7 (Ubuntu Mantic): | |
status: | Won't Fix → Invalid |
description: | updated |
Hello Nafees,
Can you share this setup.py that we can use to reproduce the problem and investigate?
Regards,
Fabio Martins