Mold Linker 3.0.0 发布——使用 Rust 重写
Mold Linker Version 3.0.0 Release – Rewritten in Rust

原始链接: https://github.com/rui314/mold/releases/tag/v3.0.0

```mold 3.0 是 mold 从 C++ 重写为 Rust 后的首个版本。它旨在作为 2.42.1 的直接替代品,除修复内容外,命令行界面、目标支持、性能和输出均保持一致。Rust 实现还会对损坏的输入进行边界检查,以防止越界读取和段错误。 本次发布解决了与 GNU ld 的兼容性差距,尤其是链接器脚本方面的兼容性,并修复了大量崩溃、错误输出、不确定性以及 `-r` 相关问题。它还改进了垃圾回收、符号大小、ICF、版本控制、GOT 相对重定位、命令行选项解析、可复现构建和无效选项组合,将原先可能静默造成数据损坏或崩溃的问题替换为更清晰的错误提示。 其他修复还包括范围扩展跳板、重定位、TLS、IFUNC、压缩输出,以及 AArch64、ARM、RISC-V、LoongArch、PPC、SH4、SPARC 等架构的特定行为。此次版本还新增了对重定位的支持,尤其是针对 AArch64 和 ARM。由于构建系统发生了变化,从源代码构建的用户应查阅本次版本的构建说明。```

相关文章

原文

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.

  • 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:

    联系我们 contact @ memedata.com