Skip to content

staticlib + sancov + full LTO fails with 1.56 #90300

@glandium

Description

@glandium
Contributor

Code

For a reduced-ish testcase, create a lib with the following Cargo.toml:

[package]
name = "testcase"
version = "0.1.0"

[lib]
crate-type = ["staticlib"]
path = "lib.rs"

[dependencies]
wast = { version = "38.0.1" }

profile.release]
lto = true

and lib.rs:

extern crate wast;

The following command fails:

$ RUSTFLAGS="-Cpasses=sancov -Cllvm-args=-sanitizer-coverage-level=4 -Cembed-bitcode=yes" cargo build  --release
   Compiling leb128 v0.2.5
   Compiling wast v38.0.1
   Compiling testcase v0.1.0 (/tmp/testcase)
warning: Linking COMDATs named '_ZN4core3ptr66drop_in_place$LT$alloc..vec..Vec$LT$wast..ast..func..Local$GT$$GT$17h37651afa29ff204cE': nodeduplicate has been violated!

error: failed to load bc of "wast-c09551a471674a65.wast.553280a2-cgu.1.rcgu.o": 

This worked fine up to 1.55. This fails with 1.56. Values of -sanitizer-coverage-level between 1 and 4 fail.

It also fails with nightly (but -Cpasses=sancov needs to be replaced with -Cpasses=sancov-module), and the error message is slightly different:

warning: Linking COMDATs named '_ZN4core3ptr79drop_in_place$LT$core..option..Option$LT$wast..ast..types..FunctionType$GT$$GT$17he370b2da7c4642faE': GlobalVariable required for data dependent selection!

error: failed to load bc of "wast-262865a11263ff3e.wast.a15963cd-cgu.1.rcgu.o": 

Disabling LTO or using thin LTO makes it work.

Activity

added
C-bugCategory: This is a bug.
regression-untriagedUntriaged performance or correctness regression.
on Oct 26, 2021
added
I-prioritizeIssue: Indicates that prioritization has been requested for this issue.
on Oct 26, 2021
added
regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.
A-LTOArea: Link-time optimization (LTO)
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
E-needs-mcveCall for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example
and removed
regression-untriagedUntriaged performance or correctness regression.
on Oct 27, 2021
hellow554

hellow554 commented on Oct 27, 2021

@hellow554
Contributor

The following bash script will create a MCVE:

Bash Script
#!/bin/bash

cat > Cargo.toml << EOF
[package]
name = "abc"
version = "0.1.0"

[lib]
crate-type = ["staticlib"]
path = "lib.rs"

[dependencies]
other = { path = "./other" }

[profile.release]
lto = true
EOF

cat > lib.rs << EOF
extern crate other;
EOF

mkdir other
cat > other/Cargo.toml << EOF
[package]
name = "other"
version = "0.1.0"

[lib]
path = "lib.rs"

[dependencies]
EOF

cat > other/lib.rs << EOF

pub struct FloatVal {
    integral: &'static str,
    exponent: Option<&'static str>,
}

impl FloatVal {
    pub fn fmt(&self, f: &mut ::std::fmt::Formatter) {
        match *self {
            FloatVal {
                ref integral,
                ref exponent,
            } => {
                let debug_trait_builder = &mut ::std::fmt::Formatter::debug_struct(f, "FloatVal");
                let _ = ::std::fmt::DebugStruct::field(
                    debug_trait_builder,
                    "integral",
                    &&(*integral),
                );
                let _ = ::std::fmt::DebugStruct::field(
                    debug_trait_builder,
                    "exponent",
                    &&(*exponent),
                );
            }
        };
    }
}
EOF

Running RUSTFLAGS="-Cpasses=sancov-module -Cllvm-args=-sanitizer-coverage-level=4 -Cembed-bitcode=yes" cargo build --release will lead to the following error:

Compiling other v0.1.0 (/tmp/tmp.6tIcUpzVmX/other)
   Compiling abc v0.1.0 (/tmp/tmp.6tIcUpzVmX)
warning: Linking COMDATs named '_ZN4core3ptr32drop_in_place$LT$$RF$$RF$str$GT$17h3b1e30fa522258e5E': GlobalVariable required for data dependent selection!

error: failed to load bc of "other-89ce141d2e74e95c.other.1caaf38b-cgu.1.rcgu.o":

warning: `abc` (lib) generated 1 warning
error: could not compile `abc` due to previous error; 1 warning emitted

@rustbot modify labels: -E-needs-mcve

removed
E-needs-mcveCall for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example
on Oct 27, 2021
hellow554

hellow554 commented on Oct 27, 2021

@hellow554
Contributor

Regression in db002a0

cc #87570 @nikic

@rustbot modify labels: A-llvm

added
A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.
on Oct 27, 2021
apiraino

apiraino commented on Feb 24, 2022

@apiraino
Contributor

Assigning priority as discussed in the Zulip thread of the Prioritization Working Group.

@rustbot label -I-prioritize +P-medium

added and removed
I-prioritizeIssue: Indicates that prioritization has been requested for this issue.
on Feb 24, 2022

2 remaining items

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.A-LTOArea: Link-time optimization (LTO)C-bugCategory: This is a bug.P-mediumMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @lqd@hellow554@glandium@apiraino@JohnTitor

        Issue actions

          staticlib + sancov + full LTO fails with 1.56 · Issue #90300 · rust-lang/rust