Skip to content

Solve the pinned memchr problem #127890

Closed
@ehuss

Description

@ehuss

Ever since #120454, the memchr crate has been pinned at 2.5.0. This is causing problems when trying to update things which depend on a newer version (like regex). This issue is to track trying to get that problem resolved.

The dependency is pinned because the x86_64-pc-windows-gnu target fails some tests with the 2.6.0 release. These tests fail when linking with "undefined reference" symbol errors in memchr (which ends up in the standard library via the object dependency for backtraces).

The errors look like:

...ld.exe: ...-cgu.0.rcgu.o.rcgu.o:std.33d504e26fbb75:(.text+0x66963): undefined reference to `__imp__ZN6memchr4arch6x86_646memchr10memchr_raw2FN17h0aa7d2dff3bebec3E'

The underlying problem isn't with memchr. It's just that version 2.6 is just triggering a bug that has been around for a long while due to some refactoring of the code.

Reproduction

  1. Edit rustc_ast/Cargo.toml and remove the = on memchr.

  2. cargo update -p memchr

  3. ./x test tests/ui --build=x86_64-pc-windows-msvc --host=x86_64-pc-windows-gnu

This currently fails these tests:

    [ui] tests\ui\extern\issue-64655-extern-rust-must-allow-unwind.rs#thin0
    [ui] tests\ui\extern\issue-64655-extern-rust-must-allow-unwind.rs#thin1
    [ui] tests\ui\extern\issue-64655-allow-unwind-when-calling-panic-directly.rs#thin
    [ui] tests\ui\extern\issue-64655-extern-rust-must-allow-unwind.rs#thin2
    [ui] tests\ui\extern\issue-64655-extern-rust-must-allow-unwind.rs#thin3
    [ui] tests\ui\lto\all-crates.rs
    [ui] tests\ui\lto\lto-thin-rustc-loads-linker-plugin.rs
    [ui] tests\ui\lto\thin-lto-inlines2.rs

Theories

This is likely some interaction with Thin LTO and inline.

A theory is that this is a bug in ld.bfd (just based on the evidence that it works with lld). However, it may also be possible that rustc is generating things in an incorrect way, and lld is just more tolerant of it.

Note that memchr is doing some fancy things with function pointers (https://github.com/BurntSushi/memchr/blob/2.7.4/src/arch/x86_64/memchr.rs#L58-L160) with inline(always) functions.

Notes

Possible solutions

  • Demote *-pc-windows-gnu and replace with *-pc-windows-gnullvm. To the best of our understanding, lld does not have this problem.
  • Report this to the binutils maintainers to see if it is possible to fix it in ld.bfd.
  • Is it possible to switch to gold or lld?
  • Disable the tests on *-pc-windows-gnu until someone can fix the problem. This means any user using thin-lto will likely run into the same problem. Perhaps this will motivate one of them to try to fix it? 😉

Non-solutions

  • We could change the inline attribute in memchr for windows-gnu, but nobody wants to do that. It's not memchr's fault, and we don't want to paper over the real problem.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-linkageArea: linking into static, shared libraries and binariesC-bugCategory: This is a bug.O-windows-gnuToolchain: GNU, Operating system: WindowsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions