JuliaHubOSS / llvm-cbe

resurrected LLVM "C Backend", with improvements
Other
826 stars 141 forks source link

Undefined symbols when building hello world Rust program #109

Closed XAMPPRocky closed 3 years ago

XAMPPRocky commented 3 years ago

Consider the following Rust code:

fn main() {
    println!("Hello World!");
}

This can be compiled using the following.

  1. Install Rust
  2. cargo new --lib cbe-test
  3. Paste the above code into src/lib.rs
  4. cargo rustc -- --emit llvm-ir
  5. In your target/debug/deps folder there should be an cbe-test.ll or similar file.
  6. llvm-cbe ./cbe-test.ll -o cbe-test.c
  7. clang cbe-test.c

You get the following error.

scratchpad.c:128:67: warning: declaration of 'struct l_struct_unwind_KD__KD_libunwind_KD__KD__Unwind_Exception' will not be visible outside of this function [-Wvisibility]
uint32_t rust_eh_personality(uint32_t, uint32_t, uint64_t, struct l_struct_unwind_KD__KD_libunwind_KD__KD__Unwind_Exception*, void*) __ATTRIBUTELIST__((nothrow));
                                                                  ^
1 warning generated.
Undefined symbols for architecture x86_64:
  "std::io::stdio::_print::hea90da9dad6f182d", referenced from:
      scratchpad::main::h3e4e0a32c31c7911 in scratchpad-763b88.o
  "std::rt::lang_start_internal::h86f505dc7de50d93", referenced from:
      std::rt::lang_start::h3d503a6b6a81c10b in scratchpad-763b88.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
LLVM IR

