Skip to content

miri no longer builds after rust-lang/rust#66547 #66862

@rust-highfive

Description

@rust-highfive
Contributor

Hello, this is your friendly neighborhood mergebot.
After merging PR #66547, I observed that the tool miri has failing tests.
A follow-up PR to the repository https://github.com/rust-lang/miri is needed to fix the fallout.

cc @leo60228, do you think you would have time to do the follow-up work?
If so, that would be great!

cc @dtolnay, the PR reviewer, and nominating for compiler team prioritization.

Activity

added
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
on Nov 29, 2019
dtolnay

dtolnay commented on Nov 29, 2019

@dtolnay
Member

This test is failing: https://github.com/rust-lang/miri/blob/3bf51f591f7ffdd45f51cd1d42a4002482af2bd5/tests/run-pass/args.rs

normalized stdout:


expected stdout:
args


diff of stdout:

-args
-
dtolnay

dtolnay commented on Nov 29, 2019

@dtolnay
Member

rust-lang/miri#624 might give a hint what needs to be updated. I haven't gotten a chance to look closely yet.

RalfJung

RalfJung commented on Nov 29, 2019

@RalfJung
Member

Yeah, we'll need to emulate that new static thing added by #66547. Unfortunately I don't entirely understand the static magic that goes on there... there's just a fn ptr stored in a particular section and somehow that is enough?!?

eddyb

eddyb commented on Nov 29, 2019

@eddyb
Member

Yes, all platforms have sections that they treat as an array of fn pointers, filling the entire section, which makes it easy to append more entries, as linkers will happily concatenate sections with the same name.
This is how C++ global constructors are implemented everywhere.

So I guess there's two levels to this:

  • miri should collect the platform-specific global ctors/dtors (on Linux I think there's also init/fini which work similarly) and execute them before C main (and after, in the case of dtors)
  • when targer_env is "gnu", the ctors (or just the init flavor?) can also take 1, 2 or 3 arguments, not only 0 arguments (I believe this is also how C main technically works)
RalfJung

RalfJung commented on Nov 29, 2019

@RalfJung
Member

miri should collect the platform-specific global ctors/dtors (on Linux I think there's also init/fini which work similarly) and execute them before C main (and after, in the case of dtors)

Okay. This is basically rust-lang/miri#450. I hoped we'd never have to do this...

For dtors, we already run TLS dtors, but those are entirely separate (we hook the pthread calls where dtors are set, and then run those functions later). There's no way those can be unified to one mechanism, is there?

Also, this begs the question in which order stuff is called before/after main.

eddyb

eddyb commented on Nov 29, 2019

@eddyb
Member

Also, this begs the question in which order stuff is called before/after main.

C++ asks itself the same question and I personally haven't heard of there being an answer.

The safe thing to do is to make sure any order is safe (in Rust you have to initialize global state before any runtime initialization, so it's safer than C++ where before the constructor runs, the fields are uninitialized).

The implementations just go through the sections in order, so the unknown quantity is what order the linker concatenates all of these sections.
In miri you don't have the linker to think about, but you do need a mechanisms to access all statics from all crates.

eddyb

eddyb commented on Nov 29, 2019

@eddyb
Member

Wait, why can't libstd initialize the args from the start lang item as well? Surely there's an inexpensive way to do so?

leo60228

leo60228 commented on Nov 29, 2019

@leo60228
Contributor

@eddyb That's what I did originally, but @joshtriplett said not to.

leo60228

leo60228 commented on Nov 29, 2019

@leo60228
Contributor

Reverting d448ab0 should fix this.

RalfJung

RalfJung commented on Nov 29, 2019

@RalfJung
Member

We could either adjust the cfg's to no use the new method when cfg(miri) is set, or we could implement those initializers. Seems like we'll want them eventually anyway...

you do need a mechanisms to access all statics from all crates.

What would be the best way to do that?

11 remaining items

eddyb

eddyb commented on Nov 29, 2019

@eddyb
Member

@eddyb I would prefer to avoid duplicate initialization of arguments. I'd like to make Rust executables smaller, not larger.

I don't understand, this would only be a few bytes with #[inline(never)]?

We could either adjust the cfg's to no use the new method when cfg(miri) is set,

To unbreak miri it's probably fine but I'm increasingly worried about cfg(miri), as it allows divergence to exist in ways which are not controlled within miri itself.

eddyb

eddyb commented on Nov 29, 2019

@eddyb
Member

The safe thing to do is to make sure any order is safe (in Rust you have to initialize global state before any runtime initialization, so it's safer than C++ where before the constructor runs, the fields are uninitialized).

I don't see any way to actually do that.

@RalfJung I was talking about a user of these facilities, not miri implementation.
To expand a bit (although it's kind of offtopic):
Rust forces you to mutate a static that started out with a constant value (e.g. Mutex::new(None)), which means nothing else would observe an uninitialized value, just the initial constant value, if it happened to ran before the runtime initialization (which would e.g. replace the None with a Some).
This makes Rust + .init_array safer in general than C++ with global constructors.

dtolnay

dtolnay commented on Nov 30, 2019

@dtolnay
Member

Well, actually closing the issue will require also bumping the submodule to include rust-lang/miri#1085.

Ack.

RalfJung

RalfJung commented on Nov 30, 2019

@RalfJung
Member

Aand now we also need to wait for #66896 to land. That's the third independent Miri-breaking PR in 24h, impressive. ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

T-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

    Participants

    @eddyb@joshtriplett@RalfJung@oli-obk@dtolnay

    Issue actions

      `miri` no longer builds after rust-lang/rust#66547 · Issue #66862 · rust-lang/rust