Skip to content

Commit f37099c

Browse files
committed
pythongh-132026: Ensure _MIPS_SIM has defined _ABI identifiers for comparison
When built on a MIPS architecture, `_MIPS_SIM` is used to determine architecture specifics. The value is expected to match either `_ABIO32`, `_ABIN32` or `_ABI64`. In `gcc` config/mips/mips.h these values are defined as compiler `builtin_define` inside of a switch/case. That means, mips64el and mips64 architectures know about `_ABI64` but don't know about `_ABIO32` and `_ABIN32`. In turn, when CPython tries to use them in comparison, they may be undefined identifiers. In default compiler behavior, the undefined identifier will be evaluated as zero, and it will not match `_MIPS_SIM`. However, the issues pop up when `-Wundef` (or, even worse, `-Werror=undef`) compiler flag is enabled. Then suddenly it's visible as a warning or error.
1 parent c0661df commit f37099c

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Use of undefined identifiers is removed for determining architecture
2+
specifics when building C code on MIPS architectures.

Diff for: Misc/platform_triplet.c

+12-12
Original file line numberDiff line numberDiff line change
@@ -57,21 +57,21 @@ PLATFORM_TRIPLET=arm-linux-androideabi
5757
# endif
5858
# if defined(_MIPS_SIM)
5959
# if defined(__mips_hard_float)
60-
# if _MIPS_SIM == _ABIO32
60+
# if defined(_ABIO32) && _MIPS_SIM == _ABIO32
6161
# define LIBC_MIPS gnu
62-
# elif _MIPS_SIM == _ABIN32
62+
# elif defined(_ABIN32) && _MIPS_SIM == _ABIN32
6363
# define LIBC_MIPS gnuabin32
64-
# elif _MIPS_SIM == _ABI64
64+
# elif defined(_ABI64) && _MIPS_SIM == _ABI64
6565
# define LIBC_MIPS gnuabi64
6666
# else
6767
# error unknown mips sim value
6868
# endif
6969
# else
70-
# if _MIPS_SIM == _ABIO32
70+
# if defined(_ABIO32) && _MIPS_SIM == _ABIO32
7171
# define LIBC_MIPS gnusf
72-
# elif _MIPS_SIM == _ABIN32
72+
# elif defined(_ABIN32) && _MIPS_SIM == _ABIN32
7373
# define LIBC_MIPS gnuabin32sf
74-
# elif _MIPS_SIM == _ABI64
74+
# elif defined(_ABI64) && _MIPS_SIM == _ABI64
7575
# define LIBC_MIPS gnuabi64sf
7676
# else
7777
# error unknown mips sim value
@@ -107,21 +107,21 @@ PLATFORM_TRIPLET=arm-linux-androideabi
107107
# endif
108108
# if defined(_MIPS_SIM)
109109
# if defined(__mips_hard_float)
110-
# if _MIPS_SIM == _ABIO32
110+
# if defined(_ABIO32) && _MIPS_SIM == _ABIO32
111111
# define LIBC_MIPS musl
112-
# elif _MIPS_SIM == _ABIN32
112+
# elif defined(_ABIN32) && _MIPS_SIM == _ABIN32
113113
# define LIBC_MIPS musln32
114-
# elif _MIPS_SIM == _ABI64
114+
# elif defined(_ABI64) && _MIPS_SIM == _ABI64
115115
# define LIBC_MIPS musl
116116
# else
117117
# error unknown mips sim value
118118
# endif
119119
# else
120-
# if _MIPS_SIM == _ABIO32
120+
# if defined(_ABIO32) && _MIPS_SIM == _ABIO32
121121
# define LIBC_MIPS muslsf
122-
# elif _MIPS_SIM == _ABIN32
122+
# elif defined(_ABIN32) && _MIPS_SIM == _ABIN32
123123
# define LIBC_MIPS musln32sf
124-
# elif _MIPS_SIM == _ABI64
124+
# elif defined(_ABI64) && _MIPS_SIM == _ABI64
125125
# define LIBC_MIPS muslsf
126126
# else
127127
# error unknown mips sim value

0 commit comments

Comments
 (0)