Skip to content

Commit

Permalink
Remove code for the sold linker
Browse files Browse the repository at this point in the history
  • Loading branch information
rui314 committed Feb 25, 2024
1 parent 8a4fb3b commit 8c39678
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 64 deletions.
54 changes: 1 addition & 53 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -212,11 +212,6 @@ else()
mold_add_tbb()
endif()

# Check if this is a commercial version of mold (a.k.a. "sold")
if(EXISTS "${CMAKE_SOURCE_DIR}/LICENSE.md")
set(MOLD_IS_SOLD ON)
endif()

# We always use Clang to build mold on Windows. MSVC can't compile mold.
if(WIN32)
if(MSVC AND NOT CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
Expand Down Expand Up @@ -351,14 +346,6 @@ foreach (SOURCE IN LISTS MOLD_ELF_TEMPLATE_FILES)
endforeach()
endforeach()

if(MOLD_IS_SOLD)
foreach (SOURCE IN LISTS MOLD_MACHO_TEMPLATE_FILES)
foreach(TARGET IN LISTS MOLD_MACHO_TARGETS)
mold_instantiate_templates(${SOURCE} ${TARGET})
endforeach()
endforeach()
endif()

# Add other non-template source files.
target_sources(mold PRIVATE
common/compress.cc
Expand Down Expand Up @@ -388,26 +375,9 @@ target_sources(mold PRIVATE
third-party/rust-demangle/rust-demangle.c
)

if(MOLD_IS_SOLD)
target_sources(mold PRIVATE
macho/arch-arm64.cc
macho/arch-x86-64.cc
macho/yaml.cc
)
endif()

# Add frequently included header files for pre-compiling.
# target_precompile_headers is supported by CMake 3.16.0 or newer.
if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.16.0")
if(MOLD_IS_SOLD)
target_precompile_headers(mold PRIVATE
"$<$<COMPILE_LANGUAGE:CXX>:${CMAKE_SOURCE_DIR}/elf/mold.h>"
"$<$<COMPILE_LANGUAGE:CXX>:${CMAKE_SOURCE_DIR}/macho/mold.h>")
else()
target_precompile_headers(mold PRIVATE
"$<$<COMPILE_LANGUAGE:CXX>:${CMAKE_SOURCE_DIR}/elf/mold.h>")
endif()

# ccache needs this flag along with `sloppiness = pch_defines,time_macros`
# to enable caching
target_compile_options(mold PRIVATE -fpch-preprocess)
Expand All @@ -424,22 +394,9 @@ if(BUILD_TESTING)
BYPRODUCTS ld
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
VERBATIM)

if(MOLD_IS_SOLD)
add_custom_command(
TARGET mold POST_BUILD
COMMAND ${CMAKE_COMMAND} -E create_symlink mold ld64
BYPRODUCTS ld64
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
VERBATIM)
endif()
endif()

if(${APPLE})
if(MOLD_IS_SOLD)
add_subdirectory(test/macho)
endif()
elseif(${UNIX})
if(${UNIX})
add_subdirectory(test/elf)
endif()
endif()
Expand Down Expand Up @@ -473,13 +430,4 @@ if(NOT CMAKE_SKIP_INSTALL_RULES)
${CMAKE_INSTALL_BINDIR}/ld.mold${CMAKE_EXECUTABLE_SUFFIX})
mold_install_relative_symlink(${CMAKE_INSTALL_MANDIR}/man1/mold.1
${CMAKE_INSTALL_MANDIR}/man1/ld.mold.1)

if(MOLD_IS_SOLD)
mold_install_relative_symlink(${CMAKE_INSTALL_BINDIR}/mold
${CMAKE_INSTALL_BINDIR}/ld64.mold)
mold_install_relative_symlink(${CMAKE_INSTALL_BINDIR}/mold
${CMAKE_INSTALL_BINDIR}/ld.sold)
mold_install_relative_symlink(${CMAKE_INSTALL_BINDIR}/mold
${CMAKE_INSTALL_BINDIR}/ld64.sold)
endif()
endif()
1 change: 0 additions & 1 deletion common/config.h.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
#define MOLD_VERSION "@mold_VERSION@"
#define MOLD_LIBDIR "@CMAKE_INSTALL_FULL_LIBDIR@"
#cmakedefine01 MOLD_IS_SOLD
13 changes: 3 additions & 10 deletions common/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ int main(int argc, char **argv);
}

static std::string get_mold_version() {
std::string name = MOLD_IS_SOLD ? "mold (sold) " : "mold ";
if (mold_git_hash.empty())
return name + MOLD_VERSION + " (compatible with GNU ld)";
return name + MOLD_VERSION + " (" + mold_git_hash + "; compatible with GNU ld)";
return "mold "s + MOLD_VERSION + " (compatible with GNU ld)";
return "mold "s + MOLD_VERSION + " (" + mold_git_hash +
"; compatible with GNU ld)";
}

void cleanup() {
Expand Down Expand Up @@ -178,12 +178,5 @@ i64 get_default_thread_count() {

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

#if MOLD_IS_SOLD
std::string cmd = mold::filepath(argv[0]).filename().string();
if (cmd == "ld64" || cmd.starts_with("ld64."))
return mold::macho::main(argc, argv);
#endif

return mold::elf::main(argc, argv);
}

0 comments on commit 8c39678

Please sign in to comment.