From ebe37ef642cfc5799cb34c33e7c6fc45b36ea2d9 Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Tue, 18 May 2021 21:42:37 +0900 Subject: [PATCH] Include a version number to the --version message --- Makefile | 1 + cmdline.cc | 12 +++++++++--- docs/mold.1 | 10 +++++----- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 0bdcab24..859428d0 100644 --- a/Makefile +++ b/Makefile @@ -5,6 +5,7 @@ MIMALLOC_LIB = mimalloc/out/release/libmimalloc.a CPPFLAGS = -g -Imimalloc/include -pthread -std=c++20 \ -Wno-deprecated-volatile -Wno-switch \ + -DMOLD_VERSION=\"0.1\" \ -DGIT_HASH=\"$(shell git rev-parse HEAD)\" \ $(EXTRA_CPPFLAGS) LDFLAGS = $(EXTRA_LDFLAGS) diff --git a/cmdline.cc b/cmdline.cc index 010b69c9..f708171a 100644 --- a/cmdline.cc +++ b/cmdline.cc @@ -353,6 +353,12 @@ static i64 get_default_thread_count() { return std::min(n, 32); } +template +static void print_version(Context &ctx) { + SyncOut(ctx) << "mold " << MOLD_VERSION << " (" + << GIT_HASH << "; compatible with GNU ld)"; +} + template void parse_nonpositional_args(Context &ctx, std::vector &remaining) { @@ -365,13 +371,13 @@ void parse_nonpositional_args(Context &ctx, std::string_view arg; if (read_flag(args, "v") || read_flag(args, "version")) { - SyncOut(ctx) << "mold " GIT_HASH " (compatible with GNU ld)"; + print_version(ctx); exit(0); } if (read_flag(args, "V")) { - SyncOut(ctx) << "mold " GIT_HASH " (compatible with GNU ld)\n" - << " Supported emulations:\n elf_x86_64\n elf_i386"; + print_version(ctx); + SyncOut(ctx) << " Supported emulations:\n elf_x86_64\n elf_i386"; exit(0); } diff --git a/docs/mold.1 b/docs/mold.1 index d90ea3a3..939ff590 100644 --- a/docs/mold.1 +++ b/docs/mold.1 @@ -52,7 +52,7 @@ functions to run \fBmold\fR if \fB/usr/bin/ld\fR is attempted to be run. .PP If you don't want to use the \fB\-run\fR option, and if you are using -\fBclang\fR, you can pass \fB\-fuse\-ld=/absolute/path/to/mold\fR to +\fBclang\fR, you can pass \fB\-fuse\-ld\fR=\fI/absolute/path/to/mold\fR to \fBclang\fR to used \fBmold\fR. If you are using \fBgcc\fR, it looks like there's unfortunately no easy way (other than \fB\-run\fR) to force it to use \fBmold\fR, as \fBgcc\fR doesn't take an arbitrary @@ -84,17 +84,17 @@ files appear on command line. They process input files from the first input files, they maintain sets of defined and undefined symbols. When visiting an archive file (\fB.a\fR files), they pull out object files to resolve as many undefined symbols as possible and go on to -the next input file. If an object file wasn't pulled out from an -archive file, it will never have a chance for a second look. +the next input file. Object files that weren't pulled out will never +have a chance for a second look. .PP -Due to this semantics, you usually had to add archive files at the end +Due to this semantics, you usually have to add archive files at the end of a command line, so that when a linker reaches archive files, it knows what symbols are remain undefined. If you put archive files at the beginning of a command line, a linker doesn't have any undefined symbol, and thus no object files will be pulled out from archives. .PP You can change the processing order by \fB\-\-start\-group\fR and -\fB\-\-end\-group\fR options, though they degrade the performance. +\fB\-\-end\-group\fR options, though they make a linker slower. .PP \fBmold\fR as well as LLVM \fBlld\fR linker take a different approach. They memorize what symbols can be resolved from archive