rust-lang / rust-lang/rust

Tracking Issue for `core::arch::return_address`

Open
#154,966 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

C-tracking-issue S-tracking-impl-incomplete T-libs
Dominant language
Rust
Stars
119k
Forks
16.2k
PR merge metrics
PR metrics pending

Description

Feature gate: #![feature(return_address)]

This is a tracking issue for core::arch::return_address

The core::arch::return_address!() macro returns a pointer with an address that corresponds to the caller of the function that invoked the return_address!() macro, or a null pointer if it cannot be determined, for debugging purposes

Public API
// core::arch

// Conceptual Signature: fn return_address() -> *const ();
pub macro return_address();

The core::arch::return_address!() macro returns a pointer with an address that corresponds to the caller of the function that invoked the return_address!() macro, or a null pointer if it cannot be determined. The pointer has no provenance, as if created by core::ptr::without_provenance. It cannot be used to read memory (other than ZSTs)

The value returned by the macro depends highly on the architecture and compiler (including any options set). In particular, it is allowed to be wrong (particularily if inlining is involved), or even contain a nonsense value. The result of this macro must not be relied upon for soundness or correctness, only for debugging purposes.
Formally, this function returns a pointer with a non-deterministic address and no provenance.

This is equivalent to the gcc __builtin_return_address(0) intrinsic (other forms of the intrinsic are not supported). Because the operation can be always performed by the compiler without crashing or causing undefined behaviour, invoking the macro is a safe operation.

Steps / History

(Remember to update the S-tracking-* label when checking boxes.)

  • ACP: rust-lang/libs-team#768
  • Implementation: #154972
  • Implement for gcc and miri
    • Implementation for miri:
    • Implementation for codegen_gcc:
  • Final comment period (FCP)^1
  • Stabilization PR
Unresolved Questions
  • Should this take the form of a macro or an #[inline(always)] function?
  • How should we handle "weird" architectures where pointers to code aren't the same size as pointers to data.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the core::arch::return_address!() API and the checked implementation in #154972. Investigate the remaining gcc and miri implementations, while reviewing the unresolved macro-versus-function and unusual-architecture questions. Done means both implementations are addressed and the tracking checklist is updated.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.