Skip to content

LLVM error while building Rust Crypto's AES-GCM usage example code for target x86_64-unknown-none-linuxkernel #87642

@prathikgowda

Description

@prathikgowda

I tried this code:

#![no_std]

use aes_gcm::Aes256Gcm;
use aes_gcm::aead::{Aead, NewAead};

use generic_array::GenericArray;

pub fn encrypt_data() {
    let key = GenericArray::from_slice(b"an example very very secret key.");
    let cipher = Aes256Gcm::new(key);

    let nonce = GenericArray::from_slice(b"unique nonce"); // 96-bits; unique per message

    let ciphertext = cipher.encrypt(nonce, b"plaintext message".as_ref())
        .expect("encryption failure!"); // NOTE: handle this error to avoid panics!

    let plaintext = cipher.decrypt(nonce, ciphertext.as_ref())
        .expect("decryption failure!"); // NOTE: handle this error to avoid panics!

    assert_eq!(&plaintext, b"plaintext message");
}

Build command:

cargo build -Z build-std=core,alloc --release --target=x86_64-unknown-none-linuxkernel

Alternate build command (with AES and AVX2 explicitly enabled):

-Ctarget-cpu=native -Ctarget-feature=+aes,+ssse3,+avx2" cargo build -Z build-std=core,alloc --release --target=x86_64-unknown-none-linuxkernel

I expected to see this happen: Compilation without an LLVM error, as this is usage example code from the AES-GCM documentation (https://docs.rs/aes-gcm/0.9.3/aes_gcm/index.html).

Instead, this happened: I got this LLVM error (same error for both commands):

   Compiling encryption v0.1.0 (/home/prathik/Code/encryption)
LLVM ERROR: Do not know how to split the result of this operator!

error: could not compile `encryption`

Meta

The issue disappears if I don't set the target to the linuxkernel target. I'm stumped since this is an LLVM error rather than a rustc/cargo error with line numbers. The maintainer of AES-GCM suggested explicitly enabling AES and AVX2 target support, but to no avail (see above).

rustc --version --verbose:

rustc 1.53.0-nightly (968425893 2021-04-26)
binary: rustc
commit-hash: 9684258936dabda2ba49d4c67f041a6baf388348
commit-date: 2021-04-26
host: x86_64-unknown-linux-gnu
release: 1.53.0-nightly
LLVM version: 12.0.0

Backtrace

prathik@prathiks-buntobox:~/Code/encryption$ RUST_BACKTRACE=1 cargo build -Z build-std=core,alloc --release --target=x86_64-unknown-none-linuxkernel
   Compiling encryption v0.1.0 (/home/prathik/Code/encryption)
LLVM ERROR: Do not know how to split the result of this operator!

error: could not compile `encryption`

To learn more, run the command again with --verbose.

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.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way. When possible, use a F-* label instead.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions