Add --ltoindexopt to pass options to LTO indexing step

This makes it much easier to pass options just to the LTO indexing. Previously these had to be passed via --linkopt, but that also passed the options to the final native link, which causes issues since most useful ThinLTO indexing options are plugin options and gold gives an error when these are passed to native links not involving a plugin.

--
MOS_MIGRATED_REVID=140735846
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfiguration.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfiguration.java
index 5a43a71..91ef450 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfiguration.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfiguration.java
@@ -319,6 +319,7 @@
   private final ImmutableList<String> testOnlyLinkFlags;
 
   private final ImmutableList<String> linkOptions;
+  private final ImmutableList<String> ltoindexOptions;
 
   private final ImmutableList<String> objcopyOptions;
   private final ImmutableList<String> ldOptions;
@@ -587,6 +588,10 @@
     }
     this.linkOptions = linkoptsBuilder.build();
 
+    ImmutableList.Builder<String> ltoindexoptsBuilder = ImmutableList.builder();
+    ltoindexoptsBuilder.addAll(cppOptions.ltoindexoptList);
+    this.ltoindexOptions = ltoindexoptsBuilder.build();
+
     ImmutableList.Builder<String> coptsBuilder = ImmutableList.<String>builder()
         .addAll(toolchain.getCompilerFlagList())
         .addAll(cFlags.get(compilationMode))
@@ -1456,6 +1461,11 @@
     return linkOptions;
   }
 
+  /** Returns the set of command-line LTO indexing options. */
+  public ImmutableList<String> getLTOIndexOptions() {
+    return ltoindexOptions;
+  }
+
   /**
    * Returns the immutable list of linker options for fully statically linked
    * outputs. Does not include command-line options passed via --linkopt or
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkActionBuilder.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkActionBuilder.java
index ed09f52..4b32f11 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkActionBuilder.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppLinkActionBuilder.java
@@ -646,6 +646,7 @@
     } else {
       List<String> opts = new ArrayList<>(linkopts);
       opts.addAll(featureConfiguration.getCommandLine("lto-indexing", buildVariables));
+      opts.addAll(cppConfiguration.getLTOIndexOptions());
       linkCommandLineBuilder.setLinkopts(ImmutableList.copyOf(opts));
     }
 
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppOptions.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppOptions.java
index becf653..0a1f16b 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppOptions.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppOptions.java
@@ -316,6 +316,15 @@
   public List<String> linkoptList;
 
   @Option(
+    name = "ltoindexopt",
+    defaultValue = "",
+    category = "flags",
+    allowMultiple = true,
+    help = "Additional option to pass to the LTO indexing step (under --features=thin_lto)."
+  )
+  public List<String> ltoindexoptList;
+
+  @Option(
     name = "stripopt",
     allowMultiple = true,
     defaultValue = "",