Skip to content

Should we have a way to give functions a stable address? #515

Open
@RalfJung

Description

@RalfJung

Nominally we currently do not guarantee anything about a function's address -- the same function can have different addresses when it is turned into a function pointer multiple times, and different functions can have the same address. (The mechanics why that can happen is that we set the unnamed_addr flag in LLVM, so the duplicates of this function that are generated in different CGUs can have visibly different addresses, and LLVM can deduplicate different functions if they have identical assembly code.)

Following that, Miri used to generate a fresh address each time a function item is turned into a function pointer. However, that turned out to be problematic: the std formatting machinery used to depend on one function having a fixed address (but this got fixed recently), and the backtrace machinery uses function pointer comparison to shorten the backtrace and hide frames that are part of the std pre-main life. So we now have a sort of hack in Miri where we do give specific functions a stable address, namely if they are monomorphic and inline(never). But of course this is not actually a semantic guarantee.

So maybe it would make sense to have an attribute we can attach to a function that disables unnamed_addr? Then we should not see any de-duplication any more, I hope. I am not sure about duplication -- is there a way that all the copies of a function that exist for inlining and generics can be given a consistent address, or is that not possible and we have to enforce such "functions with stable address" to be monomorphic and inline(never)?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions