You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
assignee='https://github.com/xdegaye'closed_at=<Date2017-01-04.20:58:21.080>created_at=<Date2016-04-26.12:20:11.511>labels= ['type-feature', '3.7', 'build']
title='android compilation and link flags'updated_at=<Date2017-03-31.16:36:19.595>user='https://github.com/xdegaye'
The previous patch was using awkwardly, a 'host_cpu' configure argument to specify the arm ABI and missed setting LDFLAGS for the armv7 ABI.
This patch instead uses the __ARM_ARCH macro defined by each compiler of the Android toolchains:
Note: build-flags_3.patch includes configure.ac and configure. Usually, we suggest to not included generated files (configure) in patches, but push them when the patch is ready.
xdegaye commented on Jul 25, 2016
xdegayemannequin
MannequinAuthor
More actions
Thanks for the suggestion, I won't include them anymore in patches then.
xdegaye commented on Jul 26, 2016
xdegayemannequin
MannequinAuthor
More actions
New patch. The sed commands used to evaluate ANDROID_API_LEVEL and _arm_arch do not need to discard comment lines and empty lines in the output of the preprocessor.
I am still curious what configures the preprocessor to set __ARM_ARCH to 7 (I guess the clang -target argument?), and why we can’t set LDFLAGS at the same time or place. Is it just more convenient this way?
xdegaye commented on Jul 28, 2016
xdegayemannequin
MannequinAuthor
More actions
I am still curious what configures the preprocessor to set __ARM_ARCH to 7 (I guess the clang -target argument?)
Yes, the -target clang argument or the -march gcc argument.
and why we can’t set LDFLAGS at the same time or place. Is it just more convenient this way?
I don't understand the question. LDFLAGS is set at the time we know that __ARM_ARCH is 7, just after the preprocessing is done. Would you set it elsewhere ?
LDFLAGS is set in configure.ac with always this same idiom: LDFLAGS="$LDFLAGS new_options..." and this setting is done in what seems to be random places in configure.ac.
CCSHARED is set in one case statement.
Where is the code that sets the clang -target argument, or gcc -march? Is it hidden away somewhere in the autoconf code? Do you manually set it with ‘./configure CFLAGS="-target . . ." ’?
xdegaye commented on Jul 28, 2016
xdegayemannequin
MannequinAuthor
More actions
Yes, the packager must use appropriately either CFLAGS CPPFLAGS [1] and LDFLAGS, or CC. I am using:
CC="clang --sysroot=$(SYSROOT) -target $(TARGET) -gcc-toolchain $(GCC_TOOLCHAIN)".
[1] See bpo-27453, for the remaining problem upon using CPPFLAGS.
'-march=armv7-a' is not set in BASECFLAGS anymore as this is redundant: this option is already set in the configure command line or is implicitly set by the the first component of the triple of the '-target' clang option.
Do not set '-mthumb' as this is optional and may be set for the armv7 arch as well. Also this option crashes Python on armv5te when built with clang, bpo-27606.
Latest patch committed with the following simplification: BASECFLAGS and LDFLAGS are now set for armv7 at the same place, as suggested by Martin in msg271518.
In the code review Victor asked the following question:
I'm a little bit surprised that you need to pass so much options which are specific to the platform. GCC doesn't have a generic option "hello, please compile for my architecture?"
ARM defines two incompatible floating point ABIS that specify the functions calling conventions, whether to use integer registers (soft floating point ABI) or the floating point registers (hard floating point ABI). The compiler must be told which one to use and whether the hardware FPU may be used if present when the soft floating point ABI has been chosen. This last case is set with the command line option '-mfloat-abi=softfp'. The following two documents describe this feature in details: https://wiki.debian.org/ArmHardFloatPort/VfpComparison https://wiki.debian.org/ArmHardFloatPort
The following command prints the command line options, including implicitly predefined ones of the clang compiler in android-ndk-r13b and shows that the default is '-mfloat-abi=soft' for armv7:
Note that the system libffi must also be compiled with these same flags. The bundled libffi is deprecated in 3.6 by bpo-27976 and has been removed in 3.7 by bpo-27979.
yan12125 commented on Jan 5, 2017
yan12125mannequin
Mannequin
More actions
Note that the system libffi must also be compiled with these same flags
Just tried. With my packaging scripts, CPython on ARM is compiled with -mfloat-abi=softfp -mfpu=vfpv3-d16 while libffi not. test_ctypes pass as usual. Maybe ctypes test suite is not complete?
And by the way, if all packages on a system should be compiled with the same set of flags, shouldn't those flags specified in build/package scripts rather than Makefile of individual packages?
xdegaye commented on Jan 5, 2017
xdegayemannequin
MannequinAuthor
More actions
Just tried. With my packaging scripts, CPython on ARM is compiled with -mfloat-abi=softfp -mfpu=vfpv3-d16 while libffi not. test_ctypes pass as usual.
This works as expected, '-mfloat-abi=softfp' and the default '-mfloat-abi=soft' use the same ABI [1]: "Function calls are generated to pass FP arguments (float, double) in integer registers (one for float, a pair of registers for double)".
Activity
xdegaye commentedon Apr 26, 2016
The attached patch:
Sets the recommended android compilation flags, see: http://developer.android.com/ndk/guides/standalone_toolchain.html#abi. Note that the android toolchains already set the -fpic flag, as shown with:
arm-linux-androideabi-gcc -v -S main.c 2>&1 | grep main.c
Sets the Position independent executables (PIE) flag which is mandatory starting at API level 21 and supported starting with API level 16.
xdegaye commentedon Jul 24, 2016
The previous patch was using awkwardly, a 'host_cpu' configure argument to specify the arm ABI and missed setting LDFLAGS for the armv7 ABI.
This patch instead uses the __ARM_ARCH macro defined by each compiler of the Android toolchains:
Python built with clang for the armv5te target crashes as reported in bpo-27606.
vadmium commentedon Jul 25, 2016
I left some suggestions and questions on the code review.
xdegaye commentedon Jul 25, 2016
Thanks for the review and the suggestions Martin :)
New patch.
xdegaye commentedon Jul 25, 2016
The first 'build-flags_3.patch' file that was uploaded did not get a review button because ssh://hg@hg.python.org/cpython was down at that time.
The second upload has been successfull !
vstinner commentedon Jul 25, 2016
Note: build-flags_3.patch includes configure.ac and configure. Usually, we suggest to not included generated files (configure) in patches, but push them when the patch is ready.
xdegaye commentedon Jul 25, 2016
Thanks for the suggestion, I won't include them anymore in patches then.
xdegaye commentedon Jul 26, 2016
New patch. The sed commands used to evaluate ANDROID_API_LEVEL and _arm_arch do not need to discard comment lines and empty lines in the output of the preprocessor.
vadmium commentedon Jul 28, 2016
All the bits that I understand look okay now. :)
I am still curious what configures the preprocessor to set __ARM_ARCH to 7 (I guess the clang -target argument?), and why we can’t set LDFLAGS at the same time or place. Is it just more convenient this way?
xdegaye commentedon Jul 28, 2016
vadmium commentedon Jul 28, 2016
Where is the code that sets the clang -target argument, or gcc -march? Is it hidden away somewhere in the autoconf code? Do you manually set it with ‘./configure CFLAGS="-target . . ." ’?
xdegaye commentedon Jul 28, 2016
Yes, the packager must use appropriately either CFLAGS CPPFLAGS [1] and LDFLAGS, or CC. I am using:$(TARGET) -gcc-toolchain $ (GCC_TOOLCHAIN)".
CC="clang --sysroot=$(SYSROOT) -target
[1] See bpo-27453, for the remaining problem upon using CPPFLAGS.
xdegaye commentedon Oct 15, 2016
See also the clang cross compilation documentation at http://clang.llvm.org/docs/CrossCompilation.html.
xdegaye commentedon Oct 15, 2016
This new patch fixes the following:
python-dev commentedon Jan 4, 2017
New changeset fa2bc63e64c6 by Xavier de Gaye in branch '3.6':
Issue bpo-26851: Set Android compilation and link flags.
https://hg.python.org/cpython/rev/fa2bc63e64c6
New changeset af363b5200ff by Xavier de Gaye in branch 'default':
Issue bpo-26851: Merge 3.6.
https://hg.python.org/cpython/rev/af363b5200ff
xdegaye commentedon Jan 4, 2017
Latest patch committed with the following simplification: BASECFLAGS and LDFLAGS are now set for armv7 at the same place, as suggested by Martin in msg271518.
xdegaye commentedon Jan 5, 2017
In the code review Victor asked the following question:
ARM defines two incompatible floating point ABIS that specify the functions calling conventions, whether to use integer registers (soft floating point ABI) or the floating point registers (hard floating point ABI). The compiler must be told which one to use and whether the hardware FPU may be used if present when the soft floating point ABI has been chosen. This last case is set with the command line option '-mfloat-abi=softfp'. The following two documents describe this feature in details:
https://wiki.debian.org/ArmHardFloatPort/VfpComparison
https://wiki.debian.org/ArmHardFloatPort
The following command prints the command line options, including implicitly predefined ones of the clang compiler in android-ndk-r13b and shows that the default is '-mfloat-abi=soft' for armv7:
Note that the system libffi must also be compiled with these same flags. The bundled libffi is deprecated in 3.6 by bpo-27976 and has been removed in 3.7 by bpo-27979.
yan12125 commentedon Jan 5, 2017
Just tried. With my packaging scripts, CPython on ARM is compiled with -mfloat-abi=softfp -mfpu=vfpv3-d16 while libffi not. test_ctypes pass as usual. Maybe ctypes test suite is not complete?
And by the way, if all packages on a system should be compiled with the same set of flags, shouldn't those flags specified in build/package scripts rather than Makefile of individual packages?
xdegaye commentedon Jan 5, 2017
This works as expected, '-mfloat-abi=softfp' and the default '-mfloat-abi=soft' use the same ABI [1]: "Function calls are generated to pass FP arguments (float, double) in integer registers (one for float, a pair of registers for double)".
[1] https://wiki.debian.org/ArmHardFloatPort/VfpComparison