Skip to content

Commit

Permalink
Remove "commercial/free edition" from the version message
Browse files Browse the repository at this point in the history
Commercial version will get a different brand name ("sold") and
maintained in a separate repository than this repo.
  • Loading branch information
rui314 committed Nov 18, 2022
1 parent 428218c commit df00fe8
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 45 deletions.
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@

cmake_minimum_required(VERSION 3.13)
project(mold VERSION 1.7.0)
set(MOLD_PRODUCT_NAME "mold")

include(CMakeDependentOption)
include(GNUInstallDirs)
Expand Down Expand Up @@ -397,6 +398,7 @@ if(NOT CMAKE_SKIP_INSTALL_RULES)
file(MAKE_DIRECTORY \$ENV{DESTDIR}\${NEW_DIR})
file(CREATE_LINK \${OLD_REL} \$ENV{DESTDIR}\${NEW_ABS} SYMBOLIC)")
endfunction()

mold_install_relative_symlink(${CMAKE_INSTALL_BINDIR}/mold
${CMAKE_INSTALL_LIBEXECDIR}/mold/ld)
mold_install_relative_symlink(${CMAKE_INSTALL_BINDIR}/mold
Expand All @@ -405,4 +407,9 @@ if(NOT CMAKE_SKIP_INSTALL_RULES)
${CMAKE_INSTALL_BINDIR}/ld64.mold)
mold_install_relative_symlink(${CMAKE_INSTALL_MANDIR}/man1/mold.1
${CMAKE_INSTALL_MANDIR}/man1/ld.mold.1)

if(NOT MOLD_PRODUCT_NAME STREQUAL "mold")
mold_install_relative_symlink(${CMAKE_INSTALL_BINDIR}/mold
${CMAKE_INSTALL_BINDIR}/ld.${MOLD_PRODUCT_NAME})
endif()
endif()
2 changes: 1 addition & 1 deletion config.h.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#define MOLD_VERSION "@mold_VERSION@"
#define MOLD_LIBDIR "@CMAKE_INSTALL_FULL_LIBDIR@"
#cmakedefine01 MOLD_HAS_COMMERCIAL_LICENSE
#define MOLD_PRODUCT_NAME "@MOLD_PRODUCT_NAME@"
22 changes: 8 additions & 14 deletions main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,11 @@ namespace macho {
int main(int argc, char **argv);
}

static bool has_commercial_license() {
if (MOLD_HAS_COMMERCIAL_LICENSE)
return true;
char *env = getenv("MOLD_HAS_COMMERCIAL_LICENSE");
return env && env[0];
}

static std::string get_mold_version() {
std::string ver = "mold " MOLD_VERSION;
ver += has_commercial_license() ? " commercial edition" : " free edition";

if (mold_git_hash.empty())
return ver + " (compatible with GNU ld)";
return ver + " (" + mold_git_hash + "; compatible with GNU ld)";
return MOLD_PRODUCT_NAME " " MOLD_VERSION " (compatible with GNU ld)";
return MOLD_PRODUCT_NAME " " MOLD_VERSION " (" + mold_git_hash +
"; compatible with GNU ld)";
}

void cleanup() {
Expand Down Expand Up @@ -101,7 +92,8 @@ static LONG WINAPI vectored_handler(_EXCEPTION_POINTERS *exception_info) {
(ULONG_PTR)output_buffer_start <= exception_information[1] &&
exception_information[1] < (ULONG_PTR)output_buffer_end) {

const char msg[] = "mold: failed to write to an output file. Disk full?\n";
const char msg[] =
MOLD_PRODUCT_NAME ": failed to write to an output file. Disk full?\n";
(void)!write(_fileno(stderr), msg, sizeof(msg) - 1);
}

Expand All @@ -122,7 +114,8 @@ static void sighandler(int signo, siginfo_t *info, void *ucontext) {
if ((signo == SIGSEGV || signo == SIGBUS) &&
output_buffer_start <= info->si_addr &&
info->si_addr < output_buffer_end) {
const char msg[] = "mold: failed to write to an output file. Disk full?\n";
const char msg[] =
MOLD_PRODUCT_NAME ": failed to write to an output file. Disk full?\n";
(void)!write(STDERR_FILENO, msg, sizeof(msg) - 1);
}

Expand Down Expand Up @@ -154,6 +147,7 @@ i64 get_default_thread_count() {

int main(int argc, char **argv) {
mold::mold_version = mold::get_mold_version();
mold::mold_product_name = MOLD_PRODUCT_NAME;

std::string cmd = mold::filepath(argv[0]).filename().string();
if (cmd == "ld64" || cmd == "ld64.mold")
Expand Down
5 changes: 3 additions & 2 deletions mold.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ inline u8 *output_buffer_start = nullptr;
inline u8 *output_buffer_end = nullptr;

inline std::string mold_version;
inline std::string mold_product_name;
extern std::string mold_version_string;
extern std::string mold_git_hash;

Expand Down Expand Up @@ -109,8 +110,8 @@ class SyncOut {
template <typename C>
static std::string add_color(C &ctx, std::string msg) {
if (ctx.arg.color_diagnostics)
return "mold: \033[0;1;31m" + msg + ":\033[0m ";
return "mold: " + msg + ": ";
return mold_product_name + ": \033[0;1;31m" + msg + ":\033[0m ";
return mold_product_name + ": " + msg + ": ";
}

template <typename C>
Expand Down
2 changes: 1 addition & 1 deletion test/elf/comment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ int main() {}
EOF

$CC -B. -o $t/exe $t/a.o
readelf -p .comment $t/exe | grep -q 'mold'
readelf -p .comment $t/exe | grep -q '[ms]old'
readelf -SW $t/exe | grep -Eq '\.comment.*\bMS\b'
8 changes: 4 additions & 4 deletions test/elf/repro.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ $CC -B. -o $t/exe $t/a.o
$CC -B. -o $t/exe $t/a.o -Wl,-repro

tar -C $t -xf $t/exe.repro.tar
grep -Fq /a.o $t/exe.repro/response.txt
grep -Fq mold $t/exe.repro/version.txt
grep -q /a.o $t/exe.repro/response.txt
grep -q '[ms]old' $t/exe.repro/version.txt

rm -rf $t/exe.repro $t/exe.repro.tar

MOLD_REPRO=1 $CC -B. -o $t/exe $t/a.o
tar -C $t -xf $t/exe.repro.tar
grep -Fq /a.o $t/exe.repro/response.txt
grep -Fq mold $t/exe.repro/version.txt
grep -q /a.o $t/exe.repro/response.txt
grep -q '[ms]old' $t/exe.repro/version.txt
2 changes: 1 addition & 1 deletion test/elf/run-clang.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ EOF
LD_PRELOAD=`pwd`/mold-wrapper.so MOLD_PATH=`pwd`/mold \
clang -no-pie -o $t/exe $t/a.o -fuse-ld=/usr/bin/ld
readelf -p .comment $t/exe > $t/log
grep -q mold $t/log
grep -q '[ms]old' $t/log
28 changes: 14 additions & 14 deletions test/elf/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,23 @@ EOF
LD_PRELOAD=`pwd`/mold-wrapper.so MOLD_PATH=`pwd`/mold \
$GCC -o $t/exe $t/a.o -B/usr/bin
readelf -p .comment $t/exe > $t/log
grep -q mold $t/log
grep -q '[ms]old' $t/log

./mold -run env | grep -q '^MOLD_PATH=.*/mold$'

./mold -run /usr/bin/ld --version | grep -q mold
./mold -run /usr/bin/ld.lld --version | grep -q mold
./mold -run /usr/bin/ld.gold --version | grep -q mold
./mold -run /usr/bin/ld --version | grep -q '[ms]old'
./mold -run /usr/bin/ld.lld --version | grep -q '[ms]old'
./mold -run /usr/bin/ld.gold --version | grep -q '[ms]old'

rm -f $t/ld $t/ld.lld $t/ld.gold $t/foo.ld
touch $t/ld $t/ld.lld $t/ld.gold
echo "#!/bin/sh" >$t/foo.ld
chmod 755 $t/ld $t/ld.lld $t/ld.gold $t/foo.ld

./mold -run $t/ld --version | grep -q mold
./mold -run $t/ld.lld --version | grep -q mold
./mold -run $t/ld.gold --version | grep -q mold
./mold -run $t/foo.ld --version | grep -q mold && false
./mold -run $t/ld --version | grep -q '[ms]old'
./mold -run $t/ld.lld --version | grep -q '[ms]old'
./mold -run $t/ld.gold --version | grep -q '[ms]old'
./mold -run $t/foo.ld --version | grep -q '[ms]old' && false

cat <<'EOF' > $t/sh
#!/bin/sh
Expand All @@ -43,10 +43,10 @@ EOF

chmod 755 $t/sh

./mold -run $t/sh ld --version | grep -q mold
./mold -run $t/sh foo.ld --version >& /dev/null | grep -q mold && false
./mold -run $t/sh ld --version | grep -q '[ms]old'
./mold -run $t/sh foo.ld --version >& /dev/null | grep -q '[ms]old' && false

./mold -run $t/sh $t/ld --version | grep -q mold
./mold -run $t/sh $t/ld.lld --version | grep -q mold
./mold -run $t/sh $t/ld.gold --version | grep -q mold
./mold -run $t/sh $t/foo.ld --version | grep -q mold && false
./mold -run $t/sh $t/ld --version | grep -q '[ms]old'
./mold -run $t/sh $t/ld.lld --version | grep -q '[ms]old'
./mold -run $t/sh $t/ld.gold --version | grep -q '[ms]old'
./mold -run $t/sh $t/foo.ld --version | grep -q '[ms]old' && false
10 changes: 5 additions & 5 deletions test/elf/version.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/bin/bash
. $(dirname $0)/common.inc

./mold -v | grep -q 'mold .*compatible with GNU ld'
./mold --version | grep -q 'mold .*compatible with GNU ld'
./mold -v | grep -q '[ms]old .*compatible with GNU ld'
./mold --version | grep -q '[ms]old .*compatible with GNU ld'

./mold -V | grep -q 'mold .*compatible with GNU ld'
./mold -V | grep -q '[ms]old .*compatible with GNU ld'
./mold -V | grep -q elf_x86_64
./mold -V | grep -q elf_i386

Expand All @@ -17,10 +17,10 @@ int main() {
EOF

rm -f $t/exe
$CC -B. -Wl,--version -o $t/exe $t/a.o 2>&1 | grep -q mold
$CC -B. -Wl,--version -o $t/exe $t/a.o 2>&1 | grep -q '[ms]old'
! [ -f $t/exe ] || false

$CC -B. -Wl,-v -o $t/exe $t/a.o 2>&1 | grep -q mold
$CC -B. -Wl,-v -o $t/exe $t/a.o 2>&1 | grep -q '[ms]old'
$QEMU $t/exe | grep -q 'Hello world'

! ./mold --v >& $t/log
Expand Down
2 changes: 1 addition & 1 deletion test/macho/dependency-info.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ EOF

cc --ld-path=./ld64 -o $t/exe $t/a.o -Wl,-dependency_info,$t/dep

grep -q mold $t/dep
grep -q '[ms]old' $t/dep
grep -q "\x10$t/a.o" $t/dep
grep -q "@$t/exe" $t/dep

Expand Down
4 changes: 2 additions & 2 deletions test/macho/version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ echo -n "Testing $testname ... "
t=out/test/macho/$(uname -m)/$testname
mkdir -p $t

./ld64 -v | grep -q mold
./ld64 -v | grep -q '[ms]old'

cat <<EOF | cc -o $t/a.o -c -xc -
#include <stdio.h>
Expand All @@ -16,7 +16,7 @@ int main() {
}
EOF

cc --ld-path=./ld64 -Wl,-v -o $t/exe $t/a.o | grep -q mold
cc --ld-path=./ld64 -Wl,-v -o $t/exe $t/a.o | grep -q '[ms]old'
$t/exe | grep -q 'Hello world'

echo OK

0 comments on commit df00fe8

Please sign in to comment.