[lld] [lld][ELF] Support LLVM repository and LLVM revision information (PR #97323)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 1 10:17:35 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-lld-coff
Author: Hongyu Chen (yugier)
<details>
<summary>Changes</summary>
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@<!-- -->hongyuchy:~/llvm-project/.build_lld_version$ bin/ld.lld --version
LLD 19.0.0 (compatible with GNU linkers)
```
After this change:
```
hongyuchy@<!-- -->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
```
---
Full diff: https://github.com/llvm/llvm-project/pull/97323.diff
4 Files Affected:
- (modified) lld/Common/Version.cpp (+17-1)
- (modified) lld/ELF/Driver.cpp (+5-2)
- (modified) lld/include/lld/Common/Version.h (+2)
- (modified) lld/test/ELF/version.test (+1-1)
``````````diff
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) {{.*}} {{.*}}
``````````
</details>
https://github.com/llvm/llvm-project/pull/97323
More information about the llvm-commits
mailing list