Example #1
0
static enum ld_plugin_status
all_symbols_read_handler (void)
{
  unsigned i;
  unsigned num_lto_args = num_claimed_files + lto_wrapper_num_args + 1;
  char **lto_argv;
  const char **lto_arg_ptr;
  if (num_claimed_files == 0)
    return LDPS_OK;

  if (nop)
    {
      use_original_files ();
      return LDPS_OK;
    }

  lto_argv = (char **) xcalloc (sizeof (char *), num_lto_args);
  lto_arg_ptr = (const char **) lto_argv;
  assert (lto_wrapper_argv);

  write_resolution ();

  free_1 ();

  for (i = 0; i < lto_wrapper_num_args; i++)
    *lto_arg_ptr++ = lto_wrapper_argv[i];

  for (i = 0; i < num_claimed_files; i++)
    {
      struct plugin_file_info *info = &claimed_files[i];

      *lto_arg_ptr++ = info->name;
    }

  *lto_arg_ptr++ = NULL;
  exec_lto_wrapper (lto_argv);

  free (lto_argv);

  /* --pass-through is not needed when using gold 1.11 or later.  */
  if (pass_through_items && gold_version < 111)
    {
      unsigned int i;
      for (i = 0; i < num_pass_through_items; i++)
        {
          if (strncmp (pass_through_items[i], "-l", 2) == 0)
            add_input_library (pass_through_items[i] + 2);
          else
            add_input_file (pass_through_items[i]);
          free (pass_through_items[i]);
          pass_through_items[i] = NULL;
        }
      free (pass_through_items);
      pass_through_items = NULL;
    }

  return LDPS_OK;
}
static enum ld_plugin_status
all_symbols_read_handler (void)
{
  unsigned i;
  unsigned num_lto_args = num_claimed_files + lto_wrapper_num_args + 2
    	   + !linker_output_known;
  char **lto_argv;
  const char *linker_output_str = NULL;
  const char **lto_arg_ptr;
  if (num_claimed_files + num_offload_files == 0)
    return LDPS_OK;

  if (nop)
    {
      use_original_files ();
      return LDPS_OK;
    }

  lto_argv = (char **) xcalloc (sizeof (char *), num_lto_args);
  lto_arg_ptr = (const char **) lto_argv;
  assert (lto_wrapper_argv);

  write_resolution ();

  free_1 (claimed_files, num_claimed_files);

  for (i = 0; i < lto_wrapper_num_args; i++)
    *lto_arg_ptr++ = lto_wrapper_argv[i];

  if (!linker_output_known)
    {
      assert (linker_output_set);
      switch (linker_output)
	{
	case LDPO_REL:
	  if (non_claimed_files)
	    {
	      message (LDPL_WARNING, "incremental linking of LTO and non-LTO "
		       "objects; using -flinker-output=nolto-rel which will "
		       "bypass whole program optimization");
	      linker_output_str = "-flinker-output=nolto-rel";
	    }
	  else
	    linker_output_str = "-flinker-output=rel";
	  break;
	case LDPO_DYN:
	  linker_output_str = "-flinker-output=dyn";
	  break;
	case LDPO_PIE:
	  linker_output_str = "-flinker-output=pie";
	  break;
	case LDPO_EXEC:
	  linker_output_str = "-flinker-output=exec";
	  break;
	default:
	  message (LDPL_FATAL, "unsupported linker output %i", linker_output);
	  break;
	}
      *lto_arg_ptr++ = xstrdup (linker_output_str);
    }

  if (num_offload_files > 0)
    {
      FILE *f;
      char *arg;
      char *offload_objects_file_name;
      struct plugin_offload_file *ofld;

      offload_objects_file_name = make_temp_file (".ofldlist");
      check (offload_objects_file_name, LDPL_FATAL,
	     "Failed to generate a temporary file name");
      f = fopen (offload_objects_file_name, "w");
      check (f, LDPL_FATAL, "could not open file with offload objects");
      fprintf (f, "%u\n", num_offload_files);

      /* Skip the dummy item at the start of the list.  */
      ofld = offload_files->next;
      while (ofld)
	{
	  fprintf (f, "%s\n", ofld->name);
	  ofld = ofld->next;
	}
      fclose (f);

      arg = concat ("-foffload-objects=", offload_objects_file_name, NULL);
      check (arg, LDPL_FATAL, "could not allocate");
      *lto_arg_ptr++ = arg;
    }

  for (i = 0; i < num_claimed_files; i++)
    {
      struct plugin_file_info *info = &claimed_files[i];

      *lto_arg_ptr++ = info->name;
    }

  *lto_arg_ptr++ = NULL;
  exec_lto_wrapper (lto_argv);

  free (lto_argv);

  /* --pass-through is not needed when using gold 1.11 or later.  */
  if (pass_through_items && gold_version < 111)
    {
      unsigned int i;
      for (i = 0; i < num_pass_through_items; i++)
        {
          if (strncmp (pass_through_items[i], "-l", 2) == 0)
            add_input_library (pass_through_items[i] + 2);
          else
            add_input_file (pass_through_items[i]);
          free (pass_through_items[i]);
          pass_through_items[i] = NULL;
        }
      free (pass_through_items);
      pass_through_items = NULL;
    }

  return LDPS_OK;
}