Skip to content

rustc deadlocks on FreeBSD #44433

Closed
@jld

Description

@jld
Contributor

Steps to reproduce, on my FreeBSD/amd64 11.0 system: rustc --crate-type staticlib conftest.rs, where conftest.rs is:

pub extern fn hello() { println!("Hello world"); }

It's not 100%, but it usually happens after a few tries at most. I'll skip all the debugging and source-diving and just say that it's the same basic problem as #36905: threads A and B are both in LLVMRustWriteOutputFile, thread A gets to llvm::X86InstrFMA3Info::initGroupsOnce first and call_onces a lambda, then thread B enters llvm::X86InstrFMA3Info::initGroupsOnce and blocks in pthread_once with the std::call_once global mutex held, then thread A calls std::call_once reentrantly on a different once_flag and deadlocks.

But there might be a nicer solution than for #36905, because downstream has this patch:

--- src/librustc_llvm/build.rs.orig     2017-06-06 00:42:59 UTC
+++ src/librustc_llvm/build.rs
@@ -241,6 +241,8 @@ fn main() {
     let stdcppname = if target.contains("openbsd") {
         // OpenBSD has a particular C++ runtime library name
         "estdc++"
+    } else if target.contains("freebsd") {
+        "c++"
     } else if target.contains("netbsd") && llvm_static_stdcpp.is_some() {
         // NetBSD uses a separate library when relocation is required
         "stdc++_pic"

FreeBSD switched to libc++ in 10.0, on all platforms where they use Clang (apparently x86, little-endian ARM, and PPC), and 10.x is now the oldest supported release branch. libc++ appears to have a self-contained call_once that doesn't use pthread_once, and emprically the Rust 1.18.0 package available via pkg install doesn't deadlock.

So, it might be enough to upstream that patch and update the build environment to 10.x if it isn't already.

Activity

mattico

mattico commented on Sep 8, 2017

@mattico
Contributor

Looks like we're using 10.2 on ci:

URL=ftp://ftp.freebsd.org/pub/FreeBSD/releases/amd64/10.2-RELEASE/base.txz

jld

jld commented on Sep 16, 2017

@jld
ContributorAuthor

Thanks for the pointer. I took a (much) closer look at this, and I've gotten the build more or less working using Ubuntu's regular Clang package, which can cross-compile out of the box. I'll send a PR once I've gotten things cleaned up and tested a bit more.

added
A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.
C-bugCategory: This is a bug.
O-freebsdOperating system: FreeBSD
on Sep 17, 2017
jld

jld commented on Sep 28, 2017

@jld
ContributorAuthor

So I'm kind of stuck because, when I try to test locally, I run into #43982 unless I remove --enable-extended, which isn't maximally useful because I don't have Cargo and therefore can't build Cargo. This happens even without my changes, but the same container running on Travis CI seems to work, and I'm at a loss as to what differences there could be that would affect (apparently?) the type checker. I suppose I could just test what I can and send a PR and hope for the best, but if possible I'd prefer to understand what my local setup is doing wrong.

valpackett

valpackett commented on Oct 2, 2017

@valpackett
Contributor

Noticed this on 12-CURRENT, compilers from rustup always lock up when compiling libloading, but it usually succeeds after a couple tries. It's nearly always libloading!

valpackett

valpackett commented on Oct 3, 2017

@valpackett
Contributor

Hmm, the rust from ports (that doesn't have this problem IIRC??) is built with bundled llvm by default…

added a commit that references this issue on Oct 7, 2017
270c517

9 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.C-bugCategory: This is a bug.O-freebsdOperating system: FreeBSD

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @valpackett@jld@mattico@TimNN

      Issue actions

        rustc deadlocks on FreeBSD · Issue #44433 · rust-lang/rust