@@ -989,27 +989,16 @@ def skipUnlessAArch64MTELinuxCompiler(func):
989989
990990 def is_toolchain_with_mte ():
991991 compiler_path = lldbplatformutil .getCompiler ()
992- f_src = tempfile .NamedTemporaryFile (delete = False )
993- f_out = tempfile .NamedTemporaryFile (delete = False )
992+ f = tempfile .NamedTemporaryFile (delete = False )
994993 if lldbplatformutil .getPlatform () == "windows" :
995994 return "MTE tests are not compatible with 'windows'"
996995
997996 # Note hostos may be Windows.
998- f_src .close ()
999- f_out .close ()
997+ f .close ()
1000998
1001- with open (f_src .name , "w" ) as f :
1002- f .write ("int main() {}" )
1003- cmd = f"{ compiler_path } -x c -o { f_out .name } { f_src .name } "
1004- if os .popen (cmd ).close () is not None :
1005- try :
1006- os .remove (f_src .name )
1007- except OSError :
1008- pass
1009- try :
1010- os .remove (f_out .name )
1011- except OSError :
1012- pass
999+ cmd = f"{ compiler_path } -x c -o { f .name } -"
1000+ if subprocess .run (cmd , input = "int main() {}" .encode ()).returncode != 0 :
1001+ os .remove (f .name )
10131002 # Cannot compile at all, don't skip the test
10141003 # so that we report the broken compiler normally.
10151004 return None
@@ -1024,21 +1013,10 @@ def is_toolchain_with_mte():
10241013 int main() {
10251014 void* ptr = __arm_mte_create_random_tag((void*)(0), 0);
10261015 }"""
1027- with open (f_src .name , "w" ) as f :
1028- f .write (test_src )
1029- cmd = (
1030- f"{ compiler_path } -march=armv8.5-a+memtag -x c -o { f_out .name } { f_src .name } "
1031- )
1032- res = os .popen (cmd ).close ()
1033- try :
1034- os .remove (f_src .name )
1035- except OSError :
1036- pass
1037- try :
1038- os .remove (f_out .name )
1039- except OSError :
1040- pass
1041- if res is not None :
1016+ cmd = f"{ compiler_path } -march=armv8.5-a+memtag -x c -o { f .name } -"
1017+ res = subprocess .run (cmd , input = test_src .encode ())
1018+ os .remove (f .name )
1019+ if res .returncode != 0 :
10421020 return "Toolchain does not support MTE"
10431021 return None
10441022
0 commit comments