Skip to content

Commit d9902b1

Browse files
authored
config: prevent aarch64_be from being autodetected (#345)
Autodetection doesn't check for endianess, and therefore the ARM generator will be incorrectly selected in a big endian aarch64 system. Move endianess detection and add an exception to invalidate its detection for that configuration.
1 parent 35ffee1 commit d9902b1

3 files changed

Lines changed: 71 additions & 50 deletions

File tree

sljit_src/sljitConfig.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ extern "C" {
133133
nonzero value - FPU is present.
134134
*/
135135

136-
/* For further configurations, see the beginning of sljitConfigInternal.h */
136+
/* For further configurations, see sljitConfigCPU.h and sljitConfigInternal.h */
137137

138138
#ifdef __cplusplus
139139
} /* extern "C" */

sljit_src/sljitConfigCPU.h

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,4 +185,74 @@
185185
#define SLJIT_CONFIG_LOONGARCH 1
186186
#endif
187187

188+
/*************************/
189+
/* Endianness detection. */
190+
/*************************/
191+
192+
#if !defined(SLJIT_BIG_ENDIAN) && !defined(SLJIT_LITTLE_ENDIAN)
193+
194+
#if defined(SLJIT_CONFIG_ARM) && SLJIT_CONFIG_ARM
195+
196+
#ifdef __ARM_BIG_ENDIAN
197+
#define SLJIT_BIG_ENDIAN 1
198+
#else
199+
#define SLJIT_LITTLE_ENDIAN 1
200+
#endif
201+
202+
#elif (defined SLJIT_CONFIG_PPC && SLJIT_CONFIG_PPC)
203+
204+
#ifdef __LITTLE_ENDIAN__
205+
#define SLJIT_LITTLE_ENDIAN 1
206+
#else
207+
#define SLJIT_BIG_ENDIAN 1
208+
#endif
209+
210+
#elif (defined SLJIT_CONFIG_MIPS && SLJIT_CONFIG_MIPS)
211+
212+
#ifdef __MIPSEL__
213+
#define SLJIT_LITTLE_ENDIAN 1
214+
#else
215+
#define SLJIT_BIG_ENDIAN 1
216+
#endif
217+
218+
#ifndef SLJIT_MIPS_REV
219+
220+
/* Auto detecting mips revision. */
221+
#if (defined __mips_isa_rev) && (__mips_isa_rev >= 6)
222+
#define SLJIT_MIPS_REV 6
223+
#elif defined(__mips_isa_rev) && __mips_isa_rev >= 1
224+
#define SLJIT_MIPS_REV __mips_isa_rev
225+
#elif defined(__clang__) \
226+
&& (defined(_MIPS_ARCH_OCTEON) || defined(_MIPS_ARCH_P5600))
227+
/* clang either forgets to define (clang-7) __mips_isa_rev at all
228+
* or sets it to zero (clang-8,-9) for -march=octeon (MIPS64 R2+)
229+
* and -march=p5600 (MIPS32 R5).
230+
* It also sets the __mips macro to 64 or 32 for -mipsN when N <= 5
231+
* (should be set to N exactly) so we cannot rely on this too.
232+
*/
233+
#define SLJIT_MIPS_REV 1
234+
#endif
235+
236+
#endif /* !SLJIT_MIPS_REV */
237+
238+
#elif (defined SLJIT_CONFIG_S390X && SLJIT_CONFIG_S390X)
239+
240+
#define SLJIT_BIG_ENDIAN 1
241+
242+
#else
243+
244+
#define SLJIT_LITTLE_ENDIAN 1
245+
246+
#endif
247+
248+
#endif /* !defined(SLJIT_BIG_ENDIAN) && !defined(SLJIT_LITTLE_ENDIAN) */
249+
250+
#if (defined(SLJIT_CONFIG_ARM_64) && SLJIT_CONFIG_ARM_64) \
251+
&& (defined(SLJIT_BIG_ENDIAN) && SLJIT_BIG_ENDIAN)
252+
253+
#undef SLJIT_CONFIG_ARM_64
254+
#define SLJIT_CONFIG_UNSUPPORTED 1
255+
256+
#endif
257+
188258
#endif /* SLJIT_CONFIG_CPU_H_ */

sljit_src/sljitConfigInternal.h

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -464,55 +464,6 @@ typedef double sljit_f64;
464464
/* Endianness detection. */
465465
/*************************/
466466

467-
#if !defined(SLJIT_BIG_ENDIAN) && !defined(SLJIT_LITTLE_ENDIAN)
468-
469-
/* These macros are mostly useful for the applications. */
470-
#if (defined SLJIT_CONFIG_PPC && SLJIT_CONFIG_PPC)
471-
472-
#ifdef __LITTLE_ENDIAN__
473-
#define SLJIT_LITTLE_ENDIAN 1
474-
#else
475-
#define SLJIT_BIG_ENDIAN 1
476-
#endif
477-
478-
#elif (defined SLJIT_CONFIG_MIPS && SLJIT_CONFIG_MIPS)
479-
480-
#ifdef __MIPSEL__
481-
#define SLJIT_LITTLE_ENDIAN 1
482-
#else
483-
#define SLJIT_BIG_ENDIAN 1
484-
#endif
485-
486-
#ifndef SLJIT_MIPS_REV
487-
488-
/* Auto detecting mips revision. */
489-
#if (defined __mips_isa_rev) && (__mips_isa_rev >= 6)
490-
#define SLJIT_MIPS_REV 6
491-
#elif defined(__mips_isa_rev) && __mips_isa_rev >= 1
492-
#define SLJIT_MIPS_REV __mips_isa_rev
493-
#elif defined(__clang__) \
494-
&& (defined(_MIPS_ARCH_OCTEON) || defined(_MIPS_ARCH_P5600))
495-
/* clang either forgets to define (clang-7) __mips_isa_rev at all
496-
* or sets it to zero (clang-8,-9) for -march=octeon (MIPS64 R2+)
497-
* and -march=p5600 (MIPS32 R5).
498-
* It also sets the __mips macro to 64 or 32 for -mipsN when N <= 5
499-
* (should be set to N exactly) so we cannot rely on this too.
500-
*/
501-
#define SLJIT_MIPS_REV 1
502-
#endif
503-
504-
#endif /* !SLJIT_MIPS_REV */
505-
506-
#elif (defined SLJIT_CONFIG_S390X && SLJIT_CONFIG_S390X)
507-
508-
#define SLJIT_BIG_ENDIAN 1
509-
510-
#else
511-
#define SLJIT_LITTLE_ENDIAN 1
512-
#endif
513-
514-
#endif /* !defined(SLJIT_BIG_ENDIAN) && !defined(SLJIT_LITTLE_ENDIAN) */
515-
516467
/* Sanity check. */
517468
#if (defined SLJIT_BIG_ENDIAN && SLJIT_BIG_ENDIAN) && (defined SLJIT_LITTLE_ENDIAN && SLJIT_LITTLE_ENDIAN)
518469
#error "Exactly one endianness must be selected"

0 commit comments

Comments
 (0)