aboutsummaryrefslogtreecommitdiff
path: root/lld/MinGW
diff options
context:
space:
mode:
authorZequan Wu <zequanwu@google.com>2023-12-05 14:57:45 -0500
committerGitHub <noreply@github.com>2023-12-05 14:57:45 -0500
commitaaf3a8ded47121c8ec8136f97a7a2c39112b3e59 (patch)
treeaa4441035ee7d64410400ad94bb0593b7782ae48 /lld/MinGW
parentaf03e2928971bbed2901e096b446e1e1a078de43 (diff)
downloadllvm-aaf3a8ded47121c8ec8136f97a7a2c39112b3e59.zip
llvm-aaf3a8ded47121c8ec8136f97a7a2c39112b3e59.tar.gz
llvm-aaf3a8ded47121c8ec8136f97a7a2c39112b3e59.tar.bz2
[LLD][COFF] Add -build-id flag to generate .buildid section. (#71433)
[RFC](https://discourse.llvm.org/t/rfc-add-build-id-flag-to-lld-link/74661) Before, lld-link only generate the debug directory containing guid when generating PDB with the hash of PDB content. With this change, lld-link can generate the debug directory when only `/build-id` is given: 1. If generating PDB, `/build-id` is ignored. Same behaviour as before. 2. Not generating PDB, using hash of the binary. - Not under MinGW, the debug directory is still in `.rdata` section. - Under MinGW, place the debug directory into new `.buildid` section.
Diffstat (limited to 'lld/MinGW')
-rw-r--r--lld/MinGW/Driver.cpp15
-rw-r--r--lld/MinGW/Options.td4
2 files changed, 18 insertions, 1 deletions
diff --git a/lld/MinGW/Driver.cpp b/lld/MinGW/Driver.cpp
index 19bf2d1..d22b617 100644
--- a/lld/MinGW/Driver.cpp
+++ b/lld/MinGW/Driver.cpp
@@ -302,6 +302,21 @@ 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 {
+ if (args.hasArg(OPT_strip_debug) || args.hasArg(OPT_strip_all))
+ add("-build-id:no");
+ else
+ add("-build-id");
+ }
if (args.hasFlag(OPT_fatal_warnings, OPT_no_fatal_warnings, false))
add("-WX");
diff --git a/lld/MinGW/Options.td b/lld/MinGW/Options.td
index fa4c4ec..d4a49cd 100644
--- a/lld/MinGW/Options.td
+++ b/lld/MinGW/Options.td
@@ -196,6 +196,9 @@ defm guard_longjmp : B<"guard-longjmp",
"Do not enable Control Flow Guard long jump hardening">;
defm error_limit:
EqLong<"error-limit", "Maximum number of errors to emit before stopping (0 = no limit)">;
+def build_id: J<"build-id=">, HelpText<"Generate build ID note (pass none to disable)">,
+ MetaVarName<"<arg>">;
+def : F<"build-id">, Alias<build_id>, HelpText<"Alias for --build-id=">;
// Alias
def alias_Bdynamic_call_shared: Flag<["-"], "call_shared">, Alias<Bdynamic>;
@@ -213,7 +216,6 @@ def alias_undefined_u: JoinedOrSeparate<["-"], "u">, Alias<undefined>;
// Ignored options
def: Joined<["-"], "O">;
def: F<"as-needed">;
-def: F<"build-id">;
def: F<"disable-auto-image-base">;
def: F<"enable-auto-image-base">;
def: F<"end-group">;