https://github.com/rui314/mold Skip to content Toggle navigation Sign up * Product + Actions Automate any workflow + Packages Host and manage packages + Security Find and fix vulnerabilities + Codespaces Instant dev environments + Copilot Write better code with AI + Code review Manage code changes + Issues Plan and track work + Discussions Collaborate outside of code + Explore + All features + Documentation + GitHub Skills + Blog * Solutions + For + Enterprise + Teams + Startups + Education + By Solution + CI/CD & Automation + DevOps + DevSecOps + Case Studies + Customer Stories + Resources * Open Source + GitHub Sponsors Fund open source developers + The ReadME Project GitHub community articles + Repositories + Topics + Trending + Collections * Pricing [ ] * # In this repository All GitHub | Jump to | * No suggested jump to results * # In this repository All GitHub | Jump to | * # In this user All GitHub | Jump to | * # In this repository All GitHub | Jump to | Sign in Sign up {{ message }} rui314 / mold Public * * Notifications * Fork 350 * Star 10k mold: A Modern Linker License View license 10k stars 350 forks Star Notifications * Code * Issues 115 * Pull requests 17 * Discussions * Actions * Projects 0 * Wiki * Security * Insights More * Code * Issues * Pull requests * Discussions * Actions * Projects * Wiki * Security * Insights rui314/mold This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository. main Switch branches/tags [ ] Branches Tags Could not load branches Nothing to show {{ refName }} default View all branches Could not load tags Nothing to show {{ refName }} default View all tags Name already in use A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch? Cancel Create 5 branches 34 tags Code * Local * Codespaces * Clone HTTPS GitHub CLI [https://github.com/r] Use Git or checkout with SVN using the web URL. [gh repo clone rui314] Work fast with our official CLI. Learn more. * Open with GitHub Desktop * Download ZIP Sign In Required Please sign in to use Codespaces. Launching GitHub Desktop If nothing happens, download GitHub Desktop and try again. Launching GitHub Desktop If nothing happens, download GitHub Desktop and try again. Launching Xcode If nothing happens, download Xcode and try again. Launching Visual Studio Code Your codespace will open once ready. There was a problem preparing your codespace, please try again. Latest commit @rui314 rui314 [x86] Always relax TLSGD/TLSLD if -static ... d233570 Jan 14, 2023 [x86] Always relax TLSGD/TLSLD if -static d233570 Git stats * 5,801 commits Files Permalink Failed to load latest commit information. Type Name Latest commit message Commit time .github Support 32-bit PowerPC ABI Dec 31, 2022 docs [x86-64] Implement TLSGD to TLSIE relaxation Jan 14, 2023 elf [x86] Always relax TLSGD/TLSLD if -static Jan 14, 2023 test [x86] Always relax TLSGD/TLSLD if -static Jan 14, 2023 third-party Fix -Wunused-function Dec 10, 2022 .gitignore [Mach-O] Create __objc_{methname,selrefs,stubs} sections Dec 8, 2022 CMakeLists.txt Fix building on MinGW-w64 Jan 10, 2023 CMakeSettings.json Use clang-cl instead of MSVC's cl as a compiler on Windows Aug 13, 2022 CONTRIBUTING.md Clarify and simplify the sign-off guideline Oct 19, 2022 Dockerfile Dockerfile: fix OpenSSL libdir Dec 12, 2022 LICENSE Add libzstd to support --compress-debug-sections=zstd Sep 13, 2022 README.md Bump mold version to 1.9.0 Jan 6, 2023 archive-file.h Refactor Jan 7, 2023 cmdline.h Refactor Jan 7, 2023 compress.cc Fix -Wunused-variable warnings Sep 14, 2022 config.h.in Automatically detect if mold is sold Dec 12, 2022 demangle.cc Simplify Aug 12, 2022 dist.sh Revert "Link against libc++ instead of libstdc++ if -DMOLD_MOSTLY_STA... Dec 7, 2022 filepath.cc [ELF] Fix absolute paths handling in linker scripts Oct 26, 2022 filetype.h Refactor Jan 7, 2023 glob.cc Move glob pattern matchers out of elf directory Jun 5, 2022 hyperloglog.cc Refactor Jan 16, 2022 install-build-deps.sh Improve instal-build-deps script Jan 14, 2023 integers.h Rename inttypes.h integers.h Dec 30, 2022 main.cc Remove mold/macOS Dec 12, 2022 mold.h Avoid sequentially consistent memory access Jan 11, 2023 multi-glob.cc [ELF] Fix precedence with C++ version script rules. Nov 9, 2022 output-file-unix.h Refactor Jan 7, 2023 output-file-win32.h Refactor Jan 7, 2023 output-file.h Fix more compile errors for Windows Aug 13, 2022 perf.cc Simplify Aug 12, 2022 sha.h Simplify Oct 18, 2022 tar.cc Fix -Wdeprecated-declarations Nov 7, 2022 update-git-hash.cmake Simplify Nov 10, 2022 uuid.cc [Mach-O] Compute LC_UUID as a tree hash of ad-hoc code signatures May 27, 2022 View code [ ] mold: A Modern Linker Why does the speed of linking matter? Install How to build Install dependencies Compile mold How to use Why is mold so fast? License Sponsors Corporate sponsors Individual sponsors README.md mold: A Modern Linker CI build result This is a repo of a free, AGPL-licensed version of the linker. If you are looking for a commercial, non-AGPL version of the same linker, please visit the repo of the sold linker. mold is a faster drop-in replacement for existing Unix linkers. It is several times faster than the LLVM lld linker, the second-fastest open-source linker which I originally created a few years ago. mold is designed to increase developer productivity by reducing build time, especially in rapid debug-edit-rebuild cycles. Here is a performance comparison of GNU gold, LLVM lld, and mold for linking final debuginfo-enabled executables of major large programs on a simulated 8-core 16-threads machine. Link speed comparison Program (linker output size) GNU gold LLVM lld mold Chrome 96 (1.89 GiB) 53.86s 11.74s 2.21s Clang 13 (3.18 GiB) 64.12s 5.82s 2.90s Firefox 89 libxul (1.64 GiB) 32.95s 6.80s 1.42s mold is so fast that it is only 2x slower than cp on the same machine. Feel free to file a bug if you find mold is not faster than other linkers. mold supports x86-64, i386, ARM64, ARM32, 64-bit/32-bit little/ big-endian RISC-V, 32-bit PowerPC, 64-bit big-endian PowerPC ELFv1, 64-bit little-endian PowerPC ELFv2, s390x, SPARC64, m68k, SH-4 and DEC Alpha. mold/macOS is commercial software. For mold/macOS, please visit https://github.com/bluewhalesystems/sold. Why does the speed of linking matter? If you are using a compiled language such as C, C++ or Rust, a build consists of two phases. In the first phase, a compiler compiles source files into object files (.o files). In the second phase, a linker takes all object files to combine them into a single executable or a shared library file. The second phase takes a long time if your build output is large. mold can make it faster, saving your time and keeping you from being distracted while waiting for a long build to finish. The difference is most noticeable when you are in rapid debug-edit-rebuild cycles. Install Binary packages for the following systems are currently available. Packaging status How to build mold is written in C++20, so if you build mold yourself, you need a recent version of a C++ compiler and a C++ standard library. GCC 10.2 or Clang 12.0.0 (or later) as well as libstdc++ 10 or libc++ 7 (or later) are recommended. Install dependencies To install build dependencies, run ./install-build-deps.sh in this directory. It recognizes your Linux distribution and tries to install necessary packages. You may want to run it as root. Compile mold git clone https://github.com/rui314/mold.git mkdir mold/build cd mold/build git checkout v1.9.0 ../install-build-deps.sh cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_COMPILER=c++ .. cmake --build . -j $(nproc) sudo cmake --install . You may need to pass a C++20 compiler command name to cmake. In the above case, c++ is passed. If it doesn't work for you, try a specific version of a compiler such as g++-10 or clang++-12. By default, mold is installed to /usr/local/bin. You can change that by passing -DCMAKE_INSTALL_PREFIX=. For other cmake options, see the comments in CMakeLists.txt. If you don't use a recent enough Linux distribution, or if for any reason cmake in the above commands doesn't work for you, you can use Docker to build it in a Docker environment. To do so, just run ./ dist.sh in this directory instead of cmake. The shell script pulls a Docker image, builds mold and auxiliary files inside it, and packs them into a single tar file mold-$version-$arch-linux.tar.gz. You can extract the tar file anywhere and use mold executable in it. How to use A classic way to use mold On Unix, the linker command (which is usually /usr/bin/ld) is invoked indirectly by the compiler driver (which is usually cc, gcc or clang), which is typically in turn indirectly invoked by make or some other build system command. If you can specify an additional command line option to your compiler driver by modifying build system's config files, add one of the following flags to use mold instead of /usr/bin/ld: * Clang: pass -fuse-ld=mold * GCC 12.1.0 or later: pass -fuse-ld=mold * GCC before 12.1.0: -fuse-ld does not accept mold as a valid argument, so you need to use -B option instead. -B is an option to tell GCC where to look for external commands such as ld. If you have installed mold with make install, there should be a directory named /usr/libexec/mold (or /usr/local/libexec/mold, depending on your $PREFIX), and ld command should be there. The ld is actually a symlink to mold. So, all you need is to pass -B/ usr/libexec/mold (or -B/usr/local/libexec/mold) to GCC. If you haven't installed ld.mold to any $PATH, you can still pass -fuse-ld=/absolute/path/to/mold to clang to use mold. GCC does not take an absolute path as an argument for -fuse-ld though. If you are using Rust Create .cargo/config.toml in your project directory with the following: [target.x86_64-unknown-linux-gnu] linker = "clang" rustflags = ["-C", "link-arg=-fuse-ld=/path/to/mold"] where /path/to/mold is an absolute path to mold exectuable. In the above example, we use clang as a linker driver as it can always take the -fuse-ld option. If your GCC is recent enough to recognize the option, you may be able to remove the linker = "clang" line. [target.x86_64-unknown-linux-gnu] rustflags = ["-C", "link-arg=-fuse-ld=/path/to/mold"] If you want to use mold for all projects, put the above snippet to ~ /.cargo/config.toml. If you are using macOS, you can modify config.toml in a similar manner. Here is an example with mold installed via Homebrew. [target.x86_64-apple-darwin] linker = "clang" rustflags = ["-C", "link-arg=-fuse-ld=mold"] [target.aarch64-apple-darwin] linker = "clang" rustflags = ["-C", "link-arg=-fuse-ld=mold"] If you are using Nim Create config.nims in your project directory with the following: when findExe("mold").len > 0 and defined(linux): switch("passL", "-fuse-ld=mold") where mold must be included in the PATH environment variable. In this example The above example uses gcc as the linker driver. Use the fuse-ld option. If your GCC is recent enough to recognize this option. If you want to use mold for all projects, put the above snippet to ~ /.config/config.nims. If you are using macOS, you can modify config.nims in a similar manner. Here is an example with mold installed via Homebrew. when findExe("ld64.mold").len > 0 and defined(macosx): switch("passL", "-fuse-ld=ld64.mold") mold -run It is sometimes very hard to pass an appropriate command line option to cc to specify an alternative linker. To deal with the situation, mold has a feature to intercept all invocations of ld, ld.lld or ld.gold and redirect it to itself. To use the feature, run make (or another build command) as a subcommand of mold as follows: mold -run make Internally, mold invokes a given command with LD_PRELOAD environment variable set to its companion shared object file. The shared object file intercepts all function calls to exec(3)-family functions to replace argv[0] with mold if it is ld, ld.gold or ld.lld. On macOS mold/macOS is available as an alpha version. It can be used to build not only macOS apps but also iOS apps because their binary formats are the same. The command name of mold/macOS is ld64.mold. If you build mold on macOS, it still produces mold and ld.mold, but these executables are useful only for cross compilation (i.e. building Linux apps on macOS.) If you find any issue with mold/macOS, please file it to our GitHub Issues. GitHub Actions You can use our setup-mold GitHub Action to speed up GitHub-hosted continuous build. GitHub Actions runs on a two-core machine, but mold is still significantly faster than the default GNU linker there especially when a program being linked is large. Verify that you are using mold mold leaves its identification string in .comment section in an output file. You can print it out to verify that you are actually using mold. $ readelf -p .comment String dump of section '.comment': [ 0] GCC: (Ubuntu 10.2.0-5ubuntu1~20.04) 10.2.0 [ 2b] mold 9a1679b47d9b22012ec7dfbda97c8983956716f7 If mold is in .comment, the file is created by mold. Online manual Since mold is a drop-in replacement, you should be able to use it without reading its manual. But just in case you need it, it's available online at here. You can also read the same manual by man mold. Why is mold so fast? One reason is because it simply uses faster algorithms and efficient data structures than other linkers do. The other reason is that the new linker is highly parallelized. Here is a side-by-side comparison of per-core CPU usage of lld (left) and mold (right). They are linking the same program, Chromium executable. CPU usage comparison in htop animation As you can see, mold uses all available cores throughout its execution and finishes quickly. On the other hand, lld failed to use available cores most of the time. In this demo, the maximum parallelism is artificially capped to 16 so that the bars fit in the GIF. For details, please read design notes. License mold is available under AGPL. Note that that does not mean that you have to license your program under AGPL if you use mold to link your program. An output of the mold linker is a derived work of the object files and libraries you pass to the linker but not a derived work of the mold linker itself. Besides that, you can also buy a commercial, non-AGPL license with technical support from our company, Blue Whale Systems PTE LTD. If you are a big company, please consider obtaining it before making hundreds or thousands of developers of your company to depend on mold. mold is mostly a single-person open-source project, and just like other open-source projects, we are not legally obligated to keep maintaining it. A legally-binding commercial license contract addresses the concern. By purchasing a license, you are guaranteed that mold will be maintained for you. Please contact us for a commercial license inquiry. Sponsors We accept donations via GitHub Sponsors and OpenCollective. We thank you to everybody who sponsors our project. In particular, we'd like to acknowledge the following people and organizations who have sponsored $128/month or more: Corporate sponsors Mercury * Uber * Signal Slot Inc. Individual sponsors * 300baud * Johan Andersson * Wei Wu * kyle-elliott About mold: A Modern Linker Resources Readme License View license Stars 10k stars Watchers 108 watching Forks 350 forks Releases 30 mold 1.9.0 Latest Jan 6, 2023 + 29 releases Sponsor this project Sponsor Learn more about GitHub Sponsors Packages 0 No packages published Contributors 82 * @rui314 * @ishitatsuyuki * @marxin * @sicherha * @ksco * @llunak * @ZhongRuoyu * @clemenswasser * @nehaljwani * @dmantipov * @Logarithmus + 71 contributors Languages * C++ 81.7% * Shell 16.3% * CMake 1.6% * Other 0.4% Footer (c) 2023 GitHub, Inc. Footer navigation * Terms * Privacy * Security * Status * Docs * Contact GitHub * Pricing * API * Training * Blog * About You can't perform that action at this time. You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.