{"id":13440282,"url":"https://github.com/rui314/mold","last_synced_at":"2025-05-12T05:18:45.768Z","repository":{"id":37086566,"uuid":"299510783","full_name":"rui314/mold","owner":"rui314","description":"Mold: A Modern Linker 🦠","archived":false,"fork":false,"pushed_at":"2025-05-12T01:56:17.000Z","size":24647,"stargazers_count":15182,"open_issues_count":184,"forks_count":498,"subscribers_count":108,"default_branch":"main","last_synced_at":"2025-05-12T02:43:20.917Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rui314.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":["rui314"],"patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"lfx_crowdfunding":null,"custom":null}},"created_at":"2020-09-29T05:12:48.000Z","updated_at":"2025-05-12T01:53:43.000Z","dependencies_parsed_at":"2024-04-28T09:39:55.141Z","dependency_job_id":"695eb59c-8d8c-4d6b-b026-3ff0d529ee7c","html_url":"https://github.com/rui314/mold","commit_stats":{"total_commits":6775,"total_committers":112,"mean_commits":60.49107142857143,"dds":0.06332103321033211,"last_synced_commit":"3b1e2a9aa33d3734ec711f89e5ab8fe98995cdfc"},"previous_names":[],"tags_count":61,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rui314%2Fmold","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rui314%2Fmold/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rui314%2Fmold/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rui314%2Fmold/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rui314","download_url":"https://codeload.github.com/rui314/mold/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253672696,"owners_count":21945480,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T03:01:21.315Z","updated_at":"2025-05-12T05:18:45.747Z","avatar_url":"https://github.com/rui314.png","language":"C++","funding_links":["https://github.com/sponsors/rui314","https://github.com/sponsors/rui314)!"],"categories":["HarmonyOS","C++","Compilers","Open Source Git Repositories"],"sub_categories":["Windows Manager","Tools"],"readme":"# mold: A Modern Linker\n\nmold is a faster drop-in replacement for existing Unix linkers. It is several\ntimes quicker than the LLVM lld linker, the second-fastest open-source linker,\nwhich I initially developed a few years ago. mold aims to enhance developer\nproductivity by minimizing build time, particularly in rapid\ndebug-edit-rebuild cycles.\n\nHere is a performance comparison of GNU ld, GNU gold, LLVM lld, and\nmold when linking final debuginfo-enabled executables for major large\nprograms on a simulated 16-core, 32-thread machine.\n\n![Link speed comparison](docs/chart.svg)\n\n| Program (linker output size)  | GNU ld | GNU gold | LLVM lld | mold\n|-------------------------------|--------|----------|----------|------\n| MySQL 8.3 (0.47 GiB)          | 10.84s | 7.47s    | 1.64s    | 0.46s\n| Clang 19 (1.56 GiB)           | 42.07s | 33.13s   | 5.20s    | 1.35s\n| Chromium 124 (1.35 GiB)       | N/A    | 27.40s   | 6.10s    | 1.52s\n\nmold is so fast that it is only 2x _slower_ than the `cp` command on the same\nmachine. If you find that mold is not faster than other linkers, feel\nfree to [file a bug report](https://github.com/rui314/mold/issues).\n\nmold supports x86-64, i386, ARM64, ARM32, 64-bit/32-bit little/big-endian\nRISC-V, 32-bit PowerPC, 64-bit big-endian PowerPC ELFv1, 64-bit little-endian\nPowerPC ELFv2, s390x, 64-bit/32-bit LoongArch, SPARC64, m68k, and SH-4.\n\n## Why does linking speed matter?\n\nIf you are using a compiled language such as C, C++, or Rust, a build consists\nof two phases. In the first phase, a compiler compiles source files into\nobject files (`.o` files). In the second phase, a linker takes all object\nfiles and combines them into a single executable or shared library file.\n\nThe second phase can be time-consuming if your build output is large. mold can\nspeed up this process, saving you time and preventing distractions while\nwaiting for a lengthy build to finish. The difference is most noticeable\nduring rapid debug-edit-rebuild cycles.\n\n## Installation\n\nBinary packages for the following systems are currently available:\n\n[![Packaging status](https://repology.org/badge/vertical-allrepos/mold.svg)](https://repology.org/project/mold/versions)\n\n## How to Build\n\nmold is written in C++20, so if you build mold yourself, you will need a\nrecent version of a C++ compiler and a C++ standard library. We recommend GCC\n10.2 or Clang 12.0.0 (or later) and libstdc++ 10 or libc++ 7 (or later).\n\n### Install Dependencies\n\nTo install build dependencies, run `./install-build-deps.sh` in this\ndirectory. It will detect your Linux distribution and attempt to install the\nnecessary packages. You may need to run it as root.\n\n### Compile mold\n\n```shell\ngit clone --branch stable https://github.com/rui314/mold.git\ncd mold\n./install-build-deps.sh\ncmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_COMPILER=c++ -B build\ncmake --build build -j$(nproc)\nsudo cmake --build build --target install\n```\n\nYou might need to pass a C++20 compiler command name to `cmake`. In the\nexample above, `c++` is passed. If that doesn't work for you, try a specific\nversion of a compiler, such as `g++-10` or `clang++-12`.\n\nBy default, `mold` is installed to `/usr/local/bin`. You can change the\ninstallation location by passing `-DCMAKE_INSTALL_PREFIX=\u003cdirectory\u003e`.\nFor other cmake options, see the comments in `CMakeLists.txt`.\n\nIf you are not using a recent enough Linux distribution, or if `cmake` does\nnot work for you for any reason, you can use Podman to build mold in a\ncontainer. To do so, run `./dist.sh` in this directory instead of using\n`cmake`. The shell script will pull a container image, build mold and auxiliary\nfiles inside it, and package them into a single tar file named\n`dist/mold-$version-$arch-linux.tar.gz`. You can extract the tar file anywhere\nand use the mold executable in it.\n\n## How to use\n\n\u003cdetails\u003e\u003csummary\u003eA classic way to use mold\u003c/summary\u003e\n\nOn Unix, the linker command (usually `/usr/bin/ld`) is indirectly invoked by\nthe compiler driver (typically `cc`, `gcc`, or `clang`), which is in turn\nindirectly invoked by `make` or other build system commands.\n\nIf you can specify an additional command line option for your compiler driver\nby modifying the build system's config files, add one of the following flags\nto use mold instead of `/usr/bin/ld`:\n\n- For Clang: pass `-fuse-ld=mold`\n\n- For GCC 12.1.0 or later: pass `-fuse-ld=mold`\n\n- For GCC before 12.1.0: the `-fuse-ld` option does not accept `mold` as a\n  valid argument, so you need to use the `-B` option instead. The `-B` option\n  tells GCC where to look for external commands like `ld`.\n\n  If you have installed mold with `make install`, there should be a directory\n  named `/usr/libexec/mold` (or `/usr/local/libexec/mold`, depending on your\n  `$PREFIX`), and the `ld` command should be there. The `ld` is actually a\n  symlink to `mold`. So, all you need is to pass `-B/usr/libexec/mold` (or\n  `-B/usr/local/libexec/mold`) to GCC.\n\nIf you haven't installed `ld.mold` to any `$PATH`, you can still pass\n`-fuse-ld=/absolute/path/to/mold` to clang to use mold. However, GCC does not\naccept an absolute path as an argument for `-fuse-ld`.\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\u003csummary\u003eIf you are using Rust\u003c/summary\u003e\n\nCreate `.cargo/config.toml` in your project directory with the following:\n\n```toml\n[target.'cfg(target_os = \"linux\")']\nlinker = \"clang\"\nrustflags = [\"-C\", \"link-arg=-fuse-ld=/path/to/mold\"]\n```\n\nwhere `/path/to/mold` is an absolute path to the mold executable. In the\nexample above, we use `clang` as a linker driver since it always accepts the\n`-fuse-ld` option. If your GCC is recent enough to recognize the option, you\nmay be able to remove the `linker = \"clang\"` line.\n\n```toml\n[target.'cfg(target_os = \"linux\")']\nrustflags = [\"-C\", \"link-arg=-fuse-ld=mold\"]\n```\n\nIf you want to use mold for all projects, add the above snippet to\n`~/.cargo/config.toml`.\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\u003csummary\u003eIf you are using Nim\u003c/summary\u003e\n\nCreate `config.nims` in your project directory with the following:\n\n```nim\nwhen findExe(\"mold\").len \u003e 0 and defined(linux):\n  switch(\"passL\", \"-fuse-ld=mold\")\n```\n\nwhere `mold` must be included in the `PATH` environment variable. In this\nexample, `gcc` is used as the linker driver. Use the `-fuse-ld` option if your\nGCC is recent enough to recognize this option.\n\nIf you want to use mold for all projects, add the above snippet to\n`~/.config/config.nims`.\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\u003csummary\u003eIf you are using Conan package manager\u003c/summary\u003e\n\nYou can configure [Conan](https://github.com/conan-io) to download the latest\nversion of `mold` and use it as the linker when building your dependencies and\nprojects from source. Please see the instructions [here](https://conan.io/center/recipes/mold).\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\u003csummary\u003emold -run\u003c/summary\u003e\n\nIt is sometimes very hard to pass an appropriate command line option to `cc`\nto specify an alternative linker. To address this situation, mold has a\nfeature to intercept all invocations of `ld`, `ld.bfd`, `ld.lld`, or `ld.gold`\nand redirect them to itself. To use this feature, run `make` (or another build\ncommand) as a subcommand of mold as follows:\n\n```shell\nmold -run make \u003cmake-options-if-any\u003e\n```\n\nInternally, mold invokes a given command with the `LD_PRELOAD` environment\nvariable set to its companion shared object file. The shared object file\nintercepts all function calls to `exec(3)`-family functions to replace\n`argv[0]` with `mold` if it is `ld`, `ld.bf`, `ld.gold`, or `ld.lld`.\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\u003csummary\u003eGitHub Actions\u003c/summary\u003e\n\nYou can use our [setup-mold](https://github.com/rui314/setup-mold) GitHub\nAction to speed up GitHub-hosted continuous builds. Although GitHub Actions\nrun on a 4 core machine, mold is still significantly faster than the default\nGNU linker, especially when linking large programs.\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\u003csummary\u003eVerify that you are using mold\u003c/summary\u003e\n\nmold leaves its identification string in the `.comment` section of an output\nfile. You can print it out to verify that you are actually using mold.\n\n```shell\n$ readelf -p .comment \u003cexecutable-file\u003e\n\nString dump of section '.comment':\n  [     0]  GCC: (Ubuntu 10.2.0-5ubuntu1~20.04) 10.2.0\n  [    2b]  mold 9a1679b47d9b22012ec7dfbda97c8983956716f7\n```\n\nIf `mold` is present in the `.comment` section, the file was created by mold.\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\u003csummary\u003eOnline manual\u003c/summary\u003e\n\nSince mold is a drop-in replacement, you should be able to use it without\nreading its manual. However, if you need it, [mold's man page](docs/mold.md)\nis available online. You can read the same manual by running `man mold`.\n\n\u003c/details\u003e\n\n## Why is mold so fast?\n\nOne reason is that it utilizes faster algorithms and more efficient data\nstructures compared to other linkers. Another reason is that mold is highly\nparallelized.\n\nHere is a side-by-side comparison of per-core CPU usage for lld (left) and\nmold (right), linking the same program, a Chromium executable.\n\n![CPU usage comparison in htop animation](docs/htop.gif)\n\nAs you can see, mold uses all available cores throughout its execution and\nfinishes quickly. In contrast, lld fails to utilize available cores most of\nthe time. In this demo, the maximum parallelism is artificially capped at 16,\nso that the bars fit in the GIF.\n\nFor details, please see the [design notes](docs/design.md).\n\n## Sponsors\n\nIt is taken for granted nowadays that compiler toolchains can be easily\ninstalled and used for free, and people may not think too much about the\nindividuals behind these \"free tools\". mold supports many projects, but it\nis essentially a one-person project. This situation is similar to the one\ndepicted in the following xkcd illustration.\n\n[![xkcd 2347](https://imgs.xkcd.com/comics/dependency.png)](https://xkcd.com/2347)\n\nIf you think that the \"Nebraska guy\" should be rewarded, please consider\nbecoming our [GitHub sponsor](https://github.com/sponsors/rui314)!\n\nWe thank everyone who sponsors our project. In particular, we'd like to acknowledge\nthe following people and organizations who have sponsored $128/month or more:\n\n### Corporate sponsors\n\n\u003ca href=\"https://mercury.com\"\u003e\u003cimg src=\"docs/mercury-logo.png\" align=center height=120 width=400 alt=Mercury\u003e\u003c/a\u003e\n\n\u003ca href=\"https://cybozu-global.com\"\u003e\u003cimg src=\"docs/cyboze-logo.png\" align=center height=120 width=133 alt=Cybozu\u003e\u003c/a\u003e\n\n\u003ca href=\"https://www.emergetools.com\"\u003e\u003cimg src=\"docs/emerge-tools-logo.png\" align=center height=120 width=240 alt=\"Emerge Tools\"\u003e\u003c/a\u003e\u003cbr\u003e\n\n- [G-Research](https://www.gresearch.co.uk)\n- [Signal Slot Inc.](https://github.com/signal-slot)\n- [GlareDB](https://github.com/GlareDB)\n\n### Individual sponsors\n\n- [Wei Wu](https://github.com/lazyparser)\n- [kyle-elliott](https://github.com/kyle-elliott)\n- [Bryant Biggs](https://github.com/bryantbiggs)\n- [kraptor23](https://github.com/kraptor23)\n- [Jinkyu Yi](https://github.com/jincreator)\n- [Pedro Navarro](https://github.com/pedronavf)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frui314%2Fmold","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frui314%2Fmold","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frui314%2Fmold/lists"}