[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 13:35:00 PDT 2024
https://github.com/yugier updated https://github.com/llvm/llvm-project/pull/97323
>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 1/2] [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) {{.*}} {{.*}}
>From 77f9b543114b8a699a0e5ec93524349132a0bf3c Mon Sep 17 00:00:00 2001
From: Hongyu Chen <hongyuchy at google.com>
Date: Mon, 1 Jul 2024 20:31:53 +0000
Subject: [PATCH 2/2] [lld] updated getLLDVersion
getLLDVersion didn't contain LLVM repository and LLVM revision
information which does not match its comment. This commit updates it so
it should return strings like `LLD 19.0.0
(https://github.com/yugier/llvm-project.git
4134b33c6a362cb462b335177d6d9e8235f04309) compatible with GNU linkers`
---
lld/Common/Version.cpp | 20 ++++----------------
lld/ELF/Driver.cpp | 7 ++-----
lld/include/lld/Common/Version.h | 2 --
lld/test/ELF/version.test | 2 +-
4 files changed, 7 insertions(+), 24 deletions(-)
diff --git a/lld/Common/Version.cpp b/lld/Common/Version.cpp
index da7485a4f28bb..06d995d0077db 100644
--- a/lld/Common/Version.cpp
+++ b/lld/Common/Version.cpp
@@ -22,23 +22,11 @@ std::string lld::getLLDVersion() {
#define LLD_VENDOR_DISPLAY LLD_VENDOR " "
#else
#define LLD_VENDOR_DISPLAY
+#endif
+#if defined(LLVM_REPOSITORY) || defined(LLVM_REVISION)
+ return LLD_VENDOR_DISPLAY "LLD " LLD_VERSION_STRING " (" LLVM_REPOSITORY
+ " " LLVM_REVISION ")";
#endif
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 c8b658c9d2cd2..cd61ae52afe70 100644
--- a/lld/ELF/Driver.cpp
+++ b/lld/ELF/Driver.cpp
@@ -164,7 +164,6 @@ bool link(ArrayRef<const char *> args, llvm::raw_ostream &stdoutOS,
return errorCount() == 0;
}
-
} // namespace elf
} // namespace lld
@@ -631,10 +630,8 @@ 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) " +
- getLLVMRepositoryPath() + " " + getLLVMRevision());
- }
+ if (args.hasArg(OPT_v) || args.hasArg(OPT_version))
+ message(getLLDVersion() + " compatible with GNU linkers");
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 ec1bd590647f4..9571aa2743e5b 100644
--- a/lld/include/lld/Common/Version.h
+++ b/lld/include/lld/Common/Version.h
@@ -19,8 +19,6 @@
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 ae4b145329767..bf7c5ecf7d40c 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