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

LLVM ERROR: Invalid LLVMRustLinkage value! #87813

Closed
haraldh opened this issue Aug 6, 2021 · 13 comments · Fixed by #91070
Closed

LLVM ERROR: Invalid LLVMRustLinkage value! #87813

haraldh opened this issue Aug 6, 2021 · 13 comments · Fixed by #91070
Labels
C-bug Category: This is a bug. glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ ICEBreaker-LLVM Bugs identified for the LLVM ICE-breaker group P-high High priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@haraldh
Copy link
Contributor

haraldh commented Aug 6, 2021

Code

https://github.com/haraldh/rust_llvm_error

❯ cd /tmp
❯ git clone https://github.com/haraldh/rust_llvm_error.git
❯ cd rust_llvm_error/
❯ cargo clean; cargo build
   Compiling scopeguard v1.1.0
   Compiling primordial v0.1.0
   Compiling lock_api v0.4.4
   Compiling spinning v0.1.0
   Compiling llvm_error v0.1.0 (/tmp/rust_llvm_error)
    Finished dev [unoptimized + debuginfo] target(s) in 1.20s

❯ cd ..
❯ mkdir -p /tmp/sfdgfdgdfgfdg/dfghfdgfd/fdfdgfdg/
❯ mv rust_llvm_error /tmp/sfdgfdgdfgfdg/dfghfdgfd/fdfdgfdg/
❯ cd /tmp/sfdgfdgdfgfdg/dfghfdgfd/fdfdgfdg/rust_llvm_error/
❯ cargo clean; cargo build
   Compiling scopeguard v1.1.0
   Compiling primordial v0.1.0
   Compiling lock_api v0.4.4
   Compiling spinning v0.1.0
   Compiling llvm_error v0.1.0 (/tmp/sfdgfdgdfgfdg/dfghfdgfd/fdfdgfdg/rust_llvm_error)
LLVM ERROR: Invalid LLVMRustLinkage value!
error: could not compile `llvm_error`

Meta

rustc --version --verbose:

rustc 1.54.0 (a178d0322 2021-07-26)
binary: rustc
commit-hash: a178d0322ce20e33eac124758e837cbd80a6f633
commit-date: 2021-07-26
host: x86_64-unknown-linux-gnu
release: 1.54.0
LLVM version: 12.0.1

Error output

LLVM ERROR: Invalid LLVMRustLinkage value!
error: could not compile `llvm_error`
@haraldh haraldh added 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 Aug 6, 2021
@haraldh
Copy link
Contributor Author

haraldh commented Aug 6, 2021

Forgive the unsafe mess :)

@hellow554
Copy link
Contributor

hellow554 commented Aug 10, 2021

Using a self built rustc, I get this (already c++filtered):

invalid scope
/build/librustc_driver-5f22cd2fd3625224.so(+0x6f0063)[0x7f8914a42063]
/lib/x86_64-linux-gnu/libc.so.6(+0x41030)[0x7f8913fdf030]
/build/libLLVM-12-rust-1.56.0-nightly.so(llvm::SlotTracker::CreateMetadataSlot(llvm::MDNode const*)+0xac)[0x7f8910f2f81c]
/build/libLLVM-12-rust-1.56.0-nightly.so(llvm::SlotTracker::CreateMetadataSlot(llvm::MDNode const*)+0xc5)[0x7f8910f2f835]
/build/libLLVM-12-rust-1.56.0-nightly.so(llvm::SlotTracker::CreateMetadataSlot(llvm::MDNode const*)+0xc5)[0x7f8910f2f835]
/build/libLLVM-12-rust-1.56.0-nightly.so(llvm::SlotTracker::CreateMetadataSlot(llvm::MDNode const*)+0xc5)[0x7f8910f2f835]
/build/libLLVM-12-rust-1.56.0-nightly.so(llvm::SlotTracker::processFunctionMetadata(llvm::Function const&)+0x5d)[0x7f8910f2f8fd]
/build/libLLVM-12-rust-1.56.0-nightly.so(llvm::SlotTracker::processModule()+0x52b)[0x7f8910f2f32b]
/build/libLLVM-12-rust-1.56.0-nightly.so(+0x215cf47)[0x7f8910f47f47]
/build/libLLVM-12-rust-1.56.0-nightly.so(+0x215581e)[0x7f8910f4081e]
/build/libLLVM-12-rust-1.56.0-nightly.so(+0x2312895)[0x7f89110fd895]
/build/libLLVM-12-rust-1.56.0-nightly.so(+0x231278b)[0x7f89110fd78b]
/build/libLLVM-12-rust-1.56.0-nightly.so(+0x230b852)[0x7f89110f6852]
/build/libLLVM-12-rust-1.56.0-nightly.so(+0x230cf0d)[0x7f89110f7f0d]
/build/libLLVM-12-rust-1.56.0-nightly.so(+0x230cf0d)[0x7f89110f7f0d]
/build/libLLVM-12-rust-1.56.0-nightly.so(+0x2308e0c)[0x7f89110f3e0c]
/build/libLLVM-12-rust-1.56.0-nightly.so(+0x23003d5)[0x7f89110eb3d5]
/build/libLLVM-12-rust-1.56.0-nightly.so(+0x2329143)[0x7f8911114143]
/build/libLLVM-12-rust-1.56.0-nightly.so(llvm::FPPassManager::runOnFunction(llvm::Function&)+0x639)[0x7f8911090869]
/build/libLLVM-12-rust-1.56.0-nightly.so(llvm::FPPassManager::runOnModule(llvm::Module&)+0x33)[0x7f8911097703]
/build/libLLVM-12-rust-1.56.0-nightly.so(llvm::legacy::PassManagerImpl::run(llvm::Module&)+0x470)[0x7f89110910d0]
/build/librustc_driver-5f22cd2fd3625224.so(+0x9ddf68)[0x7f8914d2ff68]
/build/librustc_driver-5f22cd2fd3625224.so(+0x9b87a1)[0x7f8914d0a7a1]
/build/librustc_driver-5f22cd2fd3625224.so(+0x9bdf79)[0x7f8914d0ff79]
/build/librustc_driver-5f22cd2fd3625224.so(+0x8870e2)[0x7f8914bd90e2]
/build/librustc_driver-5f22cd2fd3625224.so(+0x880be4)[0x7f8914bd2be4]
/build/librustc_driver-5f22cd2fd3625224.so(+0x97fbbc)[0x7f8914cd1bbc]
/build/librustc_driver-5f22cd2fd3625224.so(+0x982067)[0x7f8914cd4067]
/build/libstd-6bca756cf6c7b5ad.so(rust_metadata_std_4c245a9be68bbd28178e09733609f43+0x7f337)[0x7f891421c337]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x9450)[0x7f890eb9d450]
/lib/x86_64-linux-gnu/libc.so.6(clone+0x43)[0x7f89140b5e73]
error: could not compile `llvm_error`

I also got this recently:

munmap_chunk(): invalid pointer
warning: `llvm_error` (bin "llvm_error") generated 4 warnings
error: could not compile `llvm_error`; 4 warnings emitted

Caused by:
  process didn't exit successfully: `/home/marcel/projects/rust/llvm-path/build/x86_64-unknown-linux-gnu/stage1/bin/rustc --crate-name llvm_error --edition=2018 src/main.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C debuginfo=2 -C metadata=5e69652675a71d2c -C extra-filename=-5e69652675a71d2c --out-dir /tmp/asdf/asdf/asdf/asdf/asdf/asdf/asdf/asdf/asdf/asdf/asdf/asdf/target/debug/deps -C incremental=/tmp/asdf/asdf/asdf/asdf/asdf/asdf/asdf/asdf/asdf/asdf/asdf/asdf/target/debug/incremental -L dependency=/tmp/asdf/asdf/asdf/asdf/asdf/asdf/asdf/asdf/asdf/asdf/asdf/asdf/target/debug/deps` (signal: 6, SIGABRT: process abort signal)

@hellow554
Copy link
Contributor

hellow554 commented Aug 10, 2021

I managed to recude the code a lot.
The problem is, that the error happens on random.

I'm not sure why or what, but when running it ten times (cargo clean; cargo build) it happens maybe once...

#![feature(once_cell)]

pub mod addr {
    use std::convert::TryFrom;
    use std::marker::PhantomData as PD;

    extern "C" {
        pub static _ENARX_SALLYPORT_START: u8;
    }

    pub struct Address<T, U>(T, PD<U>);
    impl<T, U> Address<T, U> {
        pub fn f<Z>(_: &Z) -> Self {
            todo!()
        }
    }

