[lld] [LLD][COFF] Add -build-id flag to generate .buildid section. (PR #71433)

Martin Storsjö via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 29 04:47:08 PST 2023


================
@@ -302,6 +302,17 @@ bool link(ArrayRef<const char *> argsArr, llvm::raw_ostream &stdoutOS,
   } else if (!args.hasArg(OPT_strip_all)) {
     add("-debug:dwarf");
   }
+  if (auto *a = args.getLastArg(OPT_build_id)) {
+    StringRef v = a->getValue();
+    if (v == "none")
+      add("-build-id:no");
+    else {
+      if (!v.empty())
+        warn("unsupported build id hashing: " + v + ", using default hashing.");
+      add("-build-id");
+    }
+  } else
+    add("-build-id");
----------------
mstorsjo wrote:

Sorry for bringing up more changes to this bit here, but I realized that this change breaks one existing usage pattern slightly. In https://github.com/mstorsjo/llvm-mingw/issues/352 I helped a user to the conclusion that if linking with `-s` or `-S`, lld no longer produces a build id automatically.

So for this else case here, when there's no `--build-id` argument present, we should probably do this:
```
} else { // no OPT_build_id present
  if (args.hasArg(OPT_strip_debug) || args.hasArg(OPT_strip_all))
    add("-build-id:no");
  else
    add("-build-id");
}
```
(Plus a corresponding matching testcase update.)
That would preserve that aspect of the existing behaviour.

Sorry for the extra work on this bit, I guess this is what we get from changing the behaviour of the lld-link interface. :-) 

https://github.com/llvm/llvm-project/pull/71433


More information about the llvm-commits mailing list