Skip to content

Conversation

jstarks
Copy link
Member

@jstarks jstarks commented Oct 3, 2025

No description provided.

@jstarks jstarks requested a review from a team as a code owner October 3, 2025 23:35
@Copilot Copilot AI review requested due to automatic review settings October 3, 2025 23:35
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements a workaround for a linker issue with the linkme crate by modifying the distributed slice to use Option types and ensuring at least one entry exists.

  • Modified the TESTS distributed slice to use Option<fn()> instead of fn() directly
  • Added a dummy None entry to prevent linker bugs when no tests are registered
  • Removed the unsafe_code forbid directive to allow the workaround

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
petri/src/test.rs Modified test registration system to use Optional function pointers and added workaround entry
petri/src/lib.rs Removed unsafe code prohibition to accommodate linkme workaround

#[doc(hidden)]
pub mod test_macro_support {
// UNSAFETY: Needed for linkme.
Copy link

Copilot AI Oct 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The safety comment is too vague. It should explain specifically why unsafe code is needed for linkme and what safety guarantees are being maintained.

Suggested change
// UNSAFETY: Needed for linkme.
// UNSAFETY: The `linkme` crate requires `unsafe` code internally to implement distributed slices,
// which rely on linker-level manipulation to collect static references across compilation units.
// This module does not use `unsafe` code directly, but expects it due to the use of `linkme`.
// The safety of distributed slices is guaranteed by the invariants maintained by the `linkme` crate.

Copilot uses AI. Check for mistakes.

Copy link
Contributor

@mattkur mattkur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fixes the crash, thanks John.


// Always have at least one entry to work around linker bugs.
//
// See <https://github.com/llvm/llvm-project/issues/65855>.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC elsewhere where we have this workaround we have a longer comment talking about nulls as well, we should copy that to each case for full descriptiveness.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or maybe we can centralize the workaround in some way? Would it be possible to do things in a macro in a new support crate or something?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ehh, I think the null thing is hypothetical; we've never actually seen it.

Maybe we could centralize this workaround. I don't really want to right now, though.

@smmalis37
Copy link
Contributor

Ah yep, that makes sense.

@jstarks jstarks merged commit 4d87f05 into microsoft:main Oct 7, 2025
29 checks passed
@jstarks jstarks deleted the linkme_a_better_linker branch October 7, 2025 18:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants