Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Building Firefox with rustc 1.34.0-nightly fails with LLVM ERROR: broken function found. #58881

Closed
emilio opened this issue Mar 2, 2019 · 21 comments
Assignees
Labels
A-codegen Area: Code generation A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. C-bug Category: This is a bug. P-high High priority regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@emilio
Copy link
Contributor

emilio commented Mar 2, 2019

Unfortunately I haven't been able to reproduce outside of the Firefox build system. I assume this is a regression from #58408, cc @alexcrichton.

 0:13.50 Wrong types for attribute: byval inalloca nest noalias nocapture nonnull readnone readonly signext sret zeroext dereferenceable(1) dereferenceable_or_null(1)
 0:13.50   call void (i8*, ...) %96(i8* %101, { i64, i64 } %115, { i64, i64 } %118, { [0 x i8]*, i64 } %120, { i64, i64 } byval noalias nocapture dereferenceable(16) %124, { [0 x i8]*, i64 }* %5), !dbg !1889
 0:13.50 in function _ZN97_$LT$cubeb_pulse..backend..context..PulseContext$u20$as$u20$cubeb_backend..traits..ContextOps$GT$34register_device_collection_changed17update_collection17h9f106daf4cf87a02E
 0:13.50 LLVM ERROR: Broken function found, compilation aborted!
 0:13.64 error: Could not compile `cubeb-pulse`.
 0:13.67 Caused by:
 0:13.67   process didn't exit successfully: `CARGO_MANIFEST_DIR=/home/emilio/src/moz/gecko/media/libcubeb/cubeb-pulse-rs CARGO_PKG_VERSION_PRE= CARGO_PKG_NAME=cubeb-pulse CARGO_PKG_HOMEPAGE= CARGO_PKG_AUTHORS='Dan Glastonbury <dglastonbury@mozilla.com>' CARGO_PKG_DESCRIPTION='Cubeb backed for PulseAudio written in Rust' LD_LIBRARY_PATH='/home/emilio/src/moz/gecko/obj-x86_64-pc-linux-gnu/debug/deps:/home/emilio/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib:/home/emilio/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib' CARGO_PKG_VERSION_MAJOR=0 CARGO_PKG_REPOSITORY= CARGO_PKG_VERSION_MINOR=2 CARGO=/home/emilio/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/cargo CARGO_PKG_VERSION_PATCH=0 CARGO_PKG_VERSION=0.2.0 /home/emilio/.cargo/bin/rustc --crate-name cubeb_pulse media/libcubeb/cubeb-pulse-rs/src/lib.rs --color always --crate-type staticlib --crate-type rlib --emit=dep-info,link -C opt-level=1 -C panic=abort -C debuginfo=2 -C debug-assertions=on --cfg 'feature="pulse-dlopen"' --cfg 'feature="pulse-ffi"' -C metadata=d5a9783431e388af -C extra-filename=-d5a9783431e388af --out-dir /home/emilio/src/moz/gecko/obj-x86_64-pc-linux-gnu/x86_64-unknown-linux-gnu/debug/deps --target x86_64-unknown-linux-gnu -C linker=/home/emilio/src/moz/gecko/build/cargo-linker -C incremental=/home/emilio/src/moz/gecko/obj-x86_64-pc-linux-gnu/x86_64-unknown-linux-gnu/debug/incremental -L dependency=/home/emilio/src/moz/gecko/obj-x86_64-pc-linux-gnu/x86_64-unknown-linux-gnu/debug/deps -L dependency=/home/emilio/src/moz/gecko/obj-x86_64-pc-linux-gnu/debug/deps --extern cubeb_backend=/home/emilio/src/moz/gecko/obj-x86_64-pc-linux-gnu/x86_64-unknown-linux-gnu/debug/deps/libcubeb_backend-44de29cd13d09317.rlib --extern pulse=/home/emilio/src/moz/gecko/obj-x86_64-pc-linux-gnu/x86_64-unknown-linux-gnu/debug/deps/libpulse-1a07f564e62af458.rlib --extern pulse_ffi=/home/emilio/src/moz/gecko/obj-x86_64-pc-linux-gnu/x86_64-unknown-linux-gnu/debug/deps/libpulse_ffi-3634bc0fd9d2e2d4.rlib --extern semver=/home/emilio/src/moz/gecko/obj-x86_64-pc-linux-gnu/x86_64-unknown-linux-gnu/debug/deps/libsemver-d5bc6c91229d5335.rlib -C opt-level=0 -C debuginfo=2 -Dwarnings` (exit code: 101)
@Centril Centril added the A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. label Mar 3, 2019
@jonas-schievink jonas-schievink added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. C-bug Category: This is a bug. labels Mar 3, 2019
@alexcrichton
Copy link
Member

Unfortuntely this probably isn't too actionable unless we can reduce it to the point where we can give it to upstream LLVM

@emilio
Copy link
Contributor Author

emilio commented Mar 5, 2019

Ok, I tried to figure out why it wasn't reproducing outside of the build system, and manage to get some STR:

$ git clone https://github.com/djg/cubeb-pulse-rs && cd cubeb-pulse-rs
$ cargo update -p cubeb-backend --precise 0.5.0 # This was the bit that mattered, somehow.
$ cargo build

@emilio
Copy link
Contributor Author

emilio commented Mar 5, 2019

v0.5.1 works, v0.5.0 does not.

https://github.com/djg/cubeb-rs/compare/98f5a8b4..d18f114f

cc @djg

@emilio
Copy link
Contributor Author

emilio commented Mar 5, 2019

Well, the cubeb_log! macro is used in the borked update_collection function, so that's something. I'll try to reduce it further.

@emilio
Copy link
Contributor Author

emilio commented Mar 5, 2019

Ok, this test-case crashes for me:

use std::os::raw::c_char;

pub type cubeb_log_callback = Option<unsafe extern "C" fn(*const c_char, ...)>;
extern "C" {
    pub static g_cubeb_log_callback: cubeb_log_callback;
}

pub fn foo(index: u32) {
    unsafe {
        let op = "Adding";
        let dev = "sink";
        if let Some(log_callback) = g_cubeb_log_callback {
            let cstr = ::std::ffi::CString::new("%s:%d: {} {} index {}\n").unwrap();
            log_callback(cstr.as_ptr(), file!(), line!(), op, dev, index);
        }
    }
}

fn main() {
    let args = ::std::env::args().count();
    foo(args as u32);
}

The code is completely unsound of course... Passing a static string into a C variadic function makes no sense. Maybe rustc should warn about that?

@emilio
Copy link
Contributor Author

emilio commented Mar 5, 2019

This is the most reduced thing I could come up with:

extern "C" {
    pub static g_cubeb_log_callback: unsafe extern "C" fn(*const u8, ...);
}

fn main() {
    unsafe {
        let f = "file";
        let op = "Adding";
        let dev = "sink";
        let cstr = b"foo\0";
        g_cubeb_log_callback(cstr.as_ptr(), f, op, dev);
    }
}

@alexcrichton
Copy link
Member

Thanks for the reduction @emilio! I can indeed also reproduce with:

# Today's nightly, with LLVM assertions
$ rustup-toolchain-install-master a9da8fc9c267c08cfdb8cf5b39da14f154d12939 --alt
$ rustc +a9da8fc9c267c08cfdb8cf5b39da14f154d12939-alt foo.rs
warning: `extern` block uses type `()` which is not FFI-safe: tuples have unspecified layout
 --> foo.rs:2:38
  |
2 |     pub static g_cubeb_log_callback: unsafe extern "C" fn(*const u8, ...);
  |                                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: #[warn(improper_ctypes)] on by default
  = help: consider using a struct instead

Wrong types for attribute: byval inalloca nest noalias nocapture nonnull readnone readonly signext sret zeroext dereferenceable(1) dereferenceable_or_null(1)
  call void (i8*, ...) %4(i8* %5, { i64, i64 } %10, { i64, i64 } %14, { i64, i64 } byval noalias nocapture dereferenceable(16) %18)
in function _ZN3foo4main17h0e6b3bfd37376208E
LLVM ERROR: Broken function found, compilation aborted!

I'm gonna cc @rust-lang/compiler on this because this actually looks more like a codegen bug on our end than an LLVM bug, and LLVM may have just added more validation or something like that.

@alexcrichton alexcrichton added the A-codegen Area: Code generation label Mar 5, 2019
@emilio
Copy link
Contributor Author

emilio commented Mar 5, 2019

Yeah, that sounds right. Thanks for taking a look Alex!

FWIW, I worked around the bug in Firefox in https://bugzilla.mozilla.org/show_bug.cgi?id=1532645 (by updating the dependency to one that doesn't have the unsound code), so this is no longer blocking anyone, hopefully.

@nagisa
Copy link
Member

nagisa commented Mar 5, 2019 via email

moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this issue Mar 6, 2019
rust-lang/rust#58881 doesn't repro with cubeb-backend
v5.0.1, so use that so that other Rust nightly users don't get their builds
busted.

Differential Revision: https://phabricator.services.mozilla.com/D22092

--HG--
extra : moz-landing-system : lando
mykmelez pushed a commit to mykmelez/gecko that referenced this issue Mar 6, 2019
rust-lang/rust#58881 doesn't repro with cubeb-backend
v5.0.1, so use that so that other Rust nightly users don't get their builds
busted.

Differential Revision: https://phabricator.services.mozilla.com/D22092
ChunMinChang added a commit to mozilla/cubeb-coreaudio-rs that referenced this issue Mar 6, 2019
ChunMinChang added a commit to mozilla/cubeb-coreaudio-rs that referenced this issue Mar 6, 2019
ChunMinChang added a commit to mozilla/cubeb-coreaudio-rs that referenced this issue Mar 6, 2019
@stefson
Copy link

stefson commented Mar 10, 2019

@emilio do you happen to know wether esr is affected as well? It has cubeb-0.4.1 pulled in, but I'm note sure if the logic here is that <=cubeb-0.5.0 is affected, or only =cubeb-0.5.0?

@emilio
Copy link
Contributor Author

emilio commented Mar 11, 2019

@stefson I don't know off-hand, would need to test.

@pnkfelix
Copy link
Member

triage: assuming P-high since it originated as a Firefox build problem.

@pnkfelix pnkfelix added the P-high High priority label Mar 14, 2019
@pnkfelix pnkfelix self-assigned this Mar 21, 2019
@pnkfelix
Copy link
Member

assigning to self for initial investigation.

@pnkfelix
Copy link
Member

(leaving nominated for now to keep myself honest in case I somehow get to next week's meeting without looking at this. if I do investigate and it bears fruit I'll remove nomination at that time.)

@pnkfelix
Copy link
Member

This version is a little bit smaller than @emilio's great reduction above:

extern "C" {
    fn variadic(arg: u8, ...);
}

fn main() {
    unsafe {
        let f = "file";
        variadic(0, f, f, f);
    }
}

(The main feature here is that it demonstrates the problem without using a callback to a static variable, which I had mistakenly thought was an important part of replicating the problem.)

@varkor
Copy link
Member

varkor commented Mar 26, 2019

Might this be related to the recent variadic function changes? cc @dlrobertson

@pnkfelix
Copy link
Member

(FYI, bisection indicates this was injected between nightly-2019-02-28 and nightly-2019-03-01.)

@pnkfelix
Copy link
Member

@varkor that theory sounds very plausible, given the following bors merges from the point I bisected:

 % git log 7e001e5c6..350674b71 --author=bors --format=oneline

350674b Auto merge of #58250 - Zoxc:rustc-interface-1, r=oli-obk
1999a22 Auto merge of #57760 - dlrobertson:varargs1, r=alexreg
190feb6 Auto merge of #58208 - taiki-e:libstd-2018, r=Centril

@dlrobertson
Copy link
Contributor

It is very likely I caused this. I'll look into it

@pnkfelix
Copy link
Member

pnkfelix commented Mar 26, 2019

reassigning to @dlrobertson and removing nominated tag.

  • (can't reassign, they aren't in the necessary github group)

tagging as regression from stable-to-nightly.

@pnkfelix pnkfelix added regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. and removed I-nominated labels Mar 26, 2019
@dlrobertson
Copy link
Contributor

Appears to be an issue if a structure is passed to a C-variadic. E.g.

extern "C" {
    fn variadic(arg: u8, ...);
}

fn main() {
    unsafe {
        let f = b"file\0";
        variadic(0, f.as_ptr(), f.as_ptr(), f.as_ptr()); // does not ICE
        variadic(0, f, f, f); // will ICE
    }
}

Centril added a commit to Centril/rust that referenced this issue Mar 31, 2019
Fix LLVM IR generated for C-variadic arguments

It is possible to create malformed LLVM IR given variadic arguments that
are aggregate types. This occurs due to improper tracking of the current
argument in the functions list of arguments.

Fixes: rust-lang#58881
bors added a commit that referenced this issue Mar 31, 2019
Fix LLVM IR generated for C-variadic arguments

It is possible to create malformed LLVM IR given variadic arguments that
are aggregate types. This occurs due to improper tracking of the current
argument in the functions list of arguments.

Fixes: #58881
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified that referenced this issue Oct 4, 2019
rust-lang/rust#58881 doesn't repro with cubeb-backend
v5.0.1, so use that so that other Rust nightly users don't get their builds
busted.

Differential Revision: https://phabricator.services.mozilla.com/D22092

UltraBlame original commit: 9286348b9c33218e956417ce8675851ddbccaeaa
gecko-dev-updater pushed a commit to marco-c/gecko-dev-comments-removed that referenced this issue Oct 4, 2019
rust-lang/rust#58881 doesn't repro with cubeb-backend
v5.0.1, so use that so that other Rust nightly users don't get their builds
busted.

Differential Revision: https://phabricator.services.mozilla.com/D22092

UltraBlame original commit: 9286348b9c33218e956417ce8675851ddbccaeaa
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified-and-comments-removed that referenced this issue Oct 4, 2019
rust-lang/rust#58881 doesn't repro with cubeb-backend
v5.0.1, so use that so that other Rust nightly users don't get their builds
busted.

Differential Revision: https://phabricator.services.mozilla.com/D22092

UltraBlame original commit: 9286348b9c33218e956417ce8675851ddbccaeaa
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-codegen Area: Code generation A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. C-bug Category: This is a bug. P-high High priority regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

9 participants