<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/60423>60423</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [Wasm] Add support for opting out from being tracked with the producers section
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          juj
      </td>
    </tr>
</table>

<pre>
    Currently whenever one uses LLVM to build code to target WebAssembly, there will be a small producers section emitted with the build output that can be used to track the toolchain that the developer used to build the file.

Please add an option to opt out from being tracked in this manner. Something like:

```diff
diff --git a/lld/wasm/Config.h b/lld/wasm/Config.h
index 858a97860dbe..6905e7f46f6c 100644
--- a/lld/wasm/Config.h
+++ b/lld/wasm/Config.h
@@ -33,6 +33,7 @@ struct Configuration {
   bool demangle;
   bool disableVerify;
   bool experimentalPic;
+  bool noProducersSection;
 bool emitRelocs;
   bool exportAll;
   bool exportDynamic;
diff --git a/lld/wasm/Driver.cpp b/lld/wasm/Driver.cpp
index 2f2837ddbdcd..05a82a9a8e5a 100644
--- a/lld/wasm/Driver.cpp
+++ b/lld/wasm/Driver.cpp
@@ -393,6 +393,7 @@ static void readConfigs(opt::InputArgList &args) {
   config->compressRelocations = args.hasArg(OPT_compress_relocations);
   config->demangle = args.hasFlag(OPT_demangle, OPT_no_demangle, true);
 config->disableVerify = args.hasArg(OPT_disable_verify);
+ config->noProducersSection = args.hasArg(OPT_no_producers_section);
 config->emitRelocs = args.hasArg(OPT_emit_relocs);
 config->experimentalPic = args.hasArg(OPT_experimental_pic);
 config->entry = getEntry(args);
diff --git a/lld/wasm/Options.td b/lld/wasm/Options.td
index a47c852148d4..fcebb11cdcaf 100644
--- a/lld/wasm/Options.td
+++ b/lld/wasm/Options.td
@@ -82,6 +82,8 @@ defm merge_data_segments: BB<"merge-data-segments",
     "Enable merging data segments",
     "Disable merging data segments">;
 
+def no_producers_section: F<"no-producers-section">, HelpText<"Do not emit the WebAssembly producers section in generated module">;
+
 def help: F<"help">, HelpText<"Print option help">;
 
 def library: JoinedOrSeparate<["-"], "l">, MetaVarName<"<libName>">,
diff --git a/lld/wasm/Writer.cpp b/lld/wasm/Writer.cpp
index 36005037cd17..f1f0dc17d0e7 100644
--- a/lld/wasm/Writer.cpp
+++ b/lld/wasm/Writer.cpp
@@ -448,7 +448,9 @@ void Writer::addSections() {
 }
 
   addSection(out.nameSec);
- addSection(out.producersSec);
+  if (!config->noProducersSection) {
+ addSection(out.producersSec);
+  }
 addSection(out.targetFeaturesSec);
 }
 
@@ -1528,7 +1530,9 @@ void Writer::createSyntheticSections() {
   out.exportSec = make<ExportSection>();
   out.startSec = make<StartSection>();
 out.elemSec = make<ElemSection>();
-  out.producersSec = make<ProducersSection>();
+  if (!config->noProducersSection) {
+ out.producersSec = make<ProducersSection>();
+  }
 out.targetFeaturesSec = make<TargetFeaturesSection>();
 }
 
@@ -1598,8 +1602,10 @@ void Writer::run() {
 
   log("-- createSyntheticSectionsPostLayout");
 createSyntheticSectionsPostLayout();
-  log("-- populateProducers");
-  populateProducers();
+  if (!config->noProducersSection) {
+    log("-- populateProducers");
+ populateProducers();
+  }
   log("-- calculateImports");
 calculateImports();
   log("-- scanRelocations");
```

Some users find it offensive that code is being emitted to track their toolchain use, others would like to optimize the bytes that are sent over the wire and consider these kinds of "useless" user data sections unacceptable, and finally some would like to just optimize the build process itself to be as fast as possible.

Recently we found in #18623 that ~ -4.8% of build time could be optimized away from the Emscripten toolchain for small builds (e.g. in an unit test suite) if LLVM did not generate this producers section at all.

Alon Zakai noted in https://github.com/emscripten-core/emscripten/issues/18623#issuecomment-1409341841 that the producers section was not even used in practice by a project to fingerprint LLVM producers, but other techniques were employed, suggesting that maybe it was not fit for purpose even.

Would it be possible to add the above type of opt-out at minimum? Or even consider removing the feature altogether and provide all the above benefits to users by default? CC @dschuff @tlively 
</pre>
<img width="1px" height="1px" alt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