Altered SUBSYSTEM option handling when linking in msvc mode; Added preliminary UEFI support.

master
nebulaeonline 2018-12-23 22:21:32 -05:00
parent 280187031a
commit 39d32ee40a
18 changed files with 152 additions and 50 deletions

View File

@ -590,6 +590,7 @@ set(ZIG_STD_FILES
"os/freebsd/x86_64.zig" "os/freebsd/x86_64.zig"
"os/path.zig" "os/path.zig"
"os/time.zig" "os/time.zig"
"os/uefi/index.zig"
"os/windows/advapi32.zig" "os/windows/advapi32.zig"
"os/windows/error.zig" "os/windows/error.zig"
"os/windows/index.zig" "os/windows/index.zig"

View File

@ -520,7 +520,7 @@ pub const Target = union(enum) {
=> return 64, => return 64,
}, },
builtin.Os.windows => switch (id) { builtin.Os.windows, builtin.Os.uefi => switch (id) {
CInt.Id.Short, CInt.Id.Short,
CInt.Id.UShort, CInt.Id.UShort,
=> return 16, => return 16,

View File

@ -1754,8 +1754,7 @@ struct CodeGen {
bool strip_debug_symbols; bool strip_debug_symbols;
bool is_test_build; bool is_test_build;
bool is_native_target; bool is_native_target;
bool windows_subsystem_windows; ZigLLVM_MSVCSubsystemType msvc_subsystem;
bool windows_subsystem_console;
bool linker_rdynamic; bool linker_rdynamic;
bool no_rosegment_workaround; bool no_rosegment_workaround;
bool each_lib_rpath; bool each_lib_rpath;

View File

@ -3203,24 +3203,25 @@ void add_fn_export(CodeGen *g, ZigFn *fn_table_entry, Buf *symbol_name, GlobalLi
if (ccc) { if (ccc) {
if (buf_eql_str(symbol_name, "main") && g->libc_link_lib != nullptr) { if (buf_eql_str(symbol_name, "main") && g->libc_link_lib != nullptr) {
g->have_c_main = true; g->have_c_main = true;
g->windows_subsystem_windows = false; g->msvc_subsystem = ZigLLVM_MSVC_CONSOLE;
g->windows_subsystem_console = true;
} else if (buf_eql_str(symbol_name, "WinMain") && } else if (buf_eql_str(symbol_name, "WinMain") &&
g->zig_target.os == OsWindows) g->zig_target.os == OsWindows)
{ {
g->have_winmain = true; g->have_winmain = true;
g->windows_subsystem_windows = true; g->msvc_subsystem = ZigLLVM_MSVC_WINDOWS;
g->windows_subsystem_console = false;
} else if (buf_eql_str(symbol_name, "WinMainCRTStartup") && } else if (buf_eql_str(symbol_name, "WinMainCRTStartup") &&
g->zig_target.os == OsWindows) g->zig_target.os == OsWindows)
{ {
g->have_winmain_crt_startup = true; g->have_winmain_crt_startup = true;
g->msvc_subsystem = ZigLLVM_MSVC_WINDOWS;
} else if (buf_eql_str(symbol_name, "DllMainCRTStartup") && } else if (buf_eql_str(symbol_name, "DllMainCRTStartup") &&
g->zig_target.os == OsWindows) g->zig_target.os == OsWindows)
{ {
g->have_dllmain_crt_startup = true; g->have_dllmain_crt_startup = true;
g->msvc_subsystem = ZigLLVM_MSVC_WINDOWS;
} }
} }
FnExport *fn_export = fn_table_entry->export_list.add_one(); FnExport *fn_export = fn_table_entry->export_list.add_one();
memset(fn_export, 0, sizeof(FnExport)); memset(fn_export, 0, sizeof(FnExport));
buf_init_from_buf(&fn_export->name, symbol_name); buf_init_from_buf(&fn_export->name, symbol_name);
@ -4376,8 +4377,7 @@ ImportTableEntry *add_source_file(CodeGen *g, PackageTableEntry *package, Buf *r
if (is_pub && ok_cc) { if (is_pub && ok_cc) {
if (buf_eql_str(proto_name, "main")) { if (buf_eql_str(proto_name, "main")) {
g->have_pub_main = true; g->have_pub_main = true;
g->windows_subsystem_windows = false; g->msvc_subsystem = ZigLLVM_MSVC_CONSOLE;
g->windows_subsystem_console = true;
} else if (buf_eql_str(proto_name, "panic")) { } else if (buf_eql_str(proto_name, "panic")) {
g->have_pub_panic = true; g->have_pub_panic = true;
} }

View File

@ -291,11 +291,6 @@ void codegen_add_framework(CodeGen *g, const char *framework) {
g->darwin_frameworks.append(buf_create_from_str(framework)); g->darwin_frameworks.append(buf_create_from_str(framework));
} }
void codegen_set_windows_subsystem(CodeGen *g, bool mwindows, bool mconsole) {
g->windows_subsystem_windows = mwindows;
g->windows_subsystem_console = mconsole;
}
void codegen_set_mmacosx_version_min(CodeGen *g, Buf *mmacosx_version_min) { void codegen_set_mmacosx_version_min(CodeGen *g, Buf *mmacosx_version_min) {
g->mmacosx_version_min = mmacosx_version_min; g->mmacosx_version_min = mmacosx_version_min;
} }
@ -7273,7 +7268,7 @@ static void init(CodeGen *g) {
// LLVM creates invalid binaries on Windows sometimes. // LLVM creates invalid binaries on Windows sometimes.
// See https://github.com/ziglang/zig/issues/508 // See https://github.com/ziglang/zig/issues/508
// As a workaround we do not use target native features on Windows. // As a workaround we do not use target native features on Windows.
if (g->zig_target.os == OsWindows) { if (g->zig_target.os == OsWindows || g->zig_target.os == OsUefi) {
target_specific_cpu_args = ""; target_specific_cpu_args = "";
target_specific_features = ""; target_specific_features = "";
} else { } else {
@ -7519,6 +7514,7 @@ static void gen_root_source(CodeGen *g) {
report_errors_and_maybe_exit(g); report_errors_and_maybe_exit(g);
if (!g->is_test_build && g->zig_target.os != OsFreestanding && if (!g->is_test_build && g->zig_target.os != OsFreestanding &&
g->zig_target.os != OsZen && g->zig_target.os != OsUefi &&
!g->have_c_main && !g->have_winmain && !g->have_winmain_crt_startup && !g->have_c_main && !g->have_winmain && !g->have_winmain_crt_startup &&
((g->have_pub_main && g->out_type == OutTypeObj) || g->out_type == OutTypeExe)) ((g->have_pub_main && g->out_type == OutTypeObj) || g->out_type == OutTypeExe))
{ {
@ -8079,8 +8075,7 @@ static Error check_cache(CodeGen *g, Buf *manifest_dir, Buf *digest) {
cache_bool(ch, g->strip_debug_symbols); cache_bool(ch, g->strip_debug_symbols);
cache_bool(ch, g->is_test_build); cache_bool(ch, g->is_test_build);
cache_bool(ch, g->is_native_target); cache_bool(ch, g->is_native_target);
cache_bool(ch, g->windows_subsystem_windows); cache_int(ch, g->msvc_subsystem);
cache_bool(ch, g->windows_subsystem_console);
cache_bool(ch, g->linker_rdynamic); cache_bool(ch, g->linker_rdynamic);
cache_bool(ch, g->no_rosegment_workaround); cache_bool(ch, g->no_rosegment_workaround);
cache_bool(ch, g->each_lib_rpath); cache_bool(ch, g->each_lib_rpath);

View File

@ -33,7 +33,6 @@ void codegen_set_libc_include_dir(CodeGen *codegen, Buf *libc_include_dir);
void codegen_set_msvc_lib_dir(CodeGen *g, Buf *msvc_lib_dir); void codegen_set_msvc_lib_dir(CodeGen *g, Buf *msvc_lib_dir);
void codegen_set_kernel32_lib_dir(CodeGen *codegen, Buf *kernel32_lib_dir); void codegen_set_kernel32_lib_dir(CodeGen *codegen, Buf *kernel32_lib_dir);
void codegen_set_dynamic_linker(CodeGen *g, Buf *dynamic_linker); void codegen_set_dynamic_linker(CodeGen *g, Buf *dynamic_linker);
void codegen_set_windows_subsystem(CodeGen *g, bool mwindows, bool mconsole);
void codegen_add_lib_dir(CodeGen *codegen, const char *dir); void codegen_add_lib_dir(CodeGen *codegen, const char *dir);
void codegen_add_forbidden_lib(CodeGen *codegen, Buf *lib); void codegen_add_forbidden_lib(CodeGen *codegen, Buf *lib);
LinkLib *codegen_add_link_lib(CodeGen *codegen, Buf *lib); LinkLib *codegen_add_link_lib(CodeGen *codegen, Buf *lib);

View File

@ -17872,7 +17872,13 @@ static IrInstruction *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruct
if (type_is_invalid(cimport_result->value.type)) if (type_is_invalid(cimport_result->value.type))
return ira->codegen->invalid_instruction; return ira->codegen->invalid_instruction;
if (ira->codegen->msvc_subsystem != ZigLLVM_MSVC_EFI_APPLICATION &&
ira->codegen->msvc_subsystem != ZigLLVM_MSVC_EFI_BOOT_SERVICE_DRIVER &&
ira->codegen->msvc_subsystem != ZigLLVM_MSVC_EFI_ROM &&
ira->codegen->msvc_subsystem != ZigLLVM_MSVC_EFI_RUNTIME_DRIVER) {
find_libc_include_path(ira->codegen); find_libc_include_path(ira->codegen);
}
ImportTableEntry *child_import = allocate<ImportTableEntry>(1); ImportTableEntry *child_import = allocate<ImportTableEntry>(1);
child_import->decls_scope = create_decls_scope(ira->codegen, node, nullptr, nullptr, child_import); child_import->decls_scope = create_decls_scope(ira->codegen, node, nullptr, nullptr, child_import);

View File

@ -455,7 +455,7 @@ static void construct_linker_job_coff(LinkJob *lj) {
lj->args.append("-NOLOGO"); lj->args.append("-NOLOGO");
if (!g->strip_debug_symbols) { if (!g->strip_debug_symbols && g->zig_target.os != Os::OsUefi) {
lj->args.append("-DEBUG"); lj->args.append("-DEBUG");
} }
@ -466,11 +466,6 @@ static void construct_linker_job_coff(LinkJob *lj) {
coff_append_machine_arg(g, &lj->args); coff_append_machine_arg(g, &lj->args);
if (g->windows_subsystem_windows) {
lj->args.append("/SUBSYSTEM:windows");
} else if (g->windows_subsystem_console) {
lj->args.append("/SUBSYSTEM:console");
}
// The commented out stuff is from when we linked with MinGW // The commented out stuff is from when we linked with MinGW
// Now that we're linking with LLD it remains to be determined // Now that we're linking with LLD it remains to be determined
// how to handle --target-environ gnu // how to handle --target-environ gnu
@ -499,18 +494,47 @@ static void construct_linker_job_coff(LinkJob *lj) {
// } // }
//} //}
lj->args.append(buf_ptr(buf_sprintf("-OUT:%s", buf_ptr(&g->output_file_path))));
if (g->libc_link_lib != nullptr) { // These are n actual command lines from LINK.EXE UEFI builds (app & driver) to be used as guidance cleaning
lj->args.append(buf_ptr(buf_sprintf("-LIBPATH:%s", buf_ptr(g->msvc_lib_dir)))); // up a bit for building the COFF linker args:
lj->args.append(buf_ptr(buf_sprintf("-LIBPATH:%s", buf_ptr(g->kernel32_lib_dir)))); // /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"
// /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"
lj->args.append(buf_ptr(buf_sprintf("-LIBPATH:%s", buf_ptr(g->libc_lib_dir)))); // Sorry for the goto(s) :)
if (g->libc_static_lib_dir != nullptr) { switch (g->msvc_subsystem) {
lj->args.append(buf_ptr(buf_sprintf("-LIBPATH:%s", buf_ptr(g->libc_static_lib_dir)))); case ZigLLVM_MSVC_CONSOLE:
} lj->args.append("/SUBSYSTEM:console");
goto building_nt;
case ZigLLVM_MSVC_EFI_APPLICATION:
lj->args.append("/SUBSYSTEM:efi_application");
goto building_uefi;
case ZigLLVM_MSVC_EFI_BOOT_SERVICE_DRIVER:
lj->args.append("/SUBSYSTEM:efi_boot_service_driver");
goto building_uefi;
case ZigLLVM_MSVC_EFI_ROM:
lj->args.append("/SUBSYSTEM:efi_rom");
goto building_uefi;
case ZigLLVM_MSVC_EFI_RUNTIME_DRIVER:
lj->args.append("/SUBSYSTEM:efi_runtime_driver");
goto building_uefi;
case ZigLLVM_MSVC_NATIVE:
lj->args.append("/SUBSYSTEM:native");
goto building_nt;
case ZigLLVM_MSVC_POSIX:
lj->args.append("/SUBSYSTEM:posix");
goto building_nt;
case ZigLLVM_MSVC_WINDOWS:
lj->args.append("/SUBSYSTEM:windows");
goto building_nt;
case ZigLLVM_MSVC_NONE:
goto continuing_build;
} }
building_uefi:
lj->args.append("/BASE:\"0\" /ENTRY:\"EfiMain\" /OPT:REF /SAFESEH:NO /MERGE:\".rdata=.data\" /ALIGN:32 /NODEFAULTLIB /SECTION:\".xdata,D\"");
goto continuing_build;
building_nt:
if (lj->link_in_crt) { if (lj->link_in_crt) {
const char *lib_str = g->is_static ? "lib" : ""; const char *lib_str = g->is_static ? "lib" : "";
const char *d_str = (g->build_mode == BuildModeDebug) ? "d" : ""; const char *d_str = (g->build_mode == BuildModeDebug) ? "d" : "";
@ -547,16 +571,30 @@ static void construct_linker_job_coff(LinkJob *lj) {
// msvcrt depends on kernel32 // msvcrt depends on kernel32
lj->args.append("kernel32.lib"); lj->args.append("kernel32.lib");
} else { } else {
lj->args.append("-NODEFAULTLIB"); lj->args.append("/NODEFAULTLIB");
if (!is_library) { if (!is_library) {
if (g->have_winmain) { if (g->have_winmain) {
lj->args.append("-ENTRY:WinMain"); lj->args.append("/ENTRY:WinMain");
} else { } else {
lj->args.append("-ENTRY:WinMainCRTStartup"); lj->args.append("/ENTRY:WinMainCRTStartup");
} }
} }
} }
continuing_build:
lj->args.append(buf_ptr(buf_sprintf("-OUT:%s", buf_ptr(&g->output_file_path))));
if (g->libc_link_lib != nullptr) {
lj->args.append(buf_ptr(buf_sprintf("-LIBPATH:%s", buf_ptr(g->msvc_lib_dir))));
lj->args.append(buf_ptr(buf_sprintf("-LIBPATH:%s", buf_ptr(g->kernel32_lib_dir))));
lj->args.append(buf_ptr(buf_sprintf("-LIBPATH:%s", buf_ptr(g->libc_lib_dir))));
if (g->libc_static_lib_dir != nullptr) {
lj->args.append(buf_ptr(buf_sprintf("-LIBPATH:%s", buf_ptr(g->libc_static_lib_dir))));
}
}
if (is_library && !g->is_static) { if (is_library && !g->is_static) {
lj->args.append("-DLL"); lj->args.append("-DLL");
} }

View File

@ -90,9 +90,7 @@ static int print_full_usage(const char *arg0) {
" -rdynamic add all symbols to the dynamic symbol table\n" " -rdynamic add all symbols to the dynamic symbol table\n"
" -rpath [path] add directory to the runtime library search path\n" " -rpath [path] add directory to the runtime library search path\n"
" --no-rosegment compromise security to workaround valgrind bug\n" " --no-rosegment compromise security to workaround valgrind bug\n"
" -mconsole (windows) --subsystem console to the linker\n" " --msvc-subsystem [subsystem] (windows/uefi) /SUBSYSTEM:<subsystem> to the linker\n" " -framework [name] (darwin) link against framework\n"
" -mwindows (windows) --subsystem windows to the linker\n"
" -framework [name] (darwin) link against framework\n"
" -mios-version-min [ver] (darwin) set iOS deployment target\n" " -mios-version-min [ver] (darwin) set iOS deployment target\n"
" -mmacosx-version-min [ver] (darwin) set Mac OS X deployment target\n" " -mmacosx-version-min [ver] (darwin) set Mac OS X deployment target\n"
" --ver-major [ver] dynamic library semver major version\n" " --ver-major [ver] dynamic library semver major version\n"
@ -395,6 +393,7 @@ int main(int argc, char **argv) {
int runtime_args_start = -1; int runtime_args_start = -1;
bool no_rosegment_workaround = false; bool no_rosegment_workaround = false;
bool system_linker_hack = false; bool system_linker_hack = false;
ZigLLVM_MSVCSubsystemType msvc_subsystem_type = ZigLLVM_MSVC_NONE;
if (argc >= 2 && strcmp(argv[1], "build") == 0) { if (argc >= 2 && strcmp(argv[1], "build") == 0) {
Buf zig_exe_path_buf = BUF_INIT; Buf zig_exe_path_buf = BUF_INIT;
@ -540,6 +539,32 @@ int main(int argc, char **argv) {
verbose_llvm_ir = true; verbose_llvm_ir = true;
} else if (strcmp(arg, "--verbose-cimport") == 0) { } else if (strcmp(arg, "--verbose-cimport") == 0) {
verbose_cimport = true; verbose_cimport = true;
} else if (strcmp(arg, "--msvc-subsystem") == 0) {
if (i + 1 >= argc) {
fprintf(stderr, "Expected 1 argument after --msvc-subsystem\n");
return print_error_usage(arg0);
}
i += 1;
if (stricmp(argv[i], "CONSOLE") == 0) {
msvc_subsystem_type = ZigLLVM_MSVC_CONSOLE;
} else if (stricmp(argv[i], "WINDOWS") == 0) {
msvc_subsystem_type = ZigLLVM_MSVC_WINDOWS;
} else if (stricmp(argv[i], "POSIX") == 0) {
msvc_subsystem_type = ZigLLVM_MSVC_POSIX;
} else if (stricmp(argv[i], "NATIVE") == 0) {
msvc_subsystem_type = ZigLLVM_MSVC_NATIVE;
} else if (stricmp(argv[i], "EFI_APPLICATION") == 0) {
msvc_subsystem_type = ZigLLVM_MSVC_EFI_APPLICATION;
} else if (stricmp(argv[i], "EFI_BOOT_SERVICE_DRIVER") == 0) {
msvc_subsystem_type = ZigLLVM_MSVC_EFI_BOOT_SERVICE_DRIVER;
} else if (stricmp(argv[i], "EFI_ROM") == 0) {
msvc_subsystem_type = ZigLLVM_MSVC_EFI_ROM;
} else if (stricmp(argv[i], "EFI_RUNTIME_DRIVER") == 0) {
msvc_subsystem_type = ZigLLVM_MSVC_EFI_RUNTIME_DRIVER;
} else {
fprintf(stderr, "Unknown format %s for --msvc-subsystem argument\n", argv[i]);
return EXIT_FAILURE;
}
} else if (strcmp(arg, "-mwindows") == 0) { } else if (strcmp(arg, "-mwindows") == 0) {
mwindows = true; mwindows = true;
} else if (strcmp(arg, "-mconsole") == 0) { } else if (strcmp(arg, "-mconsole") == 0) {
@ -849,6 +874,8 @@ int main(int argc, char **argv) {
buf_out_name = buf_create_from_str("run"); buf_out_name = buf_create_from_str("run");
} }
CodeGen *g = codegen_create(zig_root_source_file, target, out_type, build_mode, get_zig_lib_dir()); CodeGen *g = codegen_create(zig_root_source_file, target, out_type, build_mode, get_zig_lib_dir());
g->msvc_subsystem = msvc_subsystem_type;
if (disable_pic) { if (disable_pic) {
if (out_type != OutTypeLib || !is_static) { if (out_type != OutTypeLib || !is_static) {
fprintf(stderr, "--disable-pic only applies to static libraries"); fprintf(stderr, "--disable-pic only applies to static libraries");
@ -909,7 +936,6 @@ int main(int argc, char **argv) {
codegen_add_rpath(g, rpath_list.at(i)); codegen_add_rpath(g, rpath_list.at(i));
} }
codegen_set_windows_subsystem(g, mwindows, mconsole);
codegen_set_rdynamic(g, rdynamic); codegen_set_rdynamic(g, rdynamic);
g->no_rosegment_workaround = no_rosegment_workaround; g->no_rosegment_workaround = no_rosegment_workaround;
if (mmacosx_version_min && mios_version_min) { if (mmacosx_version_min && mios_version_min) {

View File

@ -174,6 +174,7 @@ static const Os os_list[] = {
OsContiki, OsContiki,
OsAMDPAL, OsAMDPAL,
OsZen, OsZen,
OsUefi,
}; };
// Coordinate with zig_llvm.h // Coordinate with zig_llvm.h
@ -315,6 +316,8 @@ ZigLLVM_OSType get_llvm_os_type(Os os_type) {
return ZigLLVM_Contiki; return ZigLLVM_Contiki;
case OsAMDPAL: case OsAMDPAL:
return ZigLLVM_AMDPAL; return ZigLLVM_AMDPAL;
case OsUefi:
return ZigLLVM_Uefi;
} }
zig_unreachable(); zig_unreachable();
} }
@ -756,6 +759,7 @@ uint32_t target_c_type_size_in_bits(const ZigTarget *target, CIntType id) {
case CIntTypeCount: case CIntTypeCount:
zig_unreachable(); zig_unreachable();
} }
case OsUefi:
case OsWindows: case OsWindows:
switch (id) { switch (id) {
case CIntTypeShort: case CIntTypeShort:
@ -803,7 +807,7 @@ uint32_t target_c_type_size_in_bits(const ZigTarget *target, CIntType id) {
} }
const char *target_o_file_ext(ZigTarget *target) { const char *target_o_file_ext(ZigTarget *target) {
if (target->env_type == ZigLLVM_MSVC || target->os == OsWindows) { if (target->env_type == ZigLLVM_MSVC || (target->os == OsWindows || target->os == OsUefi)) {
return ".obj"; return ".obj";
} else { } else {
return ".o"; return ".o";
@ -821,13 +825,15 @@ const char *target_llvm_ir_file_ext(ZigTarget *target) {
const char *target_exe_file_ext(ZigTarget *target) { const char *target_exe_file_ext(ZigTarget *target) {
if (target->os == OsWindows) { if (target->os == OsWindows) {
return ".exe"; return ".exe";
} else if (target->os == OsUefi) {
return ".efi";
} else { } else {
return ""; return "";
} }
} }
const char *target_lib_file_ext(ZigTarget *target, bool is_static, size_t version_major, size_t version_minor, size_t version_patch) { const char *target_lib_file_ext(ZigTarget *target, bool is_static, size_t version_major, size_t version_minor, size_t version_patch) {
if (target->os == OsWindows) { if (target->os == OsWindows || target->os == OsUefi) {
if (is_static) { if (is_static) {
return ".lib"; return ".lib";
} else { } else {

View File

@ -51,6 +51,7 @@ enum Os {
OsContiki, OsContiki,
OsAMDPAL, OsAMDPAL,
OsZen, OsZen,
OsUefi,
}; };
struct ZigTarget { struct ZigTarget {
@ -59,6 +60,7 @@ struct ZigTarget {
Os os; Os os;
ZigLLVM_EnvironmentType env_type; ZigLLVM_EnvironmentType env_type;
ZigLLVM_ObjectFormatType oformat; ZigLLVM_ObjectFormatType oformat;
ZigLLVM_MSVCSubsystemType msvc_subsystem = ZigLLVM_MSVC_NONE;
}; };
enum CIntType { enum CIntType {

View File

@ -4749,8 +4749,10 @@ Error parse_h_file(ImportTableEntry *import, ZigList<ErrorMsg *> *errors, const
clang_argv.append("-isystem"); clang_argv.append("-isystem");
clang_argv.append(buf_ptr(codegen->zig_c_headers_dir)); clang_argv.append(buf_ptr(codegen->zig_c_headers_dir));
if (codegen->libc_include_dir) {
clang_argv.append("-isystem"); clang_argv.append("-isystem");
clang_argv.append(buf_ptr(codegen->libc_include_dir)); clang_argv.append(buf_ptr(codegen->libc_include_dir));
}
// windows c runtime requires -D_DEBUG if using debug libraries // windows c runtime requires -D_DEBUG if using debug libraries
if (codegen->build_mode == BuildModeDebug) { if (codegen->build_mode == BuildModeDebug) {

View File

@ -690,8 +690,15 @@ const char *ZigLLVMGetVendorTypeName(ZigLLVM_VendorType vendor) {
} }
const char *ZigLLVMGetOSTypeName(ZigLLVM_OSType os) { const char *ZigLLVMGetOSTypeName(ZigLLVM_OSType os) {
switch (os) {
case ZigLLVM_Zen:
return "unknown";
case ZigLLVM_Uefi:
return "windows";
default:
return (const char*)Triple::getOSTypeName((Triple::OSType)os).bytes_begin(); return (const char*)Triple::getOSTypeName((Triple::OSType)os).bytes_begin();
} }
}
const char *ZigLLVMGetEnvironmentTypeName(ZigLLVM_EnvironmentType env_type) { const char *ZigLLVMGetEnvironmentTypeName(ZigLLVM_EnvironmentType env_type) {
return (const char*)Triple::getEnvironmentTypeName((Triple::EnvironmentType)env_type).bytes_begin(); return (const char*)Triple::getEnvironmentTypeName((Triple::EnvironmentType)env_type).bytes_begin();

View File

@ -10,6 +10,7 @@
#include <stdbool.h> #include <stdbool.h>
#include <stddef.h> #include <stddef.h>
#include <stdint.h>
#include <llvm-c/Core.h> #include <llvm-c/Core.h>
#include <llvm-c/Analysis.h> #include <llvm-c/Analysis.h>
#include <llvm-c/Target.h> #include <llvm-c/Target.h>
@ -357,8 +358,8 @@ enum ZigLLVM_OSType {
ZigLLVM_Mesa3D, ZigLLVM_Mesa3D,
ZigLLVM_Contiki, ZigLLVM_Contiki,
ZigLLVM_AMDPAL, // AMD PAL Runtime ZigLLVM_AMDPAL, // AMD PAL Runtime
ZigLLVM_Uefi,
ZigLLVM_LastOSType = ZigLLVM_AMDPAL ZigLLVM_LastOSType = ZigLLVM_Uefi
}; };
// Synchronize with target.cpp::environ_list // Synchronize with target.cpp::environ_list
@ -397,6 +398,19 @@ enum ZigLLVM_ObjectFormatType {
ZigLLVM_Wasm, ZigLLVM_Wasm,
}; };
// For MSVC-supported subsystems
enum ZigLLVM_MSVCSubsystemType {
ZigLLVM_MSVC_NONE,
ZigLLVM_MSVC_CONSOLE,
ZigLLVM_MSVC_WINDOWS,
ZigLLVM_MSVC_POSIX,
ZigLLVM_MSVC_NATIVE,
ZigLLVM_MSVC_EFI_APPLICATION,
ZigLLVM_MSVC_EFI_BOOT_SERVICE_DRIVER,
ZigLLVM_MSVC_EFI_ROM,
ZigLLVM_MSVC_EFI_RUNTIME_DRIVER,
};
ZIG_EXTERN_C const char *ZigLLVMGetArchTypeName(enum ZigLLVM_ArchType arch); ZIG_EXTERN_C const char *ZigLLVMGetArchTypeName(enum ZigLLVM_ArchType arch);
ZIG_EXTERN_C const char *ZigLLVMGetSubArchTypeName(enum ZigLLVM_SubArchType sub_arch); ZIG_EXTERN_C const char *ZigLLVMGetSubArchTypeName(enum ZigLLVM_SubArchType sub_arch);
ZIG_EXTERN_C const char *ZigLLVMGetVendorTypeName(enum ZigLLVM_VendorType vendor); ZIG_EXTERN_C const char *ZigLLVMGetVendorTypeName(enum ZigLLVM_VendorType vendor);

View File

@ -1135,7 +1135,7 @@ pub const DebugInfo = switch (builtin.os) {
return self.ofiles.allocator; return self.ofiles.allocator;
} }
}, },
builtin.Os.windows => struct { builtin.Os.uefi, builtin.Os.windows => struct {
pdb: pdb.Pdb, pdb: pdb.Pdb,
coff: *coff.Coff, coff: *coff.Coff,
sect_contribs: []pdb.SectionContribEntry, sect_contribs: []pdb.SectionContribEntry,

View File

@ -18,6 +18,7 @@ test "std.os" {
_ = @import("test.zig"); _ = @import("test.zig");
_ = @import("time.zig"); _ = @import("time.zig");
_ = @import("windows/index.zig"); _ = @import("windows/index.zig");
_ = @import("uefi/index.zig");
_ = @import("get_app_data_dir.zig"); _ = @import("get_app_data_dir.zig");
} }
@ -26,6 +27,8 @@ pub const darwin = @import("darwin.zig");
pub const linux = @import("linux/index.zig"); pub const linux = @import("linux/index.zig");
pub const freebsd = @import("freebsd/index.zig"); pub const freebsd = @import("freebsd/index.zig");
pub const zen = @import("zen.zig"); pub const zen = @import("zen.zig");
pub const uefi = @import("uefi/index.zig");
pub const posix = switch (builtin.os) { pub const posix = switch (builtin.os) {
Os.linux => linux, Os.linux => linux,
Os.macosx, Os.ios => darwin, Os.macosx, Os.ios => darwin,
@ -33,6 +36,7 @@ pub const posix = switch (builtin.os) {
Os.zen => zen, Os.zen => zen,
else => @compileError("Unsupported OS"), else => @compileError("Unsupported OS"),
}; };
pub const net = @import("net.zig"); pub const net = @import("net.zig");
pub const ChildProcess = @import("child_process.zig").ChildProcess; pub const ChildProcess = @import("child_process.zig").ChildProcess;
@ -187,6 +191,9 @@ pub fn abort() noreturn {
} }
windows.ExitProcess(3); windows.ExitProcess(3);
}, },
Os.uefi => {
while (true) {}
},
else => @compileError("Unsupported OS"), else => @compileError("Unsupported OS"),
} }
} }

0
std/os/uefi/index.zig Normal file
View File

View File

@ -10,7 +10,7 @@ pub fn panic(msg: []const u8, error_return_trace: ?*builtin.StackTrace) noreturn
@setCold(true); @setCold(true);
switch (builtin.os) { switch (builtin.os) {
// TODO: fix panic in zen. // TODO: fix panic in zen.
builtin.Os.freestanding, builtin.Os.zen => { builtin.Os.freestanding, builtin.Os.zen, builtin.Os.uefi => {
while (true) {} while (true) {}
}, },
else => { else => {