diff --git a/core/runtime/core.odin b/core/runtime/core.odin index 542340e36..36a88a8b5 100644 --- a/core/runtime/core.odin +++ b/core/runtime/core.odin @@ -384,7 +384,12 @@ Raw_Cstring :: struct { // This is probably only useful for freestanding targets foreign { @(link_name="__$startup_runtime") - _startup_runtime :: proc "contextless" () --- + _startup_runtime :: proc() --- +} + +@(link_name="__$cleanup_runtime") +_cleanup_runtime :: proc() { + default_temp_allocator_destroy(&global_default_temp_allocator_data) } diff --git a/src/checker.cpp b/src/checker.cpp index cfe29b5ee..d3c0080de 100644 --- a/src/checker.cpp +++ b/src/checker.cpp @@ -1967,6 +1967,7 @@ void generate_minimum_dependency_set(Checker *c, Entity *start) { str_lit("__init_context"), str_lit("__type_info_of"), str_lit("cstring_to_string"), + str_lit("_cleanup_runtime"), // Pseudo-CRT required procedures str_lit("memset"), @@ -1993,7 +1994,6 @@ void generate_minimum_dependency_set(Checker *c, Entity *start) { str_lit("gnu_h2f_ieee"), str_lit("gnu_f2h_ieee"), str_lit("extendhfsf2"), - }; for (isize i = 0; i < gb_count_of(required_runtime_entities); i++) { force_add_dependency_entity(c, c->info.runtime_package->scope, required_runtime_entities[i]); diff --git a/src/llvm_backend.cpp b/src/llvm_backend.cpp index 717768240..a72ddc646 100644 --- a/src/llvm_backend.cpp +++ b/src/llvm_backend.cpp @@ -879,7 +879,10 @@ lbProcedure *lb_create_main_procedure(lbModule *m, lbProcedure *startup_runtime) } } - + + lbValue cleanup_runtime_value = lb_find_runtime_value(m, str_lit("_cleanup_runtime")); + lb_emit_call(p, cleanup_runtime_value, {}, ProcInlining_none, false); + if (is_dll_main) { LLVMBuildRet(p->builder, LLVMConstInt(lb_type(m, t_i32), 1, false));