[lld] [lld][ELF] Support LLVM repository and LLVM revision information (PR #97323)
Hongyu Chen via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 1 10:17:03 PDT 2024
https://github.com/yugier created https://github.com/llvm/llvm-project/pull/97323
Added LLVM repository and LLVM revision information for ld.lld --version. The getLLVMRepositoryPath and getLLVMRevision are under lld/common so it should be availble for other drivers to use too. This change is only to ld.lld.
Before this change:
```
hongyuchy at hongyuchy:~/llvm-project/.build_lld_version$ bin/ld.lld --version
LLD 19.0.0 (compatible with GNU linkers)
```
After this change:
```
hongyuchy at hongyuchy:~/llvm-project/.build_lld_version$ bin/ld.lld --version
LLD 19.0.0 (compatible with GNU linkers) https://github.com/yugier/llvm-project.git 4134b33c6a362cb462b335177d6d9e8235f04309
```
>From f50fd37f3d3e5a292f6f0068e31745a797894476 Mon Sep 17 00:00:00 2001
From: Hongyu Chen <hongyuchy at google.com>
Date: Mon, 1 Jul 2024 16:25:31 +0000
Subject: [PATCH] [lld][ELF] Support LLVM repository and LLVM revision
information with --version
Added LLVM repository and LLVM revision information for ld.lld
--version. The getLLVMRepositoryPath and getLLVMRevision are under
lld/common so it should be availble for other drivers to use too. This
change is only to ld.lld.
---
lld/Common/Version.cpp | 18 +++++++++++++++++-
lld/ELF/Driver.cpp | 7 +++++--
lld/include/lld/Common/Version.h | 2 ++
lld/test/ELF/version.test | 2 +-
4 files changed, 25 insertions(+), 4 deletions(-)
diff --git a/lld/Common/Version.cpp b/lld/Common/Version.cpp
index ec6eda6a6748f..da7485a4f28bb 100644
--- a/lld/Common/Version.cpp
+++ b/lld/Common/Version.cpp
@@ -11,8 +11,8 @@
//===----------------------------------------------------------------------===//
#include "lld/Common/Version.h"
-
#include "VCSVersion.inc"
+#include "llvm/Support/VCSRevision.h"
// Returns a version string, e.g.:
// LLD 14.0.0 (https://github.com/llvm/llvm-project.git
@@ -26,3 +26,19 @@ std::string lld::getLLDVersion() {
return LLD_VENDOR_DISPLAY "LLD " LLD_VERSION_STRING;
#undef LLD_VENDOR_DISPLAY
}
+
+std::string lld::getLLVMRepositoryPath() {
+#ifdef LLVM_REPOSITORY
+ return LLVM_REPOSITORY;
+#else
+ return "";
+#endif
+}
+
+std::string lld::getLLVMRevision() {
+#ifdef LLVM_REVISION
+ return LLVM_REVISION;
+#else
+ return "";
+#endif
+}
diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp
index ed773f5e69f77..c8b658c9d2cd2 100644
--- a/lld/ELF/Driver.cpp
+++ b/lld/ELF/Driver.cpp
@@ -164,6 +164,7 @@ bool link(ArrayRef<const char *> args, llvm::raw_ostream &stdoutOS,
return errorCount() == 0;
}
+
} // namespace elf
} // namespace lld
@@ -630,8 +631,10 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
// lot of "configure" scripts out there that are generated by old version
// of Libtool. We cannot convince every software developer to migrate to
// the latest version and re-generate scripts. So we have this hack.
- if (args.hasArg(OPT_v) || args.hasArg(OPT_version))
- message(getLLDVersion() + " (compatible with GNU linkers)");
+ if (args.hasArg(OPT_v) || args.hasArg(OPT_version)) {
+ message(getLLDVersion() + " (compatible with GNU linkers) " +
+ getLLVMRepositoryPath() + " " + getLLVMRevision());
+ }
if (const char *path = getReproduceOption(args)) {
// Note that --reproduce is a debug option so you can ignore it
diff --git a/lld/include/lld/Common/Version.h b/lld/include/lld/Common/Version.h
index 9571aa2743e5b..ec1bd590647f4 100644
--- a/lld/include/lld/Common/Version.h
+++ b/lld/include/lld/Common/Version.h
@@ -19,6 +19,8 @@
namespace lld {
/// Retrieves a string representing the complete lld version.
std::string getLLDVersion();
+std::string getLLVMRepositoryPath();
+std::string getLLVMRevision();
}
#endif // LLD_VERSION_H
diff --git a/lld/test/ELF/version.test b/lld/test/ELF/version.test
index cdeeb4795e185..ae4b145329767 100644
--- a/lld/test/ELF/version.test
+++ b/lld/test/ELF/version.test
@@ -7,4 +7,4 @@
# RUN: ld.lld -V 2>&1 | FileCheck %s
# RUN: not ld.lld -V %t/not-exist 2>&1 | FileCheck %s
-# CHECK: LLD {{.*}} (compatible with GNU linkers)
+# CHECK: LLD {{.*}} (compatible with GNU linkers) {{.*}} {{.*}}
More information about the llvm-commits
mailing list