| author | |
| committer | |
| log | fdea12b2d9deaea6a90c7b1451df425e84b98099 |
| tree | 7339fa363aa1124d7b83b05f94fc387ad54183ca |
| parent | 280187031a68c577e84c72add037271153d27c62 |
18 files changed, 152 insertions(+), 52 deletions(-)
CMakeLists.txt+1| ... | @@ -590,6 +590,7 @@ set(ZIG_STD_FILES | ... | @@ -590,6 +590,7 @@ set(ZIG_STD_FILES |
| 590 | "os/freebsd/x86_64.zig" | 590 | "os/freebsd/x86_64.zig" |
| 591 | "os/path.zig" | 591 | "os/path.zig" |
| 592 | "os/time.zig" | 592 | "os/time.zig" |
| 593 | "os/uefi/index.zig" | ||
| 593 | "os/windows/advapi32.zig" | 594 | "os/windows/advapi32.zig" |
| 594 | "os/windows/error.zig" | 595 | "os/windows/error.zig" |
| 595 | "os/windows/index.zig" | 596 | "os/windows/index.zig" |
src-self-hosted/target.zig+1-1| ... | @@ -520,7 +520,7 @@ pub const Target = union(enum) { | ... | @@ -520,7 +520,7 @@ pub const Target = union(enum) { |
| 520 | => return 64, | 520 | => return 64, |
| 521 | }, | 521 | }, |
| 522 | 522 | ||
| 523 | builtin.Os.windows => switch (id) { | 523 | builtin.Os.windows, builtin.Os.uefi => switch (id) { |
| 524 | CInt.Id.Short, | 524 | CInt.Id.Short, |
| 525 | CInt.Id.UShort, | 525 | CInt.Id.UShort, |
| 526 | => return 16, | 526 | => return 16, |
src/all_types.hpp+1-2| ... | @@ -1754,8 +1754,7 @@ struct CodeGen { | ... | @@ -1754,8 +1754,7 @@ struct CodeGen { |
| 1754 | bool strip_debug_symbols; | 1754 | bool strip_debug_symbols; |
| 1755 | bool is_test_build; | 1755 | bool is_test_build; |
| 1756 | bool is_native_target; | 1756 | bool is_native_target; |
| 1757 | bool windows_subsystem_windows; | 1757 | ZigLLVM_MSVCSubsystemType msvc_subsystem; |
| 1758 | bool windows_subsystem_console; | ||
| 1759 | bool linker_rdynamic; | 1758 | bool linker_rdynamic; |
| 1760 | bool no_rosegment_workaround; | 1759 | bool no_rosegment_workaround; |
| 1761 | bool each_lib_rpath; | 1760 | bool each_lib_rpath; |
src/analyze.cpp+6-6| ... | @@ -3203,24 +3203,25 @@ void add_fn_export(CodeGen *g, ZigFn *fn_table_entry, Buf *symbol_name, GlobalLi | ... | @@ -3203,24 +3203,25 @@ void add_fn_export(CodeGen *g, ZigFn *fn_table_entry, Buf *symbol_name, GlobalLi |
| 3203 | if (ccc) { | 3203 | if (ccc) { |
| 3204 | if (buf_eql_str(symbol_name, "main") && g->libc_link_lib != nullptr) { | 3204 | if (buf_eql_str(symbol_name, "main") && g->libc_link_lib != nullptr) { |
| 3205 | g->have_c_main = true; | 3205 | g->have_c_main = true; |
| 3206 | g->windows_subsystem_windows = false; | 3206 | g->msvc_subsystem = ZigLLVM_MSVC_CONSOLE; |
| 3207 | g->windows_subsystem_console = true; | ||
| 3208 | } else if (buf_eql_str(symbol_name, "WinMain") && | 3207 | } else if (buf_eql_str(symbol_name, "WinMain") && |
| 3209 | g->zig_target.os == OsWindows) | 3208 | g->zig_target.os == OsWindows) |
| 3210 | { | 3209 | { |
| 3211 | g->have_winmain = true; | 3210 | g->have_winmain = true; |
| 3212 | g->windows_subsystem_windows = true; | 3211 | g->msvc_subsystem = ZigLLVM_MSVC_WINDOWS; |
| 3213 | g->windows_subsystem_console = false; | ||
| 3214 | } else if (buf_eql_str(symbol_name, "WinMainCRTStartup") && | 3212 | } else if (buf_eql_str(symbol_name, "WinMainCRTStartup") && |
| 3215 | g->zig_target.os == OsWindows) | 3213 | g->zig_target.os == OsWindows) |
| 3216 | { | 3214 | { |
| 3217 | g->have_winmain_crt_startup = true; | 3215 | g->have_winmain_crt_startup = true; |
| 3216 | g->msvc_subsystem = ZigLLVM_MSVC_WINDOWS; | ||
| 3218 | } else if (buf_eql_str(symbol_name, "DllMainCRTStartup") && | 3217 | } else if (buf_eql_str(symbol_name, "DllMainCRTStartup") && |
| 3219 | g->zig_target.os == OsWindows) | 3218 | g->zig_target.os == OsWindows) |
| 3220 | { | 3219 | { |
| 3221 | g->have_dllmain_crt_startup = true; | 3220 | g->have_dllmain_crt_startup = true; |
| 3221 | g->msvc_subsystem = ZigLLVM_MSVC_WINDOWS; | ||
| 3222 | } | 3222 | } |
| 3223 | } | 3223 | } |
| 3224 | |||
| 3224 | FnExport *fn_export = fn_table_entry->export_list.add_one(); | 3225 | FnExport *fn_export = fn_table_entry->export_list.add_one(); |
| 3225 | memset(fn_export, 0, sizeof(FnExport)); | 3226 | memset(fn_export, 0, sizeof(FnExport)); |
| 3226 | buf_init_from_buf(&fn_export->name, symbol_name); | 3227 | buf_init_from_buf(&fn_export->name, symbol_name); |
| ... | @@ -4376,8 +4377,7 @@ ImportTableEntry *add_source_file(CodeGen *g, PackageTableEntry *package, Buf *r | ... | @@ -4376,8 +4377,7 @@ ImportTableEntry *add_source_file(CodeGen *g, PackageTableEntry *package, Buf *r |
| 4376 | if (is_pub && ok_cc) { | 4377 | if (is_pub && ok_cc) { |
| 4377 | if (buf_eql_str(proto_name, "main")) { | 4378 | if (buf_eql_str(proto_name, "main")) { |
| 4378 | g->have_pub_main = true; | 4379 | g->have_pub_main = true; |
| 4379 | g->windows_subsystem_windows = false; | 4380 | g->msvc_subsystem = ZigLLVM_MSVC_CONSOLE; |
| 4380 | g->windows_subsystem_console = true; | ||
| 4381 | } else if (buf_eql_str(proto_name, "panic")) { | 4381 | } else if (buf_eql_str(proto_name, "panic")) { |
| 4382 | g->have_pub_panic = true; | 4382 | g->have_pub_panic = true; |
| 4383 | } | 4383 | } |
src/codegen.cpp+3-8| ... | @@ -291,11 +291,6 @@ void codegen_add_framework(CodeGen *g, const char *framework) { | ... | @@ -291,11 +291,6 @@ void codegen_add_framework(CodeGen *g, const char *framework) { |
| 291 | g->darwin_frameworks.append(buf_create_from_str(framework)); | 291 | g->darwin_frameworks.append(buf_create_from_str(framework)); |
| 292 | } | 292 | } |
| 293 | 293 | ||
| 294 | void codegen_set_windows_subsystem(CodeGen *g, bool mwindows, bool mconsole) { | ||
| 295 | g->windows_subsystem_windows = mwindows; | ||
| 296 | g->windows_subsystem_console = mconsole; | ||
| 297 | } | ||
| 298 | |||
| 299 | void codegen_set_mmacosx_version_min(CodeGen *g, Buf *mmacosx_version_min) { | 294 | void codegen_set_mmacosx_version_min(CodeGen *g, Buf *mmacosx_version_min) { |
| 300 | g->mmacosx_version_min = mmacosx_version_min; | 295 | g->mmacosx_version_min = mmacosx_version_min; |
| 301 | } | 296 | } |
| ... | @@ -7273,7 +7268,7 @@ static void init(CodeGen *g) { | ... | @@ -7273,7 +7268,7 @@ static void init(CodeGen *g) { |
| 7273 | // LLVM creates invalid binaries on Windows sometimes. | 7268 | // LLVM creates invalid binaries on Windows sometimes. |
| 7274 | // See https://github.com/ziglang/zig/issues/508 | 7269 | // See https://github.com/ziglang/zig/issues/508 |
| 7275 | // As a workaround we do not use target native features on Windows. | 7270 | // As a workaround we do not use target native features on Windows. |
| 7276 | if (g->zig_target.os == OsWindows) { | 7271 | if (g->zig_target.os == OsWindows || g->zig_target.os == OsUefi) { |
| 7277 | target_specific_cpu_args = ""; | 7272 | target_specific_cpu_args = ""; |
| 7278 | target_specific_features = ""; | 7273 | target_specific_features = ""; |
| 7279 | } else { | 7274 | } else { |
| ... | @@ -7519,6 +7514,7 @@ static void gen_root_source(CodeGen *g) { | ... | @@ -7519,6 +7514,7 @@ static void gen_root_source(CodeGen *g) { |
| 7519 | report_errors_and_maybe_exit(g); | 7514 | report_errors_and_maybe_exit(g); |
| 7520 | 7515 | ||
| 7521 | if (!g->is_test_build && g->zig_target.os != OsFreestanding && | 7516 | if (!g->is_test_build && g->zig_target.os != OsFreestanding && |
| 7517 | g->zig_target.os != OsZen && g->zig_target.os != OsUefi && | ||
| 7522 | !g->have_c_main && !g->have_winmain && !g->have_winmain_crt_startup && | 7518 | !g->have_c_main && !g->have_winmain && !g->have_winmain_crt_startup && |
| 7523 | ((g->have_pub_main && g->out_type == OutTypeObj) || g->out_type == OutTypeExe)) | 7519 | ((g->have_pub_main && g->out_type == OutTypeObj) || g->out_type == OutTypeExe)) |
| 7524 | { | 7520 | { |
| ... | @@ -8079,8 +8075,7 @@ static Error check_cache(CodeGen *g, Buf *manifest_dir, Buf *digest) { | ... | @@ -8079,8 +8075,7 @@ static Error check_cache(CodeGen *g, Buf *manifest_dir, Buf *digest) { |
| 8079 | cache_bool(ch, g->strip_debug_symbols); | 8075 | cache_bool(ch, g->strip_debug_symbols); |
| 8080 | cache_bool(ch, g->is_test_build); | 8076 | cache_bool(ch, g->is_test_build); |
| 8081 | cache_bool(ch, g->is_native_target); | 8077 | cache_bool(ch, g->is_native_target); |
| 8082 | cache_bool(ch, g->windows_subsystem_windows); | 8078 | cache_int(ch, g->msvc_subsystem); |
| 8083 | cache_bool(ch, g->windows_subsystem_console); | ||
| 8084 | cache_bool(ch, g->linker_rdynamic); | 8079 | cache_bool(ch, g->linker_rdynamic); |
| 8085 | cache_bool(ch, g->no_rosegment_workaround); | 8080 | cache_bool(ch, g->no_rosegment_workaround); |
| 8086 | cache_bool(ch, g->each_lib_rpath); | 8081 | cache_bool(ch, g->each_lib_rpath); |
src/codegen.hpp-1| ... | @@ -33,7 +33,6 @@ void codegen_set_libc_include_dir(CodeGen *codegen, Buf *libc_include_dir); | ... | @@ -33,7 +33,6 @@ void codegen_set_libc_include_dir(CodeGen *codegen, Buf *libc_include_dir); |
| 33 | void codegen_set_msvc_lib_dir(CodeGen *g, Buf *msvc_lib_dir); | 33 | void codegen_set_msvc_lib_dir(CodeGen *g, Buf *msvc_lib_dir); |
| 34 | void codegen_set_kernel32_lib_dir(CodeGen *codegen, Buf *kernel32_lib_dir); | 34 | void codegen_set_kernel32_lib_dir(CodeGen *codegen, Buf *kernel32_lib_dir); |
| 35 | void codegen_set_dynamic_linker(CodeGen *g, Buf *dynamic_linker); | 35 | void codegen_set_dynamic_linker(CodeGen *g, Buf *dynamic_linker); |
| 36 | void codegen_set_windows_subsystem(CodeGen *g, bool mwindows, bool mconsole); | ||
| 37 | void codegen_add_lib_dir(CodeGen *codegen, const char *dir); | 36 | void codegen_add_lib_dir(CodeGen *codegen, const char *dir); |
| 38 | void codegen_add_forbidden_lib(CodeGen *codegen, Buf *lib); | 37 | void codegen_add_forbidden_lib(CodeGen *codegen, Buf *lib); |
| 39 | LinkLib *codegen_add_link_lib(CodeGen *codegen, Buf *lib); | 38 | LinkLib *codegen_add_link_lib(CodeGen *codegen, Buf *lib); |
src/ir.cpp+7-1| ... | @@ -17872,7 +17872,13 @@ static IrInstruction *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruct | ... | @@ -17872,7 +17872,13 @@ static IrInstruction *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruct |
| 17872 | if (type_is_invalid(cimport_result->value.type)) | 17872 | if (type_is_invalid(cimport_result->value.type)) |
| 17873 | return ira->codegen->invalid_instruction; | 17873 | return ira->codegen->invalid_instruction; |
| 17874 | 17874 | ||
| 17875 | find_libc_include_path(ira->codegen); | 17875 | if (ira->codegen->msvc_subsystem != ZigLLVM_MSVC_EFI_APPLICATION && |
| 17876 | 		ira->codegen->msvc_subsystem != ZigLLVM_MSVC_EFI_BOOT_SERVICE_DRIVER && | ||
| 17877 | 		ira->codegen->msvc_subsystem != ZigLLVM_MSVC_EFI_ROM && | ||
| 17878 | 		ira->codegen->msvc_subsystem != ZigLLVM_MSVC_EFI_RUNTIME_DRIVER) { | ||
| 17879 | |||
| 17880 | 		find_libc_include_path(ira->codegen); | ||
| 17881 | 	} | ||
| 17876 | 17882 | ||
| 17877 | ImportTableEntry *child_import = allocate<ImportTableEntry>(1); | 17883 | ImportTableEntry *child_import = allocate<ImportTableEntry>(1); |
| 17878 | child_import->decls_scope = create_decls_scope(ira->codegen, node, nullptr, nullptr, child_import); | 17884 | child_import->decls_scope = create_decls_scope(ira->codegen, node, nullptr, nullptr, child_import); |
src/link.cpp+58-20| ... | @@ -455,7 +455,7 @@ static void construct_linker_job_coff(LinkJob *lj) { | ... | @@ -455,7 +455,7 @@ static void construct_linker_job_coff(LinkJob *lj) { |
| 455 | 455 | ||
| 456 | lj->args.append("-NOLOGO"); | 456 | lj->args.append("-NOLOGO"); |
| 457 | 457 | ||
| 458 | if (!g->strip_debug_symbols) { | 458 | if (!g->strip_debug_symbols && g->zig_target.os != Os::OsUefi) { |
| 459 | lj->args.append("-DEBUG"); | 459 | lj->args.append("-DEBUG"); |
| 460 | } | 460 | } |
| 461 | 461 | ||
| ... | @@ -466,11 +466,6 @@ static void construct_linker_job_coff(LinkJob *lj) { | ... | @@ -466,11 +466,6 @@ static void construct_linker_job_coff(LinkJob *lj) { |
| 466 | 466 | ||
| 467 | coff_append_machine_arg(g, &lj->args); | 467 | coff_append_machine_arg(g, &lj->args); |
| 468 | 468 | ||
| 469 | if (g->windows_subsystem_windows) { | ||
| 470 | lj->args.append("/SUBSYSTEM:windows"); | ||
| 471 | } else if (g->windows_subsystem_console) { | ||
| 472 | lj->args.append("/SUBSYSTEM:console"); | ||
| 473 | } | ||
| 474 | // The commented out stuff is from when we linked with MinGW | 469 | // The commented out stuff is from when we linked with MinGW |
| 475 | // Now that we're linking with LLD it remains to be determined | 470 | // Now that we're linking with LLD it remains to be determined |
| 476 | // how to handle --target-environ gnu | 471 | // how to handle --target-environ gnu |
| ... | @@ -499,18 +494,47 @@ static void construct_linker_job_coff(LinkJob *lj) { | ... | @@ -499,18 +494,47 @@ static void construct_linker_job_coff(LinkJob *lj) { |
| 499 | // } | 494 | // } |
| 500 | //} | 495 | //} |
| 501 | 496 | ||
| 502 | lj->args.append(buf_ptr(buf_sprintf("-OUT:%s", buf_ptr(&g->output_file_path)))); | ||
| 503 | |||
| 504 | if (g->libc_link_lib != nullptr) { | ||
| 505 | lj->args.append(buf_ptr(buf_sprintf("-LIBPATH:%s", buf_ptr(g->msvc_lib_dir)))); | ||
| 506 | lj->args.append(buf_ptr(buf_sprintf("-LIBPATH:%s", buf_ptr(g->kernel32_lib_dir)))); | ||
| 507 | |||
| 508 | lj->args.append(buf_ptr(buf_sprintf("-LIBPATH:%s", buf_ptr(g->libc_lib_dir)))); | ||
| 509 | if (g->libc_static_lib_dir != nullptr) { | ||
| 510 | lj->args.append(buf_ptr(buf_sprintf("-LIBPATH:%s", buf_ptr(g->libc_static_lib_dir)))); | ||
| 511 | } | ||
| 512 | } | ||
| 513 | 497 | ||
| 498 | // These are n actual command lines from LINK.EXE UEFI builds (app & driver) to be used as guidance cleaning | ||
| 499 | // up a bit for building the COFF linker args: | ||
| 500 | // /OUT:"J:\coding\nebulae\k\x64\Release\k.efi" /LTCG:incremental /Driver /PDB:"J:\coding\nebulae\k\x64\Release\k.pdb" "UefiApplicationEntryPoint.lib" "UefiRuntimeLib.lib" "UefiHiiLib.lib" "UefiHiiServicesLib.lib" "UefiSortLib.lib" "UefiShellLib.lib" "GlueLib.lib" "BaseLib.lib" "BaseDebugPrintErrorLevelLib.lib" "BasePrintLib.lib" "UefiLib.lib" "UefiBootServicesTableLib.lib" "UefiRuntimeServicesTableLib.lib" "UefiDevicePathLibDevicePathProtocol.lib" "UefiDebugLibConOut.lib" "UefiMemoryLib.lib" "UefiMemoryAllocationLib.lib" "BaseSynchronizationLib.lib" "UefiFileHandleLib.lib" /IMPLIB:"J:\coding\nebulae\k\x64\Release\k.lib" /DEBUG:FASTLINK /BASE:"0" /MACHINE:X64 /ENTRY:"EfiMain" /OPT:REF /SAFESEH:NO /SUBSYSTEM:EFI_APPLICATION /MERGE:".rdata=.data" /NOLOGO /ALIGN:32 /NODEFAULTLIB /SECTION:".xdata,D" | ||
| 501 | // /OUT:"J:\coding\VisualUefi\samples\x64\Release\UefiDriver.efi" /LTCG:incremental /Driver /PDB:"J:\coding\VisualUefi\samples\x64\Release\UefiDriver.pdb" "UefiDriverEntryPoint.lib" "UefiHiiLib.lib" "UefiHiiServicesLib.lib" "UefiSortLib.lib" "UefiShellLib.lib" "GlueLib.lib" "BaseLib.lib" "BaseDebugPrintErrorLevelLib.lib" "BasePrintLib.lib" "UefiLib.lib" "UefiBootServicesTableLib.lib" "UefiRuntimeServicesTableLib.lib" "UefiDevicePathLibDevicePathProtocol.lib" "UefiDebugLibConOut.lib" "UefiMemoryLib.lib" "UefiMemoryAllocationLib.lib" "BaseSynchronizationLib.lib" "UefiFileHandleLib.lib" /IMPLIB:"J:\coding\VisualUefi\samples\x64\Release\UefiDriver.lib" /DEBUG:FASTLINK /BASE:"0" /MACHINE:X64 /ENTRY:"EfiMain" /OPT:REF /SAFESEH:NO /SUBSYSTEM:EFI_BOOT_SERVICE_DRIVER /MERGE:".rdata=.data" /NOLOGO /ALIGN:32 /NODEFAULTLIB /SECTION:".xdata,D" | ||
| 502 | |||
| 503 | // Sorry for the goto(s) :) | ||
| 504 | switch (g->msvc_subsystem) { | ||
| 505 | case ZigLLVM_MSVC_CONSOLE: | ||
| 506 | lj->args.append("/SUBSYSTEM:console"); | ||
| 507 | goto building_nt; | ||
| 508 | case ZigLLVM_MSVC_EFI_APPLICATION: | ||
| 509 | lj->args.append("/SUBSYSTEM:efi_application"); | ||
| 510 | goto building_uefi; | ||
| 511 | case ZigLLVM_MSVC_EFI_BOOT_SERVICE_DRIVER: | ||
| 512 | lj->args.append("/SUBSYSTEM:efi_boot_service_driver"); | ||
| 513 | goto building_uefi; | ||
| 514 | case ZigLLVM_MSVC_EFI_ROM: | ||
| 515 | lj->args.append("/SUBSYSTEM:efi_rom"); | ||
| 516 | goto building_uefi; | ||
| 517 | case ZigLLVM_MSVC_EFI_RUNTIME_DRIVER: | ||
| 518 | lj->args.append("/SUBSYSTEM:efi_runtime_driver"); | ||
| 519 | goto building_uefi; | ||
| 520 | case ZigLLVM_MSVC_NATIVE: | ||
| 521 | lj->args.append("/SUBSYSTEM:native"); | ||
| 522 | goto building_nt; | ||
| 523 | case ZigLLVM_MSVC_POSIX: | ||
| 524 | lj->args.append("/SUBSYSTEM:posix"); | ||
| 525 | goto building_nt; | ||
| 526 | case ZigLLVM_MSVC_WINDOWS: | ||
| 527 | lj->args.append("/SUBSYSTEM:windows"); | ||
| 528 | goto building_nt; | ||
| 529 | case ZigLLVM_MSVC_NONE: | ||
| 530 | goto continuing_build; | ||
| 531 | } | ||
| 532 | |||
| 533 | building_uefi: | ||
| 534 | lj->args.append("/BASE:\"0\" /ENTRY:\"EfiMain\" /OPT:REF /SAFESEH:NO /MERGE:\".rdata=.data\" /ALIGN:32 /NODEFAULTLIB /SECTION:\".xdata,D\""); | ||
| 535 | goto continuing_build; | ||
| 536 | |||
| 537 | building_nt: | ||
| 514 | if (lj->link_in_crt) { | 538 | if (lj->link_in_crt) { |
| 515 | const char *lib_str = g->is_static ? "lib" : ""; | 539 | const char *lib_str = g->is_static ? "lib" : ""; |
| 516 | const char *d_str = (g->build_mode == BuildModeDebug) ? "d" : ""; | 540 | const char *d_str = (g->build_mode == BuildModeDebug) ? "d" : ""; |
| ... | @@ -547,16 +571,30 @@ static void construct_linker_job_coff(LinkJob *lj) { | ... | @@ -547,16 +571,30 @@ static void construct_linker_job_coff(LinkJob *lj) { |
| 547 | // msvcrt depends on kernel32 | 571 | // msvcrt depends on kernel32 |
| 548 | lj->args.append("kernel32.lib"); | 572 | lj->args.append("kernel32.lib"); |
| 549 | } else { | 573 | } else { |
| 550 | lj->args.append("-NODEFAULTLIB"); | 574 | lj->args.append("/NODEFAULTLIB"); |
| 551 | if (!is_library) { | 575 | if (!is_library) { |
| 552 | if (g->have_winmain) { | 576 | if (g->have_winmain) { |
| 553 | lj->args.append("-ENTRY:WinMain"); | 577 | lj->args.append("/ENTRY:WinMain"); |
| 554 | } else { | 578 | } else { |
| 555 | lj->args.append("-ENTRY:WinMainCRTStartup"); | 579 | lj->args.append("/ENTRY:WinMainCRTStartup"); |
| 556 | } | 580 | } |
| 557 | } | 581 | } |
| 558 | } | 582 | } |
| 559 | 583 | ||
| 584 | continuing_build: | ||
| 585 | |||
| 586 | lj->args.append(buf_ptr(buf_sprintf("-OUT:%s", buf_ptr(&g->output_file_path)))); | ||
| 587 | |||
| 588 | if (g->libc_link_lib != nullptr) { | ||
| 589 | lj->args.append(buf_ptr(buf_sprintf("-LIBPATH:%s", buf_ptr(g->msvc_lib_dir)))); | ||
| 590 | lj->args.append(buf_ptr(buf_sprintf("-LIBPATH:%s", buf_ptr(g->kernel32_lib_dir)))); | ||
| 591 | |||
| 592 | lj->args.append(buf_ptr(buf_sprintf("-LIBPATH:%s", buf_ptr(g->libc_lib_dir)))); | ||
| 593 | if (g->libc_static_lib_dir != nullptr) { | ||
| 594 | lj->args.append(buf_ptr(buf_sprintf("-LIBPATH:%s", buf_ptr(g->libc_static_lib_dir)))); | ||
| 595 | } | ||
| 596 | } | ||
| 597 | |||
| 560 | if (is_library && !g->is_static) { | 598 | if (is_library && !g->is_static) { |
| 561 | lj->args.append("-DLL"); | 599 | lj->args.append("-DLL"); |
| 562 | } | 600 | } |
src/main.cpp+30-4| ... | @@ -90,9 +90,7 @@ static int print_full_usage(const char *arg0) { | ... | @@ -90,9 +90,7 @@ static int print_full_usage(const char *arg0) { |
| 90 | " -rdynamic add all symbols to the dynamic symbol table\n" | 90 | " -rdynamic add all symbols to the dynamic symbol table\n" |
| 91 | " -rpath [path] add directory to the runtime library search path\n" | 91 | " -rpath [path] add directory to the runtime library search path\n" |
| 92 | " --no-rosegment compromise security to workaround valgrind bug\n" | 92 | " --no-rosegment compromise security to workaround valgrind bug\n" |
| 93 | " -mconsole (windows) --subsystem console to the linker\n" | 93 | " --msvc-subsystem [subsystem] (windows/uefi) /SUBSYSTEM:<subsystem> to the linker\n" " -framework [name] (darwin) link against framework\n" |
| 94 | " -mwindows (windows) --subsystem windows to the linker\n" | ||
| 95 | " -framework [name] (darwin) link against framework\n" | ||
| 96 | " -mios-version-min [ver] (darwin) set iOS deployment target\n" | 94 | " -mios-version-min [ver] (darwin) set iOS deployment target\n" |
| 97 | " -mmacosx-version-min [ver] (darwin) set Mac OS X deployment target\n" | 95 | " -mmacosx-version-min [ver] (darwin) set Mac OS X deployment target\n" |
| 98 | " --ver-major [ver] dynamic library semver major version\n" | 96 | " --ver-major [ver] dynamic library semver major version\n" |
| ... | @@ -395,6 +393,7 @@ int main(int argc, char **argv) { | ... | @@ -395,6 +393,7 @@ int main(int argc, char **argv) { |
| 395 | int runtime_args_start = -1; | 393 | int runtime_args_start = -1; |
| 396 | bool no_rosegment_workaround = false; | 394 | bool no_rosegment_workaround = false; |
| 397 | bool system_linker_hack = false; | 395 | bool system_linker_hack = false; |
| 396 | ZigLLVM_MSVCSubsystemType msvc_subsystem_type = ZigLLVM_MSVC_NONE; | ||
| 398 | 397 | ||
| 399 | if (argc >= 2 && strcmp(argv[1], "build") == 0) { | 398 | if (argc >= 2 && strcmp(argv[1], "build") == 0) { |
| 400 | Buf zig_exe_path_buf = BUF_INIT; | 399 | Buf zig_exe_path_buf = BUF_INIT; |
| ... | @@ -540,6 +539,32 @@ int main(int argc, char **argv) { | ... | @@ -540,6 +539,32 @@ int main(int argc, char **argv) { |
| 540 | verbose_llvm_ir = true; | 539 | verbose_llvm_ir = true; |
| 541 | } else if (strcmp(arg, "--verbose-cimport") == 0) { | 540 | } else if (strcmp(arg, "--verbose-cimport") == 0) { |
| 542 | verbose_cimport = true; | 541 | verbose_cimport = true; |
| 542 | } else if (strcmp(arg, "--msvc-subsystem") == 0) { | ||
| 543 | if (i + 1 >= argc) { | ||
| 544 | fprintf(stderr, "Expected 1 argument after --msvc-subsystem\n"); | ||
| 545 | return print_error_usage(arg0); | ||
| 546 | } | ||
| 547 | i += 1; | ||
| 548 | if (stricmp(argv[i], "CONSOLE") == 0) { | ||
| 549 | msvc_subsystem_type = ZigLLVM_MSVC_CONSOLE; | ||
| 550 | } else if (stricmp(argv[i], "WINDOWS") == 0) { | ||
| 551 | msvc_subsystem_type = ZigLLVM_MSVC_WINDOWS; | ||
| 552 | } else if (stricmp(argv[i], "POSIX") == 0) { | ||
| 553 | msvc_subsystem_type = ZigLLVM_MSVC_POSIX; | ||
| 554 | } else if (stricmp(argv[i], "NATIVE") == 0) { | ||
| 555 | msvc_subsystem_type = ZigLLVM_MSVC_NATIVE; | ||
| 556 | } else if (stricmp(argv[i], "EFI_APPLICATION") == 0) { | ||
| 557 | msvc_subsystem_type = ZigLLVM_MSVC_EFI_APPLICATION; | ||
| 558 | } else if (stricmp(argv[i], "EFI_BOOT_SERVICE_DRIVER") == 0) { | ||
| 559 | msvc_subsystem_type = ZigLLVM_MSVC_EFI_BOOT_SERVICE_DRIVER; | ||
| 560 | } else if (stricmp(argv[i], "EFI_ROM") == 0) { | ||
| 561 | msvc_subsystem_type = ZigLLVM_MSVC_EFI_ROM; | ||
| 562 | } else if (stricmp(argv[i], "EFI_RUNTIME_DRIVER") == 0) { | ||
| 563 | msvc_subsystem_type = ZigLLVM_MSVC_EFI_RUNTIME_DRIVER; | ||
| 564 | } else { | ||
| 565 | fprintf(stderr, "Unknown format %s for --msvc-subsystem argument\n", argv[i]); | ||
| 566 | return EXIT_FAILURE; | ||
| 567 | } | ||
| 543 | } else if (strcmp(arg, "-mwindows") == 0) { | 568 | } else if (strcmp(arg, "-mwindows") == 0) { |
| 544 | mwindows = true; | 569 | mwindows = true; |
| 545 | } else if (strcmp(arg, "-mconsole") == 0) { | 570 | } else if (strcmp(arg, "-mconsole") == 0) { |
| ... | @@ -849,6 +874,8 @@ int main(int argc, char **argv) { | ... | @@ -849,6 +874,8 @@ int main(int argc, char **argv) { |
| 849 | buf_out_name = buf_create_from_str("run"); | 874 | buf_out_name = buf_create_from_str("run"); |
| 850 | } | 875 | } |
| 851 | CodeGen *g = codegen_create(zig_root_source_file, target, out_type, build_mode, get_zig_lib_dir()); | 876 | CodeGen *g = codegen_create(zig_root_source_file, target, out_type, build_mode, get_zig_lib_dir()); |
| 877 | g->msvc_subsystem = msvc_subsystem_type; | ||
| 878 | |||
| 852 | if (disable_pic) { | 879 | if (disable_pic) { |
| 853 | if (out_type != OutTypeLib || !is_static) { | 880 | if (out_type != OutTypeLib || !is_static) { |
| 854 | fprintf(stderr, "--disable-pic only applies to static libraries"); | 881 | fprintf(stderr, "--disable-pic only applies to static libraries"); |
| ... | @@ -909,7 +936,6 @@ int main(int argc, char **argv) { | ... | @@ -909,7 +936,6 @@ int main(int argc, char **argv) { |
| 909 | codegen_add_rpath(g, rpath_list.at(i)); | 936 | codegen_add_rpath(g, rpath_list.at(i)); |
| 910 | } | 937 | } |
| 911 | 938 | ||
| 912 | codegen_set_windows_subsystem(g, mwindows, mconsole); | ||
| 913 | codegen_set_rdynamic(g, rdynamic); | 939 | codegen_set_rdynamic(g, rdynamic); |
| 914 | g->no_rosegment_workaround = no_rosegment_workaround; | 940 | g->no_rosegment_workaround = no_rosegment_workaround; |
| 915 | if (mmacosx_version_min && mios_version_min) { | 941 | if (mmacosx_version_min && mios_version_min) { |
src/target.cpp+8-2| ... | @@ -174,6 +174,7 @@ static const Os os_list[] = { | ... | @@ -174,6 +174,7 @@ static const Os os_list[] = { |
| 174 | OsContiki, | 174 | OsContiki, |
| 175 | OsAMDPAL, | 175 | OsAMDPAL, |
| 176 | OsZen, | 176 | OsZen, |
| 177 | OsUefi, | ||
| 177 | }; | 178 | }; |
| 178 | 179 | ||
| 179 | // Coordinate with zig_llvm.h | 180 | // Coordinate with zig_llvm.h |
| ... | @@ -315,6 +316,8 @@ ZigLLVM_OSType get_llvm_os_type(Os os_type) { | ... | @@ -315,6 +316,8 @@ ZigLLVM_OSType get_llvm_os_type(Os os_type) { |
| 315 | return ZigLLVM_Contiki; | 316 | return ZigLLVM_Contiki; |
| 316 | case OsAMDPAL: | 317 | case OsAMDPAL: |
| 317 | return ZigLLVM_AMDPAL; | 318 | return ZigLLVM_AMDPAL; |
| 319 | case OsUefi: | ||
| 320 | return ZigLLVM_Uefi; | ||
| 318 | } | 321 | } |
| 319 | zig_unreachable(); | 322 | zig_unreachable(); |
| 320 | } | 323 | } |
| ... | @@ -756,6 +759,7 @@ uint32_t target_c_type_size_in_bits(const ZigTarget *target, CIntType id) { | ... | @@ -756,6 +759,7 @@ uint32_t target_c_type_size_in_bits(const ZigTarget *target, CIntType id) { |
| 756 | case CIntTypeCount: | 759 | case CIntTypeCount: |
| 757 | zig_unreachable(); | 760 | zig_unreachable(); |
| 758 | } | 761 | } |
| 762 | case OsUefi: | ||
| 759 | case OsWindows: | 763 | case OsWindows: |
| 760 | switch (id) { | 764 | switch (id) { |
| 761 | case CIntTypeShort: | 765 | case CIntTypeShort: |
| ... | @@ -803,7 +807,7 @@ uint32_t target_c_type_size_in_bits(const ZigTarget *target, CIntType id) { | ... | @@ -803,7 +807,7 @@ uint32_t target_c_type_size_in_bits(const ZigTarget *target, CIntType id) { |
| 803 | } | 807 | } |
| 804 | 808 | ||
| 805 | const char *target_o_file_ext(ZigTarget *target) { | 809 | const char *target_o_file_ext(ZigTarget *target) { |
| 806 | if (target->env_type == ZigLLVM_MSVC || target->os == OsWindows) { | 810 | if (target->env_type == ZigLLVM_MSVC || (target->os == OsWindows || target->os == OsUefi)) { |
| 807 | return ".obj"; | 811 | return ".obj"; |
| 808 | } else { | 812 | } else { |
| 809 | return ".o"; | 813 | return ".o"; |
| ... | @@ -821,13 +825,15 @@ const char *target_llvm_ir_file_ext(ZigTarget *target) { | ... | @@ -821,13 +825,15 @@ const char *target_llvm_ir_file_ext(ZigTarget *target) { |
| 821 | const char *target_exe_file_ext(ZigTarget *target) { | 825 | const char *target_exe_file_ext(ZigTarget *target) { |
| 822 | if (target->os == OsWindows) { | 826 | if (target->os == OsWindows) { |
| 823 | return ".exe"; | 827 | return ".exe"; |
| 828 | } else if (target->os == OsUefi) { | ||
| 829 | return ".efi"; | ||
| 824 | } else { | 830 | } else { |
| 825 | return ""; | 831 | return ""; |
| 826 | } | 832 | } |
| 827 | } | 833 | } |
| 828 | 834 | ||
| 829 | const char *target_lib_file_ext(ZigTarget *target, bool is_static, size_t version_major, size_t version_minor, size_t version_patch) { | 835 | const char *target_lib_file_ext(ZigTarget *target, bool is_static, size_t version_major, size_t version_minor, size_t version_patch) { |
| 830 | if (target->os == OsWindows) { | 836 | if (target->os == OsWindows || target->os == OsUefi) { |
| 831 | if (is_static) { | 837 | if (is_static) { |
| 832 | return ".lib"; | 838 | return ".lib"; |
| 833 | } else { | 839 | } else { |
src/target.hpp+2| ... | @@ -51,6 +51,7 @@ enum Os { | ... | @@ -51,6 +51,7 @@ enum Os { |
| 51 | OsContiki, | 51 | OsContiki, |
| 52 | OsAMDPAL, | 52 | OsAMDPAL, |
| 53 | OsZen, | 53 | OsZen, |
| 54 | OsUefi, | ||
| 54 | }; | 55 | }; |
| 55 | 56 | ||
| 56 | struct ZigTarget { | 57 | struct ZigTarget { |
| ... | @@ -59,6 +60,7 @@ struct ZigTarget { | ... | @@ -59,6 +60,7 @@ struct ZigTarget { |
| 59 | Os os; | 60 | Os os; |
| 60 | ZigLLVM_EnvironmentType env_type; | 61 | ZigLLVM_EnvironmentType env_type; |
| 61 | ZigLLVM_ObjectFormatType oformat; | 62 | ZigLLVM_ObjectFormatType oformat; |
| 63 | ZigLLVM_MSVCSubsystemType msvc_subsystem = ZigLLVM_MSVC_NONE; | ||
| 62 | }; | 64 | }; |
| 63 | 65 | ||
| 64 | enum CIntType { | 66 | enum CIntType { |
src/translate_c.cpp+4-2| ... | @@ -4749,8 +4749,10 @@ Error parse_h_file(ImportTableEntry *import, ZigList<ErrorMsg *> *errors, const | ... | @@ -4749,8 +4749,10 @@ Error parse_h_file(ImportTableEntry *import, ZigList<ErrorMsg *> *errors, const |
| 4749 | clang_argv.append("-isystem"); | 4749 | clang_argv.append("-isystem"); |
| 4750 | clang_argv.append(buf_ptr(codegen->zig_c_headers_dir)); | 4750 | clang_argv.append(buf_ptr(codegen->zig_c_headers_dir)); |
| 4751 | 4751 | ||
| 4752 | clang_argv.append("-isystem"); | 4752 | if (codegen->libc_include_dir) { |
| 4753 | clang_argv.append(buf_ptr(codegen->libc_include_dir)); | 4753 | clang_argv.append("-isystem"); |
| 4754 | clang_argv.append(buf_ptr(codegen->libc_include_dir)); | ||
| 4755 | } | ||
| 4754 | 4756 | ||
| 4755 | // windows c runtime requires -D_DEBUG if using debug libraries | 4757 | // windows c runtime requires -D_DEBUG if using debug libraries |
| 4756 | if (codegen->build_mode == BuildModeDebug) { | 4758 | if (codegen->build_mode == BuildModeDebug) { |
src/zig_llvm.cpp+6-1| ... | @@ -690,7 +690,12 @@ const char *ZigLLVMGetVendorTypeName(ZigLLVM_VendorType vendor) { | ... | @@ -690,7 +690,12 @@ const char *ZigLLVMGetVendorTypeName(ZigLLVM_VendorType vendor) { |
| 690 | } | 690 | } |
| 691 | 691 | ||
| 692 | const char *ZigLLVMGetOSTypeName(ZigLLVM_OSType os) { | 692 | const char *ZigLLVMGetOSTypeName(ZigLLVM_OSType os) { |
| 693 | return (const char*)Triple::getOSTypeName((Triple::OSType)os).bytes_begin(); | 693 | switch (os) { |
| 694 | 	case ZigLLVM_Uefi: | ||
| 695 | 		return "windows"; | ||
| 696 | 	default: | ||
| 697 | 		return (const char*)Triple::getOSTypeName((Triple::OSType)os).bytes_begin(); | ||
| 698 | 	} | ||
| 694 | } | 699 | } |
| 695 | 700 | ||
| 696 | const char *ZigLLVMGetEnvironmentTypeName(ZigLLVM_EnvironmentType env_type) { | 701 | const char *ZigLLVMGetEnvironmentTypeName(ZigLLVM_EnvironmentType env_type) { |
src/zig_llvm.h+16-2| ... | @@ -10,6 +10,7 @@ | ... | @@ -10,6 +10,7 @@ |
| 10 | 10 | ||
| 11 | #include <stdbool.h> | 11 | #include <stdbool.h> |
| 12 | #include <stddef.h> | 12 | #include <stddef.h> |
| 13 | #include <stdint.h> | ||
| 13 | #include <llvm-c/Core.h> | 14 | #include <llvm-c/Core.h> |
| 14 | #include <llvm-c/Analysis.h> | 15 | #include <llvm-c/Analysis.h> |
| 15 | #include <llvm-c/Target.h> | 16 | #include <llvm-c/Target.h> |
| ... | @@ -357,8 +358,8 @@ enum ZigLLVM_OSType { | ... | @@ -357,8 +358,8 @@ enum ZigLLVM_OSType { |
| 357 | ZigLLVM_Mesa3D, | 358 | ZigLLVM_Mesa3D, |
| 358 | ZigLLVM_Contiki, | 359 | ZigLLVM_Contiki, |
| 359 | ZigLLVM_AMDPAL, // AMD PAL Runtime | 360 | ZigLLVM_AMDPAL, // AMD PAL Runtime |
| 360 | 361 | ZigLLVM_Uefi, | |
| 361 | ZigLLVM_LastOSType = ZigLLVM_AMDPAL | 362 | ZigLLVM_LastOSType = ZigLLVM_Uefi |
| 362 | }; | 363 | }; |
| 363 | 364 | ||
| 364 | // Synchronize with target.cpp::environ_list | 365 | // Synchronize with target.cpp::environ_list |
| ... | @@ -397,6 +398,19 @@ enum ZigLLVM_ObjectFormatType { | ... | @@ -397,6 +398,19 @@ enum ZigLLVM_ObjectFormatType { |
| 397 | ZigLLVM_Wasm, | 398 | ZigLLVM_Wasm, |
| 398 | }; | 399 | }; |
| 399 | 400 | ||
| 401 | // For MSVC-supported subsystems | ||
| 402 | enum ZigLLVM_MSVCSubsystemType { | ||
| 403 | ZigLLVM_MSVC_NONE, | ||
| 404 | ZigLLVM_MSVC_CONSOLE, | ||
| 405 | ZigLLVM_MSVC_WINDOWS, | ||
| 406 | ZigLLVM_MSVC_POSIX, | ||
| 407 | ZigLLVM_MSVC_NATIVE, | ||
| 408 | ZigLLVM_MSVC_EFI_APPLICATION, | ||
| 409 | ZigLLVM_MSVC_EFI_BOOT_SERVICE_DRIVER, | ||
| 410 | ZigLLVM_MSVC_EFI_ROM, | ||
| 411 | ZigLLVM_MSVC_EFI_RUNTIME_DRIVER, | ||
| 412 | }; | ||
| 413 | |||
| 400 | ZIG_EXTERN_C const char *ZigLLVMGetArchTypeName(enum ZigLLVM_ArchType arch); | 414 | ZIG_EXTERN_C const char *ZigLLVMGetArchTypeName(enum ZigLLVM_ArchType arch); |
| 401 | ZIG_EXTERN_C const char *ZigLLVMGetSubArchTypeName(enum ZigLLVM_SubArchType sub_arch); | 415 | ZIG_EXTERN_C const char *ZigLLVMGetSubArchTypeName(enum ZigLLVM_SubArchType sub_arch); |
| 402 | ZIG_EXTERN_C const char *ZigLLVMGetVendorTypeName(enum ZigLLVM_VendorType vendor); | 416 | ZIG_EXTERN_C const char *ZigLLVMGetVendorTypeName(enum ZigLLVM_VendorType vendor); |
std/debug/index.zig+1-1| ... | @@ -1135,7 +1135,7 @@ pub const DebugInfo = switch (builtin.os) { | ... | @@ -1135,7 +1135,7 @@ pub const DebugInfo = switch (builtin.os) { |
| 1135 | return self.ofiles.allocator; | 1135 | return self.ofiles.allocator; |
| 1136 | } | 1136 | } |
| 1137 | }, | 1137 | }, |
| 1138 | builtin.Os.windows => struct { | 1138 | builtin.Os.uefi, builtin.Os.windows => struct { |
| 1139 | pdb: pdb.Pdb, | 1139 | pdb: pdb.Pdb, |
| 1140 | coff: *coff.Coff, | 1140 | coff: *coff.Coff, |
| 1141 | sect_contribs: []pdb.SectionContribEntry, | 1141 | sect_contribs: []pdb.SectionContribEntry, |
std/os/index.zig+7| ... | @@ -18,6 +18,7 @@ test "std.os" { | ... | @@ -18,6 +18,7 @@ test "std.os" { |
| 18 | _ = @import("test.zig"); | 18 | _ = @import("test.zig"); |
| 19 | _ = @import("time.zig"); | 19 | _ = @import("time.zig"); |
| 20 | _ = @import("windows/index.zig"); | 20 | _ = @import("windows/index.zig"); |
| 21 | _ = @import("uefi/index.zig"); | ||
| 21 | _ = @import("get_app_data_dir.zig"); | 22 | _ = @import("get_app_data_dir.zig"); |
| 22 | } | 23 | } |
| 23 | 24 | ||
| ... | @@ -26,6 +27,8 @@ pub const darwin = @import("darwin.zig"); | ... | @@ -26,6 +27,8 @@ pub const darwin = @import("darwin.zig"); |
| 26 | pub const linux = @import("linux/index.zig"); | 27 | pub const linux = @import("linux/index.zig"); |
| 27 | pub const freebsd = @import("freebsd/index.zig"); | 28 | pub const freebsd = @import("freebsd/index.zig"); |
| 28 | pub const zen = @import("zen.zig"); | 29 | pub const zen = @import("zen.zig"); |
| 30 | pub const uefi = @import("uefi/index.zig"); | ||
| 31 | |||
| 29 | pub const posix = switch (builtin.os) { | 32 | pub const posix = switch (builtin.os) { |
| 30 | Os.linux => linux, | 33 | Os.linux => linux, |
| 31 | Os.macosx, Os.ios => darwin, | 34 | Os.macosx, Os.ios => darwin, |
| ... | @@ -33,6 +36,7 @@ pub const posix = switch (builtin.os) { | ... | @@ -33,6 +36,7 @@ pub const posix = switch (builtin.os) { |
| 33 | Os.zen => zen, | 36 | Os.zen => zen, |
| 34 | else => @compileError("Unsupported OS"), | 37 | else => @compileError("Unsupported OS"), |
| 35 | }; | 38 | }; |
| 39 | |||
| 36 | pub const net = @import("net.zig"); | 40 | pub const net = @import("net.zig"); |
| 37 | 41 | ||
| 38 | pub const ChildProcess = @import("child_process.zig").ChildProcess; | 42 | pub const ChildProcess = @import("child_process.zig").ChildProcess; |
| ... | @@ -187,6 +191,9 @@ pub fn abort() noreturn { | ... | @@ -187,6 +191,9 @@ pub fn abort() noreturn { |
| 187 | } | 191 | } |
| 188 | windows.ExitProcess(3); | 192 | windows.ExitProcess(3); |
| 189 | }, | 193 | }, |
| 194 | Os.uefi => { | ||
| 195 | while (true) {} | ||
| 196 | }, | ||
| 190 | else => @compileError("Unsupported OS"), | 197 | else => @compileError("Unsupported OS"), |
| 191 | } | 198 | } |
| 192 | } | 199 | } |
std/os/uefi/index.zig createdstd/special/panic.zig+1-1| ... | @@ -10,7 +10,7 @@ pub fn panic(msg: []const u8, error_return_trace: ?*builtin.StackTrace) noreturn | ... | @@ -10,7 +10,7 @@ pub fn panic(msg: []const u8, error_return_trace: ?*builtin.StackTrace) noreturn |
| 10 | @setCold(true); | 10 | @setCold(true); |
| 11 | switch (builtin.os) { | 11 | switch (builtin.os) { |
| 12 | // TODO: fix panic in zen. | 12 | // TODO: fix panic in zen. |
| 13 | builtin.Os.freestanding, builtin.Os.zen => { | 13 | builtin.Os.freestanding, builtin.Os.zen, builtin.Os.uefi => { |
| 14 | while (true) {} | 14 | while (true) {} |
| 15 | }, | 15 | }, |
| 16 | else => { | 16 | else => { |