cdisselkoen / llvm-ir

LLVM IR in natural Rust data structures
MIT License
550 stars 46 forks source link

Read bitcode casuses stack overflow #27

Open feldeg opened 1 year ago

feldeg commented 1 year ago

Hi,

I got the following code

#[no_mangle]
fn foo() -> i32 {
    let a = 41 + 42;
    return a;
}

fn main() {
    println!("The magic number {}", foo());
}

That I compile this with

RUSTFLAGS="--emit=llvm-bc --emit=llvm-ir -Clto -Cembed-bitcode=yes" cargo build

where the rustc version is 1.63.

When trying to read this file with the simple program

use llvm_ir::Module;

fn main() {
    let path = "foo.bc";
    let module = Module::from_bc_path(path).unwrap();
    println!("Done parsing");
}

it throws a stack overflowed error when running cargo run. I've tried to increase my stack with ulimit -s all the way up to 2097152kb but with no different result.

When digging thru the code I'd assume when collecting from from_llvm_ref of the different modules it blows the stack. I guess the solution is to wrap each Vec with Box or Rc in order for it to put it on the heap or is there any other solution?

Running the latest commit on llvm-ir (552d11e18079ff8e9187e49d6dc07da715192947) and on a Ubuntu 20.04.

Cheers!

cdisselkoen commented 1 year ago

Can you attach the foo.bc file?

I'd be surprised if it's so large that from_llvm_ref blows the stack even for a stack of size 2GB. My first guess is there must be some infinite recursion in from_llvm_ref somewhere due to something in the particular bitcode for this file.

Does the issue only occur with the -Clto -Cembed-bitcode=yes flags, or does it still happen with either of those flags removed?

feldeg commented 1 year ago

Absolutely. Uploaded it here https://github.com/feldeg/foo/blob/main/foo.bc sha256sum c6b89e1c9dfef78a74c24e55d39c47853df1fefb517119bccbc2bb2fb00f697a

Smart, actually I never thought that the bc code itself could cause an infinite recursion but now when I think about it, it sure does make sense. That would probably be solved by using each block/function as a leaf and have a visit bool or am I dumb thinking in that direction?

Yes, I've only notice this issue when the those flags are added.

cdisselkoen commented 1 year ago

Yep, I can reproduce the issue with that foo.bc file. However, running in gdb is giving me a SIGBUS error (with no useful backtrace) rather than the stack overflow that I get without gdb.

feldeg commented 1 year ago

Sorry about the late response, life came in the way.

This is interesting. When I run it with gdb I get a SIGSEGV error and can do some sort of backtrace. It seems like it crashes on https://github.com/cdisselkoen/llvm-ir/blob/6bbb1e42575c4c2c685844bc4280648588bae207/src/types.rs#L920 if I understand the bt correct?

#0  0x0000555555add297 in core::num::<impl u64>::wrapping_add (self=0x74eeb85354094b66, rhs=0xf440268503b5ccd9) at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/core/src/num/uint_macros.rs:1184
#1  <core::hash::sip::Sip13Rounds as core::hash::sip::Sip>::d_rounds (state=0x7fffff7ff2b8) at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/core/src/hash/sip.rs:378
#2  0x00005555559fe0e4 in <core::hash::sip::Hasher<S> as core::hash::Hasher>::finish (self=0x7fffff7ff348) at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/core/src/hash/sip.rs:332
#3  0x0000555555adce7f in <core::hash::sip::SipHasher13 as core::hash::Hasher>::finish (self=0x7fffff7ff348) at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/core/src/hash/sip.rs:254
#4  0x0000555555ab8dce in <std::collections::hash::map::DefaultHasher as core::hash::Hasher>::finish (self=0x7fffff7ff348) at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/collections/hash/map.rs:3189
#5  0x0000555555ac2c43 in core::hash::BuildHasher::hash_one (self=0x7fffffffa918, x=0x7fffff7ff4b0) at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/core/src/hash/mod.rs:707
#6  0x0000555555ab2714 in hashbrown::map::make_hash (hash_builder=0x7fffffffa918, val=0x7fffff7ff4b0) at /cargo/registry/src/github.com-1ecc6299db9ec823/hashbrown-0.12.3/src/map.rs:265
#7  0x0000555555ab1c50 in hashbrown::map::HashMap<K,V,S,A>::get_inner (self=0x7fffffffa918, k=0x7fffff7ff4b0) at /cargo/registry/src/github.com-1ecc6299db9ec823/hashbrown-0.12.3/src/map.rs:1270
#8  0x0000555555aafa74 in hashbrown::map::HashMap<K,V,S,A>::get (self=0x7fffffffa918, k=0x7fffff7ff4b0) at /cargo/registry/src/github.com-1ecc6299db9ec823/hashbrown-0.12.3/src/map.rs:1223
#9  0x0000555555ac1154 in std::collections::hash::map::HashMap<K,V,S>::get (self=0x7fffffffa918, k=0x7fffff7ff4b0) at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/std/src/collections/hash/map.rs:879
#10 0x0000555555a050b5 in llvm_ir::types::TypesBuilder::type_from_llvm_ref (self=0x7fffffffa738, ty=0x555556847b90) at src/types.rs:921
#11 0x0000555555a0575e in llvm_ir::types::TypesBuilder::parse_type_from_llvm_ref (self=0x7fffffffa738, ty=0x555556847bc0) at src/types.rs:940
#12 0x0000555555a050f9 in llvm_ir::types::TypesBuilder::type_from_llvm_ref (self=0x7fffffffa738, ty=0x555556847bc0) at src/types.rs:926
#13 0x0000555555a00c89 in llvm_ir::types::TypesBuilder::struct_type_from_llvm_ref::{{closure}} (t=0x555556847bc0) at src/types.rs:1057
#14 0x0000555555a73a0e in <core::iter::adapters::map::Map<I,F> as core::iter::traits::iterator::Iterator>::__iterator_get_unchecked (self=0x7fffff7ffc38, idx=0x1) at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/core/src/iter/adapters/map.rs:134
#15 0x0000555555a7bad8 in <I as alloc::vec::in_place_collect::SpecInPlaceCollect<T,I>>::collect_in_place (self=0x7fffff7ffc38, dst_buf=0x555559e2fac0, end=0x555559e2fad8) at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/alloc/src/vec/in_place_collect.rs:272
#16 0x0000555555a8672d in alloc::vec::in_place_collect::<impl alloc::vec::spec_from_iter::SpecFromIter<T,I> for alloc::vec::Vec<T>>::from_iter (iterator=...) at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/alloc/src/vec/in_place_collect.rs:178
#17 0x0000555555a89b2d in <alloc::vec::Vec<T> as core::iter::traits::collect::FromIterator<T>>::from_iter (iter=...) at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/alloc/src/vec/mod.rs:2645
#18 0x0000555555a7653c in core::iter::traits::iterator::Iterator::collect (self=...) at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/core/src/iter/traits/iterator.rs:1792
#19 0x0000555555a061d2 in llvm_ir::types::TypesBuilder::struct_type_from_llvm_ref (self=0x7fffffffa738, ty=0x555556847b50) at src/types.rs:1055
#20 0x0000555555a059a4 in llvm_ir::types::TypesBuilder::parse_type_from_llvm_ref (self=0x7fffffffa738, ty=0x555556847b50) at src/types.rs:999
#21 0x0000555555a050f9 in llvm_ir::types::TypesBuilder::type_from_llvm_ref (self=0x7fffffffa738, ty=0x555556847b50) at src/types.rs:926
#22 0x0000555555a0575e in llvm_ir::types::TypesBuilder::parse_type_from_llvm_ref (self=0x7fffffffa738, ty=0x555556847b70) at src/types.rs:940
#23 0x0000555555a050f9 in llvm_ir::types::TypesBuilder::type_from_llvm_ref (self=0x7fffffffa738, ty=0x555556847b70) at src/types.rs:926
#24 0x0000555555a00c59 in llvm_ir::types::TypesBuilder::parse_type_from_llvm_ref::{{closure}} (t=0x555556847b70) at src/types.rs:1013
#25 0x0000555555a73ace in <core::iter::adapters::map::Map<I,F> as core::iter::traits::iterator::Iterator>::__iterator_get_unchecked (self=0x7fffff800978, idx=0x1) at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/core/src/iter/adapters/map.rs:134
#26 0x0000555555a7b3e8 in <I as alloc::vec::in_place_collect::SpecInPlaceCollect<T,I>>::collect_in_place (self=0x7fffff800978, dst_buf=0x555559e2faa0, end=0x555559e2fab0) at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/alloc/src/vec/in_place_collect.rs:272
#27 0x0000555555a8583d in alloc::vec::in_place_collect::<impl alloc::vec::spec_from_iter::SpecFromIter<T,I> for alloc::vec::Vec<T>>::from_iter (iterator=...) at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/alloc/src/vec/in_place_collect.rs:178
#28 0x0000555555a8a15d in <alloc::vec::Vec<T> as core::iter::traits::collect::FromIterator<T>>::from_iter (iter=...) at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/alloc/src/vec/mod.rs:2645
#29 0x0000555555a7657c in core::iter::traits::iterator::Iterator::collect (self=...) at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/core/src/iter/traits/iterator.rs:1792
#30 0x0000555555a05ec1 in llvm_ir::types::TypesBuilder::parse_type_from_llvm_ref (self=0x7fffffffa738, ty=0x555556847b90) at src/types.rs:1011
#31 0x0000555555a050f9 in llvm_ir::types::TypesBuilder::type_from_llvm_ref (self=0x7fffffffa738, ty=0x555556847b90) at src/types.rs:926
#32 0x0000555555a0575e in llvm_ir::types::TypesBuilder::parse_type_from_llvm_ref (self=0x7fffffffa738, ty=0x555556847bc0) at src/types.rs:940
#33 0x0000555555a050f9 in llvm_ir::types::TypesBuilder::type_from_llvm_ref (self=0x7fffffffa738, ty=0x555556847bc0) at src/types.rs:926
#34 0x0000555555a00c89 in llvm_ir::types::TypesBuilder::struct_type_from_llvm_ref::{{closure}} (t=0x555556847bc0) at src/types.rs:1057
#35 0x0000555555a73a0e in <core::iter::adapters::map::Map<I,F> as core::iter::traits::iterator::Iterator>::__iterator_get_unchecked (self=0x7fffff801588, idx=0x1) at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/core/src/iter/adapters/map.rs:134
#36 0x0000555555a7bad8 in <I as alloc::vec::in_place_collect::SpecInPlaceCollect<T,I>>::collect_in_place (self=0x7fffff801588, dst_buf=0x555559e2fa80, end=0x555559e2fa98) at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/alloc/src/vec/in_place_collect.rs:272
#37 0x0000555555a8672d in alloc::vec::in_place_collect::<impl alloc::vec::spec_from_iter::SpecFromIter<T,I> for alloc::vec::Vec<T>>::from_iter (iterator=...) at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/alloc/src/vec/in_place_collect.rs:178
#38 0x0000555555a89b2d in <alloc::vec::Vec<T> as core::iter::traits::collect::FromIterator<T>>::from_iter (iter=...) at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/alloc/src/vec/mod.rs:2645
#39 0x0000555555a7653c in core::iter::traits::iterator::Iterator::collect (self=...) at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/core/src/iter/traits/iterator.rs:1792
#40 0x0000555555a061d2 in llvm_ir::types::TypesBuilder::struct_type_from_llvm_ref (self=0x7fffffffa738, ty=0x555556847b50) at src/types.rs:1055
#41 0x0000555555a059a4 in llvm_ir::types::TypesBuilder::parse_type_from_llvm_ref (self=0x7fffffffa738, ty=0x555556847b50) at src/types.rs:999
#42 0x0000555555a050f9 in llvm_ir::types::TypesBuilder::type_from_llvm_ref (self=0x7fffffffa738, ty=0x555556847b50) at src/types.rs:926
#43 0x0000555555a0575e in llvm_ir::types::TypesBuilder::parse_type_from_llvm_ref (self=0x7fffffffa738, ty=0x555556847b70) at src/types.rs:940
#44 0x0000555555a050f9 in llvm_ir::types::TypesBuilder::type_from_llvm_ref (self=0x7fffffffa738, ty=0x555556847b70) at src/types.rs:926
#45 0x0000555555a00c59 in llvm_ir::types::TypesBuilder::parse_type_from_llvm_ref::{{closure}} (t=0x555556847b70) at src/types.rs:1013
#46 0x0000555555a73ace in <core::iter::adapters::map::Map<I,F> as core::iter::traits::iterator::Iterator>::__iterator_get_unchecked (self=0x7fffff8022c8, idx=0x1) at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/core/src/iter/adapters/map.rs:134
#47 0x0000555555a7b3e8 in <I as alloc::vec::in_place_collect::SpecInPlaceCollect<T,I>>::collect_in_place (self=0x7fffff8022c8, dst_buf=0x555559e2fa60, end=0x555559e2fa70) at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/alloc/src/vec/in_place_collect.rs:272
#48 0x0000555555a8583d in alloc::vec::in_place_collect::<impl alloc::vec::spec_from_iter::SpecFromIter<T,I> for alloc::vec::Vec<T>>::from_iter (iterator=...) at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/alloc/src/vec/in_place_collect.rs:178
#49 0x0000555555a8a15d in <alloc::vec::Vec<T> as core::iter::traits::collect::FromIterator<T>>::from_iter (iter=...) at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/alloc/src/vec/mod.rs:2645
#50 0x0000555555a7657c in core::iter::traits::iterator::Iterator::collect (self=...) at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/core/src/iter/traits/iterator.rs:1792
#51 0x0000555555a05ec1 in llvm_ir::types::TypesBuilder::parse_type_from_llvm_ref (self=0x7fffffffa738, ty=0x555556847b90) at src/types.rs:1011
#52 0x0000555555a050f9 in llvm_ir::types::TypesBuilder::type_from_llvm_ref (self=0x7fffffffa738, ty=0x555556847b90) at src/types.rs:926
#53 0x0000555555a0575e in llvm_ir::types::TypesBuilder::parse_type_from_llvm_ref (self=0x7fffffffa738, ty=0x555556847bc0) at src/types.rs:940
#54 0x0000555555a050f9 in llvm_ir::types::TypesBuilder::type_from_llvm_ref (self=0x7fffffffa738, ty=0x555556847bc0) at src/types.rs:926
#55 0x0000555555a00c89 in llvm_ir::types::TypesBuilder::struct_type_from_llvm_ref::{{closure}} (t=0x555556847bc0) at src/types.rs:1057
#56 0x0000555555a73a0e in <core::iter::adapters::map::Map<I,F> as core::iter::traits::iterator::Iterator>::__iterator_get_unchecked (self=0x7fffff802ed8, idx=0x1) at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/core/src/iter/adapters/map.rs:134
#57 0x0000555555a7bad8 in <I as alloc::vec::in_place_collect::SpecInPlaceCollect<T,I>>::collect_in_place (self=0x7fffff802ed8, dst_buf=0x555559e2fa40, end=0x555559e2fa58) at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/alloc/src/vec/in_place_collect.rs:272
#58 0x0000555555a8672d in alloc::vec::in_place_collect::<impl alloc::vec::spec_from_iter::SpecFromIter<T,I> for alloc::vec::Vec<T>>::from_iter (iterator=...) at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/alloc/src/vec/in_place_collect.rs:178
#59 0x0000555555a89b2d in <alloc::vec::Vec<T> as core::iter::traits::collect::FromIterator<T>>::from_iter (iter=...) at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/alloc/src/vec/mod.rs:2645
#60 0x0000555555a7653c in core::iter::traits::iterator::Iterator::collect (self=...) at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/core/src/iter/traits/iterator.rs:1792
#61 0x0000555555a061d2 in llvm_ir::types::TypesBuilder::struct_type_from_llvm_ref (self=0x7fffffffa738, ty=0x555556847b50) at src/types.rs:1055
#62 0x0000555555a059a4 in llvm_ir::types::TypesBuilder::parse_type_from_llvm_ref (self=0x7fffffffa738, ty=0x555556847b50) at src/types.rs:999
#63 0x0000555555a050f9 in llvm_ir::types::TypesBuilder::type_from_llvm_ref (self=0x7fffffffa738, ty=0x555556847b50) at src/types.rs:926
#64 0x0000555555a0575e in llvm_ir::types::TypesBuilder::parse_type_from_llvm_ref (self=0x7fffffffa738, ty=0x555556847b70) at src/types.rs:940
#65 0x0000555555a050f9 in llvm_ir::types::TypesBuilder::type_from_llvm_ref (self=0x7fffffffa738, ty=0x555556847b70) at src/types.rs:926
#66 0x0000555555a00c59 in llvm_ir::types::TypesBuilder::parse_type_from_llvm_ref::{{closure}} (t=0x555556847b70) at src/types.rs:1013
#67 0x0000555555a73ace in <core::iter::adapters::map::Map<I,F> as core::iter::traits::iterator::Iterator>::__iterator_get_unchecked (self=0x7fffff803c18, idx=0x1) at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/core/src/iter/adapters/map.rs:134
#68 0x0000555555a7b3e8 in <I as alloc::vec::in_place_collect::SpecInPlaceCollect<T,I>>::collect_in_place (self=0x7fffff803c18, dst_buf=0x555559e2fa20, end=0x555559e2fa30) at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/alloc/src/vec/in_place_collect.rs:272
#69 0x0000555555a8583d in alloc::vec::in_place_collect::<impl alloc::vec::spec_from_iter::SpecFromIter<T,I> for alloc::vec::Vec<T>>::from_iter (iterator=...) at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/alloc/src/vec/in_place_collect.rs:178
#70 0x0000555555a8a15d in <alloc::vec::Vec<T> as core::iter::traits::collect::FromIterator<T>>::from_iter (iter=...) at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/alloc/src/vec/mod.rs:2645
#71 0x0000555555a7657c in core::iter::traits::iterator::Iterator::collect (self=...) at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/core/src/iter/traits/iterator.rs:1792
#72 0x0000555555a05ec1 in llvm_ir::types::TypesBuilder::parse_type_from_llvm_ref (self=0x7fffffffa738, ty=0x555556847b90) at src/types.rs:1011
#73 0x0000555555a050f9 in llvm_ir::types::TypesBuilder::type_from_llvm_ref (self=0x7fffffffa738, ty=0x555556847b90) at src/types.rs:926
#74 0x0000555555a0575e in llvm_ir::types::TypesBuilder::parse_type_from_llvm_ref (self=0x7fffffffa738, ty=0x555556847bc0) at src/types.rs:940
#75 0x0000555555a050f9 in llvm_ir::types::TypesBuilder::type_from_llvm_ref (self=0x7fffffffa738, ty=0x555556847bc0) at src/types.rs:926
#76 0x0000555555a00c89 in llvm_ir::types::TypesBuilder::struct_type_from_llvm_ref::{{closure}} (t=0x555556847bc0) at src/types.rs:1057
#77 0x0000555555a73a0e in <core::iter::adapters::map::Map<I,F> as core::iter::traits::iterator::Iterator>::__iterator_get_unchecked (self=0x7fffff804828, idx=0x1) at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/core/src/iter/adapters/map.rs:134
#78 0x0000555555a7bad8 in <I as alloc::vec::in_place_collect::SpecInPlaceCollect<T,I>>::collect_in_place (self=0x7fffff804828, dst_buf=0x555559e2fa00, end=0x555559e2fa18) at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/alloc/src/vec/in_place_collect.rs:272
#79 0x0000555555a8672d in alloc::vec::in_place_collect::<impl alloc::vec::spec_from_iter::SpecFromIter<T,I> for alloc::vec::Vec<T>>::from_iter (iterator=...) at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/alloc/src/vec/in_place_collect.rs:178
#80 0x0000555555a89b2d in <alloc::vec::Vec<T> as core::iter::traits::collect::FromIterator<T>>::from_iter (iter=...) at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/alloc/src/vec/mod.rs:2645
#81 0x0000555555a7653c in core::iter::traits::iterator::Iterator::collect (self=...) at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/core/src/iter/traits/iterator.rs:1792
#82 0x0000555555a061d2 in llvm_ir::types::TypesBuilder::struct_type_from_llvm_ref (self=0x7fffffffa738, ty=0x555556847b50) at src/types.rs:1055
#83 0x0000555555a059a4 in llvm_ir::types::TypesBuilder::parse_type_from_llvm_ref (self=0x7fffffffa738, ty=0x555556847b50) at src/types.rs:999
#84 0x0000555555a050f9 in llvm_ir::types::TypesBuilder::type_from_llvm_ref (self=0x7fffffffa738, ty=0x555556847b50) at src/types.rs:926
#85 0x0000555555a0575e in llvm_ir::types::TypesBuilder::parse_type_from_llvm_ref (self=0x7fffffffa738, ty=0x555556847b70) at src/types.rs:940
#86 0x0000555555a050f9 in llvm_ir::types::TypesBuilder::type_from_llvm_ref (self=0x7fffffffa738, ty=0x555556847b70) at src/types.rs:926
#87 0x0000555555a00c59 in llvm_ir::types::TypesBuilder::parse_type_from_llvm_ref::{{closure}} (t=0x555556847b70) at src/types.rs:1013
#88 0x0000555555a73ace in <core::iter::adapters::map::Map<I,F> as core::iter::traits::iterator::Iterator>::__iterator_get_unchecked (self=0x7fffff805568, idx=0x1) at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/core/src/iter/adapters/map.rs:134
#89 0x0000555555a7b3e8 in <I as alloc::vec::in_place_collect::SpecInPlaceCollect<T,I>>::collect_in_place (self=0x7fffff805568, dst_buf=0x555559e2f9e0, end=0x555559e2f9f0) at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/alloc/src/vec/in_place_collect.rs:272
#90 0x0000555555a8583d in alloc::vec::in_place_collect::<impl alloc::vec::spec_from_iter::SpecFromIter<T,I> for alloc::vec::Vec<T>>::from_iter (iterator=...) at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/alloc/src/vec/in_place_collect.rs:178
#91 0x0000555555a8a15d in <alloc::vec::Vec<T> as core::iter::traits::collect::FromIterator<T>>::from_iter (iter=...) at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/alloc/src/vec/mod.rs:2645
#92 0x0000555555a7657c in core::iter::traits::iterator::Iterator::collect (self=...) at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/core/src/iter/traits/iterator.rs:1792
#93 0x0000555555a05ec1 in llvm_ir::types::TypesBuilder::parse_type_from_llvm_ref (self=0x7fffffffa738, ty=0x555556847b90) at src/types.rs:1011
#94 0x0000555555a050f9 in llvm_ir::types::TypesBuilder::type_from_llvm_ref (self=0x7fffffffa738, ty=0x555556847b90) at src/types.rs:926
#95 0x0000555555a0575e in llvm_ir::types::TypesBuilder::parse_type_from_llvm_ref (self=0x7fffffffa738, ty=0x555556847bc0) at src/types.rs:940
#96 0x0000555555a050f9 in llvm_ir::types::TypesBuilder::type_from_llvm_ref (self=0x7fffffffa738, ty=0x555556847bc0) at src/types.rs:926
#97 0x0000555555a00c89 in llvm_ir::types::TypesBuilder::struct_type_from_llvm_ref::{{closure}} (t=0x555556847bc0) at src/types.rs:1057
#98 0x0000555555a73a0e in <core::iter::adapters::map::Map<I,F> as core::iter::traits::iterator::Iterator>::__iterator_get_unchecked (self=0x7fffff806178, idx=0x1) at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/core/src/iter/adapters/map.rs:134
#99 0x0000555555a7bad8 in <I as alloc::vec::in_place_collect::SpecInPlaceCollect<T,I>>::collect_in_place (self=0x7fffff806178, dst_buf=0x555559e2f9c0, end=0x555559e2f9d8) at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/alloc/src/vec/in_place_collect.rs:272
cdisselkoen commented 1 year ago

It seems like the problem is that this bitcode contains an anonymous struct type that is somehow infinitely recursive. If my investigation is correct, the problem struct type has 3 fields, one of which is a pointer to something that contains the same anonymous struct type.

For named struct types we properly handle this recursion (that's one of the major purposes of NamedStructType), but we don't for anonymous struct types, and I'm not immediately sure what the proper fix is. Probably the optimization done by -Clto -Cembed-bitcode=yes is removing the struct name, and that's causing this issue.