``` ; ModuleID = '2cwjgb4q3tsf1uv9' source_filename = "2cwjgb4q3tsf1uv9" target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" target triple = "x86_64-apple-macosx10.7.0" %"std::fmt::Arguments" = type { [0 x i64], { [0 x { [0 x i8]*, i64 }]*, i64 }, [0 x i64], { i64*, i64 }, [0 x i64], { [0 x { i8*, i64* }]*, i64 }, [0 x i64] } %"unwind::libunwind::_Unwind_Exception" = type { [0 x i64], i64, [0 x i64], void (i32, %"unwind::libunwind::_Unwind_Exception"*)*, [0 x i64], [6 x i64], [0 x i64] } %"unwind::libunwind::_Unwind_Context" = type { [0 x i8] } @vtable.0 = private unnamed_addr constant { void (i64**)*, i64, i64, i32 (i64**)*, i32 (i64**)*, i32 (i64**)* } { void (i64**)* @"_ZN4core3ptr85drop_in_place$LT$std..rt..lang_start$LT$$LP$$RP$$GT$..$u7b$$u7b$closure$u7d$$u7d$$GT$17h1f2c731336d07166E", i64 8, i64 8, i32 (i64**)* @"_ZN3std2rt10lang_start28_$u7b$$u7b$closure$u7d$$u7d$17he0db835a6152dd3dE", i32 (i64**)* @"_ZN3std2rt10lang_start28_$u7b$$u7b$closure$u7d$$u7d$17he0db835a6152dd3dE", i32 (i64**)* @"_ZN4core3ops8function6FnOnce40call_once$u7b$$u7b$vtable.shim$u7d$$u7d$17h07a3d3e0729b96baE" }, align 8, !dbg !0 @alloc1 = private unnamed_addr constant <{ [13 x i8] }> <{ [13 x i8] c"Hello World!\0A" }>, align 1 @alloc2 = private unnamed_addr constant <{ i8*, [8 x i8] }> <{ i8* getelementptr inbounds (<{ [13 x i8] }>, <{ [13 x i8] }>* @alloc1, i32 0, i32 0, i32 0), [8 x i8] c"\0D\00\00\00\00\00\00\00" }>, align 8 @alloc4 = private unnamed_addr constant <{ [0 x i8] }> zeroinitializer, align 8 ; std::sys_common::backtrace::__rust_begin_short_backtrace ; Function Attrs: noinline uwtable define internal void @_ZN3std10sys_common9backtrace28__rust_begin_short_backtrace17hdab553cbc2abb651E(void ()* nonnull %f) unnamed_addr #0 personality i32 (i32, i32, i64, %"unwind::libunwind::_Unwind_Exception"*, %"unwind::libunwind::_Unwind_Context"*)* @rust_eh_personality !dbg !38 { start: %0 = alloca { i8*, i32 }, align 8 %f.dbg.spill = alloca void ()*, align 8 %result.dbg.spill = alloca {}, align 1 %_5 = alloca {}, align 1 %_3 = alloca {}, align 1 call void @llvm.dbg.declare(metadata {}* %result.dbg.spill, metadata !46, metadata !DIExpression()), !dbg !52 store void ()* %f, void ()** %f.dbg.spill, align 8 call void @llvm.dbg.declare(metadata void ()** %f.dbg.spill, metadata !45, metadata !DIExpression()), !dbg !53 ; call core::ops::function::FnOnce::call_once call void @_ZN4core3ops8function6FnOnce9call_once17h21a5088bccbb7ceeE(void ()* nonnull %f), !dbg !54 br label %bb1, !dbg !54 bb1: ; preds = %start ; invoke core::hint::black_box invoke void @_ZN4core4hint9black_box17hfabbc7664b85073eE() to label %bb2 unwind label %cleanup, !dbg !55 bb2: ; preds = %bb1 ret void, !dbg !56 bb3: ; preds = %cleanup br label %bb4, !dbg !57 bb4: ; preds = %bb3 %1 = bitcast { i8*, i32 }* %0 to i8**, !dbg !58 %2 = load i8*, i8** %1, align 8, !dbg !58 %3 = getelementptr inbounds { i8*, i32 }, { i8*, i32 }* %0, i32 0, i32 1, !dbg !58 %4 = load i32, i32* %3, align 8, !dbg !58 %5 = insertvalue { i8*, i32 } undef, i8* %2, 0, !dbg !58 %6 = insertvalue { i8*, i32 } %5, i32 %4, 1, !dbg !58 resume { i8*, i32 } %6, !dbg !58 cleanup: ; preds = %bb1 %7 = landingpad { i8*, i32 } cleanup %8 = extractvalue { i8*, i32 } %7, 0 %9 = extractvalue { i8*, i32 } %7, 1 %10 = getelementptr inbounds { i8*, i32 }, { i8*, i32 }* %0, i32 0, i32 0 store i8* %8, i8** %10, align 8 %11 = getelementptr inbounds { i8*, i32 }, { i8*, i32 }* %0, i32 0, i32 1 store i32 %9, i32* %11, align 8 br label %bb3 } ; std::rt::lang_start ; Function Attrs: uwtable define hidden i64 @_ZN3std2rt10lang_start17h3d503a6b6a81c10bE(void ()* nonnull %main, i64 %argc, i8** %argv) unnamed_addr #1 !dbg !59 { start: %argv.dbg.spill = alloca i8**, align 8 %argc.dbg.spill = alloca i64, align 8 %main.dbg.spill = alloca void ()*, align 8 %_7 = alloca i64*, align 8 store void ()* %main, void ()** %main.dbg.spill, align 8 call void @llvm.dbg.declare(metadata void ()** %main.dbg.spill, metadata !67, metadata !DIExpression()), !dbg !71 store i64 %argc, i64* %argc.dbg.spill, align 8 call void @llvm.dbg.declare(metadata i64* %argc.dbg.spill, metadata !68, metadata !DIExpression()), !dbg !72 store i8** %argv, i8*** %argv.dbg.spill, align 8 call void @llvm.dbg.declare(metadata i8*** %argv.dbg.spill, metadata !69, metadata !DIExpression()), !dbg !73 %0 = bitcast i64** %_7 to void ()**, !dbg !74 store void ()* %main, void ()** %0, align 8, !dbg !74 %_4.0 = bitcast i64** %_7 to {}*, !dbg !75 ; call std::rt::lang_start_internal %1 = call i64 @_ZN3std2rt19lang_start_internal17h86f505dc7de50d93E({}* nonnull align 1 %_4.0, [3 x i64]* noalias readonly align 8 dereferenceable(24) bitcast ({ void (i64**)*, i64, i64, i32 (i64**)*, i32 (i64**)*, i32 (i64**)* }* @vtable.0 to [3 x i64]*), i64 %argc, i8** %argv), !dbg !76 br label %bb1, !dbg !76 bb1: ; preds = %start ret i64 %1, !dbg !77 } ; std::rt::lang_start::{{closure}} ; Function Attrs: inlinehint uwtable define internal i32 @"_ZN3std2rt10lang_start28_$u7b$$u7b$closure$u7d$$u7d$17he0db835a6152dd3dE"(i64** noalias readonly align 8 dereferenceable(8) %_1) unnamed_addr #2 !dbg !78 { start: %_1.dbg.spill = alloca i64**, align 8 store i64** %_1, i64*** %_1.dbg.spill, align 8 call void @llvm.dbg.declare(metadata i64*** %_1.dbg.spill, metadata !84, metadata !DIExpression(DW_OP_deref)), !dbg !85 %0 = bitcast i64** %_1 to void ()**, !dbg !86 %_3 = load void ()*, void ()** %0, align 8, !dbg !86, !nonnull !4 ; call std::sys_common::backtrace::__rust_begin_short_backtrace call void @_ZN3std10sys_common9backtrace28__rust_begin_short_backtrace17hdab553cbc2abb651E(void ()* nonnull %_3), !dbg !87 br label %bb1, !dbg !87 bb1: ; preds = %start ; call <() as std::process::Termination>::report %1 = call i32 @"_ZN54_$LT$$LP$$RP$$u20$as$u20$std..process..Termination$GT$6report17h381b611d03f4782aE"(), !dbg !87 br label %bb2, !dbg !87 bb2: ; preds = %bb1 ret i32 %1, !dbg !88 } ; std::sys::unix::process::process_common::ExitCode::as_i32 ; Function Attrs: inlinehint uwtable define internal i32 @_ZN3std3sys4unix7process14process_common8ExitCode6as_i3217he414c8ec5ab83350E(i8* noalias readonly align 1 dereferenceable(1) %self) unnamed_addr #2 !dbg !89 { start: %self.dbg.spill = alloca i8*, align 8 store i8* %self, i8** %self.dbg.spill, align 8 call void @llvm.dbg.declare(metadata i8** %self.dbg.spill, metadata !102, metadata !DIExpression()), !dbg !103 %_2 = load i8, i8* %self, align 1, !dbg !104 %0 = zext i8 %_2 to i32, !dbg !104 ret i32 %0, !dbg !105 } ; core::fmt::Arguments::new_v1 ; Function Attrs: inlinehint uwtable define internal void @_ZN4core3fmt9Arguments6new_v117h13e4f70e15a317eeE(%"std::fmt::Arguments"* noalias nocapture sret dereferenceable(48) %0, [0 x { [0 x i8]*, i64 }]* noalias nonnull readonly align 8 %pieces.0, i64 %pieces.1, [0 x { i8*, i64* }]* noalias nonnull readonly align 8 %args.0, i64 %args.1) unnamed_addr #2 !dbg !106 { start: %args.dbg.spill = alloca { [0 x { i8*, i64* }]*, i64 }, align 8 %pieces.dbg.spill = alloca { [0 x { [0 x i8]*, i64 }]*, i64 }, align 8 %_4 = alloca { i64*, i64 }, align 8 %1 = getelementptr inbounds { [0 x { [0 x i8]*, i64 }]*, i64 }, { [0 x { [0 x i8]*, i64 }]*, i64 }* %pieces.dbg.spill, i32 0, i32 0 store [0 x { [0 x i8]*, i64 }]* %pieces.0, [0 x { [0 x i8]*, i64 }]** %1, align 8 %2 = getelementptr inbounds { [0 x { [0 x i8]*, i64 }]*, i64 }, { [0 x { [0 x i8]*, i64 }]*, i64 }* %pieces.dbg.spill, i32 0, i32 1 store i64 %pieces.1, i64* %2, align 8 call void @llvm.dbg.declare(metadata { [0 x { [0 x i8]*, i64 }]*, i64 }* %pieces.dbg.spill, metadata !218, metadata !DIExpression()), !dbg !220 %3 = getelementptr inbounds { [0 x { i8*, i64* }]*, i64 }, { [0 x { i8*, i64* }]*, i64 }* %args.dbg.spill, i32 0, i32 0 store [0 x { i8*, i64* }]* %args.0, [0 x { i8*, i64* }]** %3, align 8 %4 = getelementptr inbounds { [0 x { i8*, i64* }]*, i64 }, { [0 x { i8*, i64* }]*, i64 }* %args.dbg.spill, i32 0, i32 1 store i64 %args.1, i64* %4, align 8 call void @llvm.dbg.declare(metadata { [0 x { i8*, i64* }]*, i64 }* %args.dbg.spill, metadata !219, metadata !DIExpression()), !dbg !221 %5 = bitcast { i64*, i64 }* %_4 to {}**, !dbg !222 store {}* null, {}** %5, align 8, !dbg !222 %6 = bitcast %"std::fmt::Arguments"* %0 to { [0 x { [0 x i8]*, i64 }]*, i64 }*, !dbg !223 %7 = getelementptr inbounds { [0 x { [0 x i8]*, i64 }]*, i64 }, { [0 x { [0 x i8]*, i64 }]*, i64 }* %6, i32 0, i32 0, !dbg !223 store [0 x { [0 x i8]*, i64 }]* %pieces.0, [0 x { [0 x i8]*, i64 }]** %7, align 8, !dbg !223 %8 = getelementptr inbounds { [0 x { [0 x i8]*, i64 }]*, i64 }, { [0 x { [0 x i8]*, i64 }]*, i64 }* %6, i32 0, i32 1, !dbg !223 store i64 %pieces.1, i64* %8, align 8, !dbg !223 %9 = getelementptr inbounds %"std::fmt::Arguments", %"std::fmt::Arguments"* %0, i32 0, i32 3, !dbg !223 %10 = getelementptr inbounds { i64*, i64 }, { i64*, i64 }* %_4, i32 0, i32 0, !dbg !223 %11 = load i64*, i64** %10, align 8, !dbg !223 %12 = getelementptr inbounds { i64*, i64 }, { i64*, i64 }* %_4, i32 0, i32 1, !dbg !223 %13 = load i64, i64* %12, align 8, !dbg !223 %14 = getelementptr inbounds { i64*, i64 }, { i64*, i64 }* %9, i32 0, i32 0, !dbg !223 store i64* %11, i64** %14, align 8, !dbg !223 %15 = getelementptr inbounds { i64*, i64 }, { i64*, i64 }* %9, i32 0, i32 1, !dbg !223 store i64 %13, i64* %15, align 8, !dbg !223 %16 = getelementptr inbounds %"std::fmt::Arguments", %"std::fmt::Arguments"* %0, i32 0, i32 5, !dbg !223 %17 = getelementptr inbounds { [0 x { i8*, i64* }]*, i64 }, { [0 x { i8*, i64* }]*, i64 }* %16, i32 0, i32 0, !dbg !223 store [0 x { i8*, i64* }]* %args.0, [0 x { i8*, i64* }]** %17, align 8, !dbg !223 %18 = getelementptr inbounds { [0 x { i8*, i64* }]*, i64 }, { [0 x { i8*, i64* }]*, i64 }* %16, i32 0, i32 1, !dbg !223 store i64 %args.1, i64* %18, align 8, !dbg !223 ret void, !dbg !224 } ; core::ops::function::FnOnce::call_once{{vtable.shim}} ; Function Attrs: inlinehint uwtable define internal i32 @"_ZN4core3ops8function6FnOnce40call_once$u7b$$u7b$vtable.shim$u7d$$u7d$17h07a3d3e0729b96baE"(i64** %_1) unnamed_addr #2 !dbg !225 { start: %_1.dbg.spill = alloca i64**, align 8 %_2 = alloca {}, align 1 store i64** %_1, i64*** %_1.dbg.spill, align 8 call void @llvm.dbg.declare(metadata i64*** %_1.dbg.spill, metadata !234, metadata !DIExpression()), !dbg !239 call void @llvm.dbg.declare(metadata {}* %_2, metadata !235, metadata !DIExpression()), !dbg !239 %0 = load i64*, i64** %_1, align 8, !dbg !239, !nonnull !4 ; call core::ops::function::FnOnce::call_once %1 = call i32 @_ZN4core3ops8function6FnOnce9call_once17h6e81d1ba09139127E(i64* nonnull %0), !dbg !239 br label %bb1, !dbg !239 bb1: ; preds = %start ret i32 %1, !dbg !239 } ; core::ops::function::FnOnce::call_once ; Function Attrs: inlinehint uwtable define internal void @_ZN4core3ops8function6FnOnce9call_once17h21a5088bccbb7ceeE(void ()* nonnull %_1) unnamed_addr #2 !dbg !240 { start: %_1.dbg.spill = alloca void ()*, align 8 %_2 = alloca {}, align 1 store void ()* %_1, void ()** %_1.dbg.spill, align 8 call void @llvm.dbg.declare(metadata void ()** %_1.dbg.spill, metadata !242, metadata !DIExpression()), !dbg !246 call void @llvm.dbg.declare(metadata {}* %_2, metadata !243, metadata !DIExpression()), !dbg !246 call void %_1(), !dbg !246 br label %bb1, !dbg !246 bb1: ; preds = %start ret void, !dbg !246 } ; core::ops::function::FnOnce::call_once ; Function Attrs: inlinehint uwtable define internal i32 @_ZN4core3ops8function6FnOnce9call_once17h6e81d1ba09139127E(i64* nonnull %0) unnamed_addr #2 personality i32 (i32, i32, i64, %"unwind::libunwind::_Unwind_Exception"*, %"unwind::libunwind::_Unwind_Context"*)* @rust_eh_personality !dbg !247 { start: %1 = alloca { i8*, i32 }, align 8 %_2 = alloca {}, align 1 %_1 = alloca i64*, align 8 store i64* %0, i64** %_1, align 8 call void @llvm.dbg.declare(metadata i64** %_1, metadata !251, metadata !DIExpression()), !dbg !253 call void @llvm.dbg.declare(metadata {}* %_2, metadata !252, metadata !DIExpression()), !dbg !253 ; invoke std::rt::lang_start::{{closure}} %2 = invoke i32 @"_ZN3std2rt10lang_start28_$u7b$$u7b$closure$u7d$$u7d$17he0db835a6152dd3dE"(i64** noalias readonly align 8 dereferenceable(8) %_1) to label %bb1 unwind label %cleanup, !dbg !253 bb1: ; preds = %start br label %bb2, !dbg !253 bb2: ; preds = %bb1 ret i32 %2, !dbg !253 bb3: ; preds = %cleanup br label %bb4, !dbg !253 bb4: ; preds = %bb3 %3 = bitcast { i8*, i32 }* %1 to i8**, !dbg !253 %4 = load i8*, i8** %3, align 8, !dbg !253 %5 = getelementptr inbounds { i8*, i32 }, { i8*, i32 }* %1, i32 0, i32 1, !dbg !253 %6 = load i32, i32* %5, align 8, !dbg !253 %7 = insertvalue { i8*, i32 } undef, i8* %4, 0, !dbg !253 %8 = insertvalue { i8*, i32 } %7, i32 %6, 1, !dbg !253 resume { i8*, i32 } %8, !dbg !253 cleanup: ; preds = %start %9 = landingpad { i8*, i32 } cleanup %10 = extractvalue { i8*, i32 } %9, 0 %11 = extractvalue { i8*, i32 } %9, 1 %12 = getelementptr inbounds { i8*, i32 }, { i8*, i32 }* %1, i32 0, i32 0 store i8* %10, i8** %12, align 8 %13 = getelementptr inbounds { i8*, i32 }, { i8*, i32 }* %1, i32 0, i32 1 store i32 %11, i32* %13, align 8 br label %bb3 } ; core::ptr::drop_in_place::{{closure}}> ; Function Attrs: inlinehint uwtable define internal void @"_ZN4core3ptr85drop_in_place$LT$std..rt..lang_start$LT$$LP$$RP$$GT$..$u7b$$u7b$closure$u7d$$u7d$$GT$17h1f2c731336d07166E"(i64** %_1) unnamed_addr #2 !dbg !254 { start: %_1.dbg.spill = alloca i64**, align 8 %0 = alloca {}, align 1 store i64** %_1, i64*** %_1.dbg.spill, align 8 call void @llvm.dbg.declare(metadata i64*** %_1.dbg.spill, metadata !260, metadata !DIExpression()), !dbg !263 ret void, !dbg !263 } ; core::hint::black_box ; Function Attrs: inlinehint uwtable define internal void @_ZN4core4hint9black_box17hfabbc7664b85073eE() unnamed_addr #2 !dbg !264 { start: %dummy = alloca {}, align 1 call void @llvm.dbg.declare(metadata {}* %dummy, metadata !270, metadata !DIExpression()), !dbg !271 call void asm sideeffect "", "r,~{memory},~{dirflag},~{fpsr},~{flags}"({}* %dummy), !dbg !272, !srcloc !273 ret void, !dbg !274 } ; <() as std::process::Termination>::report ; Function Attrs: inlinehint uwtable define internal i32 @"_ZN54_$LT$$LP$$RP$$u20$as$u20$std..process..Termination$GT$6report17h381b611d03f4782aE"() unnamed_addr #2 !dbg !275 { start: %self.dbg.spill = alloca {}, align 1 call void @llvm.dbg.declare(metadata {}* %self.dbg.spill, metadata !282, metadata !DIExpression()), !dbg !283 ; call ::report %0 = call i32 @"_ZN68_$LT$std..process..ExitCode$u20$as$u20$std..process..Termination$GT$6report17h391900a6658647e0E"(i8 0), !dbg !284 br label %bb1, !dbg !284 bb1: ; preds = %start ret i32 %0, !dbg !285 } ; ::report ; Function Attrs: inlinehint uwtable define internal i32 @"_ZN68_$LT$std..process..ExitCode$u20$as$u20$std..process..Termination$GT$6report17h391900a6658647e0E"(i8 %0) unnamed_addr #2 !dbg !286 { start: %self = alloca i8, align 1 store i8 %0, i8* %self, align 1 call void @llvm.dbg.declare(metadata i8* %self, metadata !293, metadata !DIExpression()), !dbg !294 ; call std::sys::unix::process::process_common::ExitCode::as_i32 %1 = call i32 @_ZN3std3sys4unix7process14process_common8ExitCode6as_i3217he414c8ec5ab83350E(i8* noalias readonly align 1 dereferenceable(1) %self), !dbg !295 br label %bb1, !dbg !295 bb1: ; preds = %start ret i32 %1, !dbg !296 } ; scratchpad::main ; Function Attrs: uwtable define internal void @_ZN10scratchpad4main17h3e4e0a32c31c7911E() unnamed_addr #1 !dbg !297 { start: %_2 = alloca %"std::fmt::Arguments", align 8 ; call core::fmt::Arguments::new_v1 call void @_ZN4core3fmt9Arguments6new_v117h13e4f70e15a317eeE(%"std::fmt::Arguments"* noalias nocapture sret dereferenceable(48) %_2, [0 x { [0 x i8]*, i64 }]* noalias nonnull readonly align 8 bitcast (<{ i8*, [8 x i8] }>* @alloc2 to [0 x { [0 x i8]*, i64 }]*), i64 1, [0 x { i8*, i64* }]* noalias nonnull readonly align 8 bitcast (<{ [0 x i8] }>* @alloc4 to [0 x { i8*, i64* }]*), i64 0), !dbg !300 br label %bb1, !dbg !300 bb1: ; preds = %start ; call std::io::stdio::_print call void @_ZN3std2io5stdio6_print17hea90da9dad6f182dE(%"std::fmt::Arguments"* noalias nocapture dereferenceable(48) %_2), !dbg !300 br label %bb2, !dbg !300 bb2: ; preds = %bb1 ret void, !dbg !301 } ; Function Attrs: nounwind uwtable declare i32 @rust_eh_personality(i32, i32, i64, %"unwind::libunwind::_Unwind_Exception"*, %"unwind::libunwind::_Unwind_Context"*) unnamed_addr #3 ; Function Attrs: nounwind readnone speculatable willreturn declare void @llvm.dbg.declare(metadata, metadata, metadata) #4 ; std::rt::lang_start_internal ; Function Attrs: uwtable declare i64 @_ZN3std2rt19lang_start_internal17h86f505dc7de50d93E({}* nonnull align 1, [3 x i64]* noalias readonly align 8 dereferenceable(24), i64, i8**) unnamed_addr #1 ; std::io::stdio::_print ; Function Attrs: uwtable declare void @_ZN3std2io5stdio6_print17hea90da9dad6f182dE(%"std::fmt::Arguments"* noalias nocapture dereferenceable(48)) unnamed_addr #1 define i32 @main(i32 %0, i8** %1) unnamed_addr #5 { top: %2 = sext i32 %0 to i64 ; call std::rt::lang_start %3 = call i64 @_ZN3std2rt10lang_start17h3d503a6b6a81c10bE(void ()* @_ZN10scratchpad4main17h3e4e0a32c31c7911E, i64 %2, i8** %1) %4 = trunc i64 %3 to i32 ret i32 %4 } attributes #0 = { noinline uwtable "frame-pointer"="all" "probe-stack"="__rust_probestack" "target-cpu"="core2" } attributes #1 = { uwtable "frame-pointer"="all" "probe-stack"="__rust_probestack" "target-cpu"="core2" } attributes #2 = { inlinehint uwtable "frame-pointer"="all" "probe-stack"="__rust_probestack" "target-cpu"="core2" } attributes #3 = { nounwind uwtable "frame-pointer"="all" "probe-stack"="__rust_probestack" "target-cpu"="core2" } attributes #4 = { nounwind readnone speculatable willreturn } attributes #5 = { "frame-pointer"="all" "target-cpu"="core2" } !llvm.module.flags = !{!14, !15, !16, !17} !llvm.dbg.cu = !{!18} !0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression()) !1 = distinct !DIGlobalVariable(name: "vtable", scope: null, file: !2, type: !3, isLocal: true, isDefinition: true) !2 = !DIFile(filename: "", directory: "") !3 = !DICompositeType(tag: DW_TAG_structure_type, name: "vtable", file: !2, align: 64, flags: DIFlagArtificial, elements: !4, vtableHolder: !5, identifier: "vtable") !4 = !{} !5 = !DICompositeType(tag: DW_TAG_structure_type, name: "closure-0", scope: !6, file: !2, size: 64, align: 64, elements: !9, templateParams: !4, identifier: "d165d88e24f1c6d771abba0a450bb05b") !6 = !DINamespace(name: "lang_start", scope: !7) !7 = !DINamespace(name: "rt", scope: !8) !8 = !DINamespace(name: "std", scope: null) !9 = !{!10} !10 = !DIDerivedType(tag: DW_TAG_member, name: "__0", scope: !5, file: !2, baseType: !11, size: 64, align: 64) !11 = !DIDerivedType(tag: DW_TAG_pointer_type, name: "fn()", baseType: !12, size: 64, align: 64, dwarfAddressSpace: 0) !12 = !DISubroutineType(types: !13) !13 = !{null} !14 = !{i32 7, !"PIC Level", i32 2} !15 = !{i32 7, !"PIE Level", i32 2} !16 = !{i32 2, !"Dwarf Version", i32 2} !17 = !{i32 2, !"Debug Info Version", i32 3} !18 = distinct !DICompileUnit(language: DW_LANG_Rust, file: !19, producer: "clang LLVM (rustc version 1.51.0 (2fd73fabe 2021-03-23))", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !20, globals: !37) !19 = !DIFile(filename: "src/main.rs/@/2cwjgb4q3tsf1uv9", directory: "/Users/src/scratchpad/target/debug/deps") !20 = !{!21, !32} !21 = !DICompositeType(tag: DW_TAG_enumeration_type, name: "Alignment", scope: !22, file: !2, baseType: !26, size: 8, align: 8, flags: DIFlagEnumClass, elements: !27) !22 = !DINamespace(name: "v1", scope: !23) !23 = !DINamespace(name: "rt", scope: !24) !24 = !DINamespace(name: "fmt", scope: !25) !25 = !DINamespace(name: "core", scope: null) !26 = !DIBasicType(name: "u8", size: 8, encoding: DW_ATE_unsigned) !27 = !{!28, !29, !30, !31} !28 = !DIEnumerator(name: "Left", value: 0) !29 = !DIEnumerator(name: "Right", value: 1) !30 = !DIEnumerator(name: "Center", value: 2) !31 = !DIEnumerator(name: "Unknown", value: 3) !32 = !DICompositeType(tag: DW_TAG_enumeration_type, name: "Result", scope: !33, file: !2, baseType: !26, size: 8, align: 8, flags: DIFlagEnumClass, elements: !34) !33 = !DINamespace(name: "result", scope: !25) !34 = !{!35, !36} !35 = !DIEnumerator(name: "Ok", value: 0) !36 = !DIEnumerator(name: "Err", value: 1) !37 = !{!0} !38 = distinct !DISubprogram(name: "__rust_begin_short_backtrace", linkageName: "_ZN3std10sys_common9backtrace28__rust_begin_short_backtrace17hdab553cbc2abb651E", scope: !40, file: !39, line: 121, type: !42, scopeLine: 121, flags: DIFlagPrototyped, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition, unit: !18, templateParams: !49, retainedNodes: !44) !39 = !DIFile(filename: "/Users/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/library/std/src/sys_common/backtrace.rs", directory: "", checksumkind: CSK_MD5, checksum: "a66d3ea15c41bfcbfadc8617be007fe2") !40 = !DINamespace(name: "backtrace", scope: !41) !41 = !DINamespace(name: "sys_common", scope: !8) !42 = !DISubroutineType(types: !43) !43 = !{null, !11} !44 = !{!45, !46} !45 = !DILocalVariable(name: "f", arg: 1, scope: !38, file: !39, line: 121, type: !11) !46 = !DILocalVariable(name: "result", scope: !47, file: !39, line: 125, type: !48, align: 1) !47 = distinct !DILexicalBlock(scope: !38, file: !39, line: 125, column: 5) !48 = !DIBasicType(name: "()", encoding: DW_ATE_unsigned) !49 = !{!50, !51} !50 = !DITemplateTypeParameter(name: "F", type: !11) !51 = !DITemplateTypeParameter(name: "T", type: !48) !52 = !DILocation(line: 125, column: 9, scope: !47) !53 = !DILocation(line: 121, column: 43, scope: !38) !54 = !DILocation(line: 125, column: 18, scope: !38) !55 = !DILocation(line: 128, column: 5, scope: !47) !56 = !DILocation(line: 131, column: 2, scope: !38) !57 = !DILocation(line: 131, column: 1, scope: !38) !58 = !DILocation(line: 121, column: 1, scope: !38) !59 = distinct !DISubprogram(name: "lang_start<()>", linkageName: "_ZN3std2rt10lang_start17h3d503a6b6a81c10bE", scope: !7, file: !60, line: 60, type: !61, scopeLine: 60, flags: DIFlagPrototyped, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition, unit: !18, templateParams: !70, retainedNodes: !66) !60 = !DIFile(filename: "/Users/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/library/std/src/rt.rs", directory: "", checksumkind: CSK_MD5, checksum: "a29dbe91f6c44a4e9c1b3c06440e8785") !61 = !DISubroutineType(types: !62) !62 = !{!63, !11, !63, !64} !63 = !DIBasicType(name: "isize", size: 64, encoding: DW_ATE_signed) !64 = !DIDerivedType(tag: DW_TAG_pointer_type, name: "*const *const u8", baseType: !65, size: 64, align: 64, dwarfAddressSpace: 0) !65 = !DIDerivedType(tag: DW_TAG_pointer_type, name: "*const u8", baseType: !26, size: 64, align: 64, dwarfAddressSpace: 0) !66 = !{!67, !68, !69} !67 = !DILocalVariable(name: "main", arg: 1, scope: !59, file: !60, line: 61, type: !11) !68 = !DILocalVariable(name: "argc", arg: 2, scope: !59, file: !60, line: 62, type: !63) !69 = !DILocalVariable(name: "argv", arg: 3, scope: !59, file: !60, line: 63, type: !64) !70 = !{!51} !71 = !DILocation(line: 61, column: 5, scope: !59) !72 = !DILocation(line: 62, column: 5, scope: !59) !73 = !DILocation(line: 63, column: 5, scope: !59) !74 = !DILocation(line: 66, column: 10, scope: !59) !75 = !DILocation(line: 66, column: 9, scope: !59) !76 = !DILocation(line: 65, column: 5, scope: !59) !77 = !DILocation(line: 70, column: 2, scope: !59) !78 = distinct !DISubprogram(name: "{{closure}}<()>", linkageName: "_ZN3std2rt10lang_start28_$u7b$$u7b$closure$u7d$$u7d$17he0db835a6152dd3dE", scope: !6, file: !60, line: 66, type: !79, scopeLine: 66, flags: DIFlagPrototyped, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition, unit: !18, templateParams: !70, retainedNodes: !83) !79 = !DISubroutineType(types: !80) !80 = !{!81, !82} !81 = !DIBasicType(name: "i32", size: 32, encoding: DW_ATE_signed) !82 = !DIDerivedType(tag: DW_TAG_pointer_type, name: "&closure-0", baseType: !5, size: 64, align: 64, dwarfAddressSpace: 0) !83 = !{!84} !84 = !DILocalVariable(name: "main", scope: !78, file: !60, line: 61, type: !11, align: 8) !85 = !DILocation(line: 61, column: 5, scope: !78) !86 = !DILocation(line: 66, column: 77, scope: !78) !87 = !DILocation(line: 66, column: 18, scope: !78) !88 = !DILocation(line: 66, column: 91, scope: !78) !89 = distinct !DISubprogram(name: "as_i32", linkageName: "_ZN3std3sys4unix7process14process_common8ExitCode6as_i3217he414c8ec5ab83350E", scope: !91, file: !90, line: 438, type: !98, scopeLine: 438, flags: DIFlagPrototyped, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition, unit: !18, templateParams: !4, retainedNodes: !101) !90 = !DIFile(filename: "/Users/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/library/std/src/sys/unix/process/process_common.rs", directory: "", checksumkind: CSK_MD5, checksum: "d300b907711dcef2ce326bed41b448e0") !91 = !DICompositeType(tag: DW_TAG_structure_type, name: "ExitCode", scope: !92, file: !2, size: 8, align: 8, elements: !96, templateParams: !4, identifier: "b813ae4ed90a52032198ff3c3d4664ee") !92 = !DINamespace(name: "process_common", scope: !93) !93 = !DINamespace(name: "process", scope: !94) !94 = !DINamespace(name: "unix", scope: !95) !95 = !DINamespace(name: "sys", scope: !8) !96 = !{!97} !97 = !DIDerivedType(tag: DW_TAG_member, name: "__0", scope: !91, file: !2, baseType: !26, size: 8, align: 8) !98 = !DISubroutineType(types: !99) !99 = !{!81, !100} !100 = !DIDerivedType(tag: DW_TAG_pointer_type, name: "&std::sys::unix::process::process_common::ExitCode", baseType: !91, size: 64, align: 64, dwarfAddressSpace: 0) !101 = !{!102} !102 = !DILocalVariable(name: "self", arg: 1, scope: !89, file: !90, line: 438, type: !100) !103 = !DILocation(line: 438, column: 19, scope: !89) !104 = !DILocation(line: 439, column: 9, scope: !89) !105 = !DILocation(line: 440, column: 6, scope: !89) !106 = distinct !DISubprogram(name: "new_v1", linkageName: "_ZN4core3fmt9Arguments6new_v117h13e4f70e15a317eeE", scope: !108, file: !107, line: 313, type: !215, scopeLine: 313, flags: DIFlagPrototyped, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition, unit: !18, templateParams: !4, retainedNodes: !217) !107 = !DIFile(filename: "/Users/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/library/core/src/fmt/mod.rs", directory: "", checksumkind: CSK_MD5, checksum: "9c2303bc954c30225b64b2e88dce24d2") !108 = !DICompositeType(tag: DW_TAG_structure_type, name: "Arguments", scope: !24, file: !2, size: 384, align: 64, elements: !109, templateParams: !4, identifier: "c97889ed63520f7838c201501c69e884") !109 = !{!110, !121, !170} !110 = !DIDerivedType(tag: DW_TAG_member, name: "pieces", scope: !108, file: !2, baseType: !111, size: 128, align: 64) !111 = !DICompositeType(tag: DW_TAG_structure_type, name: "&[&str]", file: !2, size: 128, align: 64, elements: !112, templateParams: !4, identifier: "e5181a2ba73cefd2b9372dc5646453a9") !112 = !{!113, !120} !113 = !DIDerivedType(tag: DW_TAG_member, name: "data_ptr", scope: !111, file: !2, baseType: !114, size: 64, align: 64) !114 = !DIDerivedType(tag: DW_TAG_pointer_type, name: "*const &str", baseType: !115, size: 64, align: 64, dwarfAddressSpace: 0) !115 = !DICompositeType(tag: DW_TAG_structure_type, name: "&str", file: !2, size: 128, align: 64, elements: !116, templateParams: !4, identifier: "7ef2a91eecc7bcf4b4aaea2dbce79437") !116 = !{!117, !118} !117 = !DIDerivedType(tag: DW_TAG_member, name: "data_ptr", scope: !115, file: !2, baseType: !65, size: 64, align: 64) !118 = !DIDerivedType(tag: DW_TAG_member, name: "length", scope: !115, file: !2, baseType: !119, size: 64, align: 64, offset: 64) !119 = !DIBasicType(name: "usize", size: 64, encoding: DW_ATE_unsigned) !120 = !DIDerivedType(tag: DW_TAG_member, name: "length", scope: !111, file: !2, baseType: !119, size: 64, align: 64, offset: 64) !121 = !DIDerivedType(tag: DW_TAG_member, name: "fmt", scope: !108, file: !2, baseType: !122, size: 128, align: 64, offset: 128) !122 = !DICompositeType(tag: DW_TAG_structure_type, name: "Option<&[core::fmt::rt::v1::Argument]>", scope: !123, file: !2, size: 128, align: 64, elements: !124, identifier: "24e3a58af97ae33230759935e3d6e419") !123 = !DINamespace(name: "option", scope: !25) !124 = !{!125} !125 = !DICompositeType(tag: DW_TAG_variant_part, scope: !123, file: !2, size: 128, align: 64, elements: !126, templateParams: !129, identifier: "24e3a58af97ae33230759935e3d6e419_variant_part", discriminator: !169) !126 = !{!127, !165} !127 = !DIDerivedType(tag: DW_TAG_member, name: "None", scope: !125, file: !2, baseType: !128, size: 128, align: 64, extraData: i64 0) !128 = !DICompositeType(tag: DW_TAG_structure_type, name: "None", scope: !122, file: !2, size: 128, align: 64, elements: !4, templateParams: !129, identifier: "24e3a58af97ae33230759935e3d6e419::None") !129 = !{!130} !130 = !DITemplateTypeParameter(name: "T", type: !131) !131 = !DICompositeType(tag: DW_TAG_structure_type, name: "&[core::fmt::rt::v1::Argument]", file: !2, size: 128, align: 64, elements: !132, templateParams: !4, identifier: "7d74bef5e81819056642b0d75803bf26") !132 = !{!133, !164} !133 = !DIDerivedType(tag: DW_TAG_member, name: "data_ptr", scope: !131, file: !2, baseType: !134, size: 64, align: 64) !134 = !DIDerivedType(tag: DW_TAG_pointer_type, name: "*const core::fmt::rt::v1::Argument", baseType: !135, size: 64, align: 64, dwarfAddressSpace: 0) !135 = !DICompositeType(tag: DW_TAG_structure_type, name: "Argument", scope: !22, file: !2, size: 448, align: 64, elements: !136, templateParams: !4, identifier: "fcab46e727498f565afb8b0dfbda8552") !136 = !{!137, !138} !137 = !DIDerivedType(tag: DW_TAG_member, name: "position", scope: !135, file: !2, baseType: !119, size: 64, align: 64) !138 = !DIDerivedType(tag: DW_TAG_member, name: "format", scope: !135, file: !2, baseType: !139, size: 384, align: 64, offset: 64) !139 = !DICompositeType(tag: DW_TAG_structure_type, name: "FormatSpec", scope: !22, file: !2, size: 384, align: 64, elements: !140, templateParams: !4, identifier: "ed39b7fb5fb3bf6ba76cc9faa920c8a6") !140 = !{!141, !143, !144, !146, !163} !141 = !DIDerivedType(tag: DW_TAG_member, name: "fill", scope: !139, file: !2, baseType: !142, size: 32, align: 32, offset: 256) !142 = !DIBasicType(name: "char", size: 32, encoding: DW_ATE_unsigned_char) !143 = !DIDerivedType(tag: DW_TAG_member, name: "align", scope: !139, file: !2, baseType: !21, size: 8, align: 8, offset: 320) !144 = !DIDerivedType(tag: DW_TAG_member, name: "flags", scope: !139, file: !2, baseType: !145, size: 32, align: 32, offset: 288) !145 = !DIBasicType(name: "u32", size: 32, encoding: DW_ATE_unsigned) !146 = !DIDerivedType(tag: DW_TAG_member, name: "precision", scope: !139, file: !2, baseType: !147, size: 128, align: 64) !147 = !DICompositeType(tag: DW_TAG_structure_type, name: "Count", scope: !22, file: !2, size: 128, align: 64, elements: !148, identifier: "6913423e5d3ed5ee5cf4e16b07b4cf0c") !148 = !{!149} !149 = !DICompositeType(tag: DW_TAG_variant_part, scope: !22, file: !2, size: 128, align: 64, elements: !150, templateParams: !4, identifier: "6913423e5d3ed5ee5cf4e16b07b4cf0c_variant_part", discriminator: !161) !150 = !{!151, !155, !159} !151 = !DIDerivedType(tag: DW_TAG_member, name: "Is", scope: !149, file: !2, baseType: !152, size: 128, align: 64, extraData: i64 0) !152 = !DICompositeType(tag: DW_TAG_structure_type, name: "Is", scope: !147, file: !2, size: 128, align: 64, elements: !153, templateParams: !4, identifier: "6913423e5d3ed5ee5cf4e16b07b4cf0c::Is") !153 = !{!154} !154 = !DIDerivedType(tag: DW_TAG_member, name: "__0", scope: !152, file: !2, baseType: !119, size: 64, align: 64, offset: 64) !155 = !DIDerivedType(tag: DW_TAG_member, name: "Param", scope: !149, file: !2, baseType: !156, size: 128, align: 64, extraData: i64 1) !156 = !DICompositeType(tag: DW_TAG_structure_type, name: "Param", scope: !147, file: !2, size: 128, align: 64, elements: !157, templateParams: !4, identifier: "6913423e5d3ed5ee5cf4e16b07b4cf0c::Param") !157 = !{!158} !158 = !DIDerivedType(tag: DW_TAG_member, name: "__0", scope: !156, file: !2, baseType: !119, size: 64, align: 64, offset: 64) !159 = !DIDerivedType(tag: DW_TAG_member, name: "Implied", scope: !149, file: !2, baseType: !160, size: 128, align: 64, extraData: i64 2) !160 = !DICompositeType(tag: DW_TAG_structure_type, name: "Implied", scope: !147, file: !2, size: 128, align: 64, elements: !4, templateParams: !4, identifier: "6913423e5d3ed5ee5cf4e16b07b4cf0c::Implied") !161 = !DIDerivedType(tag: DW_TAG_member, scope: !22, file: !2, baseType: !162, size: 64, align: 64, flags: DIFlagArtificial) !162 = !DIBasicType(name: "u64", size: 64, encoding: DW_ATE_unsigned) !163 = !DIDerivedType(tag: DW_TAG_member, name: "width", scope: !139, file: !2, baseType: !147, size: 128, align: 64, offset: 128) !164 = !DIDerivedType(tag: DW_TAG_member, name: "length", scope: !131, file: !2, baseType: !119, size: 64, align: 64, offset: 64) !165 = !DIDerivedType(tag: DW_TAG_member, name: "Some", scope: !125, file: !2, baseType: !166, size: 128, align: 64) !166 = !DICompositeType(tag: DW_TAG_structure_type, name: "Some", scope: !122, file: !2, size: 128, align: 64, elements: !167, templateParams: !129, identifier: "24e3a58af97ae33230759935e3d6e419::Some") !167 = !{!168} !168 = !DIDerivedType(tag: DW_TAG_member, name: "__0", scope: !166, file: !2, baseType: !131, size: 128, align: 64) !169 = !DIDerivedType(tag: DW_TAG_member, scope: !123, file: !2, baseType: !162, size: 64, align: 64, flags: DIFlagArtificial) !170 = !DIDerivedType(tag: DW_TAG_member, name: "args", scope: !108, file: !2, baseType: !171, size: 128, align: 64, offset: 256) !171 = !DICompositeType(tag: DW_TAG_structure_type, name: "&[core::fmt::ArgumentV1]", file: !2, size: 128, align: 64, elements: !172, templateParams: !4, identifier: "edb2f81e53993615824fd77bfc84df") !172 = !{!173, !214} !173 = !DIDerivedType(tag: DW_TAG_member, name: "data_ptr", scope: !171, file: !2, baseType: !174, size: 64, align: 64) !174 = !DIDerivedType(tag: DW_TAG_pointer_type, name: "*const core::fmt::ArgumentV1", baseType: !175, size: 64, align: 64, dwarfAddressSpace: 0) !175 = !DICompositeType(tag: DW_TAG_structure_type, name: "ArgumentV1", scope: !24, file: !2, size: 128, align: 64, elements: !176, templateParams: !4, identifier: "cfef9ae16338f0f9578d5938b6ae2ae") !176 = !{!177, !180} !177 = !DIDerivedType(tag: DW_TAG_member, name: "value", scope: !175, file: !2, baseType: !178, size: 64, align: 64) !178 = !DIDerivedType(tag: DW_TAG_pointer_type, name: "&core::fmt::::Opaque", baseType: !179, size: 64, align: 64, dwarfAddressSpace: 0) !179 = !DICompositeType(tag: DW_TAG_structure_type, name: "Opaque", file: !2, align: 8, elements: !4, identifier: "19dbc199322150ab263937aae573b37") !180 = !DIDerivedType(tag: DW_TAG_member, name: "formatter", scope: !175, file: !2, baseType: !181, size: 64, align: 64, offset: 64) !181 = !DIDerivedType(tag: DW_TAG_pointer_type, name: "fn(&core::fmt::::Opaque, &mut core::fmt::Formatter) -> core::result::Result<(), core::fmt::Error>", baseType: !182, size: 64, align: 64, dwarfAddressSpace: 0) !182 = !DISubroutineType(types: !183) !183 = !{!32, !178, !184} !184 = !DIDerivedType(tag: DW_TAG_pointer_type, name: "&mut core::fmt::Formatter", baseType: !185, size: 64, align: 64, dwarfAddressSpace: 0) !185 = !DICompositeType(tag: DW_TAG_structure_type, name: "Formatter", scope: !24, file: !2, size: 512, align: 64, elements: !186, templateParams: !4, identifier: "4d3d64d4971e8eb46222592601ca7f01") !186 = !{!187, !188, !189, !190, !203, !204} !187 = !DIDerivedType(tag: DW_TAG_member, name: "flags", scope: !185, file: !2, baseType: !145, size: 32, align: 32, offset: 384) !188 = !DIDerivedType(tag: DW_TAG_member, name: "fill", scope: !185, file: !2, baseType: !142, size: 32, align: 32, offset: 416) !189 = !DIDerivedType(tag: DW_TAG_member, name: "align", scope: !185, file: !2, baseType: !21, size: 8, align: 8, offset: 448) !190 = !DIDerivedType(tag: DW_TAG_member, name: "width", scope: !185, file: !2, baseType: !191, size: 128, align: 64) !191 = !DICompositeType(tag: DW_TAG_structure_type, name: "Option", scope: !123, file: !2, size: 128, align: 64, elements: !192, identifier: "32da615cea8de1eaac7cee351a20e93e") !192 = !{!193} !193 = !DICompositeType(tag: DW_TAG_variant_part, scope: !123, file: !2, size: 128, align: 64, elements: !194, templateParams: !197, identifier: "32da615cea8de1eaac7cee351a20e93e_variant_part", discriminator: !169) !194 = !{!195, !199} !195 = !DIDerivedType(tag: DW_TAG_member, name: "None", scope: !193, file: !2, baseType: !196, size: 128, align: 64, extraData: i64 0) !196 = !DICompositeType(tag: DW_TAG_structure_type, name: "None", scope: !191, file: !2, size: 128, align: 64, elements: !4, templateParams: !197, identifier: "32da615cea8de1eaac7cee351a20e93e::None") !197 = !{!198} !198 = !DITemplateTypeParameter(name: "T", type: !119) !199 = !DIDerivedType(tag: DW_TAG_member, name: "Some", scope: !193, file: !2, baseType: !200, size: 128, align: 64, extraData: i64 1) !200 = !DICompositeType(tag: DW_TAG_structure_type, name: "Some", scope: !191, file: !2, size: 128, align: 64, elements: !201, templateParams: !197, identifier: "32da615cea8de1eaac7cee351a20e93e::Some") !201 = !{!202} !202 = !DIDerivedType(tag: DW_TAG_member, name: "__0", scope: !200, file: !2, baseType: !119, size: 64, align: 64, offset: 64) !203 = !DIDerivedType(tag: DW_TAG_member, name: "precision", scope: !185, file: !2, baseType: !191, size: 128, align: 64, offset: 128) !204 = !DIDerivedType(tag: DW_TAG_member, name: "buf", scope: !185, file: !2, baseType: !205, size: 128, align: 64, offset: 256) !205 = !DICompositeType(tag: DW_TAG_structure_type, name: "&mut Write", scope: !24, file: !2, size: 128, align: 64, elements: !206, templateParams: !4, identifier: "6a0a5efcce52242d13c2f422ef1051c6") !206 = !{!207, !209} !207 = !DIDerivedType(tag: DW_TAG_member, name: "pointer", scope: !205, file: !2, baseType: !208, size: 64, align: 64, flags: DIFlagArtificial) !208 = !DIDerivedType(tag: DW_TAG_pointer_type, name: "*mut u8", baseType: !26, size: 64, align: 64, dwarfAddressSpace: 0) !209 = !DIDerivedType(tag: DW_TAG_member, name: "vtable", scope: !205, file: !2, baseType: !210, size: 64, align: 64, offset: 64, flags: DIFlagArtificial) !210 = !DIDerivedType(tag: DW_TAG_pointer_type, name: "&[usize; 3]", baseType: !211, size: 64, align: 64, dwarfAddressSpace: 0) !211 = !DICompositeType(tag: DW_TAG_array_type, baseType: !119, size: 192, align: 64, elements: !212) !212 = !{!213} !213 = !DISubrange(count: 3, lowerBound: 0) !214 = !DIDerivedType(tag: DW_TAG_member, name: "length", scope: !171, file: !2, baseType: !119, size: 64, align: 64, offset: 64) !215 = !DISubroutineType(types: !216) !216 = !{!108, !111, !171} !217 = !{!218, !219} !218 = !DILocalVariable(name: "pieces", arg: 1, scope: !106, file: !107, line: 313, type: !111) !219 = !DILocalVariable(name: "args", arg: 2, scope: !106, file: !107, line: 313, type: !171) !220 = !DILocation(line: 313, column: 19, scope: !106) !221 = !DILocation(line: 313, column: 47, scope: !106) !222 = !DILocation(line: 314, column: 34, scope: !106) !223 = !DILocation(line: 314, column: 9, scope: !106) !224 = !DILocation(line: 315, column: 6, scope: !106) !225 = distinct !DISubprogram(name: "call_once", linkageName: "_ZN4core3ops8function6FnOnce40call_once$u7b$$u7b$vtable.shim$u7d$$u7d$17h07a3d3e0729b96baE", scope: !227, file: !226, line: 227, type: !230, scopeLine: 227, flags: DIFlagPrototyped, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition, unit: !18, templateParams: !236, retainedNodes: !233) !226 = !DIFile(filename: "/Users/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/library/core/src/ops/function.rs", directory: "", checksumkind: CSK_MD5, checksum: "e7b2206724943b8a8140f7c1065997a3") !227 = !DINamespace(name: "FnOnce", scope: !228) !228 = !DINamespace(name: "function", scope: !229) !229 = !DINamespace(name: "ops", scope: !25) !230 = !DISubroutineType(types: !231) !231 = !{!81, !232} !232 = !DIDerivedType(tag: DW_TAG_pointer_type, name: "*mut closure-0", baseType: !5, size: 64, align: 64, dwarfAddressSpace: 0) !233 = !{!234, !235} !234 = !DILocalVariable(arg: 1, scope: !225, file: !226, line: 227, type: !232) !235 = !DILocalVariable(arg: 2, scope: !225, file: !226, line: 227, type: !48) !236 = !{!237, !238} !237 = !DITemplateTypeParameter(name: "Self", type: !5) !238 = !DITemplateTypeParameter(name: "Args", type: !48) !239 = !DILocation(line: 227, column: 5, scope: !225) !240 = distinct !DISubprogram(name: "call_once", linkageName: "_ZN4core3ops8function6FnOnce9call_once17h21a5088bccbb7ceeE", scope: !227, file: !226, line: 227, type: !42, scopeLine: 227, flags: DIFlagPrototyped, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition, unit: !18, templateParams: !244, retainedNodes: !241) !241 = !{!242, !243} !242 = !DILocalVariable(arg: 1, scope: !240, file: !226, line: 227, type: !11) !243 = !DILocalVariable(arg: 2, scope: !240, file: !226, line: 227, type: !48) !244 = !{!245, !238} !245 = !DITemplateTypeParameter(name: "Self", type: !11) !246 = !DILocation(line: 227, column: 5, scope: !240) !247 = distinct !DISubprogram(name: "call_once", linkageName: "_ZN4core3ops8function6FnOnce9call_once17h6e81d1ba09139127E", scope: !227, file: !226, line: 227, type: !248, scopeLine: 227, flags: DIFlagPrototyped, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition, unit: !18, templateParams: !236, retainedNodes: !250) !248 = !DISubroutineType(types: !249) !249 = !{!81, !5} !250 = !{!251, !252} !251 = !DILocalVariable(arg: 1, scope: !247, file: !226, line: 227, type: !5) !252 = !DILocalVariable(arg: 2, scope: !247, file: !226, line: 227, type: !48) !253 = !DILocation(line: 227, column: 5, scope: !247) !254 = distinct !DISubprogram(name: "drop_in_place", linkageName: "_ZN4core3ptr85drop_in_place$LT$std..rt..lang_start$LT$$LP$$RP$$GT$..$u7b$$u7b$closure$u7d$$u7d$$GT$17h1f2c731336d07166E", scope: !256, file: !255, line: 179, type: !257, scopeLine: 179, flags: DIFlagPrototyped, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition, unit: !18, templateParams: !261, retainedNodes: !259) !255 = !DIFile(filename: "/Users/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/library/core/src/ptr/mod.rs", directory: "", checksumkind: CSK_MD5, checksum: "a4f2d8ba04981bbf92ef9174cf1f1763") !256 = !DINamespace(name: "ptr", scope: !25) !257 = !DISubroutineType(types: !258) !258 = !{null, !232} !259 = !{!260} !260 = !DILocalVariable(arg: 1, scope: !254, file: !255, line: 179, type: !232) !261 = !{!262} !262 = !DITemplateTypeParameter(name: "T", type: !5) !263 = !DILocation(line: 179, column: 1, scope: !254) !264 = distinct !DISubprogram(name: "black_box<()>", linkageName: "_ZN4core4hint9black_box17hfabbc7664b85073eE", scope: !266, file: !265, line: 159, type: !267, scopeLine: 159, flags: DIFlagPrototyped, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition, unit: !18, templateParams: !70, retainedNodes: !269) !265 = !DIFile(filename: "/Users/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/library/core/src/hint.rs", directory: "", checksumkind: CSK_MD5, checksum: "e859926b2ab373eb68666ba2c9fa193f") !266 = !DINamespace(name: "hint", scope: !25) !267 = !DISubroutineType(types: !268) !268 = !{null, !48} !269 = !{!270} !270 = !DILocalVariable(name: "dummy", arg: 1, scope: !264, file: !265, line: 159, type: !48) !271 = !DILocation(line: 159, column: 21, scope: !264) !272 = !DILocation(line: 170, column: 9, scope: !264) !273 = !{i32 2770798} !274 = !DILocation(line: 174, column: 2, scope: !264) !275 = distinct !DISubprogram(name: "report", linkageName: "_ZN54_$LT$$LP$$RP$$u20$as$u20$std..process..Termination$GT$6report17h381b611d03f4782aE", scope: !277, file: !276, line: 1828, type: !279, scopeLine: 1828, flags: DIFlagPrototyped, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition, unit: !18, templateParams: !4, retainedNodes: !281) !276 = !DIFile(filename: "/Users/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/library/std/src/process.rs", directory: "", checksumkind: CSK_MD5, checksum: "af3deb4955b6b6f458d03bf15fd16325") !277 = !DINamespace(name: "{{impl}}", scope: !278) !278 = !DINamespace(name: "process", scope: !8) !279 = !DISubroutineType(types: !280) !280 = !{!81, !48} !281 = !{!282} !282 = !DILocalVariable(name: "self", arg: 1, scope: !275, file: !276, line: 1828, type: !48) !283 = !DILocation(line: 1828, column: 15, scope: !275) !284 = !DILocation(line: 1829, column: 9, scope: !275) !285 = !DILocation(line: 1830, column: 6, scope: !275) !286 = distinct !DISubprogram(name: "report", linkageName: "_ZN68_$LT$std..process..ExitCode$u20$as$u20$std..process..Termination$GT$6report17h391900a6658647e0E", scope: !277, file: !276, line: 1862, type: !287, scopeLine: 1862, flags: DIFlagPrototyped, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition, unit: !18, templateParams: !4, retainedNodes: !292) !287 = !DISubroutineType(types: !288) !288 = !{!81, !289} !289 = !DICompositeType(tag: DW_TAG_structure_type, name: "ExitCode", scope: !278, file: !2, size: 8, align: 8, elements: !290, templateParams: !4, identifier: "a7dd51933509084bf20279b80497c3") !290 = !{!291} !291 = !DIDerivedType(tag: DW_TAG_member, name: "__0", scope: !289, file: !2, baseType: !91, size: 8, align: 8) !292 = !{!293} !293 = !DILocalVariable(name: "self", arg: 1, scope: !286, file: !276, line: 1862, type: !289) !294 = !DILocation(line: 1862, column: 15, scope: !286) !295 = !DILocation(line: 1863, column: 9, scope: !286) !296 = !DILocation(line: 1864, column: 6, scope: !286) !297 = distinct !DISubprogram(name: "main", linkageName: "_ZN10scratchpad4main17h3e4e0a32c31c7911E", scope: !299, file: !298, line: 1, type: !12, scopeLine: 1, flags: DIFlagPrototyped, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition | DISPFlagMainSubprogram, unit: !18, templateParams: !4, retainedNodes: !4) !298 = !DIFile(filename: "src/main.rs", directory: "/Users/src/scratchpad", checksumkind: CSK_MD5, checksum: "0348174be99be8fb4e0b52f8b130cc69") !299 = !DINamespace(name: "scratchpad", scope: null) !300 = !DILocation(line: 2, column: 5, scope: !297) !301 = !DILocation(line: 3, column: 2, scope: !297) ```

