Hi,

I've found a bug in intelmic-mkoffload, it works only when the path to gcc is
absolute or relative, but doesn't work when it's specified in the PATH env var.
Here is the fix, I've got a piece of code from gcc/config/nvptx/mkoffload.c.
Regtested on x86_64-linux and i686-linux.  Ok for trunk?


gcc/
        * config/i386/intelmic-mkoffload.c: Include intelmic-offload.h instead
        of libgomp-plugin.h.
        (find_target_compiler): Support a case when the path to gcc is specified
        in the PATH env var, so COLLECT_GCC doesn't contain a path.
        (generate_host_descr_file): Use GOMP_DEVICE_INTEL_MIC from
        intelmic-offload.h instead of OFFLOAD_TARGET_TYPE_INTEL_MIC from
        libgomp-plugin.h.
        (main): Use GCC_INSTALL_NAME as target_driver_name.
        * config/i386/t-intelmic (CFLAGS-mkoffload.o): Add GCC_INSTALL_NAME
        define.
        (mkoffload.o): Remove obsolete include path and defines.
        (mkoffload$(exeext)): Use $(LINKER) instead of $(COMPILER).


diff --git a/gcc/config/i386/intelmic-mkoffload.c 
b/gcc/config/i386/intelmic-mkoffload.c
index e6394e9..f93007c 100644
--- a/gcc/config/i386/intelmic-mkoffload.c
+++ b/gcc/config/i386/intelmic-mkoffload.c
@@ -22,13 +22,13 @@
 
 #include "config.h"
 #include <libgen.h>
-#include "libgomp-plugin.h"
 #include "system.h"
 #include "coretypes.h"
 #include "obstack.h"
 #include "intl.h"
 #include "diagnostic.h"
 #include "collect-utils.h"
+#include "intelmic-offload.h"
 
 const char tool_name[] = "intelmic mkoffload";
 
@@ -158,10 +158,21 @@ find_target_compiler (const char *name)
   bool found = false;
   char **paths = NULL;
   unsigned n_paths, i;
-  const char *collect_path = dirname (ASTRDUP (getenv ("COLLECT_GCC")));
-  size_t len = strlen (collect_path) + 1 + strlen (name) + 1;
-  char *target_compiler = XNEWVEC (char, len);
-  sprintf (target_compiler, "%s/%s", collect_path, name);
+  char *target_compiler;
+  const char *collect_gcc = getenv ("COLLECT_GCC");
+  const char *gcc_path = dirname (ASTRDUP (collect_gcc));
+  const char *gcc_exec = basename (ASTRDUP (collect_gcc));
+
+  if (strcmp (gcc_exec, collect_gcc) == 0)
+    {
+      /* collect_gcc has no path, so it was found in PATH.  Make sure we also
+        find accel-gcc in PATH.  */
+      target_compiler = XDUPVEC (char, name, strlen (name) + 1);
+      found = true;
+      goto out;
+    }
+
+  target_compiler = concat (gcc_path, "/", name, NULL);
   if (access_check (target_compiler, X_OK) == 0)
     {
       found = true;
@@ -171,7 +182,7 @@ find_target_compiler (const char *name)
   n_paths = parse_env_var (getenv ("COMPILER_PATH"), &paths);
   for (i = 0; i < n_paths; i++)
     {
-      len = strlen (paths[i]) + 1 + strlen (name) + 1;
+      size_t len = strlen (paths[i]) + 1 + strlen (name) + 1;
       target_compiler = XRESIZEVEC (char, target_compiler, len);
       sprintf (target_compiler, "%s/%s", paths[i], name);
       if (access_check (target_compiler, X_OK) == 0)
@@ -346,7 +357,7 @@ generate_host_descr_file (const char *host_compiler)
           "init (void)\n"
           "{\n"
           "  GOMP_offload_register (&__OFFLOAD_TABLE__, %d, 
__offload_target_data);\n"
-          "}\n", OFFLOAD_TARGET_TYPE_INTEL_MIC);
+          "}\n", GOMP_DEVICE_INTEL_MIC);
   fclose (src_file);
 
   unsigned new_argc = 0;
@@ -483,8 +494,7 @@ main (int argc, char **argv)
   if (!host_compiler)
     fatal_error (input_location, "COLLECT_GCC must be set");
 
-  const char *target_driver_name
-    = DEFAULT_REAL_TARGET_MACHINE "-accel-" DEFAULT_TARGET_MACHINE "-gcc";
+  const char *target_driver_name = GCC_INSTALL_NAME;
   char *target_compiler = find_target_compiler (target_driver_name);
   if (target_compiler == NULL)
     fatal_error (input_location, "offload compiler %s not found",
diff --git a/gcc/config/i386/t-intelmic b/gcc/config/i386/t-intelmic
index 287460e..9de4b76 100644
--- a/gcc/config/i386/t-intelmic
+++ b/gcc/config/i386/t-intelmic
@@ -1,10 +1,10 @@
+CFLAGS-mkoffload.o += $(DRIVER_DEFINES) 
-DGCC_INSTALL_NAME=\"$(GCC_INSTALL_NAME)\"
+
 mkoffload.o: $(srcdir)/config/i386/intelmic-mkoffload.c
-       $(COMPILER) -c $(ALL_COMPILERFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) \
-         -I$(srcdir)/../libgomp \
-         -DDEFAULT_REAL_TARGET_MACHINE=\"$(real_target_noncanonical)\" \
-         -DDEFAULT_TARGET_MACHINE=\"$(target_noncanonical)\" \
-         $< $(OUTPUT_OPTION)
+       $(COMPILE) $<
+       $(POSTCOMPILE)
 ALL_HOST_OBJS += mkoffload.o
 
 mkoffload$(exeext): mkoffload.o collect-utils.o libcommon-target.a 
$(LIBIBERTY) $(LIBDEPS)
-       $(COMPILER) -o $@ mkoffload.o collect-utils.o libcommon-target.a 
$(LIBIBERTY) $(LIBS)
+       $(LINKER) $(ALL_LINKERFLAGS) $(LDFLAGS) -o $@ \
+         mkoffload.o collect-utils.o libcommon-target.a $(LIBIBERTY) $(LIBS)


Thanks,
  -- Ilya

Reply via email to