mold 3.0.0 is a new major release of the high-speed linker. As we announced in the 2.42.1 release notes, we have rewritten mold from C++ to Rust, and this is the first release of the Rust version. 2.42.1 is the last release of the C++ version. The goal of mold 3.x is to close the remaining compatibility gaps with GNU ld, particularly in linker script support, and to pave the way for mold to be adopted as the default linker in Linux distributions.
mold 3.0 is meant to be a drop-in replacement for 2.42.1. It accepts the same command-line options, supports the same target architectures, and produces the same output except for the bug fixes listed below. Linking performance remains on par with 2.42.1. We verified compatibility by running the test suite on every supported target, comparing linker output across a broad range of real-world workloads and option combinations, and building all Gentoo packages. We found no regressions.
The move to Rust also makes mold safer with corrupted input files. The C++ version could read memory out of bounds on such input and crash with a segmentation fault. In mold 3.0, those reads are bounds-checked, so mold stops with a panic at the faulty access instead.
If you build mold yourself, note that the build system has changed. See "Build Changes" below.
Build Changes
-
mold is now built with Cargo instead of CMake. It requires Rust 1.95 or later and a C compiler. Run
cargo build --releaseto build mold and./install-mold.shto install it; the install script acceptsPREFIXandDESTDIR. The CMake options have been removed. -
If you install mold's libraries into a directory other than
$PREFIX/lib, such as/usr/lib64, set theMOLD_LIBDIRenvironment variable to that directory both when building and when installing mold, so thatmold -runcan findmold-wrapper.so. -
mold no longer depends on oneTBB. It statically links mimalloc 3.5.3 as before; build with
--features system-allocatorto use the system's malloc instead. mold links the system's zlib if available and includes zstd and BLAKE3; setZSTD_SYS_USE_PKG_CONFIG=1to link the system's zstd. (56ee0f8) -
The
MOLD_TARGETSCMake variable has been replaced with Cargo features. As before, distributions should build mold for all targets. -
The test suite now runs with
cargo testinstead ofctest.install-build-deps.shhas been replaced withinstall-test-deps.sh, which you need only to run the tests.
Bug Fixes and Compatibility Improvements
-
Fixed a crash when creating a statically-linked executable with a version script or
--default-symver. (f10b0c4) -
Fixed a crash or a corrupted output when the output file is also an input file, as in
mold -r -o foo.o foo.o bar.o. (d2b88ab) -
--gc-sectionsno longer removes the functions given by--initand--fini. (c9e4cc4) -
Common symbols of the same name with different sizes now get the largest size and the strictest alignment, as in GNU ld and lld. (d5781d5)
-
--icf=safeno longer folds functions exported from a shared library, and--icf=allno longer crashes with--emit-relocs. (ceab12c, 3dcd1df) -
A versioned reference such as
foo@VERin a shared library no longer pulls in an archive member that defines an unversionedfoo. (#1657) (44bfa2a) -
Fixed several cases of nondeterministic output, in
--dependency-file,--repro,-rwith many COMDAT groups of the same name, and some dynamic relocations. (5164561, 6d33903, 51e23d4, 696ed71) -
Fixed several
-rbugs: C++ exceptions broke in code from the second and later input files;-x,-Xand-sremoved symbols that relocations referred to;--gc-sectionsdropped data that relocations referred to;sh_linkofSHF_LINK_ORDERsections such as.ARM.exidxwas not set; and mold crashed with--strip-debugand DWARF type units. (0e41bb9, 3717460, b2c3d1d, 9aacb62, a247ca2, e41ed90) -
GOT-relative relocations such as
R_X86_64_GOTOFF64, andR_ARM_REL32, against symbols defined in shared libraries silently got wrong addresses. They are now handled correctly or reported as errors. (#1668) (659780e, 7fe68bf) -
Errors for PC-relative relocations that can't be used in position-independent output now explain the cause and how to fix it. (39e6a01, 17b7b85)
-
The following now cause errors instead of a broken output or a crash:
--defsymaliasing a symbol defined in a shared library, an undefined non-weak hidden symbol in a shared library or with--unresolved-symbols=ignore-all, a--defsymvalue that doesn't fit in 64 bits, an allocated section that is also compressed, and--strip-allwith--emit-relocs. (56b862b, b3566fa, e3a89f2, a980054, 8233a75) -
--noinhibit-execno longer crashes on references to symbols in discarded COMDAT groups. (8f17166, 80baa5d) -
Options starting with a single dash are now read as GNU ld reads them. For example,
-entry=mainwas read as-e ntry=main. (#1671, #1670) (830a860) -
--dynamic-list-data,--lto-pseudo-probe-for-profilingand--thinlto-index-onlyno longer consume the next argument, and--no-color-diagnosticsis now accepted. (2ca893e, 04b493e) -
If a version script lists a symbol in more than one version node, the first one now takes precedence, as in GNU ld and lld. (b7048f5)
-
Fixed relative paths with
-C,--chrootand--repro. (e3bc349, 04e7dd8, a368d22) -
mold no longer reserves 8 GiB of virtual address space at startup, so it works under
ulimit -v. (cc69390, b18be91) -
MOLD_JOBSnow works ifXDG_RUNTIME_DIRis an empty string. (8a360ff) -
Files created by
--separate-debug-fileno longer contain a.gnu_debuglinksection. (#1656) (b56649e) -
mold no longer creates the meaningless
__start_EHDR,__stop_EHDR,__start_PHDRand__stop_PHDRsymbols. (0ee71d3) -
[AArch64][PPC32][ARM32] Fixed calls to static functions in other sections through range extension thunks, which jumped to wrong addresses in large programs such as the ARM64 debug build of Chromium. (4165d0e, 9b91621)
-
[AArch64] Added support for more relocation types, such as
R_AARCH64_TSTBR14andR_AARCH64_GOT_LD_PREL19. (96d0282, a4b64d8) -
[ARM32] Added support for more relocation types, such as
R_ARM_ALU_PC_G0andR_ARM_THM_PC12, and fixed-routput for big-endian ARM. (c0f9cd6, 4c9aad3, 4c26f16) -
[ARM32][i386]
-rno longer corrupts instructions referred to by some branch and TLS relocations. (1b17bdf) -
[RISC-V][LoongArch] Fixed calls to functions folded by
--icf=allwhen relaxation shrinks them, andR_RISCV_64andR_LARCH_64relocations in 32-bit objects. (52febe9, 5b22233) -
[RISC-V] Fixed TLSDESC with object files created by Clang 18,
--emit-relocswith TLSDESC relaxation, theEF_RISCV_TSOflag,R_RISCV_ALIGNin-routput, and overflow checks for 32-bit PC-relative relocations. (fdf8422, 7c8b805, 6b60f75, 4ba7792, 85d55f3) -
[LoongArch] Added support for TLSDESC in the extreme code model, and fixed wrong values of
*64_PC_HI12relocations and spurious overflow errors for TLS relocations. (a36a161, 8133938, 13e6cc0) -
[PPC32][m68k] A GOT too large for the 16-bit offsets that
-fpiccode uses is now reported as an error instead of being silently truncated. (acc8854, 614e2a0) -
[PPC64] Fixed IFUNC calls in statically-linked executables and
@gotreferences in hand-written assembly, and mold now synthesizes the_savegpr0_*family of functions for PPC64V1 as well. (d3b2a74, b34a308, efda2fc) -
[SH4] Fixed a crash when calling a function that returns a structure through the PLT, and C++ exceptions in programs linked from
-routput. (d9cf1f0, 92161dd) -
[SPARC64] Fixed branch instructions using
R_SPARC_WDISP16, andR_SPARC_OLO10in-routput. (6df3fd2, 269fbb9)
Acknowledgements
mold is an open-source project, and we accept donations via GitHub Sponsors and OpenCollective. We thank everyone who sponsors our project. In particular, we would like to acknowledge the following organizations and people who have sponsored $32/month or more during this release cycle: