zgba 站群
Mold Linker Version 3.0.0 Release – Rewritten in Rust

Mold Linker Version 3.0.0 Release – Rewritten in Rust

There was an error while loading. Please reload this page.

There was an error while loading. Please reload this page.

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.

mold is now built with Cargo instead of CMake. It requires Rust 1.95 or later and a C compiler. Run cargo build —release to build mold and ./install-mold.sh to install it; the install script accepts PREFIX and DESTDIR. The CMake options have been removed.

If you install mold’s libraries into a directory other than $PREFIX/lib, such as /usr/lib64, set the MOLD_LIBDIR environment variable to that directory both when building and when installing mold, so that mold -run can find mold-wrapper.so.

mold no longer depends on oneTBB. It statically links mimalloc 3.5.3 as before; build with —features system-allocator to use the system’s malloc instead. mold links the system’s zlib if available and includes zstd and BLAKE3; set ZSTD_SYS_USE_PKG_CONFIG=1 to link the system’s zstd. (56ee0f8)

The MOLD_TARGETS CMake variable has been replaced with Cargo features. As before, distributions should build mold for all targets.

The test suite now runs with cargo test instead of ctest. install-build-deps.sh has been replaced with install-test-deps.sh, which you need only to run the tests.

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-sections no longer removes the functions given by —init and —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=safe no longer folds functions exported from a shared library, and —icf=all no longer crashes with —emit-relocs. (ceab12c, 3dcd1df)

A versioned reference such as foo@VER in a shared library no longer pulls in an archive member that defines an unversioned foo. (#1657) (44bfa2a)

Fixed several cases of nondeterministic output, in —dependency-file, —repro, -r with many COMDAT groups of the same name, and some dynamic relocations. (5164561, 6d33903, 51e23d4, 696ed71)

Fixed several -r bugs: C++ exceptions broke in code from the second and later input files; -x, -X and -s removed symbols that relocations referred to; —gc-sections dropped data that relocations referred to; sh_link of SHF_LINK_ORDER sections such as .ARM.exidx was not set; and mold crashed with —strip-debug and DWARF type units. (0e41bb9, 3717460, b2c3d1d, 9aacb62, a247ca2, e41ed90)

GOT-relative relocations such as R_X86_64_GOTOFF64, and R_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: —defsym aliasing a symbol defined in a shared library, an undefined non-weak hidden symbol in a shared library or with —unresolved-symbols=ignore-all, a —defsym value that doesn’t fit in 64 bits, an allocated section that is also compressed, and —strip-all with —emit-relocs. (56b862b, b3566fa, e3a89f2, a980054, 8233a75)

—noinhibit-exec no 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=main was read as -e ntry=main. (#1671, #1670) (830a860)

—dynamic-list-data, —lto-pseudo-probe-for-profiling and —thinlto-index-only no longer consume the next argument, and —no-color-diagnostics is 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, —chroot and —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_JOBS now works if XDG_RUNTIME_DIR is an empty string. (8a360ff)

Files created by —separate-debug-file no longer contain a .gnu_debuglink section. (#1656) (b56649e)

mold no longer creates the meaningless __start_EHDR, __stop_EHDR, __start_PHDR and __stop_PHDR symbols. (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_TSTBR14 and R_AARCH64_GOT_LD_PREL19. (96d0282, a4b64d8)

[ARM32] Added support for more relocation types, such as R_ARM_ALU_PC_G0 and R_ARM_THM_PC12, and fixed -r output for big-endian ARM. (c0f9cd6, 4c9aad3, 4c26f16)

[ARM32][i386] -r no longer corrupts instructions referred to by some branch and TLS relocations. (1b17bdf)

[RISC-V][LoongArch] Fixed calls to functions folded by —icf=all when relaxation shrinks them, and R_RISCV_64 and R_LARCH_64 relocations in 32-bit objects. (52febe9, 5b22233)

[RISC-V] Fixed TLSDESC with object files created by Clang 18, —emit-relocs with TLSDESC relaxation, the EF_RISCV_TSO flag, R_RISCV_ALIGN in -r output, 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_HI12 relocations and spurious overflow errors for TLS relocations. (a36a161, 8133938, 13e6cc0)

[PPC32][m68k] A GOT too large for the 16-bit offsets that -fpic code uses is now reported as an error instead of being silently truncated. (acc8854, 614e2a0)

[PPC64] Fixed IFUNC calls in statically-linked executables and @got references 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 -r output. (d9cf1f0, 92161dd)

[SPARC64] Fixed branch instructions using R_SPARC_WDISP16, and R_SPARC_OLO10 in -r output. (6df3fd2, 269fbb9)

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:

There was an error while loading. Please reload this page.

View original article