hikari-no-yume commented 3 years ago

I had the exact same experience yesterday, now that the issues with zero-sized types and missing function pointer types are fixed. I strongly suspect this is not the fault of the C backend, though. The Rust code is most likely referencing external symbols that need to be linked in, and obviously a C compiler doesn't link the Rust standard library by default.

I intend to experiment with this when I have some free time. It's hopefully as simple as adding a -l argument to the C compiler's invocation.

hikari-no-yume commented 3 years ago

Essentially the same thing happens for a C++ hello world program too, by the way.

hikari-no-yume commented 3 years ago

I strongly suspect this is not the fault of the C backend, though. The Rust code is most likely referencing external symbols that need to be linked in, and obviously a C compiler doesn't link the Rust standard library by default.

I have verified this is the problem now. You can see in the LLVM IR that there's external functions declared. I don't think there is a C backend issue here.


Regarding what you're actually trying to achieve: I probably have the same goal as you! You may be able to get the program to fully compile by telling the C compiler to link the Rust libraries, assuming they happen to be in the right format etc.

On my system, rustc --print target-libdir gave me a path to a directory with the Rust standard libraries. Listing its content with ls I got various filenames like:

libstd-4b608c2fb5366e58.dylib
libstd-4b608c2fb5366e58.rlib

I was then able to tell my C compiler to look for libraries in that directory with -L followed by that directory's path, and then -lstd-4b608c2fb5366e58 to tell it to link the std library from that directory. Notice that I omitted the lib and .dylib parts of the name.

This resulted in a successful compilation, but I had to set the LD_LIBRARY_PATH environment variable to that directory for the resulting executable to be able to load its dynamic libraries at runtime. And yes, it printed “hello, world”. 🎉

Having to link against a native Rust binary clearly undermines the whole idea of C being portable, though. I am sure this can be solved by compiling Rust's std (or at least core) to C. I haven't tried that yet. I'm sure there'll be plenty more C backend issues to fix when I do.

XAMPPRocky commented 3 years ago

Glad to know it works, I tried compiling my project and ran into other issues. https://github.com/JuliaComputingOSS/llvm-cbe/issues/111 Feel free to close or rename this issue.