mgorny created this revision.
mgorny added reviewers: MaskRay, myhsu, vsk.
Herald added subscribers: Enna1, StephenFan, dberris.
Herald added a project: All.
mgorny requested review of this revision.

Fix the is_binutils_lto_supported() function to handle missing
executables gracefully.  Currently, the function does not catch
exceptions from subprocess.Popen() and therefore causes lit to crash
if config.gold_executable does not specify a valid executable:

  lit: /usr/lib/python3.11/site-packages/lit/TestingConfig.py:136: fatal: 
unable to parse config file '/tmp/portage/sys-libs/compiler-rt-
  15.0.0/work/compiler-rt/test/lit.common.cfg.py', traceback: Traceback (most 
recent call last):
    File "/usr/lib/python3.11/site-packages/lit/TestingConfig.py", line 125, in 
load_from_path
      exec(compile(data, path, 'exec'), cfg_globals, None)
    File 
"/tmp/portage/sys-libs/compiler-rt-15.0.0/work/compiler-rt/test/lit.common.cfg.py",
 line 561, in <module>
      if is_binutils_lto_supported():
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File 
"/tmp/portage/sys-libs/compiler-rt-15.0.0/work/compiler-rt/test/lit.common.cfg.py",
 line 543, in is_binutils_lto_supported
      ld_cmd = subprocess.Popen([exe, '--help'], stdout=subprocess.PIPE, 
env={'LANG': 'C'})
               
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/usr/lib/python3.11/subprocess.py", line 1022, in __init__
      self._execute_child(args, executable, preexec_fn, close_fds,
    File "/usr/lib/python3.11/subprocess.py", line 1899, in _execute_child
      raise child_exception_type(errno_num, err_msg, err_filename)
  FileNotFoundError: [Errno 2] No such file or directory: 
'GOLD_EXECUTABLE-NOTFOUND'


https://reviews.llvm.org/D133358

Files:
  compiler-rt/test/lit.common.cfg.py


Index: compiler-rt/test/lit.common.cfg.py
===================================================================
--- compiler-rt/test/lit.common.cfg.py
+++ compiler-rt/test/lit.common.cfg.py
@@ -538,9 +538,12 @@
   # We require both ld.bfd and ld.gold exist and support plugins. They are in
   # the same repository 'binutils-gdb' and usually built together.
   for exe in (config.gnu_ld_executable, config.gold_executable):
-    ld_cmd = subprocess.Popen([exe, '--help'], stdout=subprocess.PIPE, 
env={'LANG': 'C'})
-    ld_out = ld_cmd.stdout.read().decode()
-    ld_cmd.wait()
+    try:
+      ld_cmd = subprocess.Popen([exe, '--help'], stdout=subprocess.PIPE, 
env={'LANG': 'C'})
+      ld_out = ld_cmd.stdout.read().decode()
+      ld_cmd.wait()
+    except OSError:
+      return False
     if not '-plugin' in ld_out:
       return False
 


Index: compiler-rt/test/lit.common.cfg.py
===================================================================
--- compiler-rt/test/lit.common.cfg.py
+++ compiler-rt/test/lit.common.cfg.py
@@ -538,9 +538,12 @@
   # We require both ld.bfd and ld.gold exist and support plugins. They are in
   # the same repository 'binutils-gdb' and usually built together.
   for exe in (config.gnu_ld_executable, config.gold_executable):
-    ld_cmd = subprocess.Popen([exe, '--help'], stdout=subprocess.PIPE, env={'LANG': 'C'})
-    ld_out = ld_cmd.stdout.read().decode()
-    ld_cmd.wait()
+    try:
+      ld_cmd = subprocess.Popen([exe, '--help'], stdout=subprocess.PIPE, env={'LANG': 'C'})
+      ld_out = ld_cmd.stdout.read().decode()
+      ld_cmd.wait()
+    except OSError:
+      return False
     if not '-plugin' in ld_out:
       return False
 
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to