# DP: Fix PR jit/87808.

--- a/src/gcc/jit/Make-lang.in
+++ b/src/gcc/jit/Make-lang.in
@@ -84,6 +84,9 @@
 	jit/jit-spec.o \
 	gcc.o
 
+CFLAGS-jit/jit-playback.o += \
+	-DFALLBACK_GCC_EXEC_PREFIX=\"$(libdir)/gcc/$(target_subdir)/$(version)\"
+
 # Use strict warnings for this front end.
 jit-warn = $(STRICT_WARN)
 
--- a/src/gcc/jit/jit-playback.c
+++ b/src/gcc/jit/jit-playback.c
@@ -39,6 +39,7 @@
 #include "opt-suggestions.h"
 #include "gcc.h"
 #include "diagnostic.h"
+#include "file-find.h"
 
 #include <pthread.h>
 
@@ -2482,7 +2483,31 @@
 playback::context::
 invoke_embedded_driver (const vec <char *> *argvec)
 {
+  static char* gcc_driver_file = NULL;
+
   JIT_LOG_SCOPE (get_logger ());
+
+  /* process_command(), uses make_relative_prefix(), searches PATH
+     for the external driver, which might not be found.  In this case
+     fall back to the configured default.  */
+#ifdef FALLBACK_GCC_EXEC_PREFIX
+  if (gcc_driver_file == NULL && ::getenv ("GCC_EXEC_PREFIX") == NULL)
+    {
+      struct path_prefix path;
+
+      prefix_from_env ("PATH", &path);
+      gcc_driver_file = find_a_file (&path, gcc_driver_name, X_OK);
+      if (gcc_driver_file == NULL)
+        {
+	  char *str = concat ("GCC_EXEC_PREFIX=",
+			      FALLBACK_GCC_EXEC_PREFIX, NULL);
+	  ::putenv (str);
+	  log ("gcc driver %s not found, using fallback GCC_EXEC_PREFIX=%s",
+	       gcc_driver_name, FALLBACK_GCC_EXEC_PREFIX);
+        }
+    }
+#endif
+
   driver d (true, /* can_finalize */
 	    false); /* debug */
   int result = d.main (argvec->length (),
