Skip to content

panic code is not deterministically lto'ed #52044

Closed
@glandium

Description

@glandium

This is something I noticed when comparing two builds of Firefox on automation. Both builds were done with the same flags, same toolchains, same paths, same everything. Without any sort of caching. And yet, they differed in exactly one way: the contents of std::panicking::default_hook.

See https://taskcluster-artifacts.net/IWpRV77rTgmt-9RKwTzJiA/0/public/diff.html

I tried multiple times, and there seems to be only two variants of the generated code, and that's the only code, in all of what's generated by rust in Firefox build, that differs.

It turns out this is reproducible at a much smaller scale:

$ mkdir -p foo/src; cd foo
$ cat > Cargo.toml <<EOF
[package]
name = "foo"
version = "0.1.0"

[lib]
crate-type = ["staticlib"]

[profile.release]
opt-level = 2
rpath = false
debug-assertions = false
panic = "abort"
codegen-units = 1
lto = true
EOF
$ cat > src/lib.rs <<EOF
#[no_mangle]
pub extern "C" fn foo() {
    panic!("foo");
}
EOF
$ cargo build --release
$ mv target/release/libfoo.a .
$ rm -rf target
$ cargo build --release
$ diff target/release/libfoo.a .
Binary files target/release/libfoo.a and ./libfoo.a differ

It can take a few attempts repeating the last three commands before differences show up, because there are only two variants, and you may end up getting the same variant multiple times in a row.

Cc: @alexcrichton @nikomatsakis

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.A-codegenArea: Code generationT-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

    No branches or pull requests

    Issue actions