    pub struct ShimVirtAddr<U>(Address<u64, U>);
    impl<U> TryFrom<Address<u64, U>> for ShimVirtAddr<U> {
        type Error = ();
        fn try_from(_: Address<u64, U>) -> Result<Self, Self::Error> {
            Err(())
        }
    }

    pub struct ShimPhysUnencryptedAddr<U>(Address<u64, U>);

    impl<U> ShimPhysUnencryptedAddr<U> {
        pub fn into_mut<'a>(self) -> &'a mut U {
            unsafe { &mut *(self.0 .0 as *mut U) }
        }
    }

    impl<U> TryFrom<ShimVirtAddr<U>> for ShimPhysUnencryptedAddr<U> {
        type Error = ();

        #[inline(always)]
        fn try_from(_: ShimVirtAddr<U>) -> Result<Self, Self::Error> {
            let _a = 0 < unsafe { &_ENARX_SALLYPORT_START as *const _ as u64 };

            Err(())
        }
    }
}
pub mod hostcall {
    extern "C" {
        pub static _ENARX_SALLYPORT_START: Block;
    }
    use std::convert::TryFrom;
    use std::lazy::SyncLazy;

    use crate::addr::{Address, ShimPhysUnencryptedAddr, ShimVirtAddr};

    #[repr(C)]
    #[derive(Copy, Clone)]
    pub struct Block {
        buf: [u8; 100],
    }

    pub static HOST_CALL_ALLOC: SyncLazy<HostCallAllocator> = SyncLazy::new(|| {
        let _a: *mut Block = unsafe {
            let address = Address::<u64, Block>::f(&_ENARX_SALLYPORT_START);
            let shim_virt = ShimVirtAddr::<Block>::try_from(address).unwrap();

            ShimPhysUnencryptedAddr::<Block>::try_from(shim_virt)
                .unwrap()
                .into_mut() as *mut _
        };
        HostCallAllocator([None, None])
    });

