New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
EXTRA_CFLAGS get overrided by CFLAGS_NODIST #81812
Comments
Problem: How to reproduce: If you look at GCC arguments, there is -O2 present *after* the -Og flag. This means -Og gets ignored. |
Could you provide more info, e.g. comparison between the proper and the erroneous output, as well as what it affects (test_gdb if I recall correctly)? |
I believe you mean this downstream issue: https://bugzilla.redhat.com/show_bug.cgi?id=1712977 That issue is but only a consequence of a bad flag handling. It might also cause inconveniences with other use-cases for EXTRA_CFLAGS, as they might get overridden by CFLAGS_NODIST. You can get the erroneous output by running the reproducer. That is: $./configure -Og from EXTRA_CFLAGS gets overridden by -O2 from CFLAGS_NODIST. |
Python has way too many variables to control compiler flags: I'm not sure which variables are "standard" and supposed to be overriden or not, because there is no documentation. The priority because these variables is not documented at all. For example:
Linker flags are not documented neither which caused a regression for a short time (issue ith BLDSHARED if I recall correctly). Examples of variables related to linker flags: --- PY_LDFLAGS= LDSHARED= @LDSHARED@ $(PY_LDFLAGS) |
I agree that documenting the flags is quite important, I've had a hard time trying to figure out how to implement the LDFLAGS_NODIST, and the change still broke macos builds (luckily it was fixed swiftly). Nevertheless, this is still a bug which should be addressed. On another note, where would be the best place to start documenting those flags? Makefile, the python docs, somewhere else? |
IMHO comments in Makefile.pre.in is a good start. |
Dug a bit further here. The issue is that CFLAGS_NODIST will always come after normal CFLAGS (which are subsets of PY_CFLAGS and PY_CFLAGS_NODIST) [0][1]. The EXTRA_CFLAGS variable is appended at the end of PY_CFLAGS [2], hence as reported here, whatever compiler flag comes after, embedded within PY_CFLAGS_NODIST, will override the previous flags if they contradict each other. So basically EXTRA_CFLAGS can be used only for flags that can't be overwritten by PY_CFLAGS_NODIST, which in my opinion, is not very useful in the context of just adding extra flags. Commit adding the variable to Python 2.5: 08cd598 "EXTRA_CFLAGS has been introduced as an environment variable to hold compiler flags that change binary compatibility" Apparently it was added in order to avoid using the OPT variable for the various debug builds described in https://github.com/python/cpython/blob/master/Misc/SpecialBuilds.txt On another note this flag will get passed down to distutils, so if it was used for building the interpreter, C extensions compiled by users will also inherit it. Honestly I am not sure what the best solution would be here. If the various sub-debug special builds are still relevant and they stack, by doing for example $ make CFLAGS_NODIST="-DPy_TRACE_REFS" EXTRA_CFLAGS="-DPy_REF_DEBUG" then the issue can be closed, and the documentation can be more explicit that the EXTRA_CFLAGS is to be used only for the special builds. If the EXTRA_CFLAGS can also be used for adding our own flags, then the flag handling needs to change to take this into account. [0] https://github.com/python/cpython/blob/master/setup.py#L85 |
Also this is due to an expected behaviour from gcc. From the documentation: "If you use multiple -O options, with or without level numbers, the last such option is the one that is effective. " |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: