diff mbox

[4/4] OpenMP 4.0 offloading to Intel MIC: non-fallback testing

Message ID 20150128160259.GA12176@msticlxl57.ims.intel.com
State New
Headers show

Commit Message

Ilya Verbin Jan. 28, 2015, 4:02 p.m. UTC
On 15 Jan 19:58, Jakub Jelinek wrote:
> On Thu, Jan 15, 2015 at 09:55:40PM +0300, Ilya Verbin wrote:
> > This patch enables 'make check-target-libgomp' with noninstalled offloading
> > compilers.  It creates gcc/accel/<target>/ directory in the build tree of the
> > offloading compiler, this allows lto-wrapper to find corresponding mkoffload in
> > case if there is more than one offloading compiler.  Is this approach ok?
> > I don't like changes in config.gcc and t-intelmic, probably there is a better
> > way to create a link?
> 
> Let's wait until Thomas hopefully checks in the OpenACC merge in order not
> to make him work even harder.
> I'll look at your patch afterwards.

I've rebased this patch.




  -- Ilya

Comments

Jakub Jelinek Jan. 28, 2015, 4:15 p.m. UTC | #1
On Wed, Jan 28, 2015 at 07:02:59PM +0300, Ilya Verbin wrote:
> +	= XNEWVEC (char, len + sizeof ("-B" "../" DEFAULT_TARGET_MACHINE
> +				       "/libgomp/"));
> +      sprintf (optional_target_path2, "-B%s/../../../" DEFAULT_TARGET_MACHINE
> +				      "/libgomp/", current_path);

This will surely overflow the buffer, won't it?  There is space just for
"../" but you put there "/../../../".

I'd strongly prefer if you rewrote all these XNEWVEC or XRESIZEVEC etc.
+ sprintf cases into concat, like
  optional_target_path2 = concat ("-B", current_path,
				  "/../../../" DEFAULT_TARGET_MACHINE
				  "/libgomp/", NULL);
and similar.  That way you avoid all such bugs.

	Jakub
Ilya Verbin Jan. 28, 2015, 4:20 p.m. UTC | #2
On 28 Jan 17:15, Jakub Jelinek wrote:
> On Wed, Jan 28, 2015 at 07:02:59PM +0300, Ilya Verbin wrote:
> > +	= XNEWVEC (char, len + sizeof ("-B" "../" DEFAULT_TARGET_MACHINE
> > +				       "/libgomp/"));
> > +      sprintf (optional_target_path2, "-B%s/../../../" DEFAULT_TARGET_MACHINE
> > +				      "/libgomp/", current_path);
> 
> This will surely overflow the buffer, won't it?  There is space just for
> "../" but you put there "/../../../".
> 
> I'd strongly prefer if you rewrote all these XNEWVEC or XRESIZEVEC etc.
> + sprintf cases into concat, like
>   optional_target_path2 = concat ("-B", current_path,
> 				  "/../../../" DEFAULT_TARGET_MACHINE
> 				  "/libgomp/", NULL);
> and similar.  That way you avoid all such bugs.

The variable 'len' contains sizeof ("/../../").
I agree that this code looks ugly :)  I'll rewrite it using concat.

  -- Ilya
diff mbox

Patch

diff --git a/gcc/config.gcc b/gcc/config.gcc
index bf67beb..c56c055 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -4371,7 +4371,7 @@  fi
 case ${target} in
 i[34567]86-*-* | x86_64-*-*)
 	if test x$enable_as_accelerator = xyes; then
-		extra_programs="mkoffload\$(exeext)"
+		extra_programs="mkoffload\$(exeext) accel/${target_noncanonical}/mkoffload$(exeext)"
 	fi
 	;;
 esac
diff --git a/gcc/config/i386/intelmic-mkoffload.c b/gcc/config/i386/intelmic-mkoffload.c
index 5d9ed33..73ca9ce 100644
--- a/gcc/config/i386/intelmic-mkoffload.c
+++ b/gcc/config/i386/intelmic-mkoffload.c
@@ -45,6 +45,13 @@  const char *temp_files[MAX_NUM_TEMPS];
 /* Shows if we should compile binaries for i386 instead of x86-64.  */
 bool target_ilp32 = false;
 
+/* Optional prefixes for the target compiler, which are required when target
+   compiler is not installed.  */
+char *optional_target_path1 = NULL;
+char *optional_target_path2 = NULL;
+char *optional_target_lib_path = NULL;
+
+
 /* Delete tempfiles and exit function.  */
 void
 tool_cleanup (bool from_signal ATTRIBUTE_UNUSED)
@@ -151,14 +158,18 @@  access_check (const char *name, int mode)
   return access (name, mode);
 }
 
-/* Find target compiler using a path from COLLECT_GCC or COMPILER_PATH.  */
+/* Find target compiler using a path from COLLECT_GCC, COMPILER_PATH, or a path
+   relative to ARGV0.  */
 static char *
-find_target_compiler (const char *name)
+find_target_compiler (const char *argv0)
 {
   bool found = false;
   char **paths = NULL;
   unsigned n_paths, i;
+  const char *current_path;
   const char *collect_path = dirname (ASTRDUP (getenv ("COLLECT_GCC")));
+  const char *name
+    = DEFAULT_REAL_TARGET_MACHINE "-accel-" DEFAULT_TARGET_MACHINE "-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);
@@ -177,13 +188,38 @@  find_target_compiler (const char *name)
       if (access_check (target_compiler, X_OK) == 0)
 	{
 	  found = true;
-	  break;
+	  goto out;
 	}
     }
 
+  /* If installed compiler wasn't found, try to find a non-installed compiler,
+     using a path relative to mkoffload.  */
+  current_path = dirname (ASTRDUP (argv0));
+  len = strlen (current_path) + sizeof ("/../../") - 1;
+  target_compiler = XRESIZEVEC (char, target_compiler, len + sizeof ("xgcc"));
+  sprintf (target_compiler, "%s/../../xgcc", current_path);
+  if (access_check (target_compiler, X_OK) == 0)
+    {
+      optional_target_path1 = XNEWVEC (char, len + sizeof ("-B"));
+      sprintf (optional_target_path1, "-B%s/../../", current_path);
+      optional_target_path2
+	= XNEWVEC (char, len + sizeof ("-B" "../" DEFAULT_TARGET_MACHINE
+				       "/libgomp/"));
+      sprintf (optional_target_path2, "-B%s/../../../" DEFAULT_TARGET_MACHINE
+				      "/libgomp/", current_path);
+      optional_target_lib_path
+	= XNEWVEC (char, len + sizeof ("-L" "../" DEFAULT_TARGET_MACHINE
+				       "/libgomp/.libs/"));
+      sprintf (optional_target_lib_path, "-L%s/../../../" DEFAULT_TARGET_MACHINE
+					 "/libgomp/.libs/", current_path);
+      found = true;
+    }
+
 out:
   free_array_of_ptrs ((void **) paths, n_paths);
-  return found ? target_compiler : NULL;
+  if (!found)
+    fatal_error ("offload compiler %s not found", name);
+  return target_compiler;
 }
 
 static void
@@ -193,6 +229,14 @@  compile_for_target (struct obstack *argv_obstack)
     obstack_ptr_grow (argv_obstack, "-m32");
   else
     obstack_ptr_grow (argv_obstack, "-m64");
+
+  if (optional_target_path1)
+    obstack_ptr_grow (argv_obstack, optional_target_path1);
+  if (optional_target_path2)
+    obstack_ptr_grow (argv_obstack, optional_target_path2);
+  if (optional_target_lib_path)
+    obstack_ptr_grow (argv_obstack, optional_target_lib_path);
+
   obstack_ptr_grow (argv_obstack, NULL);
   char **argv = XOBFINISH (argv_obstack, char **);
 
@@ -492,11 +536,7 @@  main (int argc, char **argv)
   if (!host_compiler)
     fatal_error ("COLLECT_GCC must be set");
 
-  const char *target_driver_name
-    = DEFAULT_REAL_TARGET_MACHINE "-accel-" DEFAULT_TARGET_MACHINE "-gcc";
-  char *target_compiler = find_target_compiler (target_driver_name);
-  if (target_compiler == NULL)
-    fatal_error ("offload compiler %s not found", target_driver_name);
+  char *target_compiler = find_target_compiler (argv[0]);
 
   /* We may be called with all the arguments stored in some file and
      passed with @file.  Expand them into argv before processing.  */
diff --git a/gcc/config/i386/t-intelmic b/gcc/config/i386/t-intelmic
index 8b36e0d..efc50fca 100644
--- a/gcc/config/i386/t-intelmic
+++ b/gcc/config/i386/t-intelmic
@@ -7,3 +7,9 @@  mkoffload.o: $(srcdir)/config/i386/intelmic-mkoffload.c | insn-modes.h
 
 mkoffload$(exeext): mkoffload.o collect-utils.o libcommon-target.a $(LIBIBERTY) $(LIBDEPS)
 	$(COMPILER) -o $@ mkoffload.o collect-utils.o libcommon-target.a $(LIBIBERTY) $(LIBS)
+
+accel/$(target_noncanonical)/mkoffload$(exeext): mkoffload$(exeext)
+	test -d accel || mkdir accel
+	test -d accel/$(target_noncanonical) || mkdir accel/$(target_noncanonical)
+	rm -f $@
+	$(LN) mkoffload$(exeext) $@
diff --git a/libgomp/configure b/libgomp/configure
index 0818707..8d96950 100755
--- a/libgomp/configure
+++ b/libgomp/configure
@@ -15226,6 +15226,9 @@  if test x"$enable_offload_targets" != x; then
     case $tgt in
       *-intelmic-* | *-intelmicemul-*)
 	tgt_name=intelmic
+	if test x"$tgt_dir" != x; then
+	  offload_additional_lib_paths="$offload_additional_lib_paths:$tgt_dir/$tgt/liboffloadmic/.libs"
+	fi
 	;;
       nvptx*)
         tgt_name=nvptx
@@ -15276,7 +15279,7 @@  rm -f core conftest.err conftest.$ac_objext \
       offload_targets=$offload_targets,$tgt_name
     fi
     if test x"$tgt_dir" != x; then
-      offload_additional_options="$offload_additional_options -B$tgt_dir/libexec/gcc/\$(target_alias)/\$(gcc_version) -B$tgt_dir/bin"
+      offload_additional_options="$offload_additional_options -B$tgt_dir/libexec/gcc/\$(target_alias)/\$(gcc_version) -B$tgt_dir/gcc -B$tgt_dir/bin"
       offload_additional_lib_paths="$offload_additional_lib_paths:$tgt_dir/lib64:$tgt_dir/lib:$tgt_dir/lib32"
     else
       offload_additional_options="$offload_additional_options -B\$(libexecdir)/gcc/\$(target_alias)/\$(gcc_version) -B\$(bindir)"
diff --git a/libgomp/plugin/configfrag.ac b/libgomp/plugin/configfrag.ac
index 254c688..2861e68 100644
--- a/libgomp/plugin/configfrag.ac
+++ b/libgomp/plugin/configfrag.ac
@@ -94,6 +94,9 @@  if test x"$enable_offload_targets" != x; then
     case $tgt in
       *-intelmic-* | *-intelmicemul-*)
 	tgt_name=intelmic
+	if test x"$tgt_dir" != x; then
+	  offload_additional_lib_paths="$offload_additional_lib_paths:$tgt_dir/$tgt/liboffloadmic/.libs"
+	fi
 	;;
       nvptx*)
         tgt_name=nvptx
@@ -133,7 +136,7 @@  if test x"$enable_offload_targets" != x; then
       offload_targets=$offload_targets,$tgt_name
     fi
     if test x"$tgt_dir" != x; then
-      offload_additional_options="$offload_additional_options -B$tgt_dir/libexec/gcc/\$(target_alias)/\$(gcc_version) -B$tgt_dir/bin"
+      offload_additional_options="$offload_additional_options -B$tgt_dir/libexec/gcc/\$(target_alias)/\$(gcc_version) -B$tgt_dir/gcc -B$tgt_dir/bin"
       offload_additional_lib_paths="$offload_additional_lib_paths:$tgt_dir/lib64:$tgt_dir/lib:$tgt_dir/lib32"
     else
       offload_additional_options="$offload_additional_options -B\$(libexecdir)/gcc/\$(target_alias)/\$(gcc_version) -B\$(bindir)"