Skip to content

Some notes about the panic #1

Open
@edwin0cheng

Description

@edwin0cheng

Hi, I am studying the https://github.com/fedochet/rust-proc-macro-expander which is an awesome project. And see the issue in rust-lang/rust#60593.

After a little bit of digging, my guess is, it is not related to ABI compatible problem. It seem to be related to the different of thread_local storage of static linkage and dynamic linkage.

The actual panic is this line.
And state is actually a thread_local :

https://github.com/rust-lang/rust/blob/dc6db14e1cd60012f25be4fd8d2eb96ea5b4bb68/src/libproc_macro/bridge/client.rs#L269

On the other hand, in your example code :

client.run function will call Bridge::enter and set the state to BridgeState::Connected. Note that this is statically link to main crate.

And after that, when the actual TokenStream start to parse, Bridge::with will be called from shared library crate and it will trigger the panic.

It seem to be two thread local are different, such that the panic get raised. But I don't know enough about linux shared librrary and thread local mechanism to understand this bug.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions