Mold Linker Version 3.0.0 Release – Rewritten in Rust
Mold Linker Version 3.0.0 Release – Rewritten in Rust
Mold 链接器 3.0.0 版本发布 —— 使用 Rust 重写
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. mold 3.0.0 是这款高速链接器的一个重要新版本。正如我们在 2.42.1 版本说明中所宣布的那样,我们已经将 mold 从 C++ 重写为 Rust,这是 Rust 版本的首次发布。2.42.1 是 C++ 版本的最后一个版本。
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.x 的目标是缩小与 GNU ld 之间剩余的兼容性差距,特别是在链接器脚本支持方面,并为 mold 被 Linux 发行版采纳为默认链接器铺平道路。
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. mold 3.0 旨在作为 2.42.1 的直接替代品。它接受相同的命令行选项,支持相同的目标架构,并且除了下面列出的错误修复外,产生相同的输出。链接性能与 2.42.1 持平。我们通过在每个支持的目标上运行测试套件、比较各种实际工作负载和选项组合下的链接器输出,以及构建所有 Gentoo 软件包来验证了兼容性。我们没有发现任何回归问题。
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. 转向 Rust 也使得 mold 在处理损坏的输入文件时更加安全。C++ 版本在处理此类输入时可能会读取越界内存并导致段错误崩溃。在 mold 3.0 中,这些读取操作经过了边界检查,因此 mold 会在出现错误访问时触发 panic 并停止运行,而不是崩溃。
If you build mold yourself, note that the build system has changed. See “Build Changes” below. 如果您自行构建 mold,请注意构建系统已更改。请参阅下方的“构建变更”。
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 --release to build mold and ./install-mold.sh to install it; the install script accepts PREFIX and DESTDIR. The CMake options have been removed.
mold 现在使用 Cargo 而不是 CMake 进行构建。它需要 Rust 1.95 或更高版本以及 C 编译器。运行 cargo build --release 构建 mold,并运行 ./install-mold.sh 进行安装;安装脚本接受 PREFIX 和 DESTDIR 参数。CMake 选项已被移除。
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 的库安装到 $PREFIX/lib 以外的目录(例如 /usr/lib64),请在构建和安装 mold 时将 MOLD_LIBDIR 环境变量设置为该目录,以便 mold -run 能够找到 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.
mold 不再依赖 oneTBB。它像以前一样静态链接 mimalloc 3.5.3;使用 --features system-allocator 构建以改用系统的 malloc。如果可用,mold 会链接系统的 zlib,并包含 zstd 和 BLAKE3;设置 ZSTD_SYS_USE_PKG_CONFIG=1 以链接系统的 zstd。
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.
MOLD_TARGETS CMake 变量已被 Cargo 特性(features)取代。和以前一样,发行版应为所有目标构建 mold。测试套件现在使用 cargo test 而不是 ctest 运行。install-build-deps.sh 已被 install-test-deps.sh 取代,该脚本仅在运行测试时需要。
Bug Fixes and Compatibility Improvements / 错误修复与兼容性改进
(Note: Due to the extensive list of technical fixes, key highlights include:) (注:由于技术修复列表较长,以下为主要亮点:)
- Fixed crashes when creating statically-linked executables with version scripts or
--default-symver. 修复了使用版本脚本或--default-symver创建静态链接可执行文件时的崩溃问题。 - Fixed crashes or corrupted output when the output file is also an input file. 修复了当输出文件同时作为输入文件时导致的崩溃或输出损坏问题。
--gc-sections不再移除由--init和--fini指定的函数。--gc-sectionsno longer removes the functions given by--initand--fini.- Common symbols of the same name with different sizes now get the largest size and the strictest alignment, matching GNU ld and lld. 同名但大小不同的公共符号现在会采用最大尺寸和最严格的对齐方式,与 GNU ld 和 lld 保持一致。
- Fixed several cases of nondeterministic output and various
-rrelated bugs. 修复了多种非确定性输出的情况以及各种与-r相关的错误。 - GOT-relative relocations against symbols defined in shared libraries are now handled correctly or reported as errors. 针对共享库中定义的符号的 GOT 相对重定位现在可以被正确处理或报告为错误。
- Options starting with a single dash are now read as GNU ld reads them. 以单横杠开头的选项现在按照 GNU ld 的方式读取。
- mold no longer reserves 8 GiB of virtual address space at startup, improving compatibility with
ulimit -v. mold 不再在启动时预留 8 GiB 的虚拟地址空间,提高了与ulimit -v的兼容性。