public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@redhat.com>
To: Ilya Verbin <iverbin@gmail.com>
Cc: Jan Hubicka <hubicka@ucw.cz>, Richard Biener <rguenther@suse.de>,
	       gcc-patches@gcc.gnu.org,
	Bernd Schmidt <bernds@codesourcery.com>,
	       Thomas Schwinge <thomas@codesourcery.com>,
	       Kirill Yukhin <kirill.yukhin@gmail.com>,
	       Andrey Turetskiy <andrey.turetskiy@gmail.com>
Subject: Re: [PATCH 4/n] OpenMP 4.0 offloading infrastructure: lto-wrapper
Date: Wed, 08 Oct 2014 10:27:00 -0000	[thread overview]
Message-ID: <20141008102650.GV1986@tucnak.redhat.com> (raw)
In-Reply-To: <20141002151457.GA59899@msticlxl57.ims.intel.com>

On Thu, Oct 02, 2014 at 07:14:57PM +0400, Ilya Verbin wrote:
> @@ -1296,6 +1297,9 @@ static const char *const standard_startfile_prefix_2
>     relative to the driver.  */
>  static const char *const tooldir_base_prefix = TOOLDIR_BASE_PREFIX;
>  
> +/* A prefix to be used when this is an accelerator compiler.  */
> +static const char *const accel_dir_suffix = ACCEL_DIR_SUFFIX;

Is ACCEL_DIR_SUFFIX here "" or something starting with "/ ?

> @@ -4122,15 +4126,15 @@ process_command (unsigned int decoded_options_count,
>      }
>  
>    gcc_assert (!IS_ABSOLUTE_PATH (tooldir_base_prefix));
> -  tooldir_prefix2 = concat (tooldir_base_prefix, spec_machine,
> +  tooldir_prefix2 = concat (tooldir_base_prefix, spec_host_machine,
>  			    dir_separator_str, NULL);
>  
>    /* Look for tools relative to the location from which the driver is
>       running, or, if that is not available, the configured prefix.  */
>    tooldir_prefix
>      = concat (gcc_exec_prefix ? gcc_exec_prefix : standard_exec_prefix,
> -	      spec_machine, dir_separator_str,
> -	      spec_version, dir_separator_str, tooldir_prefix2, NULL);
> +	      spec_host_machine, dir_separator_str, spec_version,
> +	      accel_dir_suffix, dir_separator_str, tooldir_prefix2, NULL);
>    free (tooldir_prefix2);
>  
>    add_prefix (&exec_prefixes,

The reason I'm asking is that otherwise it seems gcc.c heavily uses
dir_separator_str for the separators.  Don't have any experience with
targets where DIR_SEPARATOR is not / though, perhaps it is a non-issue.

> @@ -6878,8 +6882,8 @@ main (int argc, char **argv)
>  
>    /* Read specs from a file if there is one.  */
>  
> -  machine_suffix = concat (spec_machine, dir_separator_str,
> -			   spec_version, dir_separator_str, NULL);
> +  machine_suffix = concat (spec_host_machine, dir_separator_str, spec_version,
> +			   accel_dir_suffix, dir_separator_str, NULL);
>    just_machine_suffix = concat (spec_machine, dir_separator_str, NULL);
>  
>    specs_file = find_a_file (&startfile_prefixes, "specs", R_OK, true);
> @@ -6889,16 +6893,17 @@ main (int argc, char **argv)
>    else
>      init_spec ();
>  
> +#ifndef ACCEL_COMPILER
>    /* We need to check standard_exec_prefix/just_machine_suffix/specs
>       for any override of as, ld and libraries.  */
>    specs_file = (char *) alloca (strlen (standard_exec_prefix)
>  		       + strlen (just_machine_suffix) + sizeof ("specs"));
> -
>    strcpy (specs_file, standard_exec_prefix);
>    strcat (specs_file, just_machine_suffix);
>    strcat (specs_file, "specs");
>    if (access (specs_file, R_OK) == 0)
>      read_specs (specs_file, true, false);
> +#endif

Why do you want to disable specs reading for the accel compiler?
Then users won't have the possibility to override defaults etc. easily...

> @@ -7097,6 +7103,16 @@ main (int argc, char **argv)
>    obstack_grow (&collect_obstack, argv[0], strlen (argv[0]) + 1);
>    xputenv (XOBFINISH (&collect_obstack, char *));
>  
> +  if (strlen (OFFLOAD_TARGETS) > 0)
> +    {
> +      obstack_init (&collect_obstack);
> +      obstack_grow (&collect_obstack, "OFFLOAD_TARGET_NAMES=",
> +		    sizeof ("OFFLOAD_TARGET_NAMES=") - 1);
> +      obstack_grow (&collect_obstack, OFFLOAD_TARGETS,
> +		    strlen (OFFLOAD_TARGETS) + 1);
> +      xputenv (XOBFINISH (&collect_obstack, char *));
> +    }
> +

I'm surprised to see the obstack_init call here, but looking at
gcc.c, I'm surprised to see it in more places.

I've always thought that obstack_init was something you invoke generally
once on a given obstack object, then work with the obstack and then
obstack_free (..., NULL) it at the end.  Now, if it wants the obstack to be
live until exit, it just would not obstack_free it.  But calling
obstack_init on the already initialized obstack results IMHO in memory
leaks.  It should be initialized just once somewhere.

>    /* Set up to remember the pathname of the lto wrapper. */
>  
>    if (have_c)
> diff --git a/gcc/lto-wrapper.c b/gcc/lto-wrapper.c
> index 08fd090..2c9b503 100644
> --- a/gcc/lto-wrapper.c
> +++ b/gcc/lto-wrapper.c
> @@ -49,6 +49,8 @@ along with GCC; see the file COPYING3.  If not see
>  #include "lto-section-names.h"
>  #include "collect-utils.h"
>  
> +#define OFFLOAD_TARGET_NAMES_ENV	"OFFLOAD_TARGET_NAMES"

Missing comment about the env var and what it is for.

> +/* Prepare a target image for offload TARGET, using mkoffload tool from
> +   COMPILER_PATH.  Return the name of the resultant object file.  */
> +
> +static char *
> +compile_offload_image (const char *target, const char *compiler_path,
> +		       unsigned in_argc, char *in_argv[])
> +{
> +  char *filename = NULL;
> +  char **argv;
> +  char *suffix
> +    = XALLOCAVEC (char, strlen ("/accel//mkoffload") + strlen (target) + 1);

Use sizeof ("/accel//mkoffload") + strlen (target) instead?

> +  strcpy (suffix, "/accel/");
> +  strcat (suffix, target);
> +  strcat (suffix, "/mkoffload");
> +
> +  char **paths = NULL;
> +  unsigned n_paths = parse_env_var (compiler_path, &paths, suffix);
> +
> +  const char *compiler = NULL;
> +  for (unsigned i = 0; i < n_paths; i++)
> +    if (access_check (paths[i], X_OK) == 0)
> +      {
> +	compiler = paths[i];
> +	break;
> +      }
> +
> +  if (!compiler)
> +    goto out;
> +
> +  /* Generate temporary output file name.  */
> +  filename = make_temp_file (".target.o");
> +
> +  struct obstack argv_obstack;
> +  obstack_init (&argv_obstack);
> +  obstack_ptr_grow (&argv_obstack, compiler);
> +  obstack_ptr_grow (&argv_obstack, "-o");
> +  obstack_ptr_grow (&argv_obstack, filename);
> +
> +  for (unsigned i = 1; i < in_argc; i++)
> +    obstack_ptr_grow (&argv_obstack, in_argv[i]);
> +  obstack_ptr_grow (&argv_obstack, NULL);
> +
> +  argv = XOBFINISH (&argv_obstack, char **);
> +  fork_execute (argv[0], argv, true);
> +  obstack_free (&argv_obstack, NULL);
> +
> + out:

The goto is probably unnecessary here, indenting all the lines by
4 more spaces and using if (compiler) { ... } instead doesn't need
any further warpping.

> +  free_array_of_ptrs ((void **) paths, n_paths);
> +  return filename;
> +}
> +

> +      /* By default linker does not discard .gnu.offload_lto_* sections.  */
> +      const char *linker_script = make_temp_file ("_linker_script.x");
> +      FILE *stream = fopen (linker_script, "w");
> +      if (!stream)
> +	fatal_error ("fopen %s: %m", linker_script);
> +      fprintf (stream, "SECTIONS { /DISCARD/ : { *("
> +		       OFFLOAD_SECTION_NAME_PREFIX "*) } }\n");
> +      fclose (stream);
> +      printf ("%s\n", linker_script);
> +
> +      goto finish;
> +    }

Does this work with gold?  Are there any other linkers that support plugins,
but don't support linker scripts this way?


	Jakub

  reply	other threads:[~2014-10-08 10:27 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-02 15:15 Ilya Verbin
2014-10-08 10:27 ` Jakub Jelinek [this message]
2014-10-09 12:09   ` Ilya Verbin
2014-10-09 12:13     ` Bernd Schmidt
2014-10-09 20:27     ` Ilya Verbin
2014-10-10  7:13       ` Jakub Jelinek
2014-10-10 16:52         ` Cary Coutant
2014-10-10 17:01           ` Jakub Jelinek
2014-10-10 17:10             ` Cary Coutant
2014-10-13 22:47             ` Ilya Verbin
2014-10-14  9:41               ` Jakub Jelinek
2014-10-15 14:27                 ` Ilya Verbin
2014-10-15 14:46                   ` Jakub Jelinek
2014-10-16 11:18                     ` Ilya Verbin
2014-10-16 11:27                       ` Jakub Jelinek
2014-10-29 10:28                         ` Kirill Yukhin
2014-11-06 13:00                         ` Ilya Verbin
2014-11-12  9:47                           ` Richard Biener
2014-10-15 17:03                 ` Cary Coutant
2015-05-12 16:32 ` Thomas Schwinge
2015-05-12 17:19   ` Bernd Schmidt
2015-10-02 21:28     ` Help the offload gcc driver find the right assembler (was: [PATCH 4/n] OpenMP 4.0 offloading infrastructure: lto-wrapper) Thomas Schwinge
2016-02-19 19:42 ` [PATCH 4/n] OpenMP 4.0 offloading infrastructure: lto-wrapper Thomas Schwinge
2016-02-19 19:51   ` Ilya Verbin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20141008102650.GV1986@tucnak.redhat.com \
    --to=jakub@redhat.com \
    --cc=andrey.turetskiy@gmail.com \
    --cc=bernds@codesourcery.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=hubicka@ucw.cz \
    --cc=iverbin@gmail.com \
    --cc=kirill.yukhin@gmail.com \
    --cc=rguenther@suse.de \
    --cc=thomas@codesourcery.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).