Skip to content

Commit 6def03c

Browse files
CyanoxygenBC204
authored andcommitted
detect_cpu: Fix mips32 detection on mips64
MIPS64 can run MIPS32 code natively, so there is a chance that a mixture of MIPS64 kernel and MIPS32 userland exists. Before this Meson just treats such mixture as mips64, because uname -m returns mips64. So in this case we have to check compiler builtin defines for actual architecture and CPU in use. - Also fixes mips64 related detection tests in internaltests: Normalize mips64 as mips first, then if __mips64 is defined, return mips64 for mips64* machines. This is a bit confiusing because normally one would detect if a flag of 32-bit target is defined while running on a 64-bit machine. For mips64 it is almost just the other way around - we need to detect if __mips64 is set to make sure it is a mips64 environment. Co-Authored-By: Jue Wang <[email protected]>
1 parent f5fa56f commit 6def03c

2 files changed

Lines changed: 17 additions & 9 deletions

File tree

‎mesonbuild/environment.py‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,11 @@ def detect_cpu_family(compilers: CompilersDict) -> str:
339339
# AIX always returns powerpc, check here for 64-bit
340340
if any_compiler_has_define(compilers, '__64BIT__'):
341341
trial = 'ppc64'
342+
# MIPS64 is able to run MIPS32 code natively, so there is a chance that
343+
# such mixture mentioned above exists.
344+
elif trial == 'mips64':
345+
if not any_compiler_has_define(compilers, '__mips64'):
346+
trial = 'mips'
342347

343348
if trial not in known_cpu_families:
344349
mlog.warning(f'Unknown CPU family {trial!r}, please report this at '
@@ -377,7 +382,10 @@ def detect_cpu(compilers: CompilersDict) -> str:
377382
if '64' not in trial:
378383
trial = 'mips'
379384
else:
380-
trial = 'mips64'
385+
if not any_compiler_has_define(compilers, '__mips64'):
386+
trial = 'mips'
387+
else:
388+
trial = 'mips64'
381389
elif trial == 'ppc':
382390
# AIX always returns powerpc, check here for 64-bit
383391
if any_compiler_has_define(compilers, '__64BIT__'):

‎unittests/internaltests.py‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1579,12 +1579,12 @@ def mock_trial(value: str) -> T.Iterable[None]:
15791579
('ppc', 'ppc'),
15801580
('macppc', 'ppc'),
15811581
('power macintosh', 'ppc'),
1582-
('mips64el', 'mips64'),
1583-
('mips64', 'mips64'),
1582+
('mips64el', 'mips'),
1583+
('mips64', 'mips'),
15841584
('mips', 'mips'),
15851585
('mipsel', 'mips'),
1586-
('ip30', 'mips64'),
1587-
('ip35', 'mips64'),
1586+
('ip30', 'mips'),
1587+
('ip35', 'mips'),
15881588
('parisc64', 'parisc'),
15891589
('sun4u', 'sparc64'),
15901590
('sun4v', 'sparc64'),
@@ -1602,7 +1602,7 @@ def mock_trial(value: str) -> T.Iterable[None]:
16021602
self.assertEqual(actual, expected)
16031603

16041604
with mock.patch('mesonbuild.environment.any_compiler_has_define', mock.Mock(return_value=True)):
1605-
for test, expected in [('x86_64', 'x86'), ('aarch64', 'arm'), ('ppc', 'ppc64')]:
1605+
for test, expected in [('x86_64', 'x86'), ('aarch64', 'arm'), ('ppc', 'ppc64'), ('mips64', 'mips64')]:
16061606
with self.subTest(test, has_define=True), mock_trial(test):
16071607
actual = mesonbuild.environment.detect_cpu_family({})
16081608
self.assertEqual(actual, expected)
@@ -1624,8 +1624,8 @@ def mock_trial(value: str) -> T.Iterable[None]:
16241624
('x64', 'x86_64'),
16251625
('i86pc', 'x86_64'),
16261626
('earm', 'arm'),
1627-
('mips64el', 'mips64'),
1628-
('mips64', 'mips64'),
1627+
('mips64el', 'mips'),
1628+
('mips64', 'mips'),
16291629
('mips', 'mips'),
16301630
('mipsel', 'mips'),
16311631
('aarch64', 'aarch64'),
@@ -1639,7 +1639,7 @@ def mock_trial(value: str) -> T.Iterable[None]:
16391639
self.assertEqual(actual, expected)
16401640

16411641
with mock.patch('mesonbuild.environment.any_compiler_has_define', mock.Mock(return_value=True)):
1642-
for test, expected in [('x86_64', 'i686'), ('aarch64', 'arm'), ('ppc', 'ppc64')]:
1642+
for test, expected in [('x86_64', 'i686'), ('aarch64', 'arm'), ('ppc', 'ppc64'), ('mips64', 'mips64')]:
16431643
with self.subTest(test, has_define=True), mock_trial(test):
16441644
actual = mesonbuild.environment.detect_cpu({})
16451645
self.assertEqual(actual, expected)

0 commit comments

Comments
 (0)