    pub struct HostCallAllocator([Option<&'static mut Block>; 2]);
}

fn main() {}

@jonas-schievink would you mind pinging the LLVM crew? I don't know what to do here :(

@hellow554
Copy link
Contributor

With a custom built llvm (and asserts on) I will now get this error every time 🎉

rustc: /home/marcel/projects/rust/llvm-path/src/llvm-project/llvm/include/llvm/Support/Casting.h:269: typename llvm::cast_retty<X, Y*>::ret_type llvm::cast(Y*) [with X = llvm::GlobalValue; Y = llvm::Value; typename llvm::cast_retty<X, Y*>::ret_type = llvm::GlobalValue*]: Assertion `isa<X>(Val) && "cast<Ty>() argument of incompatible type!"' failed.

@jonas-schievink
Copy link
Contributor

@rustbot ping llvm

@rustbot
Copy link
Collaborator

rustbot commented Aug 10, 2021

Hey LLVM ICE-breakers! This bug has been identified as a good
"LLVM ICE-breaking candidate". In case it's useful, here are some
instructions for tackling these sorts of bugs. Maybe take a look?
Thanks! <3

cc @camelid @comex @cuviper @DutchGhost @hdhoang @henryboisdequin @heyrutvik @higuoxing @JOE1994 @jryans @mmilenko @nagisa @nikic @Noah-Kennedy @SiavoshZarrasvand @spastorino @vertexclique

@rustbot rustbot added the ICEBreaker-LLVM Bugs identified for the LLVM ICE-breaker group label Aug 10, 2021
@hellow554
Copy link
Contributor

So, I got this:

#[inline(always)]
fn other_ext() {
    extern "C" {
        pub static _ENARX_SALLYPORT_START: u8;
    }
    unsafe { drop(&_ENARX_SALLYPORT_START) };
}

#[inline(always)]
fn this_ext() {
    extern "C" {
        pub static _ENARX_SALLYPORT_START: u16;
    }
    unsafe { drop(&_ENARX_SALLYPORT_START) };
}

fn main() {
    this_ext();
    other_ext();
}

The key is to have two identical named extern variables with a different type. They have be called and inlined for this to work.

I'm not sure if bisecting here is helpful because it will probably bisect to the LLVM12 merge. But the LLVM people here on the repo should be able to find something :)

Have fun

@haraldh
Copy link
Contributor Author

haraldh commented Aug 10, 2021

Still spurious.

❯ i=1; cargo clean; while ! grep -q 'LLVM ERROR' <(cargo build 2>&1 | tee log); do cargo clean; echo "Pass $i"; ((i++)); done; cat log
Pass 1
   Compiling llvm_erro v0.1.0 (/tmp/sfdgfdgdfgfdg/dfghfdgfd/fdfdgfdg/llvm_erro)
LLVM ERROR: Invalid LLVMRustVisibility value!

❯ i=1; cargo clean; while ! grep -q 'LLVM ERROR' <(cargo build 2>&1 | tee log); do cargo clean; echo "Pass $i"; ((i++)); done; cat log
Pass 1
Pass 2
Pass 3
Pass 4
Pass 5
Pass 6
Pass 7
   Compiling llvm_erro v0.1.0 (/tmp/sfdgfdgdfgfdg/dfghfdgfd/fdfdgfdg/llvm_erro)
LLVM ERROR: Invalid LLVMRustVisibility value!

❯ i=1; cargo clean; while ! grep -q 'LLVM ERROR' <(cargo build 2>&1 | tee log); do cargo clean; echo "Pass $i"; ((i++)); done; cat log
Pass 1
Pass 2
Pass 3
Pass 4
Pass 5
Pass 6
   Compiling llvm_erro v0.1.0 (/tmp/sfdgfdgdfgfdg/dfghfdgfd/fdfdgfdg/llvm_erro)
LLVM ERROR: Invalid LLVMRustVisibility value!

❯ i=1; cargo clean; while ! grep -q 'LLVM ERROR' <(cargo build 2>&1 | tee log); do cargo clean; echo "Pass $i"; ((i++)); done; cat log
Pass 1
   Compiling llvm_erro v0.1.0 (/tmp/sfdgfdgdfgfdg/dfghfdgfd/fdfdgfdg/llvm_erro)
LLVM ERROR: Invalid LLVMRustVisibility value!

@hellow554
Copy link
Contributor

hellow554 commented Aug 10, 2021

Still spurious.

Yes and no.

Quote:

With a custom built llvm (and asserts on) I will now get this error every time 🎉

So the key here is to have a LLVM backend with asserts enabled. AFAIK this is only possible to have when you build LLVM on your own (using x.py) and not with a pre-built build artifact.
There are the -alt builds which have asserts enabled and they give me the same result as my local built rustc (which is unsurprising and expected ;) )
You can use https://github.com/kennytm/rustup-toolchain-install-master to install them.

@apiraino
Copy link
Contributor

Assigning priority based on the discussion for #87933 in the Zulip thread of the Prioritization Working Group.

@rustbot label +regression-from-stable-to-stable +P-high

@rustbot rustbot added P-high High priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. labels Aug 12, 2021
@hellow554
Copy link
Contributor

Still an issue even with the LLVM13 upgrade :/

@cuviper
Copy link
Member

cuviper commented Nov 19, 2021

Valgrind gave me a little more clue where this is coming from for #91050.
(Assuming it is indeed the same issue, but it seems likely.)

@haraldh
Copy link
Contributor Author

haraldh commented Nov 22, 2021

seems to be fixed.. thank you!

fw-immunant added a commit to immunant/c2rust that referenced this issue Apr 12, 2022
this is necessary to make the testsuite pass; otherwise, curl and libxml hit rust-lang/rust#87813 now that we translate their inline asm (which only appears from transitive includes on ubuntu 18.04)
fw-immunant added a commit to immunant/c2rust that referenced this issue Apr 12, 2022
this is necessary to make the testsuite pass; otherwise, curl and libxml hit rust-lang/rust#87813 now that we translate their inline asm (which only appears from transitive includes on ubuntu 18.04)
fw-immunant added a commit to immunant/c2rust that referenced this issue Apr 12, 2022
this is necessary to make the testsuite pass; otherwise, curl and libxml hit rust-lang/rust#87813 now that we translate their inline asm (which only appears from transitive includes on ubuntu 18.04)
fw-immunant added a commit to immunant/c2rust that referenced this issue Apr 13, 2022
this is necessary to make the testsuite pass; otherwise, curl and libxml hit rust-lang/rust#87813 now that we translate their inline asm (which only appears from transitive includes on ubuntu 18.04)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ ICEBreaker-LLVM Bugs identified for the LLVM ICE-breaker group P-high High priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants