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

thread 'rustc' panicked at 'called Option::unwrap() on a None value', src/libcore/option.rs:347:21 #64482

Open
Bejaenka opened this issue Sep 15, 2019 · 4 comments
Labels
A-codegen Area: Code generation C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ O-macos Operating system: macOS T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Bejaenka
Copy link

when following these install instructions (which work under Ubuntu 18.04) compiling for openssl-sys fails with:
thread 'rustc' panicked at 'called Option::unwrap() on a None value', src/libcore/option.rs:347:21

 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.

 error: internal compiler error: unexpected panic

 note: the compiler unexpectedly panicked. this is a bug.

 note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports

 note: rustc 1.37.0 (eae3437df 2019-08-13) running on x86_64-apple-darwin

 note: compiler flags: -C opt-level=3 -C ar=/Users/bianca/Library/Android/sdk/ndk/20.0.5594570//toolchains/llvm/prebuilt/darwin-x86_64/bin/aarch64-linux-android-ar -C linker=/Users/bianca/Library/Android/sdk/ndk/20.0.5594570//toolchains/llvm/prebuilt/darwin-x86_64/bin/aarch64-linux-android29-clang --crate-type lib

 note: some of the compiler flags provided by cargo are hidden

 error: Could not compile `openssl-sys`.
 warning: build failed, waiting for other jobs to finish...
 error: build failed

.cargo/config file:
[target.aarch64-linux-android]
ar = "/Users/bianca/Library/Android/sdk/ndk/20.0.5594570//toolchains/llvm/prebuilt/darwin-x86_64/bin/aarch64-linux-android-ar"
linker = "/Users/bianca/Library/Android/sdk/ndk/20.0.5594570//toolchains/llvm/prebuilt/darwin-x86_64/bin/aarch64-linux-android29-clang"

 [target.armv7-linux-androideabi]
 ar = "/Users/bianca/Library/Android/sdk/ndk/20.0.5594570//toolchains/llvm/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-ar"
 linker = "/Users/bianca/Library/Android/sdk/ndk/20.0.5594570//toolchains/llvm/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-clang"

 [target.i686-linux-android]
 ar = "/Users/bianca/Library/Android/sdk/ndk/20.0.5594570//toolchains/llvm/prebuilt/darwin-x86_64/bin/i686-linux-android-ar"
 linker = "/Users/bianca/Library/Android/sdk/ndk/20.0.5594570//toolchains/llvm/prebuilt/darwin-x86_64/bin/i686-linux-android28-clang"

System:
MacOS Mojave (10.14.5 (18F132))
rustc 1.37.0 (eae3437 2019-08-13)

build commands:
export CC=/Users/bianca/Library/Android/sdk/ndk/20.0.5594570/toolchains/llvm/prebuilt/darwin-x86_64/bin/aarch64-linux-android29-clang
export AR=/Users/bianca/Library/Android/sdk/ndk/20.0.5594570/toolchains/llvm/prebuilt/darwin-x86_64/bin/aarch64-linux-android-ar
cargo build --target aarch64-linux-android --release

@jonas-schievink
Copy link
Contributor

Can you run against with RUST_BACKTRACE=1 and post the backtrace?

@Bejaenka
Copy link
Author

Bejaenka commented Sep 22, 2019

Sorry for the late reply. Backtrace:

stack backtrace:
     0: std::panicking::default_hook::{{closure}}
     1: std::panicking::default_hook
     2: rustc::util::common::panic_hook
     3: std::panicking::rust_panic_with_hook
     4: std::panicking::continue_panic_fmt
     5: rust_begin_unwind
     6: core::panicking::panic_fmt
     7: core::panicking::panic
     8: <rustc_codegen_llvm::back::archive::LlvmArchiveBuilder as rustc_codegen_ssa::back::archive::ArchiveBuilder>::build
     9: rustc_codegen_ssa::back::link::link_binary
    10: rustc::util::common::time
    11: <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_utils::codegen_backend::CodegenBackend>::join_codegen_and_link
    12: rustc_interface::queries::Query<T>::compute
    13: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::link
    14: rustc_interface::interface::run_compiler_in_existing_thread_pool
    15: std::thread::local::LocalKey<T>::with
     16: scoped_tls::ScopedKey<T>::set
     17: syntax::with_globals
     note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
     query stack during panic:
     end of query stack

     error: internal compiler error: unexpected panic

**BACKTRACE=full:**
     stack backtrace:
     0:        0x10550c312 - std::panicking::default_hook::{{closure}}::h6e0c5011619dccf8
   1:        0x10550bfdb - std::panicking::default_hook::h673b9cd39a829714
   2:        0x1044a34a3 - rustc::util::common::panic_hook::h84287c71f722b4de
   3:        0x10550cbe1 - std::panicking::rust_panic_with_hook::h7d6a669f1a899680
   4:        0x10550c62d - std::panicking::continue_panic_fmt::h682bc3f8dac9c5a1
   5:        0x10550c519 - rust_begin_unwind
   6:        0x1055383c2 - core::panicking::panic_fmt::he11aece98ed722cd
   7:        0x105538307 - core::panicking::panic::h89241d71a860ed98
   8:        0x1060408b4 - <rustc_codegen_llvm::back::archive::LlvmArchiveBuilder as rustc_codegen_ssa::back::archive::ArchiveBuilder>::build::hb83f4d41f3bb743f
   9:        0x106029121 - rustc_codegen_ssa::back::link::link_binary::h5ac4a21e99cf8e2d
  10:        0x1060764f5 - rustc::util::common::time::hb999715119d81bd3
  11:        0x1061225ed - <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_utils::codegen_backend::CodegenBackend>::join_codegen_and_link::h56979a2f10dbb1ea
  12:        0x1014fb632 - rustc_interface::queries::Query<T>::compute::h28c05c945908a803
  13:        0x101589c2c - rustc_interface::queries::<impl rustc_interface::interface::Compiler>::link::h13b90e3c9c77b107
  14:        0x101382ca2 - rustc_interface::interface::run_compiler_in_existing_thread_pool::hd51cad8f0ae43601
  15:        0x1013a0534 - std::thread::local::LocalKey<T>::with::h9299c21742d55aa6
  16:        0x1013b1a22 - scoped_tls::ScopedKey<T>::set::head1877c75a7c8b4
  17:        0x1013c9135 - syntax::with_globals::h8e099f446704231c
  18:        0x10137345a - std::sys_common::backtrace::__rust_begin_short_backtrace::hdebc92dc94cbb432
  19:        0x10551bf3f - __rust_maybe_catch_panic
  20:        0x101384187 - core::ops::function::FnOnce::call_once{{vtable.shim}}::h35ffbfb717702997
  21:        0x1054efc6e - <alloc::boxed::Box<F> as core::ops::function::FnOnce<A>>::call_once::ha44ca87baccc45af
  22:        0x10551ad4e - std::sys::unix::thread::Thread::new::thread_start::hceb9fd3b79bf176c
  23:     0x7fff6db1b2eb - _pthread_body
  24:     0x7fff6db1e249 - _pthread_start
query stack during panic:
end of query stack

error: internal compiler error: unexpected panic

@jonas-schievink
Copy link
Contributor

It's probably one of the .unwrap()s in this function, which would fail if some paths are not valid UTF-8. Do you know if this is the case on your system?

fn build_with_llvm(&mut self, kind: ArchiveKind) -> io::Result<()> {
let removals = mem::take(&mut self.removals);
let mut additions = mem::take(&mut self.additions);
let mut strings = Vec::new();
let mut members = Vec::new();
let dst = CString::new(self.config.dst.to_str().unwrap())?;
let should_update_symbols = self.should_update_symbols;
unsafe {
if let Some(archive) = self.src_archive() {
for child in archive.iter() {
let child = child.map_err(string_to_io_error)?;
let child_name = match child.name() {
Some(s) => s,
None => continue,
};
if removals.iter().any(|r| r == child_name) {
continue
}
let name = CString::new(child_name)?;
members.push(llvm::LLVMRustArchiveMemberNew(ptr::null(),
name.as_ptr(),
Some(child.raw)));
strings.push(name);
}
}
for addition in &mut additions {
match addition {
Addition::File { path, name_in_archive } => {
let path = CString::new(path.to_str().unwrap())?;
let name = CString::new(name_in_archive.clone())?;
members.push(llvm::LLVMRustArchiveMemberNew(path.as_ptr(),
name.as_ptr(),
None));
strings.push(path);
strings.push(name);
}
Addition::Archive { archive, skip, .. } => {
for child in archive.iter() {
let child = child.map_err(string_to_io_error)?;
if !is_relevant_child(&child) {
continue
}
let child_name = child.name().unwrap();
if skip(child_name) {
continue
}
// It appears that LLVM's archive writer is a little
// buggy if the name we pass down isn't just the
// filename component, so chop that off here and
// pass it in.
//
// See LLVM bug 25877 for more info.
let child_name = Path::new(child_name)
.file_name().unwrap()
.to_str().unwrap();
let name = CString::new(child_name)?;
let m = llvm::LLVMRustArchiveMemberNew(ptr::null(),
name.as_ptr(),
Some(child.raw));
members.push(m);
strings.push(name);
}
}
}
}
let r = llvm::LLVMRustWriteArchive(dst.as_ptr(),
members.len() as libc::size_t,
members.as_ptr() as *const &_,
should_update_symbols,
kind);
let ret = if r.into_result().is_err() {
let err = llvm::LLVMRustGetLastError();
let msg = if err.is_null() {
"failed to write archive".into()
} else {
String::from_utf8_lossy(CStr::from_ptr(err).to_bytes())
};
Err(io::Error::new(io::ErrorKind::Other, msg))
} else {
Ok(())
};
for member in members {
llvm::LLVMRustArchiveMemberFree(member);
}
ret
}
}

@jonas-schievink jonas-schievink added A-codegen Area: Code generation C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Sep 22, 2019
@Bejaenka
Copy link
Author

Bejaenka commented Sep 22, 2019

It's probably one of the .unwrap()s in this function, which would fail if some paths are not valid UTF-8. Do you know if this is the case on your system?

fn build_with_llvm(&mut self, kind: ArchiveKind) -> io::Result<()> {
let removals = mem::take(&mut self.removals);
let mut additions = mem::take(&mut self.additions);
let mut strings = Vec::new();
let mut members = Vec::new();
let dst = CString::new(self.config.dst.to_str().unwrap())?;
let should_update_symbols = self.should_update_symbols;
unsafe {
if let Some(archive) = self.src_archive() {
for child in archive.iter() {
let child = child.map_err(string_to_io_error)?;
let child_name = match child.name() {
Some(s) => s,
None => continue,
};
if removals.iter().any(|r| r == child_name) {
continue
}
let name = CString::new(child_name)?;
members.push(llvm::LLVMRustArchiveMemberNew(ptr::null(),
name.as_ptr(),
Some(child.raw)));
strings.push(name);
}
}
for addition in &mut additions {
match addition {
Addition::File { path, name_in_archive } => {
let path = CString::new(path.to_str().unwrap())?;
let name = CString::new(name_in_archive.clone())?;
members.push(llvm::LLVMRustArchiveMemberNew(path.as_ptr(),
name.as_ptr(),
None));
strings.push(path);
strings.push(name);
}
Addition::Archive { archive, skip, .. } => {
for child in archive.iter() {
let child = child.map_err(string_to_io_error)?;
if !is_relevant_child(&child) {
continue
}
let child_name = child.name().unwrap();
if skip(child_name) {
continue
}
// It appears that LLVM's archive writer is a little
// buggy if the name we pass down isn't just the
// filename component, so chop that off here and
// pass it in.
//
// See LLVM bug 25877 for more info.
let child_name = Path::new(child_name)
.file_name().unwrap()
.to_str().unwrap();
let name = CString::new(child_name)?;
let m = llvm::LLVMRustArchiveMemberNew(ptr::null(),
name.as_ptr(),
Some(child.raw));
members.push(m);
strings.push(name);
}
}
}
}
let r = llvm::LLVMRustWriteArchive(dst.as_ptr(),
members.len() as libc::size_t,
members.as_ptr() as *const &_,
should_update_symbols,
kind);
let ret = if r.into_result().is_err() {
let err = llvm::LLVMRustGetLastError();
let msg = if err.is_null() {
"failed to write archive".into()
} else {
String::from_utf8_lossy(CStr::from_ptr(err).to_bytes())
};
Err(io::Error::new(io::ErrorKind::Other, msg))
} else {
Ok(())
};
for member in members {
llvm::LLVMRustArchiveMemberFree(member);
}
ret
}
}

thanks for your help!

Then it's probably either these commands

export AR=/Users/bianca/Library/Android/sdk/ndk/20.0.5594570/toolchains/llvm/prebuilt/darwin-x86_64/bin/aarch64-linux-android-ar
export TARGET_CC=/Users/bianca/Library/Android/sdk/ndk/20.0.5594570/toolchains/llvm/prebuilt/darwin-x86_64/bin/aarch64-linux-android29-clang

or this part from my cargo config file

[target.aarch64-linux-android]
ar = "/Users/bianca/Library/Android/sdk/ndk/20.0.5594570/toolchains/llvm/prebuilt/darwin-x86_64/bin/aarch64-linux-android-ar"
linker = "/Users/bianca/Library/Android/sdk/ndk/20.0.5594570/toolchains/llvm/prebuilt/darwin-x86_64/bin/aarch64-linux-android29-clang"

@Enselic Enselic added the O-macos Operating system: macOS label Aug 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-codegen Area: Code generation C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ O-macos Operating system: macOS 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

3 participants