diff options
| author | gingerBill <bill@gingerbill.org> | 2021-08-09 21:23:24 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2021-08-09 21:23:24 +0100 |
| commit | 02f22a0b3f27715d2906011c998263f07887894c (patch) | |
| tree | b1b0ac2d03767e02207272cc84a2cbd36e126078 /src/llvm_backend.cpp | |
| parent | 193fd0eecbeb5bdcdbd1173ea65f5ae8963705bb (diff) | |
Correct DllMain behaviour
Diffstat (limited to 'src/llvm_backend.cpp')
| -rw-r--r-- | src/llvm_backend.cpp | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/src/llvm_backend.cpp b/src/llvm_backend.cpp index 9f79c5908..60552b087 100644 --- a/src/llvm_backend.cpp +++ b/src/llvm_backend.cpp @@ -765,10 +765,20 @@ lbProcedure *lb_create_main_procedure(lbModule *m, lbProcedure *startup_runtime) Type *t_ptr_cstring = alloc_type_pointer(t_cstring); + bool has_args = false; + bool is_dll_main = false; String name = str_lit("main"); - if (build_context.metrics.os == TargetOs_windows && build_context.metrics.arch == TargetArch_386) { + if (build_context.metrics.os == TargetOs_windows && build_context.build_mode == BuildMode_DynamicLibrary) { + is_dll_main = true; + name = str_lit("DllMain"); + array_init(¶ms->Tuple.variables, permanent_allocator(), 3); + params->Tuple.variables[0] = alloc_entity_param(nullptr, make_token_ident("hinstDLL"), t_rawptr, false, true); + params->Tuple.variables[1] = alloc_entity_param(nullptr, make_token_ident("fdwReason"), t_u32, false, true); + params->Tuple.variables[2] = alloc_entity_param(nullptr, make_token_ident("lpReserved"), t_rawptr, false, true); + } else if (build_context.metrics.os == TargetOs_windows && build_context.metrics.arch == TargetArch_386) { name = str_lit("mainCRTStartup"); } else { + has_args = true; array_init(¶ms->Tuple.variables, permanent_allocator(), 2); params->Tuple.variables[0] = alloc_entity_param(nullptr, make_token_ident("argc"), t_i32, false, true); params->Tuple.variables[1] = alloc_entity_param(nullptr, make_token_ident("argv"), t_ptr_cstring, false, true); @@ -787,7 +797,7 @@ lbProcedure *lb_create_main_procedure(lbModule *m, lbProcedure *startup_runtime) lb_begin_procedure_body(p); - { // initialize `runtime.args__` + if (has_args) { // initialize `runtime.args__` lbValue argc = {LLVMGetParam(p->value, 0), t_i32}; lbValue argv = {LLVMGetParam(p->value, 1), t_ptr_cstring}; LLVMSetValueName2(argc.value, "argc", 4); @@ -857,7 +867,13 @@ lbProcedure *lb_create_main_procedure(lbModule *m, lbProcedure *startup_runtime) } } - LLVMBuildRet(p->builder, LLVMConstInt(lb_type(m, t_i32), 0, false)); + + + if (is_dll_main) { + LLVMBuildRet(p->builder, LLVMConstInt(lb_type(m, t_i32), 1, false)); + } else { + LLVMBuildRet(p->builder, LLVMConstInt(lb_type(m, t_i32), 0, false)); + } lb_end_procedure_body(p); |