Skip to content

Commit 676f362

Browse files
hongyu-devlravenclaw
authored andcommitted
[lld][ELF] Support LLVM repository and LLVM revision information (llvm#97323)
Added LLVM repository and LLVM revision information for `lld::getLLDVersion()` 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 with LLVM_APPEND_VC_REV=on ``` hongyuchy@hongyuchy:~/llvm-project/.build_lld_version$ bin/ld.lld --version LLD 19.0.0 (https://github.com/yugier/llvm-project.git 4134b33), compatible with GNU linkers ``` with LLVM_APPEND_VC_REV=off ``` hongyuchy@hongyuchy:~/llvm-project/.build_lld_version$ bin/ld.lld --version LLD 19.0.0, compatible with GNU linkers ```
1 parent ad0b650 commit 676f362

File tree

5 files changed

+10
-5
lines changed

5 files changed

+10
-5
lines changed

lld/Common/Version.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
#include "lld/Common/Version.h"
14-
1514
#include "VCSVersion.inc"
15+
#include "llvm/Support/VCSRevision.h"
1616

1717
// Returns a version string, e.g.:
1818
// LLD 14.0.0 (https://github.com/llvm/llvm-project.git
@@ -23,6 +23,11 @@ std::string lld::getLLDVersion() {
2323
#else
2424
#define LLD_VENDOR_DISPLAY
2525
#endif
26+
#if defined(LLVM_REPOSITORY) || defined(LLVM_REVISION)
27+
return LLD_VENDOR_DISPLAY "LLD " LLD_VERSION_STRING " (" LLVM_REPOSITORY
28+
" " LLVM_REVISION ")";
29+
#else
2630
return LLD_VENDOR_DISPLAY "LLD " LLD_VERSION_STRING;
31+
#endif
2732
#undef LLD_VENDOR_DISPLAY
2833
}

lld/ELF/Driver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,7 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
631631
// of Libtool. We cannot convince every software developer to migrate to
632632
// the latest version and re-generate scripts. So we have this hack.
633633
if (args.hasArg(OPT_v) || args.hasArg(OPT_version))
634-
message(getLLDVersion() + " (compatible with GNU linkers)");
634+
message(getLLDVersion() + ", compatible with GNU linkers");
635635

636636
if (const char *path = getReproduceOption(args)) {
637637
// Note that --reproduce is a debug option so you can ignore it

lld/MinGW/Driver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ bool link(ArrayRef<const char *> argsArr, llvm::raw_ostream &stdoutOS,
199199
// a GNU compatible linker. As long as an output for the -v option
200200
// contains "GNU" or "with BFD", they recognize us as GNU-compatible.
201201
if (args.hasArg(OPT_v) || args.hasArg(OPT_version))
202-
message(getLLDVersion() + " (compatible with GNU linkers)");
202+
message(getLLDVersion() + ", compatible with GNU linkers");
203203

204204
// The behavior of -v or --version is a bit strange, but this is
205205
// needed for compatibility with GNU linkers.

lld/test/ELF/version.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77
# RUN: ld.lld -V 2>&1 | FileCheck %s
88
# RUN: not ld.lld -V %t/not-exist 2>&1 | FileCheck %s
99

10-
# CHECK: LLD {{.*}} (compatible with GNU linkers)
10+
# CHECK: LLD {{.*}}, compatible with GNU linkers

lld/test/MinGW/driver.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ APPCONTAINER: -appcontainer
268268
RUN: ld.lld -m i386pep --version 2>&1 | FileCheck -check-prefix=VERSION %s
269269
RUN: ld.lld -m i386pep -v 2>&1 | FileCheck -check-prefix=VERSION %s
270270
RUN: not ld.lld -m i386pep -v xyz 2>&1 | FileCheck -check-prefix=VERSION %s
271-
VERSION: LLD {{.*}} (compatible with GNU linkers)
271+
VERSION: LLD {{.*}}, compatible with GNU linkers
272272

273273
RUN: ld.lld -m i386pep --help 2>&1 | FileCheck -check-prefix=HELP %s
274274
HELP: USAGE:

0 commit comments

Comments
 (0)