authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-09-17 18:29:38-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-09-17 18:29:38-07:00
logdc478687d95ee0d495cd26182edae78a01db59af
tree1d01458b78029ec182fd07cdc39b6e5c723907b3
parentbc01887376c227a5f42715f48471dcca14b3d31b

delete all stage1 c++ code not directly related to compiling stage2

Deleted 16,000+ lines of c++ code, including: * an implementation of blake hashing * the cache hash system * compiler.cpp * all the linking code, and everything having to do with building glibc, musl, and mingw-w64 * much of the stage1 compiler internals got slimmed down since it now assumes it is always outputting an object file. More stuff: * stage1 is now built with a different strategy: we have a tiny zig0.cpp which is a slimmed down version of what stage1 main.cpp used to be. Its only purpose is to build stage2 zig code into an object file, which is then linked by the host build system (cmake) into stage1. zig0.cpp uses the same C API that stage2 now has access to, so that stage2 zig code can call into stage1 c++ code. - stage1.h is - stage2.h is - stage1.zig is the main entry point for the Zig/C++ hybrid compiler. It has the functions exported from Zig, called in C++, and bindings for the functions exported from C++, called from Zig. * removed the memory profiling instrumentation from stage1. Abandon ship! * Re-added the sections to the README about how to build stage2 and stage3. * stage2 now knows as a comptime boolean whether it is being compiled as part of stage1 or as stage2. - TODO use this flag to call into stage1 for compiling zig code. * introduce -fdll-export-fns and -fno-dll-export-fns and clarify its relationship to link_mode (static/dynamic) * implement depending on LLVM to detect native target cpu features when LLVM extensions are enabled and zig lacks CPU feature detection for that target architecture. * C importing is broken, will need some stage2 support to function again.

47 files changed, 3526 insertions(+), 12877 deletions(-)

BRANCH_TODO+20-4
...@@ -1,3 +1,21 @@...@@ -1,3 +1,21 @@
1 * `zig builtin`
2 * `zig translate-c`
3 * `zig test`
4 * `zig run`
5 * `zig init-lib`
6 * `zig init-exe`
7 * `zig build`
8 * `-ftime-report`
9 * -fstack-report print stack size diagnostics\n"
10 * -fdump-analysis write analysis.json file with type information\n"
11 * -femit-docs create a docs/ dir with html documentation\n"
12 * -fno-emit-docs do not produce docs/ dir with html documentation\n"
13 * -femit-asm output .s (assembly code)\n"
14 * -fno-emit-asm (default) do not output .s (assembly code)\n"
15 * -femit-llvm-ir produce a .ll file with LLVM IR\n"
16 * -fno-emit-llvm-ir (default) do not produce a .ll file with LLVM IR\n"
17 * --cache-dir [path] override the local cache directory\n"
18 * move main.cpp to stage2
1 * make sure zig cc works19 * make sure zig cc works
2 - using it as a preprocessor (-E)20 - using it as a preprocessor (-E)
3 - try building some software21 - try building some software
...@@ -6,26 +24,24 @@...@@ -6,26 +24,24 @@
6 - stage1 C++ code integration24 - stage1 C++ code integration
7 * build & link againstn freestanding libc25 * build & link againstn freestanding libc
8 * add CLI support for a way to pass extra flags to c source files26 * add CLI support for a way to pass extra flags to c source files
9 * implement the workaround for using LLVM to detect native CPU features
10 * self-host main.cpp
11 * capture lld stdout/stderr better27 * capture lld stdout/stderr better
12 * musl28 * musl
13 * mingw-w6429 * mingw-w64
14 * use global zig-cache dir for crt files30 * use global zig-cache dir for crt files
15 * `zig translate-c`
16 * MachO LLD linking31 * MachO LLD linking
17 * COFF LLD linking32 * COFF LLD linking
18 * WASM LLD linking33 * WASM LLD linking
19 * implement proper parsing of LLD stderr/stdout and exposing compile errors34 * implement proper parsing of LLD stderr/stdout and exposing compile errors
20 * implement proper parsing of clang stderr/stdout and exposing compile errors35 * implement proper parsing of clang stderr/stdout and exposing compile errors
21 * implement proper compile errors for failing to build glibc crt files and shared libs36 * implement proper compile errors for failing to build glibc crt files and shared libs
22 * self-host link.cpp and building libcs (#4313 and #4314). using the `zig cc` command will set a flag indicating a preference for the llvm backend, which will include linking with LLD. At least for now. If zig's self-hosted linker ever gets on par with the likes of ld and lld, we can make it always be used even for zig cc.
23 * improve the stage2 tests to support testing with LLVM extensions enabled37 * improve the stage2 tests to support testing with LLVM extensions enabled
24 * multi-thread building C objects38 * multi-thread building C objects
25 * support cross compiling stage2 with `zig build`39 * support cross compiling stage2 with `zig build`
26 * implement emit-h in stage240 * implement emit-h in stage2
27 * implement -fno-emit-bin41 * implement -fno-emit-bin
28 * audit the base cache hash42 * audit the base cache hash
43 * audit the CLI options for stage2
44
29 * implement serialization/deserialization of incremental compilation metadata45 * implement serialization/deserialization of incremental compilation metadata
30 * incremental compilation - implement detection of which source files changed46 * incremental compilation - implement detection of which source files changed
31 * improve the cache hash logic for c objects with respect to extra flags and file parameters47 * improve the cache hash logic for c objects with respect to extra flags and file parameters
CMakeLists.txt+29-42
...@@ -51,7 +51,6 @@ message("Configuring zig version ${ZIG_VERSION}")...@@ -51,7 +51,6 @@ message("Configuring zig version ${ZIG_VERSION}")
5151
52set(ZIG_STATIC off CACHE BOOL "Attempt to build a static zig executable (not compatible with glibc)")52set(ZIG_STATIC off CACHE BOOL "Attempt to build a static zig executable (not compatible with glibc)")
53set(ZIG_STATIC_LLVM off CACHE BOOL "Prefer linking against static LLVM libraries")53set(ZIG_STATIC_LLVM off CACHE BOOL "Prefer linking against static LLVM libraries")
54set(ZIG_ENABLE_MEM_PROFILE off CACHE BOOL "Activate memory usage instrumentation")
55set(ZIG_PREFER_CLANG_CPP_DYLIB off CACHE BOOL "Try to link against -lclang-cpp")54set(ZIG_PREFER_CLANG_CPP_DYLIB off CACHE BOOL "Try to link against -lclang-cpp")
56set(ZIG_WORKAROUND_4799 off CACHE BOOL "workaround for https://github.com/ziglang/zig/issues/4799")55set(ZIG_WORKAROUND_4799 off CACHE BOOL "workaround for https://github.com/ziglang/zig/issues/4799")
57set(ZIG_WORKAROUND_POLLY_SO off CACHE STRING "workaround for https://github.com/ziglang/zig/issues/4799")56set(ZIG_WORKAROUND_POLLY_SO off CACHE STRING "workaround for https://github.com/ziglang/zig/issues/4799")
...@@ -71,11 +70,6 @@ string(REGEX REPLACE "\\\\" "\\\\\\\\" ZIG_LIBC_INCLUDE_DIR_ESCAPED "${ZIG_LIBC_...@@ -71,11 +70,6 @@ string(REGEX REPLACE "\\\\" "\\\\\\\\" ZIG_LIBC_INCLUDE_DIR_ESCAPED "${ZIG_LIBC_
7170
72option(ZIG_TEST_COVERAGE "Build Zig with test coverage instrumentation" OFF)71option(ZIG_TEST_COVERAGE "Build Zig with test coverage instrumentation" OFF)
7372
74# Zig no longer has embedded LLD. This option is kept for package maintainers
75# so that they don't have to update their scripts in case we ever re-introduce
76# LLD to the tree. This option does nothing.
77option(ZIG_FORCE_EXTERNAL_LLD "does nothing" OFF)
78
79set(ZIG_TARGET_TRIPLE "native" CACHE STRING "arch-os-abi to output binaries for")73set(ZIG_TARGET_TRIPLE "native" CACHE STRING "arch-os-abi to output binaries for")
80set(ZIG_TARGET_MCPU "baseline" CACHE STRING "-mcpu parameter to output binaries for")74set(ZIG_TARGET_MCPU "baseline" CACHE STRING "-mcpu parameter to output binaries for")
81set(ZIG_EXECUTABLE "" CACHE STRING "(when cross compiling) path to already-built zig binary")75set(ZIG_EXECUTABLE "" CACHE STRING "(when cross compiling) path to already-built zig binary")
...@@ -261,15 +255,11 @@ include_directories("${CMAKE_SOURCE_DIR}/deps/dbg-macro")...@@ -261,15 +255,11 @@ include_directories("${CMAKE_SOURCE_DIR}/deps/dbg-macro")
261255
262find_package(Threads)256find_package(Threads)
263257
264# CMake doesn't let us create an empty executable, so we hang on to this one separately.258# This is our shim which will be replaced by stage1.zig.
265set(ZIG_MAIN_SRC "${CMAKE_SOURCE_DIR}/src/main.cpp")259set(ZIG0_SOURCES
266260 "${CMAKE_SOURCE_DIR}/src/zig0.cpp"
267# This is our shim which will be replaced by libstage2 written in Zig.261 "${CMAKE_SOURCE_DIR}/src/stage2.cpp"
268set(ZIG0_SHIM_SRC "${CMAKE_SOURCE_DIR}/src/stage2.cpp")262)
269
270if(ZIG_ENABLE_MEM_PROFILE)
271 set(ZIG_SOURCES_MEM_PROFILE "${CMAKE_SOURCE_DIR}/src/mem_profile.cpp")
272endif()
273263
274set(ZIG_SOURCES264set(ZIG_SOURCES
275 "${CMAKE_SOURCE_DIR}/src/analyze.cpp"265 "${CMAKE_SOURCE_DIR}/src/analyze.cpp"
...@@ -277,37 +267,34 @@ set(ZIG_SOURCES...@@ -277,37 +267,34 @@ set(ZIG_SOURCES
277 "${CMAKE_SOURCE_DIR}/src/bigfloat.cpp"267 "${CMAKE_SOURCE_DIR}/src/bigfloat.cpp"
278 "${CMAKE_SOURCE_DIR}/src/bigint.cpp"268 "${CMAKE_SOURCE_DIR}/src/bigint.cpp"
279 "${CMAKE_SOURCE_DIR}/src/buffer.cpp"269 "${CMAKE_SOURCE_DIR}/src/buffer.cpp"
280 "${CMAKE_SOURCE_DIR}/src/cache_hash.cpp"
281 "${CMAKE_SOURCE_DIR}/src/codegen.cpp"270 "${CMAKE_SOURCE_DIR}/src/codegen.cpp"
282 "${CMAKE_SOURCE_DIR}/src/compiler.cpp"
283 "${CMAKE_SOURCE_DIR}/src/dump_analysis.cpp"271 "${CMAKE_SOURCE_DIR}/src/dump_analysis.cpp"
284 "${CMAKE_SOURCE_DIR}/src/errmsg.cpp"272 "${CMAKE_SOURCE_DIR}/src/errmsg.cpp"
285 "${CMAKE_SOURCE_DIR}/src/error.cpp"273 "${CMAKE_SOURCE_DIR}/src/error.cpp"
286 "${CMAKE_SOURCE_DIR}/src/glibc.cpp"
287 "${CMAKE_SOURCE_DIR}/src/heap.cpp"274 "${CMAKE_SOURCE_DIR}/src/heap.cpp"
288 "${CMAKE_SOURCE_DIR}/src/ir.cpp"275 "${CMAKE_SOURCE_DIR}/src/ir.cpp"
289 "${CMAKE_SOURCE_DIR}/src/ir_print.cpp"276 "${CMAKE_SOURCE_DIR}/src/ir_print.cpp"
290 "${CMAKE_SOURCE_DIR}/src/link.cpp"
291 "${CMAKE_SOURCE_DIR}/src/mem.cpp"277 "${CMAKE_SOURCE_DIR}/src/mem.cpp"
292 "${CMAKE_SOURCE_DIR}/src/os.cpp"278 "${CMAKE_SOURCE_DIR}/src/os.cpp"
293 "${CMAKE_SOURCE_DIR}/src/parser.cpp"279 "${CMAKE_SOURCE_DIR}/src/parser.cpp"
294 "${CMAKE_SOURCE_DIR}/src/range_set.cpp"280 "${CMAKE_SOURCE_DIR}/src/range_set.cpp"
281 "${CMAKE_SOURCE_DIR}/src/stage1.cpp"
295 "${CMAKE_SOURCE_DIR}/src/target.cpp"282 "${CMAKE_SOURCE_DIR}/src/target.cpp"
296 "${CMAKE_SOURCE_DIR}/src/tokenizer.cpp"283 "${CMAKE_SOURCE_DIR}/src/tokenizer.cpp"
297 "${CMAKE_SOURCE_DIR}/src/util.cpp"284 "${CMAKE_SOURCE_DIR}/src/util.cpp"
298 "${CMAKE_SOURCE_DIR}/src/softfloat_ext.cpp"285 "${CMAKE_SOURCE_DIR}/src/softfloat_ext.cpp"
299 "${ZIG_SOURCES_MEM_PROFILE}"
300)286)
301set(OPTIMIZED_C_SOURCES287set(OPTIMIZED_C_SOURCES
302 "${CMAKE_SOURCE_DIR}/src/blake2b.c"
303 "${CMAKE_SOURCE_DIR}/src/parse_f128.c"288 "${CMAKE_SOURCE_DIR}/src/parse_f128.c"
304)289)
305set(ZIG_CPP_SOURCES290set(ZIG_CPP_SOURCES
291 # These are planned to stay even when we are self-hosted.
306 "${CMAKE_SOURCE_DIR}/src/zig_llvm.cpp"292 "${CMAKE_SOURCE_DIR}/src/zig_llvm.cpp"
307 "${CMAKE_SOURCE_DIR}/src/zig_clang.cpp"293 "${CMAKE_SOURCE_DIR}/src/zig_clang.cpp"
308 "${CMAKE_SOURCE_DIR}/src/zig_clang_driver.cpp"294 "${CMAKE_SOURCE_DIR}/src/zig_clang_driver.cpp"
309 "${CMAKE_SOURCE_DIR}/src/zig_clang_cc1_main.cpp"295 "${CMAKE_SOURCE_DIR}/src/zig_clang_cc1_main.cpp"
310 "${CMAKE_SOURCE_DIR}/src/zig_clang_cc1as_main.cpp"296 "${CMAKE_SOURCE_DIR}/src/zig_clang_cc1as_main.cpp"
297 # https://github.com/ziglang/zig/issues/6363
311 "${CMAKE_SOURCE_DIR}/src/windows_sdk.cpp"298 "${CMAKE_SOURCE_DIR}/src/windows_sdk.cpp"
312)299)
313300
...@@ -447,7 +434,7 @@ if(MSVC OR MINGW)...@@ -447,7 +434,7 @@ if(MSVC OR MINGW)
447 target_link_libraries(zigcompiler LINK_PUBLIC version)434 target_link_libraries(zigcompiler LINK_PUBLIC version)
448endif()435endif()
449436
450add_executable(zig0 "${ZIG_MAIN_SRC}" "${ZIG0_SHIM_SRC}")437add_executable(zig0 ${ZIG0_SOURCES})
451set_target_properties(zig0 PROPERTIES438set_target_properties(zig0 PROPERTIES
452 COMPILE_FLAGS ${EXE_CFLAGS}439 COMPILE_FLAGS ${EXE_CFLAGS}
453 LINK_FLAGS ${EXE_LDFLAGS}440 LINK_FLAGS ${EXE_LDFLAGS}
...@@ -455,37 +442,36 @@ set_target_properties(zig0 PROPERTIES...@@ -455,37 +442,36 @@ set_target_properties(zig0 PROPERTIES
455target_link_libraries(zig0 zigcompiler)442target_link_libraries(zig0 zigcompiler)
456443
457if(MSVC)444if(MSVC)
458 set(LIBSTAGE2 "${CMAKE_BINARY_DIR}/zigstage2.lib")445 set(ZIG1_OBJECT "${CMAKE_BINARY_DIR}/zig1.obj")
459else()446else()
460 set(LIBSTAGE2 "${CMAKE_BINARY_DIR}/libzigstage2.a")447 set(ZIG1_OBJECT "${CMAKE_BINARY_DIR}/zig1.o")
461endif()448endif()
462if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")449if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
463 set(LIBSTAGE2_RELEASE_ARG "")450 set(ZIG1_RELEASE_ARG "")
464else()451else()
465 set(LIBSTAGE2_RELEASE_ARG --release-fast --strip)452 set(ZIG1_RELEASE_ARG --release-fast --strip)
466endif()453endif()
467454
468set(BUILD_LIBSTAGE2_ARGS "build-lib"455set(BUILD_ZIG1_ARGS
469 "src-self-hosted/stage2.zig"456 "src-self-hosted/stage1.zig"
470 -target "${ZIG_TARGET_TRIPLE}"457 -target "${ZIG_TARGET_TRIPLE}"
471 "-mcpu=${ZIG_TARGET_MCPU}"458 "-mcpu=${ZIG_TARGET_MCPU}"
472 --name zigstage2459 --name zig1
473 --override-lib-dir "${CMAKE_SOURCE_DIR}/lib"460 --override-lib-dir "${CMAKE_SOURCE_DIR}/lib"
474 --cache on
475 --output-dir "${CMAKE_BINARY_DIR}"461 --output-dir "${CMAKE_BINARY_DIR}"
476 ${LIBSTAGE2_RELEASE_ARG}462 ${ZIG1_RELEASE_ARG}
477 --bundle-compiler-rt
478 -fPIC
479 -lc463 -lc
480 --pkg-begin build_options "${ZIG_CONFIG_ZIG_OUT}"464 --pkg-begin build_options "${ZIG_CONFIG_ZIG_OUT}"
481 --pkg-end465 --pkg-end
466 --pkg-begin compiler_rt "${CMAKE_SOURCE_DIR}/lib/std/special/compiler_rt.zig"
467 --pkg-end
482)468)
483469
484if("${ZIG_TARGET_TRIPLE}" STREQUAL "native")470if("${ZIG_TARGET_TRIPLE}" STREQUAL "native")
485 add_custom_target(zig_build_libstage2 ALL471 add_custom_target(zig_build_zig1 ALL
486 COMMAND zig0 ${BUILD_LIBSTAGE2_ARGS}472 COMMAND zig0 ${BUILD_ZIG1_ARGS}
487 DEPENDS zig0473 DEPENDS zig0
488 BYPRODUCTS "${LIBSTAGE2}"474 BYPRODUCTS "${ZIG1_OBJECT}"
489 WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"475 WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
490 )476 )
491 set(ZIG_EXECUTABLE "${zig_BINARY_DIR}/zig")477 set(ZIG_EXECUTABLE "${zig_BINARY_DIR}/zig")
...@@ -493,26 +479,27 @@ if("${ZIG_TARGET_TRIPLE}" STREQUAL "native")...@@ -493,26 +479,27 @@ if("${ZIG_TARGET_TRIPLE}" STREQUAL "native")
493 set(ZIG_EXECUTABLE "${ZIG_EXECUTABLE}.exe")479 set(ZIG_EXECUTABLE "${ZIG_EXECUTABLE}.exe")
494 endif()480 endif()
495else()481else()
496 add_custom_target(zig_build_libstage2 ALL482 add_custom_target(zig_build_zig1 ALL
497 COMMAND "${ZIG_EXECUTABLE}" ${BUILD_LIBSTAGE2_ARGS}483 COMMAND "${ZIG_EXECUTABLE}" ${BUILD_ZIG1_ARGS}
498 BYPRODUCTS "${LIBSTAGE2}"484 BYPRODUCTS "${ZIG1_OBJECT}"
499 WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"485 WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
500 )486 )
501endif()487endif()
502488
503add_executable(zig "${ZIG_MAIN_SRC}")489# cmake won't let us configure an executable without C sources.
490add_executable(zig "${CMAKE_SOURCE_DIR}/src/empty.cpp")
504491
505set_target_properties(zig PROPERTIES492set_target_properties(zig PROPERTIES
506 COMPILE_FLAGS ${EXE_CFLAGS}493 COMPILE_FLAGS ${EXE_CFLAGS}
507 LINK_FLAGS ${EXE_LDFLAGS}494 LINK_FLAGS ${EXE_LDFLAGS}
508)495)
509target_link_libraries(zig zigcompiler "${LIBSTAGE2}")496target_link_libraries(zig zigcompiler "${ZIG1_OBJECT}")
510if(MSVC)497if(MSVC)
511 target_link_libraries(zig ntdll.lib)498 target_link_libraries(zig ntdll.lib)
512elseif(MINGW)499elseif(MINGW)
513 target_link_libraries(zig ntdll)500 target_link_libraries(zig ntdll)
514endif()501endif()
515add_dependencies(zig zig_build_libstage2)502add_dependencies(zig zig_build_zig1)
516503
517install(TARGETS zig DESTINATION bin)504install(TARGETS zig DESTINATION bin)
518505
README.md+37
...@@ -22,6 +22,8 @@ Note that you can...@@ -22,6 +22,8 @@ Note that you can
2222
23### Stage 1: Build Zig from C++ Source Code23### Stage 1: Build Zig from C++ Source Code
2424
25This step must be repeated when you make changes to any of the C++ source code.
26
25#### Dependencies27#### Dependencies
2628
27##### POSIX29##### POSIX
...@@ -77,6 +79,41 @@ Hopefully this will be fixed upstream with LLVM 10.0.1....@@ -77,6 +79,41 @@ Hopefully this will be fixed upstream with LLVM 10.0.1.
7779
78See https://github.com/ziglang/zig/wiki/Building-Zig-on-Windows80See https://github.com/ziglang/zig/wiki/Building-Zig-on-Windows
7981
82### Stage 2: Build Self-Hosted Zig from Zig Source Code
83
84Now we use the stage1 binary:
85
86```
87zig build --prefix $(pwd)/stage2 -Denable-llvm
88```
89
90This produces `stage2/bin/zig` which can be used for testing and development.
91Once it is feature complete, it will be used to build stage 3 - the final compiler
92binary.
93
94### Stage 3: Rebuild Self-Hosted Zig Using the Self-Hosted Compiler
95
96*Note: Stage 2 compiler is not yet able to build Stage 3. Building Stage 3 is
97not yet supported.*
98
99Once the self-hosted compiler can build itself, this will be the actual
100compiler binary that we will install to the system. Until then, users should
101use stage 1.
102
103#### Debug / Development Build
104
105```
106stage2/bin/zig build
107```
108
109This produces `zig-cache/bin/zig`.
110
111#### Release / Install Build
112
113```
114stage2/bin/zig build install -Drelease
115```
116
80## License117## License
81118
82The ultimate goal of the Zig project is to serve users. As a first-order119The ultimate goal of the Zig project is to serve users. As a first-order
build.zig+2
...@@ -145,6 +145,7 @@ pub fn build(b: *Builder) !void {...@@ -145,6 +145,7 @@ pub fn build(b: *Builder) !void {
145 exe.addBuildOption([]const []const u8, "log_scopes", log_scopes);145 exe.addBuildOption([]const []const u8, "log_scopes", log_scopes);
146 exe.addBuildOption([]const []const u8, "zir_dumps", zir_dumps);146 exe.addBuildOption([]const []const u8, "zir_dumps", zir_dumps);
147 exe.addBuildOption(bool, "enable_tracy", tracy != null);147 exe.addBuildOption(bool, "enable_tracy", tracy != null);
148 exe.addBuildOption(bool, "is_stage1", false);
148 if (tracy) |tracy_path| {149 if (tracy) |tracy_path| {
149 const client_cpp = fs.path.join(150 const client_cpp = fs.path.join(
150 b.allocator,151 b.allocator,
...@@ -165,6 +166,7 @@ pub fn build(b: *Builder) !void {...@@ -165,6 +166,7 @@ pub fn build(b: *Builder) !void {
165 const is_wasmtime_enabled = b.option(bool, "enable-wasmtime", "Use Wasmtime to enable and run WASI libstd tests") orelse false;166 const is_wasmtime_enabled = b.option(bool, "enable-wasmtime", "Use Wasmtime to enable and run WASI libstd tests") orelse false;
166 const glibc_multi_dir = b.option([]const u8, "enable-foreign-glibc", "Provide directory with glibc installations to run cross compiled tests that link glibc");167 const glibc_multi_dir = b.option([]const u8, "enable-foreign-glibc", "Provide directory with glibc installations to run cross compiled tests that link glibc");
167168
169 test_stage2.addBuildOption(bool, "is_stage1", false);
168 test_stage2.addBuildOption(bool, "have_llvm", enable_llvm);170 test_stage2.addBuildOption(bool, "have_llvm", enable_llvm);
169 test_stage2.addBuildOption(bool, "enable_qemu", is_qemu_enabled);171 test_stage2.addBuildOption(bool, "enable_qemu", is_qemu_enabled);
170 test_stage2.addBuildOption(bool, "enable_wine", is_wine_enabled);172 test_stage2.addBuildOption(bool, "enable_wine", is_wine_enabled);
src-self-hosted/Compilation.zig+16-2
...@@ -244,6 +244,7 @@ pub const InitOptions = struct {...@@ -244,6 +244,7 @@ pub const InitOptions = struct {
244 /// `null` means to not emit a C header file.244 /// `null` means to not emit a C header file.
245 emit_h: ?EmitLoc = null,245 emit_h: ?EmitLoc = null,
246 link_mode: ?std.builtin.LinkMode = null,246 link_mode: ?std.builtin.LinkMode = null,
247 dll_export_fns: ?bool = false,
247 object_format: ?std.builtin.ObjectFormat = null,248 object_format: ?std.builtin.ObjectFormat = null,
248 optimize_mode: std.builtin.Mode = .Debug,249 optimize_mode: std.builtin.Mode = .Debug,
249 keep_source_files_loaded: bool = false,250 keep_source_files_loaded: bool = false,
...@@ -340,9 +341,13 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {...@@ -340,9 +341,13 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
340 return error.MachineCodeModelNotSupported;341 return error.MachineCodeModelNotSupported;
341 }342 }
342343
344 const is_dyn_lib = switch (options.output_mode) {
345 .Obj, .Exe => false,
346 .Lib => (options.link_mode orelse .Static) == .Dynamic,
347 };
343 const is_exe_or_dyn_lib = switch (options.output_mode) {348 const is_exe_or_dyn_lib = switch (options.output_mode) {
344 .Obj => false,349 .Obj => false,
345 .Lib => (options.link_mode orelse .Static) == .Dynamic,350 .Lib => is_dyn_lib,
346 .Exe => true,351 .Exe => true,
347 };352 };
348 const must_dynamic_link = dl: {353 const must_dynamic_link = dl: {
...@@ -365,6 +370,8 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {...@@ -365,6 +370,8 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
365 break :blk lm;370 break :blk lm;
366 } else default_link_mode;371 } else default_link_mode;
367372
373 const dll_export_fns = if (options.dll_export_fns) |explicit| explicit else is_dyn_lib;
374
368 const libc_dirs = try detectLibCIncludeDirs(375 const libc_dirs = try detectLibCIncludeDirs(
369 arena,376 arena,
370 options.zig_lib_directory.path.?,377 options.zig_lib_directory.path.?,
...@@ -379,7 +386,12 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {...@@ -379,7 +386,12 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
379 break :b true;386 break :b true;
380 break :b link_mode == .Dynamic;387 break :b link_mode == .Dynamic;
381 };388 };
382 const pic = options.want_pic orelse must_pic;389 const pic = if (options.want_pic) |explicit| pic: {
390 if (!explicit and must_pic) {
391 return error.TargetRequiresPIC;
392 }
393 break :pic explicit;
394 } else must_pic;
383395
384 if (options.emit_h != null) fatal("-femit-h not supported yet", .{}); // TODO396 if (options.emit_h != null) fatal("-femit-h not supported yet", .{}); // TODO
385397
...@@ -464,6 +476,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {...@@ -464,6 +476,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
464 hash.add(valgrind);476 hash.add(valgrind);
465 hash.add(single_threaded);477 hash.add(single_threaded);
466 hash.add(options.target.os.getVersionRange());478 hash.add(options.target.os.getVersionRange());
479 hash.add(dll_export_fns);
467480
468 const digest = hash.final();481 const digest = hash.final();
469 const artifact_sub_dir = try std.fs.path.join(arena, &[_][]const u8{ "o", &digest });482 const artifact_sub_dir = try std.fs.path.join(arena, &[_][]const u8{ "o", &digest });
...@@ -601,6 +614,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {...@@ -601,6 +614,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
601 .single_threaded = single_threaded,614 .single_threaded = single_threaded,
602 .debug_link = options.debug_link,615 .debug_link = options.debug_link,
603 .machine_code_model = options.machine_code_model,616 .machine_code_model = options.machine_code_model,
617 .dll_export_fns = dll_export_fns,
604 });618 });
605 errdefer bin_file.destroy();619 errdefer bin_file.destroy();
606620
src-self-hosted/libcxx.zig created+66
...@@ -0,0 +1,66 @@
1//! TODO build libcxx and libcxxabi from source
2
3pub const libcxxabi_files = [_][]const u8{
4 "src/abort_message.cpp",
5 "src/cxa_aux_runtime.cpp",
6 "src/cxa_default_handlers.cpp",
7 "src/cxa_demangle.cpp",
8 "src/cxa_exception.cpp",
9 "src/cxa_exception_storage.cpp",
10 "src/cxa_guard.cpp",
11 "src/cxa_handlers.cpp",
12 "src/cxa_noexception.cpp",
13 "src/cxa_personality.cpp",
14 "src/cxa_thread_atexit.cpp",
15 "src/cxa_unexpected.cpp",
16 "src/cxa_vector.cpp",
17 "src/cxa_virtual.cpp",
18 "src/fallback_malloc.cpp",
19 "src/private_typeinfo.cpp",
20 "src/stdlib_exception.cpp",
21 "src/stdlib_stdexcept.cpp",
22 "src/stdlib_typeinfo.cpp",
23};
24
25pub const libcxx_files = [_][]const u8{
26 "src/algorithm.cpp",
27 "src/any.cpp",
28 "src/bind.cpp",
29 "src/charconv.cpp",
30 "src/chrono.cpp",
31 "src/condition_variable.cpp",
32 "src/condition_variable_destructor.cpp",
33 "src/debug.cpp",
34 "src/exception.cpp",
35 "src/experimental/memory_resource.cpp",
36 "src/filesystem/directory_iterator.cpp",
37 "src/filesystem/operations.cpp",
38 "src/functional.cpp",
39 "src/future.cpp",
40 "src/hash.cpp",
41 "src/ios.cpp",
42 "src/iostream.cpp",
43 "src/locale.cpp",
44 "src/memory.cpp",
45 "src/mutex.cpp",
46 "src/mutex_destructor.cpp",
47 "src/new.cpp",
48 "src/optional.cpp",
49 "src/random.cpp",
50 "src/regex.cpp",
51 "src/shared_mutex.cpp",
52 "src/stdexcept.cpp",
53 "src/string.cpp",
54 "src/strstream.cpp",
55 "src/support/solaris/xlocale.cpp",
56 "src/support/win32/locale_win32.cpp",
57 "src/support/win32/support.cpp",
58 "src/support/win32/thread_win32.cpp",
59 "src/system_error.cpp",
60 "src/thread.cpp",
61 "src/typeinfo.cpp",
62 "src/utility.cpp",
63 "src/valarray.cpp",
64 "src/variant.cpp",
65 "src/vector.cpp",
66};
src-self-hosted/link.zig+1
...@@ -62,6 +62,7 @@ pub const Options = struct {...@@ -62,6 +62,7 @@ pub const Options = struct {
62 stack_check: bool,62 stack_check: bool,
63 single_threaded: bool,63 single_threaded: bool,
64 debug_link: bool = false,64 debug_link: bool = false,
65 dll_export_fns: bool,
65 gc_sections: ?bool = null,66 gc_sections: ?bool = null,
66 allow_shlib_undefined: ?bool = null,67 allow_shlib_undefined: ?bool = null,
67 linker_script: ?[]const u8 = null,68 linker_script: ?[]const u8 = null,
src-self-hosted/main.zig+100-12
...@@ -92,7 +92,7 @@ pub fn log(...@@ -92,7 +92,7 @@ pub fn log(
9292
93var general_purpose_allocator = std.heap.GeneralPurposeAllocator(.{}){};93var general_purpose_allocator = std.heap.GeneralPurposeAllocator(.{}){};
9494
95pub fn main() !void {95pub fn main() anyerror!void {
96 const gpa = if (std.builtin.link_libc) std.heap.c_allocator else &general_purpose_allocator.allocator;96 const gpa = if (std.builtin.link_libc) std.heap.c_allocator else &general_purpose_allocator.allocator;
97 defer if (!std.builtin.link_libc) {97 defer if (!std.builtin.link_libc) {
98 _ = general_purpose_allocator.deinit();98 _ = general_purpose_allocator.deinit();
...@@ -102,7 +102,10 @@ pub fn main() !void {...@@ -102,7 +102,10 @@ pub fn main() !void {
102 const arena = &arena_instance.allocator;102 const arena = &arena_instance.allocator;
103103
104 const args = try process.argsAlloc(arena);104 const args = try process.argsAlloc(arena);
105 return mainArgs(gpa, arena, args);
106}
105107
108pub fn mainArgs(gpa: *Allocator, arena: *Allocator, args: []const []const u8) !void {
106 if (args.len <= 1) {109 if (args.len <= 1) {
107 std.log.info("{}", .{usage});110 std.log.info("{}", .{usage});
108 fatal("expected command argument", .{});111 fatal("expected command argument", .{});
...@@ -131,7 +134,7 @@ pub fn main() !void {...@@ -131,7 +134,7 @@ pub fn main() !void {
131 } else if (mem.eql(u8, cmd, "libc")) {134 } else if (mem.eql(u8, cmd, "libc")) {
132 return cmdLibC(gpa, cmd_args);135 return cmdLibC(gpa, cmd_args);
133 } else if (mem.eql(u8, cmd, "targets")) {136 } else if (mem.eql(u8, cmd, "targets")) {
134 const info = try std.zig.system.NativeTargetInfo.detect(arena, .{});137 const info = try detectNativeTargetInfo(arena, .{});
135 const stdout = io.getStdOut().outStream();138 const stdout = io.getStdOut().outStream();
136 return @import("print_targets.zig").cmdTargets(arena, cmd_args, stdout, info.target);139 return @import("print_targets.zig").cmdTargets(arena, cmd_args, stdout, info.target);
137 } else if (mem.eql(u8, cmd, "version")) {140 } else if (mem.eql(u8, cmd, "version")) {
...@@ -183,7 +186,7 @@ const usage_build_generic =...@@ -183,7 +186,7 @@ const usage_build_generic =
183 \\ -mcmodel=[default|tiny| Limit range of code and data virtual addresses186 \\ -mcmodel=[default|tiny| Limit range of code and data virtual addresses
184 \\ small|kernel|187 \\ small|kernel|
185 \\ medium|large]188 \\ medium|large]
186 \\ --name [name] Override output name189 \\ --name [name] Override root name (not a file path)
187 \\ --mode [mode] Set the build mode190 \\ --mode [mode] Set the build mode
188 \\ Debug (default) optimizations off, safety on191 \\ Debug (default) optimizations off, safety on
189 \\ ReleaseFast Optimizations on, safety off192 \\ ReleaseFast Optimizations on, safety off
...@@ -197,7 +200,9 @@ const usage_build_generic =...@@ -197,7 +200,9 @@ const usage_build_generic =
197 \\ -fno-sanitize-c Disable C undefined behavior detection in safe builds200 \\ -fno-sanitize-c Disable C undefined behavior detection in safe builds
198 \\ -fvalgrind Include valgrind client requests in release builds201 \\ -fvalgrind Include valgrind client requests in release builds
199 \\ -fno-valgrind Omit valgrind client requests in debug builds202 \\ -fno-valgrind Omit valgrind client requests in debug builds
200 \\ --strip Exclude debug symbols203 \\ -fdll-export-fns Mark exported functions as DLL exports (Windows)
204 \\ -fno-dll-export-fns Force-disable marking exported functions as DLL exports
205 \\ --strip Omit debug symbols
201 \\ --single-threaded Code assumes it is only used single-threaded206 \\ --single-threaded Code assumes it is only used single-threaded
202 \\ -ofmt=[mode] Override target object format207 \\ -ofmt=[mode] Override target object format
203 \\ elf Executable and Linking Format208 \\ elf Executable and Linking Format
...@@ -262,6 +267,7 @@ pub fn buildOutputType(...@@ -262,6 +267,7 @@ pub fn buildOutputType(
262 var build_mode: std.builtin.Mode = .Debug;267 var build_mode: std.builtin.Mode = .Debug;
263 var provided_name: ?[]const u8 = null;268 var provided_name: ?[]const u8 = null;
264 var link_mode: ?std.builtin.LinkMode = null;269 var link_mode: ?std.builtin.LinkMode = null;
270 var dll_export_fns: ?bool = null;
265 var root_src_file: ?[]const u8 = null;271 var root_src_file: ?[]const u8 = null;
266 var version: std.builtin.Version = .{ .major = 0, .minor = 0, .patch = 0 };272 var version: std.builtin.Version = .{ .major = 0, .minor = 0, .patch = 0 };
267 var have_version = false;273 var have_version = false;
...@@ -521,6 +527,10 @@ pub fn buildOutputType(...@@ -521,6 +527,10 @@ pub fn buildOutputType(
521 link_mode = .Dynamic;527 link_mode = .Dynamic;
522 } else if (mem.eql(u8, arg, "-static")) {528 } else if (mem.eql(u8, arg, "-static")) {
523 link_mode = .Static;529 link_mode = .Static;
530 } else if (mem.eql(u8, arg, "-fdll-export-fns")) {
531 dll_export_fns = true;
532 } else if (mem.eql(u8, arg, "-fno-dll-export-fns")) {
533 dll_export_fns = false;
524 } else if (mem.eql(u8, arg, "--strip")) {534 } else if (mem.eql(u8, arg, "--strip")) {
525 strip = true;535 strip = true;
526 } else if (mem.eql(u8, arg, "--single-threaded")) {536 } else if (mem.eql(u8, arg, "--single-threaded")) {
...@@ -902,14 +912,7 @@ pub fn buildOutputType(...@@ -902,14 +912,7 @@ pub fn buildOutputType(
902 else => |e| return e,912 else => |e| return e,
903 };913 };
904914
905 const target_info = try std.zig.system.NativeTargetInfo.detect(gpa, cross_target);915 const target_info = try detectNativeTargetInfo(gpa, cross_target);
906 if (target_info.cpu_detection_unimplemented) {
907 // TODO We want to just use detected_info.target but implementing
908 // CPU model & feature detection is todo so here we rely on LLVM.
909 // TODO The workaround to use LLVM to detect features needs to be used for
910 // `zig targets` as well.
911 fatal("CPU features detection is not yet available for this system without LLVM extensions", .{});
912 }
913916
914 if (target_info.target.os.tag != .freestanding) {917 if (target_info.target.os.tag != .freestanding) {
915 if (ensure_libc_on_non_freestanding)918 if (ensure_libc_on_non_freestanding)
...@@ -1116,6 +1119,7 @@ pub fn buildOutputType(...@@ -1116,6 +1119,7 @@ pub fn buildOutputType(
1116 .emit_bin = emit_bin_loc,1119 .emit_bin = emit_bin_loc,
1117 .emit_h = emit_h_loc,1120 .emit_h = emit_h_loc,
1118 .link_mode = link_mode,1121 .link_mode = link_mode,
1122 .dll_export_fns = dll_export_fns,
1119 .object_format = object_format,1123 .object_format = object_format,
1120 .optimize_mode = build_mode,1124 .optimize_mode = build_mode,
1121 .keep_source_files_loaded = zir_out_path != null,1125 .keep_source_files_loaded = zir_out_path != null,
...@@ -1974,3 +1978,87 @@ fn gimmeMoreOfThoseSweetSweetFileDescriptors() void {...@@ -1974,3 +1978,87 @@ fn gimmeMoreOfThoseSweetSweetFileDescriptors() void {
1974test "fds" {1978test "fds" {
1975 gimmeMoreOfThoseSweetSweetFileDescriptors();1979 gimmeMoreOfThoseSweetSweetFileDescriptors();
1976}1980}
1981
1982fn detectNativeCpuWithLLVM(
1983 arch: std.Target.Cpu.Arch,
1984 llvm_cpu_name_z: ?[*:0]const u8,
1985 llvm_cpu_features_opt: ?[*:0]const u8,
1986) !std.Target.Cpu {
1987 var result = std.Target.Cpu.baseline(arch);
1988
1989 if (llvm_cpu_name_z) |cpu_name_z| {
1990 const llvm_cpu_name = mem.spanZ(cpu_name_z);
1991
1992 for (arch.allCpuModels()) |model| {
1993 const this_llvm_name = model.llvm_name orelse continue;
1994 if (mem.eql(u8, this_llvm_name, llvm_cpu_name)) {
1995 // Here we use the non-dependencies-populated set,
1996 // so that subtracting features later in this function
1997 // affect the prepopulated set.
1998 result = std.Target.Cpu{
1999 .arch = arch,
2000 .model = model,
2001 .features = model.features,
2002 };
2003 break;
2004 }
2005 }
2006 }
2007
2008 const all_features = arch.allFeaturesList();
2009
2010 if (llvm_cpu_features_opt) |llvm_cpu_features| {
2011 var it = mem.tokenize(mem.spanZ(llvm_cpu_features), ",");
2012 while (it.next()) |decorated_llvm_feat| {
2013 var op: enum {
2014 add,
2015 sub,
2016 } = undefined;
2017 var llvm_feat: []const u8 = undefined;
2018 if (mem.startsWith(u8, decorated_llvm_feat, "+")) {
2019 op = .add;
2020 llvm_feat = decorated_llvm_feat[1..];
2021 } else if (mem.startsWith(u8, decorated_llvm_feat, "-")) {
2022 op = .sub;
2023 llvm_feat = decorated_llvm_feat[1..];
2024 } else {
2025 return error.InvalidLlvmCpuFeaturesFormat;
2026 }
2027 for (all_features) |feature, index_usize| {
2028 const this_llvm_name = feature.llvm_name orelse continue;
2029 if (mem.eql(u8, llvm_feat, this_llvm_name)) {
2030 const index = @intCast(std.Target.Cpu.Feature.Set.Index, index_usize);
2031 switch (op) {
2032 .add => result.features.addFeature(index),
2033 .sub => result.features.removeFeature(index),
2034 }
2035 break;
2036 }
2037 }
2038 }
2039 }
2040
2041 result.features.populateDependencies(all_features);
2042 return result;
2043}
2044
2045fn detectNativeTargetInfo(gpa: *Allocator, cross_target: std.zig.CrossTarget) !std.zig.system.NativeTargetInfo {
2046 var info = try std.zig.system.NativeTargetInfo.detect(gpa, cross_target);
2047 if (info.cpu_detection_unimplemented) {
2048 const arch = std.Target.current.cpu.arch;
2049
2050 // We want to just use detected_info.target but implementing
2051 // CPU model & feature detection is todo so here we rely on LLVM.
2052 // https://github.com/ziglang/zig/issues/4591
2053 if (!build_options.have_llvm)
2054 fatal("CPU features detection is not yet available for {} without LLVM extensions", .{@tagName(arch)});
2055
2056 const llvm = @import("llvm.zig");
2057 const llvm_cpu_name = llvm.GetHostCPUName();
2058 const llvm_cpu_features = llvm.GetNativeFeatures();
2059 info.target.cpu = try detectNativeCpuWithLLVM(arch, llvm_cpu_name, llvm_cpu_features);
2060 cross_target.updateCpuFeatures(&info.target.cpu.features);
2061 info.target.cpu.arch = cross_target.getCpuArch();
2062 }
2063 return info;
2064}
src-self-hosted/musl.zig created+1843
...@@ -0,0 +1,1843 @@
1//! TODO build musl libc from source
2
3pub const src_files = [_][]const u8{
4 "musl/src/aio/aio.c",
5 "musl/src/aio/aio_suspend.c",
6 "musl/src/aio/lio_listio.c",
7 "musl/src/complex/__cexp.c",
8 "musl/src/complex/__cexpf.c",
9 "musl/src/complex/cabs.c",
10 "musl/src/complex/cabsf.c",
11 "musl/src/complex/cabsl.c",
12 "musl/src/complex/cacos.c",
13 "musl/src/complex/cacosf.c",
14 "musl/src/complex/cacosh.c",
15 "musl/src/complex/cacoshf.c",
16 "musl/src/complex/cacoshl.c",
17 "musl/src/complex/cacosl.c",
18 "musl/src/complex/carg.c",
19 "musl/src/complex/cargf.c",
20 "musl/src/complex/cargl.c",
21 "musl/src/complex/casin.c",
22 "musl/src/complex/casinf.c",
23 "musl/src/complex/casinh.c",
24 "musl/src/complex/casinhf.c",
25 "musl/src/complex/casinhl.c",
26 "musl/src/complex/casinl.c",
27 "musl/src/complex/catan.c",
28 "musl/src/complex/catanf.c",
29 "musl/src/complex/catanh.c",
30 "musl/src/complex/catanhf.c",
31 "musl/src/complex/catanhl.c",
32 "musl/src/complex/catanl.c",
33 "musl/src/complex/ccos.c",
34 "musl/src/complex/ccosf.c",
35 "musl/src/complex/ccosh.c",
36 "musl/src/complex/ccoshf.c",
37 "musl/src/complex/ccoshl.c",
38 "musl/src/complex/ccosl.c",
39 "musl/src/complex/cexp.c",
40 "musl/src/complex/cexpf.c",
41 "musl/src/complex/cexpl.c",
42 "musl/src/complex/cimag.c",
43 "musl/src/complex/cimagf.c",
44 "musl/src/complex/cimagl.c",
45 "musl/src/complex/clog.c",
46 "musl/src/complex/clogf.c",
47 "musl/src/complex/clogl.c",
48 "musl/src/complex/conj.c",
49 "musl/src/complex/conjf.c",
50 "musl/src/complex/conjl.c",
51 "musl/src/complex/cpow.c",
52 "musl/src/complex/cpowf.c",
53 "musl/src/complex/cpowl.c",
54 "musl/src/complex/cproj.c",
55 "musl/src/complex/cprojf.c",
56 "musl/src/complex/cprojl.c",
57 "musl/src/complex/creal.c",
58 "musl/src/complex/crealf.c",
59 "musl/src/complex/creall.c",
60 "musl/src/complex/csin.c",
61 "musl/src/complex/csinf.c",
62 "musl/src/complex/csinh.c",
63 "musl/src/complex/csinhf.c",
64 "musl/src/complex/csinhl.c",
65 "musl/src/complex/csinl.c",
66 "musl/src/complex/csqrt.c",
67 "musl/src/complex/csqrtf.c",
68 "musl/src/complex/csqrtl.c",
69 "musl/src/complex/ctan.c",
70 "musl/src/complex/ctanf.c",
71 "musl/src/complex/ctanh.c",
72 "musl/src/complex/ctanhf.c",
73 "musl/src/complex/ctanhl.c",
74 "musl/src/complex/ctanl.c",
75 "musl/src/conf/confstr.c",
76 "musl/src/conf/fpathconf.c",
77 "musl/src/conf/legacy.c",
78 "musl/src/conf/pathconf.c",
79 "musl/src/conf/sysconf.c",
80 "musl/src/crypt/crypt.c",
81 "musl/src/crypt/crypt_blowfish.c",
82 "musl/src/crypt/crypt_des.c",
83 "musl/src/crypt/crypt_md5.c",
84 "musl/src/crypt/crypt_r.c",
85 "musl/src/crypt/crypt_sha256.c",
86 "musl/src/crypt/crypt_sha512.c",
87 "musl/src/crypt/encrypt.c",
88 "musl/src/ctype/__ctype_b_loc.c",
89 "musl/src/ctype/__ctype_get_mb_cur_max.c",
90 "musl/src/ctype/__ctype_tolower_loc.c",
91 "musl/src/ctype/__ctype_toupper_loc.c",
92 "musl/src/ctype/isalnum.c",
93 "musl/src/ctype/isalpha.c",
94 "musl/src/ctype/isascii.c",
95 "musl/src/ctype/isblank.c",
96 "musl/src/ctype/iscntrl.c",
97 "musl/src/ctype/isdigit.c",
98 "musl/src/ctype/isgraph.c",
99 "musl/src/ctype/islower.c",
100 "musl/src/ctype/isprint.c",
101 "musl/src/ctype/ispunct.c",
102 "musl/src/ctype/isspace.c",
103 "musl/src/ctype/isupper.c",
104 "musl/src/ctype/iswalnum.c",
105 "musl/src/ctype/iswalpha.c",
106 "musl/src/ctype/iswblank.c",
107 "musl/src/ctype/iswcntrl.c",
108 "musl/src/ctype/iswctype.c",
109 "musl/src/ctype/iswdigit.c",
110 "musl/src/ctype/iswgraph.c",
111 "musl/src/ctype/iswlower.c",
112 "musl/src/ctype/iswprint.c",
113 "musl/src/ctype/iswpunct.c",
114 "musl/src/ctype/iswspace.c",
115 "musl/src/ctype/iswupper.c",
116 "musl/src/ctype/iswxdigit.c",
117 "musl/src/ctype/isxdigit.c",
118 "musl/src/ctype/toascii.c",
119 "musl/src/ctype/tolower.c",
120 "musl/src/ctype/toupper.c",
121 "musl/src/ctype/towctrans.c",
122 "musl/src/ctype/wcswidth.c",
123 "musl/src/ctype/wctrans.c",
124 "musl/src/ctype/wcwidth.c",
125 "musl/src/dirent/alphasort.c",
126 "musl/src/dirent/closedir.c",
127 "musl/src/dirent/dirfd.c",
128 "musl/src/dirent/fdopendir.c",
129 "musl/src/dirent/opendir.c",
130 "musl/src/dirent/readdir.c",
131 "musl/src/dirent/readdir_r.c",
132 "musl/src/dirent/rewinddir.c",
133 "musl/src/dirent/scandir.c",
134 "musl/src/dirent/seekdir.c",
135 "musl/src/dirent/telldir.c",
136 "musl/src/dirent/versionsort.c",
137 "musl/src/env/__environ.c",
138 "musl/src/env/__init_tls.c",
139 "musl/src/env/__libc_start_main.c",
140 "musl/src/env/__reset_tls.c",
141 "musl/src/env/__stack_chk_fail.c",
142 "musl/src/env/clearenv.c",
143 "musl/src/env/getenv.c",
144 "musl/src/env/putenv.c",
145 "musl/src/env/secure_getenv.c",
146 "musl/src/env/setenv.c",
147 "musl/src/env/unsetenv.c",
148 "musl/src/errno/__errno_location.c",
149 "musl/src/errno/strerror.c",
150 "musl/src/exit/_Exit.c",
151 "musl/src/exit/abort.c",
152 "musl/src/exit/arm/__aeabi_atexit.c",
153 "musl/src/exit/assert.c",
154 "musl/src/exit/at_quick_exit.c",
155 "musl/src/exit/atexit.c",
156 "musl/src/exit/exit.c",
157 "musl/src/exit/quick_exit.c",
158 "musl/src/fcntl/creat.c",
159 "musl/src/fcntl/fcntl.c",
160 "musl/src/fcntl/open.c",
161 "musl/src/fcntl/openat.c",
162 "musl/src/fcntl/posix_fadvise.c",
163 "musl/src/fcntl/posix_fallocate.c",
164 "musl/src/fenv/__flt_rounds.c",
165 "musl/src/fenv/aarch64/fenv.s",
166 "musl/src/fenv/arm/fenv-hf.S",
167 "musl/src/fenv/arm/fenv.c",
168 "musl/src/fenv/fegetexceptflag.c",
169 "musl/src/fenv/feholdexcept.c",
170 "musl/src/fenv/fenv.c",
171 "musl/src/fenv/fesetexceptflag.c",
172 "musl/src/fenv/fesetround.c",
173 "musl/src/fenv/feupdateenv.c",
174 "musl/src/fenv/i386/fenv.s",
175 "musl/src/fenv/m68k/fenv.c",
176 "musl/src/fenv/mips/fenv-sf.c",
177 "musl/src/fenv/mips/fenv.S",
178 "musl/src/fenv/mips64/fenv-sf.c",
179 "musl/src/fenv/mips64/fenv.S",
180 "musl/src/fenv/mipsn32/fenv-sf.c",
181 "musl/src/fenv/mipsn32/fenv.S",
182 "musl/src/fenv/powerpc/fenv-sf.c",
183 "musl/src/fenv/powerpc/fenv.S",
184 "musl/src/fenv/powerpc64/fenv.c",
185 "musl/src/fenv/riscv64/fenv-sf.c",
186 "musl/src/fenv/riscv64/fenv.S",
187 "musl/src/fenv/s390x/fenv.c",
188 "musl/src/fenv/sh/fenv-nofpu.c",
189 "musl/src/fenv/sh/fenv.S",
190 "musl/src/fenv/x32/fenv.s",
191 "musl/src/fenv/x86_64/fenv.s",
192 "musl/src/internal/defsysinfo.c",
193 "musl/src/internal/floatscan.c",
194 "musl/src/internal/i386/defsysinfo.s",
195 "musl/src/internal/intscan.c",
196 "musl/src/internal/libc.c",
197 "musl/src/internal/procfdname.c",
198 "musl/src/internal/sh/__shcall.c",
199 "musl/src/internal/shgetc.c",
200 "musl/src/internal/syscall_ret.c",
201 "musl/src/internal/vdso.c",
202 "musl/src/internal/version.c",
203 "musl/src/ipc/ftok.c",
204 "musl/src/ipc/msgctl.c",
205 "musl/src/ipc/msgget.c",
206 "musl/src/ipc/msgrcv.c",
207 "musl/src/ipc/msgsnd.c",
208 "musl/src/ipc/semctl.c",
209 "musl/src/ipc/semget.c",
210 "musl/src/ipc/semop.c",
211 "musl/src/ipc/semtimedop.c",
212 "musl/src/ipc/shmat.c",
213 "musl/src/ipc/shmctl.c",
214 "musl/src/ipc/shmdt.c",
215 "musl/src/ipc/shmget.c",
216 "musl/src/ldso/__dlsym.c",
217 "musl/src/ldso/aarch64/dlsym.s",
218 "musl/src/ldso/aarch64/tlsdesc.s",
219 "musl/src/ldso/arm/dlsym.s",
220 "musl/src/ldso/arm/dlsym_time64.S",
221 "musl/src/ldso/arm/find_exidx.c",
222 "musl/src/ldso/arm/tlsdesc.S",
223 "musl/src/ldso/dl_iterate_phdr.c",
224 "musl/src/ldso/dladdr.c",
225 "musl/src/ldso/dlclose.c",
226 "musl/src/ldso/dlerror.c",
227 "musl/src/ldso/dlinfo.c",
228 "musl/src/ldso/dlopen.c",
229 "musl/src/ldso/dlsym.c",
230 "musl/src/ldso/i386/dlsym.s",
231 "musl/src/ldso/i386/dlsym_time64.S",
232 "musl/src/ldso/i386/tlsdesc.s",
233 "musl/src/ldso/m68k/dlsym.s",
234 "musl/src/ldso/m68k/dlsym_time64.S",
235 "musl/src/ldso/microblaze/dlsym.s",
236 "musl/src/ldso/microblaze/dlsym_time64.S",
237 "musl/src/ldso/mips/dlsym.s",
238 "musl/src/ldso/mips/dlsym_time64.S",
239 "musl/src/ldso/mips64/dlsym.s",
240 "musl/src/ldso/mipsn32/dlsym.s",
241 "musl/src/ldso/mipsn32/dlsym_time64.S",
242 "musl/src/ldso/or1k/dlsym.s",
243 "musl/src/ldso/or1k/dlsym_time64.S",
244 "musl/src/ldso/powerpc/dlsym.s",
245 "musl/src/ldso/powerpc/dlsym_time64.S",
246 "musl/src/ldso/powerpc64/dlsym.s",
247 "musl/src/ldso/riscv64/dlsym.s",
248 "musl/src/ldso/s390x/dlsym.s",
249 "musl/src/ldso/sh/dlsym.s",
250 "musl/src/ldso/sh/dlsym_time64.S",
251 "musl/src/ldso/tlsdesc.c",
252 "musl/src/ldso/x32/dlsym.s",
253 "musl/src/ldso/x86_64/dlsym.s",
254 "musl/src/ldso/x86_64/tlsdesc.s",
255 "musl/src/legacy/cuserid.c",
256 "musl/src/legacy/daemon.c",
257 "musl/src/legacy/err.c",
258 "musl/src/legacy/euidaccess.c",
259 "musl/src/legacy/ftw.c",
260 "musl/src/legacy/futimes.c",
261 "musl/src/legacy/getdtablesize.c",
262 "musl/src/legacy/getloadavg.c",
263 "musl/src/legacy/getpagesize.c",
264 "musl/src/legacy/getpass.c",
265 "musl/src/legacy/getusershell.c",
266 "musl/src/legacy/isastream.c",
267 "musl/src/legacy/lutimes.c",
268 "musl/src/legacy/ulimit.c",
269 "musl/src/legacy/utmpx.c",
270 "musl/src/legacy/valloc.c",
271 "musl/src/linux/adjtime.c",
272 "musl/src/linux/adjtimex.c",
273 "musl/src/linux/arch_prctl.c",
274 "musl/src/linux/brk.c",
275 "musl/src/linux/cache.c",
276 "musl/src/linux/cap.c",
277 "musl/src/linux/chroot.c",
278 "musl/src/linux/clock_adjtime.c",
279 "musl/src/linux/clone.c",
280 "musl/src/linux/copy_file_range.c",
281 "musl/src/linux/epoll.c",
282 "musl/src/linux/eventfd.c",
283 "musl/src/linux/fallocate.c",
284 "musl/src/linux/fanotify.c",
285 "musl/src/linux/flock.c",
286 "musl/src/linux/getdents.c",
287 "musl/src/linux/getrandom.c",
288 "musl/src/linux/inotify.c",
289 "musl/src/linux/ioperm.c",
290 "musl/src/linux/iopl.c",
291 "musl/src/linux/klogctl.c",
292 "musl/src/linux/membarrier.c",
293 "musl/src/linux/memfd_create.c",
294 "musl/src/linux/mlock2.c",
295 "musl/src/linux/module.c",
296 "musl/src/linux/mount.c",
297 "musl/src/linux/name_to_handle_at.c",
298 "musl/src/linux/open_by_handle_at.c",
299 "musl/src/linux/personality.c",
300 "musl/src/linux/pivot_root.c",
301 "musl/src/linux/ppoll.c",
302 "musl/src/linux/prctl.c",
303 "musl/src/linux/prlimit.c",
304 "musl/src/linux/process_vm.c",
305 "musl/src/linux/ptrace.c",
306 "musl/src/linux/quotactl.c",
307 "musl/src/linux/readahead.c",
308 "musl/src/linux/reboot.c",
309 "musl/src/linux/remap_file_pages.c",
310 "musl/src/linux/sbrk.c",
311 "musl/src/linux/sendfile.c",
312 "musl/src/linux/setfsgid.c",
313 "musl/src/linux/setfsuid.c",
314 "musl/src/linux/setgroups.c",
315 "musl/src/linux/sethostname.c",
316 "musl/src/linux/setns.c",
317 "musl/src/linux/settimeofday.c",
318 "musl/src/linux/signalfd.c",
319 "musl/src/linux/splice.c",
320 "musl/src/linux/stime.c",
321 "musl/src/linux/swap.c",
322 "musl/src/linux/sync_file_range.c",
323 "musl/src/linux/syncfs.c",
324 "musl/src/linux/sysinfo.c",
325 "musl/src/linux/tee.c",
326 "musl/src/linux/timerfd.c",
327 "musl/src/linux/unshare.c",
328 "musl/src/linux/utimes.c",
329 "musl/src/linux/vhangup.c",
330 "musl/src/linux/vmsplice.c",
331 "musl/src/linux/wait3.c",
332 "musl/src/linux/wait4.c",
333 "musl/src/linux/x32/sysinfo.c",
334 "musl/src/linux/xattr.c",
335 "musl/src/locale/__lctrans.c",
336 "musl/src/locale/__mo_lookup.c",
337 "musl/src/locale/bind_textdomain_codeset.c",
338 "musl/src/locale/c_locale.c",
339 "musl/src/locale/catclose.c",
340 "musl/src/locale/catgets.c",
341 "musl/src/locale/catopen.c",
342 "musl/src/locale/dcngettext.c",
343 "musl/src/locale/duplocale.c",
344 "musl/src/locale/freelocale.c",
345 "musl/src/locale/iconv.c",
346 "musl/src/locale/iconv_close.c",
347 "musl/src/locale/langinfo.c",
348 "musl/src/locale/locale_map.c",
349 "musl/src/locale/localeconv.c",
350 "musl/src/locale/newlocale.c",
351 "musl/src/locale/pleval.c",
352 "musl/src/locale/setlocale.c",
353 "musl/src/locale/strcoll.c",
354 "musl/src/locale/strfmon.c",
355 "musl/src/locale/strxfrm.c",
356 "musl/src/locale/textdomain.c",
357 "musl/src/locale/uselocale.c",
358 "musl/src/locale/wcscoll.c",
359 "musl/src/locale/wcsxfrm.c",
360 "musl/src/malloc/aligned_alloc.c",
361 "musl/src/malloc/expand_heap.c",
362 "musl/src/malloc/lite_malloc.c",
363 "musl/src/malloc/malloc.c",
364 "musl/src/malloc/malloc_usable_size.c",
365 "musl/src/malloc/memalign.c",
366 "musl/src/malloc/posix_memalign.c",
367 "musl/src/math/__cos.c",
368 "musl/src/math/__cosdf.c",
369 "musl/src/math/__cosl.c",
370 "musl/src/math/__expo2.c",
371 "musl/src/math/__expo2f.c",
372 "musl/src/math/__fpclassify.c",
373 "musl/src/math/__fpclassifyf.c",
374 "musl/src/math/__fpclassifyl.c",
375 "musl/src/math/__invtrigl.c",
376 "musl/src/math/__math_divzero.c",
377 "musl/src/math/__math_divzerof.c",
378 "musl/src/math/__math_invalid.c",
379 "musl/src/math/__math_invalidf.c",
380 "musl/src/math/__math_oflow.c",
381 "musl/src/math/__math_oflowf.c",
382 "musl/src/math/__math_uflow.c",
383 "musl/src/math/__math_uflowf.c",
384 "musl/src/math/__math_xflow.c",
385 "musl/src/math/__math_xflowf.c",
386 "musl/src/math/__polevll.c",
387 "musl/src/math/__rem_pio2.c",
388 "musl/src/math/__rem_pio2_large.c",
389 "musl/src/math/__rem_pio2f.c",
390 "musl/src/math/__rem_pio2l.c",
391 "musl/src/math/__signbit.c",
392 "musl/src/math/__signbitf.c",
393 "musl/src/math/__signbitl.c",
394 "musl/src/math/__sin.c",
395 "musl/src/math/__sindf.c",
396 "musl/src/math/__sinl.c",
397 "musl/src/math/__tan.c",
398 "musl/src/math/__tandf.c",
399 "musl/src/math/__tanl.c",
400 "musl/src/math/aarch64/ceil.c",
401 "musl/src/math/aarch64/ceilf.c",
402 "musl/src/math/aarch64/fabs.c",
403 "musl/src/math/aarch64/fabsf.c",
404 "musl/src/math/aarch64/floor.c",
405 "musl/src/math/aarch64/floorf.c",
406 "musl/src/math/aarch64/fma.c",
407 "musl/src/math/aarch64/fmaf.c",
408 "musl/src/math/aarch64/fmax.c",
409 "musl/src/math/aarch64/fmaxf.c",
410 "musl/src/math/aarch64/fmin.c",
411 "musl/src/math/aarch64/fminf.c",
412 "musl/src/math/aarch64/llrint.c",
413 "musl/src/math/aarch64/llrintf.c",
414 "musl/src/math/aarch64/llround.c",
415 "musl/src/math/aarch64/llroundf.c",
416 "musl/src/math/aarch64/lrint.c",
417 "musl/src/math/aarch64/lrintf.c",
418 "musl/src/math/aarch64/lround.c",
419 "musl/src/math/aarch64/lroundf.c",
420 "musl/src/math/aarch64/nearbyint.c",
421 "musl/src/math/aarch64/nearbyintf.c",
422 "musl/src/math/aarch64/rint.c",
423 "musl/src/math/aarch64/rintf.c",
424 "musl/src/math/aarch64/round.c",
425 "musl/src/math/aarch64/roundf.c",
426 "musl/src/math/aarch64/sqrt.c",
427 "musl/src/math/aarch64/sqrtf.c",
428 "musl/src/math/aarch64/trunc.c",
429 "musl/src/math/aarch64/truncf.c",
430 "musl/src/math/acos.c",
431 "musl/src/math/acosf.c",
432 "musl/src/math/acosh.c",
433 "musl/src/math/acoshf.c",
434 "musl/src/math/acoshl.c",
435 "musl/src/math/acosl.c",
436 "musl/src/math/arm/fabs.c",
437 "musl/src/math/arm/fabsf.c",
438 "musl/src/math/arm/fma.c",
439 "musl/src/math/arm/fmaf.c",
440 "musl/src/math/arm/sqrt.c",
441 "musl/src/math/arm/sqrtf.c",
442 "musl/src/math/asin.c",
443 "musl/src/math/asinf.c",
444 "musl/src/math/asinh.c",
445 "musl/src/math/asinhf.c",
446 "musl/src/math/asinhl.c",
447 "musl/src/math/asinl.c",
448 "musl/src/math/atan.c",
449 "musl/src/math/atan2.c",
450 "musl/src/math/atan2f.c",
451 "musl/src/math/atan2l.c",
452 "musl/src/math/atanf.c",
453 "musl/src/math/atanh.c",
454 "musl/src/math/atanhf.c",
455 "musl/src/math/atanhl.c",
456 "musl/src/math/atanl.c",
457 "musl/src/math/cbrt.c",
458 "musl/src/math/cbrtf.c",
459 "musl/src/math/cbrtl.c",
460 "musl/src/math/ceil.c",
461 "musl/src/math/ceilf.c",
462 "musl/src/math/ceill.c",
463 "musl/src/math/copysign.c",
464 "musl/src/math/copysignf.c",
465 "musl/src/math/copysignl.c",
466 "musl/src/math/cos.c",
467 "musl/src/math/cosf.c",
468 "musl/src/math/cosh.c",
469 "musl/src/math/coshf.c",
470 "musl/src/math/coshl.c",
471 "musl/src/math/cosl.c",
472 "musl/src/math/erf.c",
473 "musl/src/math/erff.c",
474 "musl/src/math/erfl.c",
475 "musl/src/math/exp.c",
476 "musl/src/math/exp10.c",
477 "musl/src/math/exp10f.c",
478 "musl/src/math/exp10l.c",
479 "musl/src/math/exp2.c",
480 "musl/src/math/exp2f.c",
481 "musl/src/math/exp2f_data.c",
482 "musl/src/math/exp2l.c",
483 "musl/src/math/exp_data.c",
484 "musl/src/math/expf.c",
485 "musl/src/math/expl.c",
486 "musl/src/math/expm1.c",
487 "musl/src/math/expm1f.c",
488 "musl/src/math/expm1l.c",
489 "musl/src/math/fabs.c",
490 "musl/src/math/fabsf.c",
491 "musl/src/math/fabsl.c",
492 "musl/src/math/fdim.c",
493 "musl/src/math/fdimf.c",
494 "musl/src/math/fdiml.c",
495 "musl/src/math/finite.c",
496 "musl/src/math/finitef.c",
497 "musl/src/math/floor.c",
498 "musl/src/math/floorf.c",
499 "musl/src/math/floorl.c",
500 "musl/src/math/fma.c",
501 "musl/src/math/fmaf.c",
502 "musl/src/math/fmal.c",
503 "musl/src/math/fmax.c",
504 "musl/src/math/fmaxf.c",
505 "musl/src/math/fmaxl.c",
506 "musl/src/math/fmin.c",
507 "musl/src/math/fminf.c",
508 "musl/src/math/fminl.c",
509 "musl/src/math/fmod.c",
510 "musl/src/math/fmodf.c",
511 "musl/src/math/fmodl.c",
512 "musl/src/math/frexp.c",
513 "musl/src/math/frexpf.c",
514 "musl/src/math/frexpl.c",
515 "musl/src/math/hypot.c",
516 "musl/src/math/hypotf.c",
517 "musl/src/math/hypotl.c",
518 "musl/src/math/i386/__invtrigl.s",
519 "musl/src/math/i386/acos.s",
520 "musl/src/math/i386/acosf.s",
521 "musl/src/math/i386/acosl.s",
522 "musl/src/math/i386/asin.s",
523 "musl/src/math/i386/asinf.s",
524 "musl/src/math/i386/asinl.s",
525 "musl/src/math/i386/atan.s",
526 "musl/src/math/i386/atan2.s",
527 "musl/src/math/i386/atan2f.s",
528 "musl/src/math/i386/atan2l.s",
529 "musl/src/math/i386/atanf.s",
530 "musl/src/math/i386/atanl.s",
531 "musl/src/math/i386/ceil.s",
532 "musl/src/math/i386/ceilf.s",
533 "musl/src/math/i386/ceill.s",
534 "musl/src/math/i386/exp2l.s",
535 "musl/src/math/i386/exp_ld.s",
536 "musl/src/math/i386/expl.s",
537 "musl/src/math/i386/expm1l.s",
538 "musl/src/math/i386/fabs.s",
539 "musl/src/math/i386/fabsf.s",
540 "musl/src/math/i386/fabsl.s",
541 "musl/src/math/i386/floor.s",
542 "musl/src/math/i386/floorf.s",
543 "musl/src/math/i386/floorl.s",
544 "musl/src/math/i386/fmod.s",
545 "musl/src/math/i386/fmodf.s",
546 "musl/src/math/i386/fmodl.s",
547 "musl/src/math/i386/hypot.s",
548 "musl/src/math/i386/hypotf.s",
549 "musl/src/math/i386/ldexp.s",
550 "musl/src/math/i386/ldexpf.s",
551 "musl/src/math/i386/ldexpl.s",
552 "musl/src/math/i386/llrint.s",
553 "musl/src/math/i386/llrintf.s",
554 "musl/src/math/i386/llrintl.s",
555 "musl/src/math/i386/log.s",
556 "musl/src/math/i386/log10.s",
557 "musl/src/math/i386/log10f.s",
558 "musl/src/math/i386/log10l.s",
559 "musl/src/math/i386/log1p.s",
560 "musl/src/math/i386/log1pf.s",
561 "musl/src/math/i386/log1pl.s",
562 "musl/src/math/i386/log2.s",
563 "musl/src/math/i386/log2f.s",
564 "musl/src/math/i386/log2l.s",
565 "musl/src/math/i386/logf.s",
566 "musl/src/math/i386/logl.s",
567 "musl/src/math/i386/lrint.s",
568 "musl/src/math/i386/lrintf.s",
569 "musl/src/math/i386/lrintl.s",
570 "musl/src/math/i386/remainder.s",
571 "musl/src/math/i386/remainderf.s",
572 "musl/src/math/i386/remainderl.s",
573 "musl/src/math/i386/remquo.s",
574 "musl/src/math/i386/remquof.s",
575 "musl/src/math/i386/remquol.s",
576 "musl/src/math/i386/rint.s",
577 "musl/src/math/i386/rintf.s",
578 "musl/src/math/i386/rintl.s",
579 "musl/src/math/i386/scalbln.s",
580 "musl/src/math/i386/scalblnf.s",
581 "musl/src/math/i386/scalblnl.s",
582 "musl/src/math/i386/scalbn.s",
583 "musl/src/math/i386/scalbnf.s",
584 "musl/src/math/i386/scalbnl.s",
585 "musl/src/math/i386/sqrt.s",
586 "musl/src/math/i386/sqrtf.s",
587 "musl/src/math/i386/sqrtl.s",
588 "musl/src/math/i386/trunc.s",
589 "musl/src/math/i386/truncf.s",
590 "musl/src/math/i386/truncl.s",
591 "musl/src/math/ilogb.c",
592 "musl/src/math/ilogbf.c",
593 "musl/src/math/ilogbl.c",
594 "musl/src/math/j0.c",
595 "musl/src/math/j0f.c",
596 "musl/src/math/j1.c",
597 "musl/src/math/j1f.c",
598 "musl/src/math/jn.c",
599 "musl/src/math/jnf.c",
600 "musl/src/math/ldexp.c",
601 "musl/src/math/ldexpf.c",
602 "musl/src/math/ldexpl.c",
603 "musl/src/math/lgamma.c",
604 "musl/src/math/lgamma_r.c",
605 "musl/src/math/lgammaf.c",
606 "musl/src/math/lgammaf_r.c",
607 "musl/src/math/lgammal.c",
608 "musl/src/math/llrint.c",
609 "musl/src/math/llrintf.c",
610 "musl/src/math/llrintl.c",
611 "musl/src/math/llround.c",
612 "musl/src/math/llroundf.c",
613 "musl/src/math/llroundl.c",
614 "musl/src/math/log.c",
615 "musl/src/math/log10.c",
616 "musl/src/math/log10f.c",
617 "musl/src/math/log10l.c",
618 "musl/src/math/log1p.c",
619 "musl/src/math/log1pf.c",
620 "musl/src/math/log1pl.c",
621 "musl/src/math/log2.c",
622 "musl/src/math/log2_data.c",
623 "musl/src/math/log2f.c",
624 "musl/src/math/log2f_data.c",
625 "musl/src/math/log2l.c",
626 "musl/src/math/log_data.c",
627 "musl/src/math/logb.c",
628 "musl/src/math/logbf.c",
629 "musl/src/math/logbl.c",
630 "musl/src/math/logf.c",
631 "musl/src/math/logf_data.c",
632 "musl/src/math/logl.c",
633 "musl/src/math/lrint.c",
634 "musl/src/math/lrintf.c",
635 "musl/src/math/lrintl.c",
636 "musl/src/math/lround.c",
637 "musl/src/math/lroundf.c",
638 "musl/src/math/lroundl.c",
639 "musl/src/math/mips/fabs.c",
640 "musl/src/math/mips/fabsf.c",
641 "musl/src/math/mips/sqrt.c",
642 "musl/src/math/mips/sqrtf.c",
643 "musl/src/math/modf.c",
644 "musl/src/math/modff.c",
645 "musl/src/math/modfl.c",
646 "musl/src/math/nan.c",
647 "musl/src/math/nanf.c",
648 "musl/src/math/nanl.c",
649 "musl/src/math/nearbyint.c",
650 "musl/src/math/nearbyintf.c",
651 "musl/src/math/nearbyintl.c",
652 "musl/src/math/nextafter.c",
653 "musl/src/math/nextafterf.c",
654 "musl/src/math/nextafterl.c",
655 "musl/src/math/nexttoward.c",
656 "musl/src/math/nexttowardf.c",
657 "musl/src/math/nexttowardl.c",
658 "musl/src/math/pow.c",
659 "musl/src/math/pow_data.c",
660 "musl/src/math/powerpc/fabs.c",
661 "musl/src/math/powerpc/fabsf.c",
662 "musl/src/math/powerpc/fma.c",
663 "musl/src/math/powerpc/fmaf.c",
664 "musl/src/math/powerpc/sqrt.c",
665 "musl/src/math/powerpc/sqrtf.c",
666 "musl/src/math/powerpc64/ceil.c",
667 "musl/src/math/powerpc64/ceilf.c",
668 "musl/src/math/powerpc64/fabs.c",
669 "musl/src/math/powerpc64/fabsf.c",
670 "musl/src/math/powerpc64/floor.c",
671 "musl/src/math/powerpc64/floorf.c",
672 "musl/src/math/powerpc64/fma.c",
673 "musl/src/math/powerpc64/fmaf.c",
674 "musl/src/math/powerpc64/fmax.c",
675 "musl/src/math/powerpc64/fmaxf.c",
676 "musl/src/math/powerpc64/fmin.c",
677 "musl/src/math/powerpc64/fminf.c",
678 "musl/src/math/powerpc64/lrint.c",
679 "musl/src/math/powerpc64/lrintf.c",
680 "musl/src/math/powerpc64/lround.c",
681 "musl/src/math/powerpc64/lroundf.c",
682 "musl/src/math/powerpc64/round.c",
683 "musl/src/math/powerpc64/roundf.c",
684 "musl/src/math/powerpc64/sqrt.c",
685 "musl/src/math/powerpc64/sqrtf.c",
686 "musl/src/math/powerpc64/trunc.c",
687 "musl/src/math/powerpc64/truncf.c",
688 "musl/src/math/powf.c",
689 "musl/src/math/powf_data.c",
690 "musl/src/math/powl.c",
691 "musl/src/math/remainder.c",
692 "musl/src/math/remainderf.c",
693 "musl/src/math/remainderl.c",
694 "musl/src/math/remquo.c",
695 "musl/src/math/remquof.c",
696 "musl/src/math/remquol.c",
697 "musl/src/math/rint.c",
698 "musl/src/math/rintf.c",
699 "musl/src/math/rintl.c",
700 "musl/src/math/riscv64/copysign.c",
701 "musl/src/math/riscv64/copysignf.c",
702 "musl/src/math/riscv64/fabs.c",
703 "musl/src/math/riscv64/fabsf.c",
704 "musl/src/math/riscv64/fma.c",
705 "musl/src/math/riscv64/fmaf.c",
706 "musl/src/math/riscv64/fmax.c",
707 "musl/src/math/riscv64/fmaxf.c",
708 "musl/src/math/riscv64/fmin.c",
709 "musl/src/math/riscv64/fminf.c",
710 "musl/src/math/riscv64/sqrt.c",
711 "musl/src/math/riscv64/sqrtf.c",
712 "musl/src/math/round.c",
713 "musl/src/math/roundf.c",
714 "musl/src/math/roundl.c",
715 "musl/src/math/s390x/ceil.c",
716 "musl/src/math/s390x/ceilf.c",
717 "musl/src/math/s390x/ceill.c",
718 "musl/src/math/s390x/fabs.c",
719 "musl/src/math/s390x/fabsf.c",
720 "musl/src/math/s390x/fabsl.c",
721 "musl/src/math/s390x/floor.c",
722 "musl/src/math/s390x/floorf.c",
723 "musl/src/math/s390x/floorl.c",
724 "musl/src/math/s390x/fma.c",
725 "musl/src/math/s390x/fmaf.c",
726 "musl/src/math/s390x/nearbyint.c",
727 "musl/src/math/s390x/nearbyintf.c",
728 "musl/src/math/s390x/nearbyintl.c",
729 "musl/src/math/s390x/rint.c",
730 "musl/src/math/s390x/rintf.c",
731 "musl/src/math/s390x/rintl.c",
732 "musl/src/math/s390x/round.c",
733 "musl/src/math/s390x/roundf.c",
734 "musl/src/math/s390x/roundl.c",
735 "musl/src/math/s390x/sqrt.c",
736 "musl/src/math/s390x/sqrtf.c",
737 "musl/src/math/s390x/sqrtl.c",
738 "musl/src/math/s390x/trunc.c",
739 "musl/src/math/s390x/truncf.c",
740 "musl/src/math/s390x/truncl.c",
741 "musl/src/math/scalb.c",
742 "musl/src/math/scalbf.c",
743 "musl/src/math/scalbln.c",
744 "musl/src/math/scalblnf.c",
745 "musl/src/math/scalblnl.c",
746 "musl/src/math/scalbn.c",
747 "musl/src/math/scalbnf.c",
748 "musl/src/math/scalbnl.c",
749 "musl/src/math/signgam.c",
750 "musl/src/math/significand.c",
751 "musl/src/math/significandf.c",
752 "musl/src/math/sin.c",
753 "musl/src/math/sincos.c",
754 "musl/src/math/sincosf.c",
755 "musl/src/math/sincosl.c",
756 "musl/src/math/sinf.c",
757 "musl/src/math/sinh.c",
758 "musl/src/math/sinhf.c",
759 "musl/src/math/sinhl.c",
760 "musl/src/math/sinl.c",
761 "musl/src/math/sqrt.c",
762 "musl/src/math/sqrtf.c",
763 "musl/src/math/sqrtl.c",
764 "musl/src/math/tan.c",
765 "musl/src/math/tanf.c",
766 "musl/src/math/tanh.c",
767 "musl/src/math/tanhf.c",
768 "musl/src/math/tanhl.c",
769 "musl/src/math/tanl.c",
770 "musl/src/math/tgamma.c",
771 "musl/src/math/tgammaf.c",
772 "musl/src/math/tgammal.c",
773 "musl/src/math/trunc.c",
774 "musl/src/math/truncf.c",
775 "musl/src/math/truncl.c",
776 "musl/src/math/x32/__invtrigl.s",
777 "musl/src/math/x32/acosl.s",
778 "musl/src/math/x32/asinl.s",
779 "musl/src/math/x32/atan2l.s",
780 "musl/src/math/x32/atanl.s",
781 "musl/src/math/x32/ceill.s",
782 "musl/src/math/x32/exp2l.s",
783 "musl/src/math/x32/expl.s",
784 "musl/src/math/x32/expm1l.s",
785 "musl/src/math/x32/fabs.s",
786 "musl/src/math/x32/fabsf.s",
787 "musl/src/math/x32/fabsl.s",
788 "musl/src/math/x32/floorl.s",
789 "musl/src/math/x32/fma.c",
790 "musl/src/math/x32/fmaf.c",
791 "musl/src/math/x32/fmodl.s",
792 "musl/src/math/x32/llrint.s",
793 "musl/src/math/x32/llrintf.s",
794 "musl/src/math/x32/llrintl.s",
795 "musl/src/math/x32/log10l.s",
796 "musl/src/math/x32/log1pl.s",
797 "musl/src/math/x32/log2l.s",
798 "musl/src/math/x32/logl.s",
799 "musl/src/math/x32/lrint.s",
800 "musl/src/math/x32/lrintf.s",
801 "musl/src/math/x32/lrintl.s",
802 "musl/src/math/x32/remainderl.s",
803 "musl/src/math/x32/rintl.s",
804 "musl/src/math/x32/sqrt.s",
805 "musl/src/math/x32/sqrtf.s",
806 "musl/src/math/x32/sqrtl.s",
807 "musl/src/math/x32/truncl.s",
808 "musl/src/math/x86_64/__invtrigl.s",
809 "musl/src/math/x86_64/acosl.s",
810 "musl/src/math/x86_64/asinl.s",
811 "musl/src/math/x86_64/atan2l.s",
812 "musl/src/math/x86_64/atanl.s",
813 "musl/src/math/x86_64/ceill.s",
814 "musl/src/math/x86_64/exp2l.s",
815 "musl/src/math/x86_64/expl.s",
816 "musl/src/math/x86_64/expm1l.s",
817 "musl/src/math/x86_64/fabs.s",
818 "musl/src/math/x86_64/fabsf.s",
819 "musl/src/math/x86_64/fabsl.s",
820 "musl/src/math/x86_64/floorl.s",
821 "musl/src/math/x86_64/fma.c",
822 "musl/src/math/x86_64/fmaf.c",
823 "musl/src/math/x86_64/fmodl.s",
824 "musl/src/math/x86_64/llrint.s",
825 "musl/src/math/x86_64/llrintf.s",
826 "musl/src/math/x86_64/llrintl.s",
827 "musl/src/math/x86_64/log10l.s",
828 "musl/src/math/x86_64/log1pl.s",
829 "musl/src/math/x86_64/log2l.s",
830 "musl/src/math/x86_64/logl.s",
831 "musl/src/math/x86_64/lrint.s",
832 "musl/src/math/x86_64/lrintf.s",
833 "musl/src/math/x86_64/lrintl.s",
834 "musl/src/math/x86_64/remainderl.s",
835 "musl/src/math/x86_64/rintl.s",
836 "musl/src/math/x86_64/sqrt.s",
837 "musl/src/math/x86_64/sqrtf.s",
838 "musl/src/math/x86_64/sqrtl.s",
839 "musl/src/math/x86_64/truncl.s",
840 "musl/src/misc/a64l.c",
841 "musl/src/misc/basename.c",
842 "musl/src/misc/dirname.c",
843 "musl/src/misc/ffs.c",
844 "musl/src/misc/ffsl.c",
845 "musl/src/misc/ffsll.c",
846 "musl/src/misc/fmtmsg.c",
847 "musl/src/misc/forkpty.c",
848 "musl/src/misc/get_current_dir_name.c",
849 "musl/src/misc/getauxval.c",
850 "musl/src/misc/getdomainname.c",
851 "musl/src/misc/getentropy.c",
852 "musl/src/misc/gethostid.c",
853 "musl/src/misc/getopt.c",
854 "musl/src/misc/getopt_long.c",
855 "musl/src/misc/getpriority.c",
856 "musl/src/misc/getresgid.c",
857 "musl/src/misc/getresuid.c",
858 "musl/src/misc/getrlimit.c",
859 "musl/src/misc/getrusage.c",
860 "musl/src/misc/getsubopt.c",
861 "musl/src/misc/initgroups.c",
862 "musl/src/misc/ioctl.c",
863 "musl/src/misc/issetugid.c",
864 "musl/src/misc/lockf.c",
865 "musl/src/misc/login_tty.c",
866 "musl/src/misc/mntent.c",
867 "musl/src/misc/nftw.c",
868 "musl/src/misc/openpty.c",
869 "musl/src/misc/ptsname.c",
870 "musl/src/misc/pty.c",
871 "musl/src/misc/realpath.c",
872 "musl/src/misc/setdomainname.c",
873 "musl/src/misc/setpriority.c",
874 "musl/src/misc/setrlimit.c",
875 "musl/src/misc/syscall.c",
876 "musl/src/misc/syslog.c",
877 "musl/src/misc/uname.c",
878 "musl/src/misc/wordexp.c",
879 "musl/src/mman/madvise.c",
880 "musl/src/mman/mincore.c",
881 "musl/src/mman/mlock.c",
882 "musl/src/mman/mlockall.c",
883 "musl/src/mman/mmap.c",
884 "musl/src/mman/mprotect.c",
885 "musl/src/mman/mremap.c",
886 "musl/src/mman/msync.c",
887 "musl/src/mman/munlock.c",
888 "musl/src/mman/munlockall.c",
889 "musl/src/mman/munmap.c",
890 "musl/src/mman/posix_madvise.c",
891 "musl/src/mman/shm_open.c",
892 "musl/src/mq/mq_close.c",
893 "musl/src/mq/mq_getattr.c",
894 "musl/src/mq/mq_notify.c",
895 "musl/src/mq/mq_open.c",
896 "musl/src/mq/mq_receive.c",
897 "musl/src/mq/mq_send.c",
898 "musl/src/mq/mq_setattr.c",
899 "musl/src/mq/mq_timedreceive.c",
900 "musl/src/mq/mq_timedsend.c",
901 "musl/src/mq/mq_unlink.c",
902 "musl/src/multibyte/btowc.c",
903 "musl/src/multibyte/c16rtomb.c",
904 "musl/src/multibyte/c32rtomb.c",
905 "musl/src/multibyte/internal.c",
906 "musl/src/multibyte/mblen.c",
907 "musl/src/multibyte/mbrlen.c",
908 "musl/src/multibyte/mbrtoc16.c",
909 "musl/src/multibyte/mbrtoc32.c",
910 "musl/src/multibyte/mbrtowc.c",
911 "musl/src/multibyte/mbsinit.c",
912 "musl/src/multibyte/mbsnrtowcs.c",
913 "musl/src/multibyte/mbsrtowcs.c",
914 "musl/src/multibyte/mbstowcs.c",
915 "musl/src/multibyte/mbtowc.c",
916 "musl/src/multibyte/wcrtomb.c",
917 "musl/src/multibyte/wcsnrtombs.c",
918 "musl/src/multibyte/wcsrtombs.c",
919 "musl/src/multibyte/wcstombs.c",
920 "musl/src/multibyte/wctob.c",
921 "musl/src/multibyte/wctomb.c",
922 "musl/src/network/accept.c",
923 "musl/src/network/accept4.c",
924 "musl/src/network/bind.c",
925 "musl/src/network/connect.c",
926 "musl/src/network/dn_comp.c",
927 "musl/src/network/dn_expand.c",
928 "musl/src/network/dn_skipname.c",
929 "musl/src/network/dns_parse.c",
930 "musl/src/network/ent.c",
931 "musl/src/network/ether.c",
932 "musl/src/network/freeaddrinfo.c",
933 "musl/src/network/gai_strerror.c",
934 "musl/src/network/getaddrinfo.c",
935 "musl/src/network/gethostbyaddr.c",
936 "musl/src/network/gethostbyaddr_r.c",
937 "musl/src/network/gethostbyname.c",
938 "musl/src/network/gethostbyname2.c",
939 "musl/src/network/gethostbyname2_r.c",
940 "musl/src/network/gethostbyname_r.c",
941 "musl/src/network/getifaddrs.c",
942 "musl/src/network/getnameinfo.c",
943 "musl/src/network/getpeername.c",
944 "musl/src/network/getservbyname.c",
945 "musl/src/network/getservbyname_r.c",
946 "musl/src/network/getservbyport.c",
947 "musl/src/network/getservbyport_r.c",
948 "musl/src/network/getsockname.c",
949 "musl/src/network/getsockopt.c",
950 "musl/src/network/h_errno.c",
951 "musl/src/network/herror.c",
952 "musl/src/network/hstrerror.c",
953 "musl/src/network/htonl.c",
954 "musl/src/network/htons.c",
955 "musl/src/network/if_freenameindex.c",
956 "musl/src/network/if_indextoname.c",
957 "musl/src/network/if_nameindex.c",
958 "musl/src/network/if_nametoindex.c",
959 "musl/src/network/in6addr_any.c",
960 "musl/src/network/in6addr_loopback.c",
961 "musl/src/network/inet_addr.c",
962 "musl/src/network/inet_aton.c",
963 "musl/src/network/inet_legacy.c",
964 "musl/src/network/inet_ntoa.c",
965 "musl/src/network/inet_ntop.c",
966 "musl/src/network/inet_pton.c",
967 "musl/src/network/listen.c",
968 "musl/src/network/lookup_ipliteral.c",
969 "musl/src/network/lookup_name.c",
970 "musl/src/network/lookup_serv.c",
971 "musl/src/network/netlink.c",
972 "musl/src/network/netname.c",
973 "musl/src/network/ns_parse.c",
974 "musl/src/network/ntohl.c",
975 "musl/src/network/ntohs.c",
976 "musl/src/network/proto.c",
977 "musl/src/network/recv.c",
978 "musl/src/network/recvfrom.c",
979 "musl/src/network/recvmmsg.c",
980 "musl/src/network/recvmsg.c",
981 "musl/src/network/res_init.c",
982 "musl/src/network/res_mkquery.c",
983 "musl/src/network/res_msend.c",
984 "musl/src/network/res_query.c",
985 "musl/src/network/res_querydomain.c",
986 "musl/src/network/res_send.c",
987 "musl/src/network/res_state.c",
988 "musl/src/network/resolvconf.c",
989 "musl/src/network/send.c",
990 "musl/src/network/sendmmsg.c",
991 "musl/src/network/sendmsg.c",
992 "musl/src/network/sendto.c",
993 "musl/src/network/serv.c",
994 "musl/src/network/setsockopt.c",
995 "musl/src/network/shutdown.c",
996 "musl/src/network/sockatmark.c",
997 "musl/src/network/socket.c",
998 "musl/src/network/socketpair.c",
999 "musl/src/passwd/fgetgrent.c",
1000 "musl/src/passwd/fgetpwent.c",
1001 "musl/src/passwd/fgetspent.c",
1002 "musl/src/passwd/getgr_a.c",
1003 "musl/src/passwd/getgr_r.c",
1004 "musl/src/passwd/getgrent.c",
1005 "musl/src/passwd/getgrent_a.c",
1006 "musl/src/passwd/getgrouplist.c",
1007 "musl/src/passwd/getpw_a.c",
1008 "musl/src/passwd/getpw_r.c",
1009 "musl/src/passwd/getpwent.c",
1010 "musl/src/passwd/getpwent_a.c",
1011 "musl/src/passwd/getspent.c",
1012 "musl/src/passwd/getspnam.c",
1013 "musl/src/passwd/getspnam_r.c",
1014 "musl/src/passwd/lckpwdf.c",
1015 "musl/src/passwd/nscd_query.c",
1016 "musl/src/passwd/putgrent.c",
1017 "musl/src/passwd/putpwent.c",
1018 "musl/src/passwd/putspent.c",
1019 "musl/src/prng/__rand48_step.c",
1020 "musl/src/prng/__seed48.c",
1021 "musl/src/prng/drand48.c",
1022 "musl/src/prng/lcong48.c",
1023 "musl/src/prng/lrand48.c",
1024 "musl/src/prng/mrand48.c",
1025 "musl/src/prng/rand.c",
1026 "musl/src/prng/rand_r.c",
1027 "musl/src/prng/random.c",
1028 "musl/src/prng/seed48.c",
1029 "musl/src/prng/srand48.c",
1030 "musl/src/process/arm/vfork.s",
1031 "musl/src/process/execl.c",
1032 "musl/src/process/execle.c",
1033 "musl/src/process/execlp.c",
1034 "musl/src/process/execv.c",
1035 "musl/src/process/execve.c",
1036 "musl/src/process/execvp.c",
1037 "musl/src/process/fexecve.c",
1038 "musl/src/process/fork.c",
1039 "musl/src/process/i386/vfork.s",
1040 "musl/src/process/posix_spawn.c",
1041 "musl/src/process/posix_spawn_file_actions_addchdir.c",
1042 "musl/src/process/posix_spawn_file_actions_addclose.c",
1043 "musl/src/process/posix_spawn_file_actions_adddup2.c",
1044 "musl/src/process/posix_spawn_file_actions_addfchdir.c",
1045 "musl/src/process/posix_spawn_file_actions_addopen.c",
1046 "musl/src/process/posix_spawn_file_actions_destroy.c",
1047 "musl/src/process/posix_spawn_file_actions_init.c",
1048 "musl/src/process/posix_spawnattr_destroy.c",
1049 "musl/src/process/posix_spawnattr_getflags.c",
1050 "musl/src/process/posix_spawnattr_getpgroup.c",
1051 "musl/src/process/posix_spawnattr_getsigdefault.c",
1052 "musl/src/process/posix_spawnattr_getsigmask.c",
1053 "musl/src/process/posix_spawnattr_init.c",
1054 "musl/src/process/posix_spawnattr_sched.c",
1055 "musl/src/process/posix_spawnattr_setflags.c",
1056 "musl/src/process/posix_spawnattr_setpgroup.c",
1057 "musl/src/process/posix_spawnattr_setsigdefault.c",
1058 "musl/src/process/posix_spawnattr_setsigmask.c",
1059 "musl/src/process/posix_spawnp.c",
1060 "musl/src/process/s390x/vfork.s",
1061 "musl/src/process/sh/vfork.s",
1062 "musl/src/process/system.c",
1063 "musl/src/process/vfork.c",
1064 "musl/src/process/wait.c",
1065 "musl/src/process/waitid.c",
1066 "musl/src/process/waitpid.c",
1067 "musl/src/process/x32/vfork.s",
1068 "musl/src/process/x86_64/vfork.s",
1069 "musl/src/regex/fnmatch.c",
1070 "musl/src/regex/glob.c",
1071 "musl/src/regex/regcomp.c",
1072 "musl/src/regex/regerror.c",
1073 "musl/src/regex/regexec.c",
1074 "musl/src/regex/tre-mem.c",
1075 "musl/src/sched/affinity.c",
1076 "musl/src/sched/sched_cpucount.c",
1077 "musl/src/sched/sched_get_priority_max.c",
1078 "musl/src/sched/sched_getcpu.c",
1079 "musl/src/sched/sched_getparam.c",
1080 "musl/src/sched/sched_getscheduler.c",
1081 "musl/src/sched/sched_rr_get_interval.c",
1082 "musl/src/sched/sched_setparam.c",
1083 "musl/src/sched/sched_setscheduler.c",
1084 "musl/src/sched/sched_yield.c",
1085 "musl/src/search/hsearch.c",
1086 "musl/src/search/insque.c",
1087 "musl/src/search/lsearch.c",
1088 "musl/src/search/tdelete.c",
1089 "musl/src/search/tdestroy.c",
1090 "musl/src/search/tfind.c",
1091 "musl/src/search/tsearch.c",
1092 "musl/src/search/twalk.c",
1093 "musl/src/select/poll.c",
1094 "musl/src/select/pselect.c",
1095 "musl/src/select/select.c",
1096 "musl/src/setjmp/aarch64/longjmp.s",
1097 "musl/src/setjmp/aarch64/setjmp.s",
1098 "musl/src/setjmp/arm/longjmp.S",
1099 "musl/src/setjmp/arm/setjmp.S",
1100 "musl/src/setjmp/i386/longjmp.s",
1101 "musl/src/setjmp/i386/setjmp.s",
1102 "musl/src/setjmp/longjmp.c",
1103 "musl/src/setjmp/m68k/longjmp.s",
1104 "musl/src/setjmp/m68k/setjmp.s",
1105 "musl/src/setjmp/microblaze/longjmp.s",
1106 "musl/src/setjmp/microblaze/setjmp.s",
1107 "musl/src/setjmp/mips/longjmp.S",
1108 "musl/src/setjmp/mips/setjmp.S",
1109 "musl/src/setjmp/mips64/longjmp.S",
1110 "musl/src/setjmp/mips64/setjmp.S",
1111 "musl/src/setjmp/mipsn32/longjmp.S",
1112 "musl/src/setjmp/mipsn32/setjmp.S",
1113 "musl/src/setjmp/or1k/longjmp.s",
1114 "musl/src/setjmp/or1k/setjmp.s",
1115 "musl/src/setjmp/powerpc/longjmp.S",
1116 "musl/src/setjmp/powerpc/setjmp.S",
1117 "musl/src/setjmp/powerpc64/longjmp.s",
1118 "musl/src/setjmp/powerpc64/setjmp.s",
1119 "musl/src/setjmp/riscv64/longjmp.S",
1120 "musl/src/setjmp/riscv64/setjmp.S",
1121 "musl/src/setjmp/s390x/longjmp.s",
1122 "musl/src/setjmp/s390x/setjmp.s",
1123 "musl/src/setjmp/setjmp.c",
1124 "musl/src/setjmp/sh/longjmp.S",
1125 "musl/src/setjmp/sh/setjmp.S",
1126 "musl/src/setjmp/x32/longjmp.s",
1127 "musl/src/setjmp/x32/setjmp.s",
1128 "musl/src/setjmp/x86_64/longjmp.s",
1129 "musl/src/setjmp/x86_64/setjmp.s",
1130 "musl/src/signal/aarch64/restore.s",
1131 "musl/src/signal/aarch64/sigsetjmp.s",
1132 "musl/src/signal/arm/restore.s",
1133 "musl/src/signal/arm/sigsetjmp.s",
1134 "musl/src/signal/block.c",
1135 "musl/src/signal/getitimer.c",
1136 "musl/src/signal/i386/restore.s",
1137 "musl/src/signal/i386/sigsetjmp.s",
1138 "musl/src/signal/kill.c",
1139 "musl/src/signal/killpg.c",
1140 "musl/src/signal/m68k/sigsetjmp.s",
1141 "musl/src/signal/microblaze/restore.s",
1142 "musl/src/signal/microblaze/sigsetjmp.s",
1143 "musl/src/signal/mips/restore.s",
1144 "musl/src/signal/mips/sigsetjmp.s",
1145 "musl/src/signal/mips64/restore.s",
1146 "musl/src/signal/mips64/sigsetjmp.s",
1147 "musl/src/signal/mipsn32/restore.s",
1148 "musl/src/signal/mipsn32/sigsetjmp.s",
1149 "musl/src/signal/or1k/sigsetjmp.s",
1150 "musl/src/signal/powerpc/restore.s",
1151 "musl/src/signal/powerpc/sigsetjmp.s",
1152 "musl/src/signal/powerpc64/restore.s",
1153 "musl/src/signal/powerpc64/sigsetjmp.s",
1154 "musl/src/signal/psiginfo.c",
1155 "musl/src/signal/psignal.c",
1156 "musl/src/signal/raise.c",
1157 "musl/src/signal/restore.c",
1158 "musl/src/signal/riscv64/restore.s",
1159 "musl/src/signal/riscv64/sigsetjmp.s",
1160 "musl/src/signal/s390x/restore.s",
1161 "musl/src/signal/s390x/sigsetjmp.s",
1162 "musl/src/signal/setitimer.c",
1163 "musl/src/signal/sh/restore.s",
1164 "musl/src/signal/sh/sigsetjmp.s",
1165 "musl/src/signal/sigaction.c",
1166 "musl/src/signal/sigaddset.c",
1167 "musl/src/signal/sigaltstack.c",
1168 "musl/src/signal/sigandset.c",
1169 "musl/src/signal/sigdelset.c",
1170 "musl/src/signal/sigemptyset.c",
1171 "musl/src/signal/sigfillset.c",
1172 "musl/src/signal/sighold.c",
1173 "musl/src/signal/sigignore.c",
1174 "musl/src/signal/siginterrupt.c",
1175 "musl/src/signal/sigisemptyset.c",
1176 "musl/src/signal/sigismember.c",
1177 "musl/src/signal/siglongjmp.c",
1178 "musl/src/signal/signal.c",
1179 "musl/src/signal/sigorset.c",
1180 "musl/src/signal/sigpause.c",
1181 "musl/src/signal/sigpending.c",
1182 "musl/src/signal/sigprocmask.c",
1183 "musl/src/signal/sigqueue.c",
1184 "musl/src/signal/sigrelse.c",
1185 "musl/src/signal/sigrtmax.c",
1186 "musl/src/signal/sigrtmin.c",
1187 "musl/src/signal/sigset.c",
1188 "musl/src/signal/sigsetjmp.c",
1189 "musl/src/signal/sigsetjmp_tail.c",
1190 "musl/src/signal/sigsuspend.c",
1191 "musl/src/signal/sigtimedwait.c",
1192 "musl/src/signal/sigwait.c",
1193 "musl/src/signal/sigwaitinfo.c",
1194 "musl/src/signal/x32/getitimer.c",
1195 "musl/src/signal/x32/restore.s",
1196 "musl/src/signal/x32/setitimer.c",
1197 "musl/src/signal/x32/sigsetjmp.s",
1198 "musl/src/signal/x86_64/restore.s",
1199 "musl/src/signal/x86_64/sigsetjmp.s",
1200 "musl/src/stat/__xstat.c",
1201 "musl/src/stat/chmod.c",
1202 "musl/src/stat/fchmod.c",
1203 "musl/src/stat/fchmodat.c",
1204 "musl/src/stat/fstat.c",
1205 "musl/src/stat/fstatat.c",
1206 "musl/src/stat/futimens.c",
1207 "musl/src/stat/futimesat.c",
1208 "musl/src/stat/lchmod.c",
1209 "musl/src/stat/lstat.c",
1210 "musl/src/stat/mkdir.c",
1211 "musl/src/stat/mkdirat.c",
1212 "musl/src/stat/mkfifo.c",
1213 "musl/src/stat/mkfifoat.c",
1214 "musl/src/stat/mknod.c",
1215 "musl/src/stat/mknodat.c",
1216 "musl/src/stat/stat.c",
1217 "musl/src/stat/statvfs.c",
1218 "musl/src/stat/umask.c",
1219 "musl/src/stat/utimensat.c",
1220 "musl/src/stdio/__fclose_ca.c",
1221 "musl/src/stdio/__fdopen.c",
1222 "musl/src/stdio/__fmodeflags.c",
1223 "musl/src/stdio/__fopen_rb_ca.c",
1224 "musl/src/stdio/__lockfile.c",
1225 "musl/src/stdio/__overflow.c",
1226 "musl/src/stdio/__stdio_close.c",
1227 "musl/src/stdio/__stdio_exit.c",
1228 "musl/src/stdio/__stdio_read.c",
1229 "musl/src/stdio/__stdio_seek.c",
1230 "musl/src/stdio/__stdio_write.c",
1231 "musl/src/stdio/__stdout_write.c",
1232 "musl/src/stdio/__string_read.c",
1233 "musl/src/stdio/__toread.c",
1234 "musl/src/stdio/__towrite.c",
1235 "musl/src/stdio/__uflow.c",
1236 "musl/src/stdio/asprintf.c",
1237 "musl/src/stdio/clearerr.c",
1238 "musl/src/stdio/dprintf.c",
1239 "musl/src/stdio/ext.c",
1240 "musl/src/stdio/ext2.c",
1241 "musl/src/stdio/fclose.c",
1242 "musl/src/stdio/feof.c",
1243 "musl/src/stdio/ferror.c",
1244 "musl/src/stdio/fflush.c",
1245 "musl/src/stdio/fgetc.c",
1246 "musl/src/stdio/fgetln.c",
1247 "musl/src/stdio/fgetpos.c",
1248 "musl/src/stdio/fgets.c",
1249 "musl/src/stdio/fgetwc.c",
1250 "musl/src/stdio/fgetws.c",
1251 "musl/src/stdio/fileno.c",
1252 "musl/src/stdio/flockfile.c",
1253 "musl/src/stdio/fmemopen.c",
1254 "musl/src/stdio/fopen.c",
1255 "musl/src/stdio/fopencookie.c",
1256 "musl/src/stdio/fprintf.c",
1257 "musl/src/stdio/fputc.c",
1258 "musl/src/stdio/fputs.c",
1259 "musl/src/stdio/fputwc.c",
1260 "musl/src/stdio/fputws.c",
1261 "musl/src/stdio/fread.c",
1262 "musl/src/stdio/freopen.c",
1263 "musl/src/stdio/fscanf.c",
1264 "musl/src/stdio/fseek.c",
1265 "musl/src/stdio/fsetpos.c",
1266 "musl/src/stdio/ftell.c",
1267 "musl/src/stdio/ftrylockfile.c",
1268 "musl/src/stdio/funlockfile.c",
1269 "musl/src/stdio/fwide.c",
1270 "musl/src/stdio/fwprintf.c",
1271 "musl/src/stdio/fwrite.c",
1272 "musl/src/stdio/fwscanf.c",
1273 "musl/src/stdio/getc.c",
1274 "musl/src/stdio/getc_unlocked.c",
1275 "musl/src/stdio/getchar.c",
1276 "musl/src/stdio/getchar_unlocked.c",
1277 "musl/src/stdio/getdelim.c",
1278 "musl/src/stdio/getline.c",
1279 "musl/src/stdio/gets.c",
1280 "musl/src/stdio/getw.c",
1281 "musl/src/stdio/getwc.c",
1282 "musl/src/stdio/getwchar.c",
1283 "musl/src/stdio/ofl.c",
1284 "musl/src/stdio/ofl_add.c",
1285 "musl/src/stdio/open_memstream.c",
1286 "musl/src/stdio/open_wmemstream.c",
1287 "musl/src/stdio/pclose.c",
1288 "musl/src/stdio/perror.c",
1289 "musl/src/stdio/popen.c",
1290 "musl/src/stdio/printf.c",
1291 "musl/src/stdio/putc.c",
1292 "musl/src/stdio/putc_unlocked.c",
1293 "musl/src/stdio/putchar.c",
1294 "musl/src/stdio/putchar_unlocked.c",
1295 "musl/src/stdio/puts.c",
1296 "musl/src/stdio/putw.c",
1297 "musl/src/stdio/putwc.c",
1298 "musl/src/stdio/putwchar.c",
1299 "musl/src/stdio/remove.c",
1300 "musl/src/stdio/rename.c",
1301 "musl/src/stdio/rewind.c",
1302 "musl/src/stdio/scanf.c",
1303 "musl/src/stdio/setbuf.c",
1304 "musl/src/stdio/setbuffer.c",
1305 "musl/src/stdio/setlinebuf.c",
1306 "musl/src/stdio/setvbuf.c",
1307 "musl/src/stdio/snprintf.c",
1308 "musl/src/stdio/sprintf.c",
1309 "musl/src/stdio/sscanf.c",
1310 "musl/src/stdio/stderr.c",
1311 "musl/src/stdio/stdin.c",
1312 "musl/src/stdio/stdout.c",
1313 "musl/src/stdio/swprintf.c",
1314 "musl/src/stdio/swscanf.c",
1315 "musl/src/stdio/tempnam.c",
1316 "musl/src/stdio/tmpfile.c",
1317 "musl/src/stdio/tmpnam.c",
1318 "musl/src/stdio/ungetc.c",
1319 "musl/src/stdio/ungetwc.c",
1320 "musl/src/stdio/vasprintf.c",
1321 "musl/src/stdio/vdprintf.c",
1322 "musl/src/stdio/vfprintf.c",
1323 "musl/src/stdio/vfscanf.c",
1324 "musl/src/stdio/vfwprintf.c",
1325 "musl/src/stdio/vfwscanf.c",
1326 "musl/src/stdio/vprintf.c",
1327 "musl/src/stdio/vscanf.c",
1328 "musl/src/stdio/vsnprintf.c",
1329 "musl/src/stdio/vsprintf.c",
1330 "musl/src/stdio/vsscanf.c",
1331 "musl/src/stdio/vswprintf.c",
1332 "musl/src/stdio/vswscanf.c",
1333 "musl/src/stdio/vwprintf.c",
1334 "musl/src/stdio/vwscanf.c",
1335 "musl/src/stdio/wprintf.c",
1336 "musl/src/stdio/wscanf.c",
1337 "musl/src/stdlib/abs.c",
1338 "musl/src/stdlib/atof.c",
1339 "musl/src/stdlib/atoi.c",
1340 "musl/src/stdlib/atol.c",
1341 "musl/src/stdlib/atoll.c",
1342 "musl/src/stdlib/bsearch.c",
1343 "musl/src/stdlib/div.c",
1344 "musl/src/stdlib/ecvt.c",
1345 "musl/src/stdlib/fcvt.c",
1346 "musl/src/stdlib/gcvt.c",
1347 "musl/src/stdlib/imaxabs.c",
1348 "musl/src/stdlib/imaxdiv.c",
1349 "musl/src/stdlib/labs.c",
1350 "musl/src/stdlib/ldiv.c",
1351 "musl/src/stdlib/llabs.c",
1352 "musl/src/stdlib/lldiv.c",
1353 "musl/src/stdlib/qsort.c",
1354 "musl/src/stdlib/strtod.c",
1355 "musl/src/stdlib/strtol.c",
1356 "musl/src/stdlib/wcstod.c",
1357 "musl/src/stdlib/wcstol.c",
1358 "musl/src/string/arm/__aeabi_memcpy.s",
1359 "musl/src/string/arm/__aeabi_memset.s",
1360 "musl/src/string/arm/memcpy.c",
1361 "musl/src/string/arm/memcpy_le.S",
1362 "musl/src/string/bcmp.c",
1363 "musl/src/string/bcopy.c",
1364 "musl/src/string/bzero.c",
1365 "musl/src/string/explicit_bzero.c",
1366 "musl/src/string/i386/memcpy.s",
1367 "musl/src/string/i386/memmove.s",
1368 "musl/src/string/i386/memset.s",
1369 "musl/src/string/index.c",
1370 "musl/src/string/memccpy.c",
1371 "musl/src/string/memchr.c",
1372 "musl/src/string/memcmp.c",
1373 "musl/src/string/memcpy.c",
1374 "musl/src/string/memmem.c",
1375 "musl/src/string/memmove.c",
1376 "musl/src/string/mempcpy.c",
1377 "musl/src/string/memrchr.c",
1378 "musl/src/string/memset.c",
1379 "musl/src/string/rindex.c",
1380 "musl/src/string/stpcpy.c",
1381 "musl/src/string/stpncpy.c",
1382 "musl/src/string/strcasecmp.c",
1383 "musl/src/string/strcasestr.c",
1384 "musl/src/string/strcat.c",
1385 "musl/src/string/strchr.c",
1386 "musl/src/string/strchrnul.c",
1387 "musl/src/string/strcmp.c",
1388 "musl/src/string/strcpy.c",
1389 "musl/src/string/strcspn.c",
1390 "musl/src/string/strdup.c",
1391 "musl/src/string/strerror_r.c",
1392 "musl/src/string/strlcat.c",
1393 "musl/src/string/strlcpy.c",
1394 "musl/src/string/strlen.c",
1395 "musl/src/string/strncasecmp.c",
1396 "musl/src/string/strncat.c",
1397 "musl/src/string/strncmp.c",
1398 "musl/src/string/strncpy.c",
1399 "musl/src/string/strndup.c",
1400 "musl/src/string/strnlen.c",
1401 "musl/src/string/strpbrk.c",
1402 "musl/src/string/strrchr.c",
1403 "musl/src/string/strsep.c",
1404 "musl/src/string/strsignal.c",
1405 "musl/src/string/strspn.c",
1406 "musl/src/string/strstr.c",
1407 "musl/src/string/strtok.c",
1408 "musl/src/string/strtok_r.c",
1409 "musl/src/string/strverscmp.c",
1410 "musl/src/string/swab.c",
1411 "musl/src/string/wcpcpy.c",
1412 "musl/src/string/wcpncpy.c",
1413 "musl/src/string/wcscasecmp.c",
1414 "musl/src/string/wcscasecmp_l.c",
1415 "musl/src/string/wcscat.c",
1416 "musl/src/string/wcschr.c",
1417 "musl/src/string/wcscmp.c",
1418 "musl/src/string/wcscpy.c",
1419 "musl/src/string/wcscspn.c",
1420 "musl/src/string/wcsdup.c",
1421 "musl/src/string/wcslen.c",
1422 "musl/src/string/wcsncasecmp.c",
1423 "musl/src/string/wcsncasecmp_l.c",
1424 "musl/src/string/wcsncat.c",
1425 "musl/src/string/wcsncmp.c",
1426 "musl/src/string/wcsncpy.c",
1427 "musl/src/string/wcsnlen.c",
1428 "musl/src/string/wcspbrk.c",
1429 "musl/src/string/wcsrchr.c",
1430 "musl/src/string/wcsspn.c",
1431 "musl/src/string/wcsstr.c",
1432 "musl/src/string/wcstok.c",
1433 "musl/src/string/wcswcs.c",
1434 "musl/src/string/wmemchr.c",
1435 "musl/src/string/wmemcmp.c",
1436 "musl/src/string/wmemcpy.c",
1437 "musl/src/string/wmemmove.c",
1438 "musl/src/string/wmemset.c",
1439 "musl/src/string/x86_64/memcpy.s",
1440 "musl/src/string/x86_64/memmove.s",
1441 "musl/src/string/x86_64/memset.s",
1442 "musl/src/temp/__randname.c",
1443 "musl/src/temp/mkdtemp.c",
1444 "musl/src/temp/mkostemp.c",
1445 "musl/src/temp/mkostemps.c",
1446 "musl/src/temp/mkstemp.c",
1447 "musl/src/temp/mkstemps.c",
1448 "musl/src/temp/mktemp.c",
1449 "musl/src/termios/cfgetospeed.c",
1450 "musl/src/termios/cfmakeraw.c",
1451 "musl/src/termios/cfsetospeed.c",
1452 "musl/src/termios/tcdrain.c",
1453 "musl/src/termios/tcflow.c",
1454 "musl/src/termios/tcflush.c",
1455 "musl/src/termios/tcgetattr.c",
1456 "musl/src/termios/tcgetsid.c",
1457 "musl/src/termios/tcsendbreak.c",
1458 "musl/src/termios/tcsetattr.c",
1459 "musl/src/thread/__lock.c",
1460 "musl/src/thread/__set_thread_area.c",
1461 "musl/src/thread/__syscall_cp.c",
1462 "musl/src/thread/__timedwait.c",
1463 "musl/src/thread/__tls_get_addr.c",
1464 "musl/src/thread/__unmapself.c",
1465 "musl/src/thread/__wait.c",
1466 "musl/src/thread/aarch64/__set_thread_area.s",
1467 "musl/src/thread/aarch64/__unmapself.s",
1468 "musl/src/thread/aarch64/clone.s",
1469 "musl/src/thread/aarch64/syscall_cp.s",
1470 "musl/src/thread/arm/__aeabi_read_tp.s",
1471 "musl/src/thread/arm/__set_thread_area.c",
1472 "musl/src/thread/arm/__unmapself.s",
1473 "musl/src/thread/arm/atomics.s",
1474 "musl/src/thread/arm/clone.s",
1475 "musl/src/thread/arm/syscall_cp.s",
1476 "musl/src/thread/call_once.c",
1477 "musl/src/thread/clone.c",
1478 "musl/src/thread/cnd_broadcast.c",
1479 "musl/src/thread/cnd_destroy.c",
1480 "musl/src/thread/cnd_init.c",
1481 "musl/src/thread/cnd_signal.c",
1482 "musl/src/thread/cnd_timedwait.c",
1483 "musl/src/thread/cnd_wait.c",
1484 "musl/src/thread/default_attr.c",
1485 "musl/src/thread/i386/__set_thread_area.s",
1486 "musl/src/thread/i386/__unmapself.s",
1487 "musl/src/thread/i386/clone.s",
1488 "musl/src/thread/i386/syscall_cp.s",
1489 "musl/src/thread/i386/tls.s",
1490 "musl/src/thread/lock_ptc.c",
1491 "musl/src/thread/m68k/__m68k_read_tp.s",
1492 "musl/src/thread/m68k/clone.s",
1493 "musl/src/thread/m68k/syscall_cp.s",
1494 "musl/src/thread/microblaze/__set_thread_area.s",
1495 "musl/src/thread/microblaze/__unmapself.s",
1496 "musl/src/thread/microblaze/clone.s",
1497 "musl/src/thread/microblaze/syscall_cp.s",
1498 "musl/src/thread/mips/__unmapself.s",
1499 "musl/src/thread/mips/clone.s",
1500 "musl/src/thread/mips/syscall_cp.s",
1501 "musl/src/thread/mips64/__unmapself.s",
1502 "musl/src/thread/mips64/clone.s",
1503 "musl/src/thread/mips64/syscall_cp.s",
1504 "musl/src/thread/mipsn32/__unmapself.s",
1505 "musl/src/thread/mipsn32/clone.s",
1506 "musl/src/thread/mipsn32/syscall_cp.s",
1507 "musl/src/thread/mtx_destroy.c",
1508 "musl/src/thread/mtx_init.c",
1509 "musl/src/thread/mtx_lock.c",
1510 "musl/src/thread/mtx_timedlock.c",
1511 "musl/src/thread/mtx_trylock.c",
1512 "musl/src/thread/mtx_unlock.c",
1513 "musl/src/thread/or1k/__set_thread_area.s",
1514 "musl/src/thread/or1k/__unmapself.s",
1515 "musl/src/thread/or1k/clone.s",
1516 "musl/src/thread/or1k/syscall_cp.s",
1517 "musl/src/thread/powerpc/__set_thread_area.s",
1518 "musl/src/thread/powerpc/__unmapself.s",
1519 "musl/src/thread/powerpc/clone.s",
1520 "musl/src/thread/powerpc/syscall_cp.s",
1521 "musl/src/thread/powerpc64/__set_thread_area.s",
1522 "musl/src/thread/powerpc64/__unmapself.s",
1523 "musl/src/thread/powerpc64/clone.s",
1524 "musl/src/thread/powerpc64/syscall_cp.s",
1525 "musl/src/thread/pthread_atfork.c",
1526 "musl/src/thread/pthread_attr_destroy.c",
1527 "musl/src/thread/pthread_attr_get.c",
1528 "musl/src/thread/pthread_attr_init.c",
1529 "musl/src/thread/pthread_attr_setdetachstate.c",
1530 "musl/src/thread/pthread_attr_setguardsize.c",
1531 "musl/src/thread/pthread_attr_setinheritsched.c",
1532 "musl/src/thread/pthread_attr_setschedparam.c",
1533 "musl/src/thread/pthread_attr_setschedpolicy.c",
1534 "musl/src/thread/pthread_attr_setscope.c",
1535 "musl/src/thread/pthread_attr_setstack.c",
1536 "musl/src/thread/pthread_attr_setstacksize.c",
1537 "musl/src/thread/pthread_barrier_destroy.c",
1538 "musl/src/thread/pthread_barrier_init.c",
1539 "musl/src/thread/pthread_barrier_wait.c",
1540 "musl/src/thread/pthread_barrierattr_destroy.c",
1541 "musl/src/thread/pthread_barrierattr_init.c",
1542 "musl/src/thread/pthread_barrierattr_setpshared.c",
1543 "musl/src/thread/pthread_cancel.c",
1544 "musl/src/thread/pthread_cleanup_push.c",
1545 "musl/src/thread/pthread_cond_broadcast.c",
1546 "musl/src/thread/pthread_cond_destroy.c",
1547 "musl/src/thread/pthread_cond_init.c",
1548 "musl/src/thread/pthread_cond_signal.c",
1549 "musl/src/thread/pthread_cond_timedwait.c",
1550 "musl/src/thread/pthread_cond_wait.c",
1551 "musl/src/thread/pthread_condattr_destroy.c",
1552 "musl/src/thread/pthread_condattr_init.c",
1553 "musl/src/thread/pthread_condattr_setclock.c",
1554 "musl/src/thread/pthread_condattr_setpshared.c",
1555 "musl/src/thread/pthread_create.c",
1556 "musl/src/thread/pthread_detach.c",
1557 "musl/src/thread/pthread_equal.c",
1558 "musl/src/thread/pthread_getattr_np.c",
1559 "musl/src/thread/pthread_getconcurrency.c",
1560 "musl/src/thread/pthread_getcpuclockid.c",
1561 "musl/src/thread/pthread_getschedparam.c",
1562 "musl/src/thread/pthread_getspecific.c",
1563 "musl/src/thread/pthread_join.c",
1564 "musl/src/thread/pthread_key_create.c",
1565 "musl/src/thread/pthread_kill.c",
1566 "musl/src/thread/pthread_mutex_consistent.c",
1567 "musl/src/thread/pthread_mutex_destroy.c",
1568 "musl/src/thread/pthread_mutex_getprioceiling.c",
1569 "musl/src/thread/pthread_mutex_init.c",
1570 "musl/src/thread/pthread_mutex_lock.c",
1571 "musl/src/thread/pthread_mutex_setprioceiling.c",
1572 "musl/src/thread/pthread_mutex_timedlock.c",
1573 "musl/src/thread/pthread_mutex_trylock.c",
1574 "musl/src/thread/pthread_mutex_unlock.c",
1575 "musl/src/thread/pthread_mutexattr_destroy.c",
1576 "musl/src/thread/pthread_mutexattr_init.c",
1577 "musl/src/thread/pthread_mutexattr_setprotocol.c",
1578 "musl/src/thread/pthread_mutexattr_setpshared.c",
1579 "musl/src/thread/pthread_mutexattr_setrobust.c",
1580 "musl/src/thread/pthread_mutexattr_settype.c",
1581 "musl/src/thread/pthread_once.c",
1582 "musl/src/thread/pthread_rwlock_destroy.c",
1583 "musl/src/thread/pthread_rwlock_init.c",
1584 "musl/src/thread/pthread_rwlock_rdlock.c",
1585 "musl/src/thread/pthread_rwlock_timedrdlock.c",
1586 "musl/src/thread/pthread_rwlock_timedwrlock.c",
1587 "musl/src/thread/pthread_rwlock_tryrdlock.c",
1588 "musl/src/thread/pthread_rwlock_trywrlock.c",
1589 "musl/src/thread/pthread_rwlock_unlock.c",
1590 "musl/src/thread/pthread_rwlock_wrlock.c",
1591 "musl/src/thread/pthread_rwlockattr_destroy.c",
1592 "musl/src/thread/pthread_rwlockattr_init.c",
1593 "musl/src/thread/pthread_rwlockattr_setpshared.c",
1594 "musl/src/thread/pthread_self.c",
1595 "musl/src/thread/pthread_setattr_default_np.c",
1596 "musl/src/thread/pthread_setcancelstate.c",
1597 "musl/src/thread/pthread_setcanceltype.c",
1598 "musl/src/thread/pthread_setconcurrency.c",
1599 "musl/src/thread/pthread_setname_np.c",
1600 "musl/src/thread/pthread_setschedparam.c",
1601 "musl/src/thread/pthread_setschedprio.c",
1602 "musl/src/thread/pthread_setspecific.c",
1603 "musl/src/thread/pthread_sigmask.c",
1604 "musl/src/thread/pthread_spin_destroy.c",
1605 "musl/src/thread/pthread_spin_init.c",
1606 "musl/src/thread/pthread_spin_lock.c",
1607 "musl/src/thread/pthread_spin_trylock.c",
1608 "musl/src/thread/pthread_spin_unlock.c",
1609 "musl/src/thread/pthread_testcancel.c",
1610 "musl/src/thread/riscv64/__set_thread_area.s",
1611 "musl/src/thread/riscv64/__unmapself.s",
1612 "musl/src/thread/riscv64/clone.s",
1613 "musl/src/thread/riscv64/syscall_cp.s",
1614 "musl/src/thread/s390x/__set_thread_area.s",
1615 "musl/src/thread/s390x/__tls_get_offset.s",
1616 "musl/src/thread/s390x/__unmapself.s",
1617 "musl/src/thread/s390x/clone.s",
1618 "musl/src/thread/s390x/syscall_cp.s",
1619 "musl/src/thread/sem_destroy.c",
1620 "musl/src/thread/sem_getvalue.c",
1621 "musl/src/thread/sem_init.c",
1622 "musl/src/thread/sem_open.c",
1623 "musl/src/thread/sem_post.c",
1624 "musl/src/thread/sem_timedwait.c",
1625 "musl/src/thread/sem_trywait.c",
1626 "musl/src/thread/sem_unlink.c",
1627 "musl/src/thread/sem_wait.c",
1628 "musl/src/thread/sh/__set_thread_area.c",
1629 "musl/src/thread/sh/__unmapself.c",
1630 "musl/src/thread/sh/__unmapself_mmu.s",
1631 "musl/src/thread/sh/atomics.s",
1632 "musl/src/thread/sh/clone.s",
1633 "musl/src/thread/sh/syscall_cp.s",
1634 "musl/src/thread/synccall.c",
1635 "musl/src/thread/syscall_cp.c",
1636 "musl/src/thread/thrd_create.c",
1637 "musl/src/thread/thrd_exit.c",
1638 "musl/src/thread/thrd_join.c",
1639 "musl/src/thread/thrd_sleep.c",
1640 "musl/src/thread/thrd_yield.c",
1641 "musl/src/thread/tls.c",
1642 "musl/src/thread/tss_create.c",
1643 "musl/src/thread/tss_delete.c",
1644 "musl/src/thread/tss_set.c",
1645 "musl/src/thread/vmlock.c",
1646 "musl/src/thread/x32/__set_thread_area.s",
1647 "musl/src/thread/x32/__unmapself.s",
1648 "musl/src/thread/x32/clone.s",
1649 "musl/src/thread/x32/syscall_cp.s",
1650 "musl/src/thread/x86_64/__set_thread_area.s",
1651 "musl/src/thread/x86_64/__unmapself.s",
1652 "musl/src/thread/x86_64/clone.s",
1653 "musl/src/thread/x86_64/syscall_cp.s",
1654 "musl/src/time/__map_file.c",
1655 "musl/src/time/__month_to_secs.c",
1656 "musl/src/time/__secs_to_tm.c",
1657 "musl/src/time/__tm_to_secs.c",
1658 "musl/src/time/__tz.c",
1659 "musl/src/time/__year_to_secs.c",
1660 "musl/src/time/asctime.c",
1661 "musl/src/time/asctime_r.c",
1662 "musl/src/time/clock.c",
1663 "musl/src/time/clock_getcpuclockid.c",
1664 "musl/src/time/clock_getres.c",
1665 "musl/src/time/clock_gettime.c",
1666 "musl/src/time/clock_nanosleep.c",
1667 "musl/src/time/clock_settime.c",
1668 "musl/src/time/ctime.c",
1669 "musl/src/time/ctime_r.c",
1670 "musl/src/time/difftime.c",
1671 "musl/src/time/ftime.c",
1672 "musl/src/time/getdate.c",
1673 "musl/src/time/gettimeofday.c",
1674 "musl/src/time/gmtime.c",
1675 "musl/src/time/gmtime_r.c",
1676 "musl/src/time/localtime.c",
1677 "musl/src/time/localtime_r.c",
1678 "musl/src/time/mktime.c",
1679 "musl/src/time/nanosleep.c",
1680 "musl/src/time/strftime.c",
1681 "musl/src/time/strptime.c",
1682 "musl/src/time/time.c",
1683 "musl/src/time/timegm.c",
1684 "musl/src/time/timer_create.c",
1685 "musl/src/time/timer_delete.c",
1686 "musl/src/time/timer_getoverrun.c",
1687 "musl/src/time/timer_gettime.c",
1688 "musl/src/time/timer_settime.c",
1689 "musl/src/time/times.c",
1690 "musl/src/time/timespec_get.c",
1691 "musl/src/time/utime.c",
1692 "musl/src/time/wcsftime.c",
1693 "musl/src/unistd/_exit.c",
1694 "musl/src/unistd/access.c",
1695 "musl/src/unistd/acct.c",
1696 "musl/src/unistd/alarm.c",
1697 "musl/src/unistd/chdir.c",
1698 "musl/src/unistd/chown.c",
1699 "musl/src/unistd/close.c",
1700 "musl/src/unistd/ctermid.c",
1701 "musl/src/unistd/dup.c",
1702 "musl/src/unistd/dup2.c",
1703 "musl/src/unistd/dup3.c",
1704 "musl/src/unistd/faccessat.c",
1705 "musl/src/unistd/fchdir.c",
1706 "musl/src/unistd/fchown.c",
1707 "musl/src/unistd/fchownat.c",
1708 "musl/src/unistd/fdatasync.c",
1709 "musl/src/unistd/fsync.c",
1710 "musl/src/unistd/ftruncate.c",
1711 "musl/src/unistd/getcwd.c",
1712 "musl/src/unistd/getegid.c",
1713 "musl/src/unistd/geteuid.c",
1714 "musl/src/unistd/getgid.c",
1715 "musl/src/unistd/getgroups.c",
1716 "musl/src/unistd/gethostname.c",
1717 "musl/src/unistd/getlogin.c",
1718 "musl/src/unistd/getlogin_r.c",
1719 "musl/src/unistd/getpgid.c",
1720 "musl/src/unistd/getpgrp.c",
1721 "musl/src/unistd/getpid.c",
1722 "musl/src/unistd/getppid.c",
1723 "musl/src/unistd/getsid.c",
1724 "musl/src/unistd/getuid.c",
1725 "musl/src/unistd/isatty.c",
1726 "musl/src/unistd/lchown.c",
1727 "musl/src/unistd/link.c",
1728 "musl/src/unistd/linkat.c",
1729 "musl/src/unistd/lseek.c",
1730 "musl/src/unistd/mips/pipe.s",
1731 "musl/src/unistd/mips64/pipe.s",
1732 "musl/src/unistd/mipsn32/lseek.c",
1733 "musl/src/unistd/mipsn32/pipe.s",
1734 "musl/src/unistd/nice.c",
1735 "musl/src/unistd/pause.c",
1736 "musl/src/unistd/pipe.c",
1737 "musl/src/unistd/pipe2.c",
1738 "musl/src/unistd/posix_close.c",
1739 "musl/src/unistd/pread.c",
1740 "musl/src/unistd/preadv.c",
1741 "musl/src/unistd/pwrite.c",
1742 "musl/src/unistd/pwritev.c",
1743 "musl/src/unistd/read.c",
1744 "musl/src/unistd/readlink.c",
1745 "musl/src/unistd/readlinkat.c",
1746 "musl/src/unistd/readv.c",
1747 "musl/src/unistd/renameat.c",
1748 "musl/src/unistd/rmdir.c",
1749 "musl/src/unistd/setegid.c",
1750 "musl/src/unistd/seteuid.c",
1751 "musl/src/unistd/setgid.c",
1752 "musl/src/unistd/setpgid.c",
1753 "musl/src/unistd/setpgrp.c",
1754 "musl/src/unistd/setregid.c",
1755 "musl/src/unistd/setresgid.c",
1756 "musl/src/unistd/setresuid.c",
1757 "musl/src/unistd/setreuid.c",
1758 "musl/src/unistd/setsid.c",
1759 "musl/src/unistd/setuid.c",
1760 "musl/src/unistd/setxid.c",
1761 "musl/src/unistd/sh/pipe.s",
1762 "musl/src/unistd/sleep.c",
1763 "musl/src/unistd/symlink.c",
1764 "musl/src/unistd/symlinkat.c",
1765 "musl/src/unistd/sync.c",
1766 "musl/src/unistd/tcgetpgrp.c",
1767 "musl/src/unistd/tcsetpgrp.c",
1768 "musl/src/unistd/truncate.c",
1769 "musl/src/unistd/ttyname.c",
1770 "musl/src/unistd/ttyname_r.c",
1771 "musl/src/unistd/ualarm.c",
1772 "musl/src/unistd/unlink.c",
1773 "musl/src/unistd/unlinkat.c",
1774 "musl/src/unistd/usleep.c",
1775 "musl/src/unistd/write.c",
1776 "musl/src/unistd/writev.c",
1777 "musl/src/unistd/x32/lseek.c",
1778};
1779pub const compat_time32_files = [_][]const u8{
1780 "musl/compat/time32/__xstat.c",
1781 "musl/compat/time32/adjtime32.c",
1782 "musl/compat/time32/adjtimex_time32.c",
1783 "musl/compat/time32/aio_suspend_time32.c",
1784 "musl/compat/time32/clock_adjtime32.c",
1785 "musl/compat/time32/clock_getres_time32.c",
1786 "musl/compat/time32/clock_gettime32.c",
1787 "musl/compat/time32/clock_nanosleep_time32.c",
1788 "musl/compat/time32/clock_settime32.c",
1789 "musl/compat/time32/cnd_timedwait_time32.c",
1790 "musl/compat/time32/ctime32.c",
1791 "musl/compat/time32/ctime32_r.c",
1792 "musl/compat/time32/difftime32.c",
1793 "musl/compat/time32/fstat_time32.c",
1794 "musl/compat/time32/fstatat_time32.c",
1795 "musl/compat/time32/ftime32.c",
1796 "musl/compat/time32/futimens_time32.c",
1797 "musl/compat/time32/futimes_time32.c",
1798 "musl/compat/time32/futimesat_time32.c",
1799 "musl/compat/time32/getitimer_time32.c",
1800 "musl/compat/time32/getrusage_time32.c",
1801 "musl/compat/time32/gettimeofday_time32.c",
1802 "musl/compat/time32/gmtime32.c",
1803 "musl/compat/time32/gmtime32_r.c",
1804 "musl/compat/time32/localtime32.c",
1805 "musl/compat/time32/localtime32_r.c",
1806 "musl/compat/time32/lstat_time32.c",
1807 "musl/compat/time32/lutimes_time32.c",
1808 "musl/compat/time32/mktime32.c",
1809 "musl/compat/time32/mq_timedreceive_time32.c",
1810 "musl/compat/time32/mq_timedsend_time32.c",
1811 "musl/compat/time32/mtx_timedlock_time32.c",
1812 "musl/compat/time32/nanosleep_time32.c",
1813 "musl/compat/time32/ppoll_time32.c",
1814 "musl/compat/time32/pselect_time32.c",
1815 "musl/compat/time32/pthread_cond_timedwait_time32.c",
1816 "musl/compat/time32/pthread_mutex_timedlock_time32.c",
1817 "musl/compat/time32/pthread_rwlock_timedrdlock_time32.c",
1818 "musl/compat/time32/pthread_rwlock_timedwrlock_time32.c",
1819 "musl/compat/time32/pthread_timedjoin_np_time32.c",
1820 "musl/compat/time32/recvmmsg_time32.c",
1821 "musl/compat/time32/sched_rr_get_interval_time32.c",
1822 "musl/compat/time32/select_time32.c",
1823 "musl/compat/time32/sem_timedwait_time32.c",
1824 "musl/compat/time32/semtimedop_time32.c",
1825 "musl/compat/time32/setitimer_time32.c",
1826 "musl/compat/time32/settimeofday_time32.c",
1827 "musl/compat/time32/sigtimedwait_time32.c",
1828 "musl/compat/time32/stat_time32.c",
1829 "musl/compat/time32/stime32.c",
1830 "musl/compat/time32/thrd_sleep_time32.c",
1831 "musl/compat/time32/time32.c",
1832 "musl/compat/time32/time32gm.c",
1833 "musl/compat/time32/timer_gettime32.c",
1834 "musl/compat/time32/timer_settime32.c",
1835 "musl/compat/time32/timerfd_gettime32.c",
1836 "musl/compat/time32/timerfd_settime32.c",
1837 "musl/compat/time32/timespec_get_time32.c",
1838 "musl/compat/time32/utime_time32.c",
1839 "musl/compat/time32/utimensat_time32.c",
1840 "musl/compat/time32/utimes_time32.c",
1841 "musl/compat/time32/wait3_time32.c",
1842 "musl/compat/time32/wait4_time32.c",
1843};
src-self-hosted/stage1.zig created+495
...@@ -0,0 +1,495 @@
1//! This is the main entry point for the Zig/C++ hybrid compiler (stage1).
2//! It has the functions exported from Zig, called in C++, and bindings for
3//! the functions exported from C++, called from Zig.
4
5const std = @import("std");
6const assert = std.debug.assert;
7const mem = std.mem;
8const build_options = @import("build_options");
9const stage2 = @import("main.zig");
10const fatal = stage2.fatal;
11const CrossTarget = std.zig.CrossTarget;
12const Target = std.Target;
13
14comptime {
15 assert(std.builtin.link_libc);
16 assert(build_options.is_stage1);
17 _ = @import("compiler_rt");
18}
19
20pub const log = stage2.log;
21pub const log_level = stage2.log_level;
22
23pub export fn main(argc: c_int, argv: [*]const [*:0]const u8) c_int {
24 std.debug.maybeEnableSegfaultHandler();
25
26 const gpa = std.heap.c_allocator;
27 var arena_instance = std.heap.ArenaAllocator.init(gpa);
28 defer arena_instance.deinit();
29 const arena = &arena_instance.allocator;
30
31 const args = arena.alloc([]const u8, @intCast(usize, argc)) catch fatal("out of memory", .{});
32 for (args) |*arg, i| {
33 arg.* = mem.spanZ(argv[i]);
34 }
35 stage2.mainArgs(gpa, arena, args) catch |err| fatal("{}", .{err});
36 return 0;
37}
38
39// ABI warning
40export fn stage2_panic(ptr: [*]const u8, len: usize) void {
41 @panic(ptr[0..len]);
42}
43
44// ABI warning
45const Error = extern enum {
46 None,
47 OutOfMemory,
48 InvalidFormat,
49 SemanticAnalyzeFail,
50 AccessDenied,
51 Interrupted,
52 SystemResources,
53 FileNotFound,
54 FileSystem,
55 FileTooBig,
56 DivByZero,
57 Overflow,
58 PathAlreadyExists,
59 Unexpected,
60 ExactDivRemainder,
61 NegativeDenominator,
62 ShiftedOutOneBits,
63 CCompileErrors,
64 EndOfFile,
65 IsDir,
66 NotDir,
67 UnsupportedOperatingSystem,
68 SharingViolation,
69 PipeBusy,
70 PrimitiveTypeNotFound,
71 CacheUnavailable,
72 PathTooLong,
73 CCompilerCannotFindFile,
74 NoCCompilerInstalled,
75 ReadingDepFile,
76 InvalidDepFile,
77 MissingArchitecture,
78 MissingOperatingSystem,
79 UnknownArchitecture,
80 UnknownOperatingSystem,
81 UnknownABI,
82 InvalidFilename,
83 DiskQuota,
84 DiskSpace,
85 UnexpectedWriteFailure,
86 UnexpectedSeekFailure,
87 UnexpectedFileTruncationFailure,
88 Unimplemented,
89 OperationAborted,
90 BrokenPipe,
91 NoSpaceLeft,
92 NotLazy,
93 IsAsync,
94 ImportOutsidePkgPath,
95 UnknownCpuModel,
96 UnknownCpuFeature,
97 InvalidCpuFeatures,
98 InvalidLlvmCpuFeaturesFormat,
99 UnknownApplicationBinaryInterface,
100 ASTUnitFailure,
101 BadPathName,
102 SymLinkLoop,
103 ProcessFdQuotaExceeded,
104 SystemFdQuotaExceeded,
105 NoDevice,
106 DeviceBusy,
107 UnableToSpawnCCompiler,
108 CCompilerExitCode,
109 CCompilerCrashed,
110 CCompilerCannotFindHeaders,
111 LibCRuntimeNotFound,
112 LibCStdLibHeaderNotFound,
113 LibCKernel32LibNotFound,
114 UnsupportedArchitecture,
115 WindowsSdkNotFound,
116 UnknownDynamicLinkerPath,
117 TargetHasNoDynamicLinker,
118 InvalidAbiVersion,
119 InvalidOperatingSystemVersion,
120 UnknownClangOption,
121 NestedResponseFile,
122 ZigIsTheCCompiler,
123 FileBusy,
124 Locked,
125};
126
127// ABI warning
128export fn stage2_attach_segfault_handler() void {
129 if (std.debug.runtime_safety and std.debug.have_segfault_handling_support) {
130 std.debug.attachSegfaultHandler();
131 }
132}
133
134// ABI warning
135export fn stage2_progress_create() *std.Progress {
136 const ptr = std.heap.c_allocator.create(std.Progress) catch @panic("out of memory");
137 ptr.* = std.Progress{};
138 return ptr;
139}
140
141// ABI warning
142export fn stage2_progress_destroy(progress: *std.Progress) void {
143 std.heap.c_allocator.destroy(progress);
144}
145
146// ABI warning
147export fn stage2_progress_start_root(
148 progress: *std.Progress,
149 name_ptr: [*]const u8,
150 name_len: usize,
151 estimated_total_items: usize,
152) *std.Progress.Node {
153 return progress.start(
154 name_ptr[0..name_len],
155 if (estimated_total_items == 0) null else estimated_total_items,
156 ) catch @panic("timer unsupported");
157}
158
159// ABI warning
160export fn stage2_progress_disable_tty(progress: *std.Progress) void {
161 progress.terminal = null;
162}
163
164// ABI warning
165export fn stage2_progress_start(
166 node: *std.Progress.Node,
167 name_ptr: [*]const u8,
168 name_len: usize,
169 estimated_total_items: usize,
170) *std.Progress.Node {
171 const child_node = std.heap.c_allocator.create(std.Progress.Node) catch @panic("out of memory");
172 child_node.* = node.start(
173 name_ptr[0..name_len],
174 if (estimated_total_items == 0) null else estimated_total_items,
175 );
176 child_node.activate();
177 return child_node;
178}
179
180// ABI warning
181export fn stage2_progress_end(node: *std.Progress.Node) void {
182 node.end();
183 if (&node.context.root != node) {
184 std.heap.c_allocator.destroy(node);
185 }
186}
187
188// ABI warning
189export fn stage2_progress_complete_one(node: *std.Progress.Node) void {
190 node.completeOne();
191}
192
193// ABI warning
194export fn stage2_progress_update_node(node: *std.Progress.Node, done_count: usize, total_count: usize) void {
195 node.completed_items = done_count;
196 node.estimated_total_items = total_count;
197 node.activate();
198 node.context.maybeRefresh();
199}
200
201// ABI warning
202const Stage2Target = extern struct {
203 arch: c_int,
204 vendor: c_int,
205
206 abi: c_int,
207 os: c_int,
208
209 is_native_os: bool,
210 is_native_cpu: bool,
211
212 llvm_cpu_name: ?[*:0]const u8,
213 llvm_cpu_features: ?[*:0]const u8,
214 cpu_builtin_str: ?[*:0]const u8,
215 os_builtin_str: ?[*:0]const u8,
216
217 dynamic_linker: ?[*:0]const u8,
218
219 llvm_cpu_features_asm_ptr: [*]const [*:0]const u8,
220 llvm_cpu_features_asm_len: usize,
221
222 fn fromTarget(self: *Stage2Target, cross_target: CrossTarget) !void {
223 const allocator = std.heap.c_allocator;
224
225 var dynamic_linker: ?[*:0]u8 = null;
226 const target = try crossTargetToTarget(cross_target, &dynamic_linker);
227
228 const generic_arch_name = target.cpu.arch.genericName();
229 var cpu_builtin_str_buffer = try std.ArrayListSentineled(u8, 0).allocPrint(allocator,
230 \\Cpu{{
231 \\ .arch = .{},
232 \\ .model = &Target.{}.cpu.{},
233 \\ .features = Target.{}.featureSet(&[_]Target.{}.Feature{{
234 \\
235 , .{
236 @tagName(target.cpu.arch),
237 generic_arch_name,
238 target.cpu.model.name,
239 generic_arch_name,
240 generic_arch_name,
241 });
242 defer cpu_builtin_str_buffer.deinit();
243
244 var llvm_features_buffer = try std.ArrayListSentineled(u8, 0).initSize(allocator, 0);
245 defer llvm_features_buffer.deinit();
246
247 // Unfortunately we have to do the work twice, because Clang does not support
248 // the same command line parameters for CPU features when assembling code as it does
249 // when compiling C code.
250 var asm_features_list = std.ArrayList([*:0]const u8).init(allocator);
251 defer asm_features_list.deinit();
252
253 for (target.cpu.arch.allFeaturesList()) |feature, index_usize| {
254 const index = @intCast(Target.Cpu.Feature.Set.Index, index_usize);
255 const is_enabled = target.cpu.features.isEnabled(index);
256
257 if (feature.llvm_name) |llvm_name| {
258 const plus_or_minus = "-+"[@boolToInt(is_enabled)];
259 try llvm_features_buffer.append(plus_or_minus);
260 try llvm_features_buffer.appendSlice(llvm_name);
261 try llvm_features_buffer.appendSlice(",");
262 }
263
264 if (is_enabled) {
265 // TODO some kind of "zig identifier escape" function rather than
266 // unconditionally using @"" syntax
267 try cpu_builtin_str_buffer.appendSlice(" .@\"");
268 try cpu_builtin_str_buffer.appendSlice(feature.name);
269 try cpu_builtin_str_buffer.appendSlice("\",\n");
270 }
271 }
272
273 switch (target.cpu.arch) {
274 .riscv32, .riscv64 => {
275 if (Target.riscv.featureSetHas(target.cpu.features, .relax)) {
276 try asm_features_list.append("-mrelax");
277 } else {
278 try asm_features_list.append("-mno-relax");
279 }
280 },
281 else => {
282 // TODO
283 // Argh, why doesn't the assembler accept the list of CPU features?!
284 // I don't see a way to do this other than hard coding everything.
285 },
286 }
287
288 try cpu_builtin_str_buffer.appendSlice(
289 \\ }),
290 \\};
291 \\
292 );
293
294 assert(mem.endsWith(u8, llvm_features_buffer.span(), ","));
295 llvm_features_buffer.shrink(llvm_features_buffer.len() - 1);
296
297 var os_builtin_str_buffer = try std.ArrayListSentineled(u8, 0).allocPrint(allocator,
298 \\Os{{
299 \\ .tag = .{},
300 \\ .version_range = .{{
301 , .{@tagName(target.os.tag)});
302 defer os_builtin_str_buffer.deinit();
303
304 // We'll re-use the OS version range builtin string for the cache hash.
305 const os_builtin_str_ver_start_index = os_builtin_str_buffer.len();
306
307 @setEvalBranchQuota(2000);
308 switch (target.os.tag) {
309 .freestanding,
310 .ananas,
311 .cloudabi,
312 .dragonfly,
313 .fuchsia,
314 .ios,
315 .kfreebsd,
316 .lv2,
317 .solaris,
318 .haiku,
319 .minix,
320 .rtems,
321 .nacl,
322 .cnk,
323 .aix,
324 .cuda,
325 .nvcl,
326 .amdhsa,
327 .ps4,
328 .elfiamcu,
329 .tvos,
330 .watchos,
331 .mesa3d,
332 .contiki,
333 .amdpal,
334 .hermit,
335 .hurd,
336 .wasi,
337 .emscripten,
338 .uefi,
339 .other,
340 => try os_builtin_str_buffer.appendSlice(" .none = {} }\n"),
341
342 .freebsd,
343 .macosx,
344 .netbsd,
345 .openbsd,
346 => try os_builtin_str_buffer.outStream().print(
347 \\ .semver = .{{
348 \\ .min = .{{
349 \\ .major = {},
350 \\ .minor = {},
351 \\ .patch = {},
352 \\ }},
353 \\ .max = .{{
354 \\ .major = {},
355 \\ .minor = {},
356 \\ .patch = {},
357 \\ }},
358 \\ }}}},
359 \\
360 , .{
361 target.os.version_range.semver.min.major,
362 target.os.version_range.semver.min.minor,
363 target.os.version_range.semver.min.patch,
364
365 target.os.version_range.semver.max.major,
366 target.os.version_range.semver.max.minor,
367 target.os.version_range.semver.max.patch,
368 }),
369
370 .linux => try os_builtin_str_buffer.outStream().print(
371 \\ .linux = .{{
372 \\ .range = .{{
373 \\ .min = .{{
374 \\ .major = {},
375 \\ .minor = {},
376 \\ .patch = {},
377 \\ }},
378 \\ .max = .{{
379 \\ .major = {},
380 \\ .minor = {},
381 \\ .patch = {},
382 \\ }},
383 \\ }},
384 \\ .glibc = .{{
385 \\ .major = {},
386 \\ .minor = {},
387 \\ .patch = {},
388 \\ }},
389 \\ }}}},
390 \\
391 , .{
392 target.os.version_range.linux.range.min.major,
393 target.os.version_range.linux.range.min.minor,
394 target.os.version_range.linux.range.min.patch,
395
396 target.os.version_range.linux.range.max.major,
397 target.os.version_range.linux.range.max.minor,
398 target.os.version_range.linux.range.max.patch,
399
400 target.os.version_range.linux.glibc.major,
401 target.os.version_range.linux.glibc.minor,
402 target.os.version_range.linux.glibc.patch,
403 }),
404
405 .windows => try os_builtin_str_buffer.outStream().print(
406 \\ .windows = .{{
407 \\ .min = {s},
408 \\ .max = {s},
409 \\ }}}},
410 \\
411 , .{
412 target.os.version_range.windows.min,
413 target.os.version_range.windows.max,
414 }),
415 }
416 try os_builtin_str_buffer.appendSlice("};\n");
417
418 const glibc_or_darwin_version = blk: {
419 if (target.isGnuLibC()) {
420 const stage1_glibc = try std.heap.c_allocator.create(Stage2SemVer);
421 const stage2_glibc = target.os.version_range.linux.glibc;
422 stage1_glibc.* = .{
423 .major = stage2_glibc.major,
424 .minor = stage2_glibc.minor,
425 .patch = stage2_glibc.patch,
426 };
427 break :blk stage1_glibc;
428 } else if (target.isDarwin()) {
429 const stage1_semver = try std.heap.c_allocator.create(Stage2SemVer);
430 const stage2_semver = target.os.version_range.semver.min;
431 stage1_semver.* = .{
432 .major = stage2_semver.major,
433 .minor = stage2_semver.minor,
434 .patch = stage2_semver.patch,
435 };
436 break :blk stage1_semver;
437 } else {
438 break :blk null;
439 }
440 };
441
442 const std_dl = target.standardDynamicLinkerPath();
443 const std_dl_z = if (std_dl.get()) |dl|
444 (try mem.dupeZ(std.heap.c_allocator, u8, dl)).ptr
445 else
446 null;
447
448 const asm_features = asm_features_list.toOwnedSlice();
449 self.* = .{
450 .arch = @enumToInt(target.cpu.arch) + 1, // skip over ZigLLVM_UnknownArch
451 .vendor = 0,
452 .os = @enumToInt(target.os.tag),
453 .abi = @enumToInt(target.abi),
454 .llvm_cpu_name = if (target.cpu.model.llvm_name) |s| s.ptr else null,
455 .llvm_cpu_features = llvm_features_buffer.toOwnedSlice().ptr,
456 .llvm_cpu_features_asm_ptr = asm_features.ptr,
457 .llvm_cpu_features_asm_len = asm_features.len,
458 .cpu_builtin_str = cpu_builtin_str_buffer.toOwnedSlice().ptr,
459 .os_builtin_str = os_builtin_str_buffer.toOwnedSlice().ptr,
460 .is_native_os = cross_target.isNativeOs(),
461 .is_native_cpu = cross_target.isNativeCpu(),
462 .glibc_or_darwin_version = glibc_or_darwin_version,
463 .dynamic_linker = dynamic_linker,
464 .standard_dynamic_linker_path = std_dl_z,
465 };
466 }
467};
468
469fn crossTargetToTarget(cross_target: CrossTarget, dynamic_linker_ptr: *?[*:0]u8) !Target {
470 var info = try std.zig.system.NativeTargetInfo.detect(std.heap.c_allocator, cross_target);
471 if (info.cpu_detection_unimplemented) {
472 // TODO We want to just use detected_info.target but implementing
473 // CPU model & feature detection is todo so here we rely on LLVM.
474 const llvm = @import("llvm.zig");
475 const llvm_cpu_name = llvm.GetHostCPUName();
476 const llvm_cpu_features = llvm.GetNativeFeatures();
477 const arch = Target.current.cpu.arch;
478 info.target.cpu = try detectNativeCpuWithLLVM(arch, llvm_cpu_name, llvm_cpu_features);
479 cross_target.updateCpuFeatures(&info.target.cpu.features);
480 info.target.cpu.arch = cross_target.getCpuArch();
481 }
482 if (info.dynamic_linker.get()) |dl| {
483 dynamic_linker_ptr.* = try mem.dupeZ(std.heap.c_allocator, u8, dl);
484 } else {
485 dynamic_linker_ptr.* = null;
486 }
487 return info.target;
488}
489
490// ABI warning
491const Stage2SemVer = extern struct {
492 major: u32,
493 minor: u32,
494 patch: u32,
495};
src-self-hosted/stage2.zig deleted-1054
...@@ -1,1054 +0,0 @@
1// This is Zig code that is used by both stage1 and stage2.
2// The prototypes in src/userland.h must match these definitions.
3
4const std = @import("std");
5const io = std.io;
6const mem = std.mem;
7const fs = std.fs;
8const process = std.process;
9const Allocator = mem.Allocator;
10const ArrayList = std.ArrayList;
11const ArrayListSentineled = std.ArrayListSentineled;
12const Target = std.Target;
13const CrossTarget = std.zig.CrossTarget;
14const self_hosted_main = @import("main.zig");
15const DepTokenizer = @import("DepTokenizer.zig");
16const assert = std.debug.assert;
17const LibCInstallation = @import("libc_installation.zig").LibCInstallation;
18
19var stderr_file: fs.File = undefined;
20var stderr: fs.File.OutStream = undefined;
21var stdout: fs.File.OutStream = undefined;
22
23comptime {
24 _ = @import("DepTokenizer.zig");
25}
26
27// ABI warning
28export fn stage2_zen(ptr: *[*]const u8, len: *usize) void {
29 const info_zen = @import("main.zig").info_zen;
30 ptr.* = info_zen;
31 len.* = info_zen.len;
32}
33
34// ABI warning
35export fn stage2_panic(ptr: [*]const u8, len: usize) void {
36 @panic(ptr[0..len]);
37}
38
39// ABI warning
40const Error = extern enum {
41 None,
42 OutOfMemory,
43 InvalidFormat,
44 SemanticAnalyzeFail,
45 AccessDenied,
46 Interrupted,
47 SystemResources,
48 FileNotFound,
49 FileSystem,
50 FileTooBig,
51 DivByZero,
52 Overflow,
53 PathAlreadyExists,
54 Unexpected,
55 ExactDivRemainder,
56 NegativeDenominator,
57 ShiftedOutOneBits,
58 CCompileErrors,
59 EndOfFile,
60 IsDir,
61 NotDir,
62 UnsupportedOperatingSystem,
63 SharingViolation,
64 PipeBusy,
65 PrimitiveTypeNotFound,
66 CacheUnavailable,
67 PathTooLong,
68 CCompilerCannotFindFile,
69 NoCCompilerInstalled,
70 ReadingDepFile,
71 InvalidDepFile,
72 MissingArchitecture,
73 MissingOperatingSystem,
74 UnknownArchitecture,
75 UnknownOperatingSystem,
76 UnknownABI,
77 InvalidFilename,
78 DiskQuota,
79 DiskSpace,
80 UnexpectedWriteFailure,
81 UnexpectedSeekFailure,
82 UnexpectedFileTruncationFailure,
83 Unimplemented,
84 OperationAborted,
85 BrokenPipe,
86 NoSpaceLeft,
87 NotLazy,
88 IsAsync,
89 ImportOutsidePkgPath,
90 UnknownCpuModel,
91 UnknownCpuFeature,
92 InvalidCpuFeatures,
93 InvalidLlvmCpuFeaturesFormat,
94 UnknownApplicationBinaryInterface,
95 ASTUnitFailure,
96 BadPathName,
97 SymLinkLoop,
98 ProcessFdQuotaExceeded,
99 SystemFdQuotaExceeded,
100 NoDevice,
101 DeviceBusy,
102 UnableToSpawnCCompiler,
103 CCompilerExitCode,
104 CCompilerCrashed,
105 CCompilerCannotFindHeaders,
106 LibCRuntimeNotFound,
107 LibCStdLibHeaderNotFound,
108 LibCKernel32LibNotFound,
109 UnsupportedArchitecture,
110 WindowsSdkNotFound,
111 UnknownDynamicLinkerPath,
112 TargetHasNoDynamicLinker,
113 InvalidAbiVersion,
114 InvalidOperatingSystemVersion,
115 UnknownClangOption,
116 NestedResponseFile,
117 ZigIsTheCCompiler,
118 FileBusy,
119 Locked,
120};
121
122const FILE = std.c.FILE;
123const ast = std.zig.ast;
124const translate_c = @import("translate_c.zig");
125
126/// Args should have a null terminating last arg.
127export fn stage2_translate_c(
128 out_ast: **ast.Tree,
129 out_errors_ptr: *[*]translate_c.ClangErrMsg,
130 out_errors_len: *usize,
131 args_begin: [*]?[*]const u8,
132 args_end: [*]?[*]const u8,
133 resources_path: [*:0]const u8,
134) Error {
135 var errors: []translate_c.ClangErrMsg = &[0]translate_c.ClangErrMsg{};
136 out_ast.* = translate_c.translate(std.heap.c_allocator, args_begin, args_end, &errors, resources_path) catch |err| switch (err) {
137 error.SemanticAnalyzeFail => {
138 out_errors_ptr.* = errors.ptr;
139 out_errors_len.* = errors.len;
140 return .CCompileErrors;
141 },
142 error.ASTUnitFailure => return .ASTUnitFailure,
143 error.OutOfMemory => return .OutOfMemory,
144 };
145 return .None;
146}
147
148export fn stage2_free_clang_errors(errors_ptr: [*]translate_c.ClangErrMsg, errors_len: usize) void {
149 translate_c.freeErrors(errors_ptr[0..errors_len]);
150}
151
152export fn stage2_render_ast(tree: *ast.Tree, output_file: *FILE) Error {
153 const c_out_stream = std.io.cOutStream(output_file);
154 _ = std.zig.render(std.heap.c_allocator, c_out_stream, tree) catch |e| switch (e) {
155 error.WouldBlock => unreachable, // stage1 opens stuff in exclusively blocking mode
156 error.NotOpenForWriting => unreachable,
157 error.SystemResources => return .SystemResources,
158 error.OperationAborted => return .OperationAborted,
159 error.BrokenPipe => return .BrokenPipe,
160 error.DiskQuota => return .DiskQuota,
161 error.FileTooBig => return .FileTooBig,
162 error.NoSpaceLeft => return .NoSpaceLeft,
163 error.AccessDenied => return .AccessDenied,
164 error.OutOfMemory => return .OutOfMemory,
165 error.Unexpected => return .Unexpected,
166 error.InputOutput => return .FileSystem,
167 };
168 return .None;
169}
170
171export fn stage2_fmt(argc: c_int, argv: [*]const [*:0]const u8) c_int {
172 if (std.debug.runtime_safety) {
173 fmtMain(argc, argv) catch unreachable;
174 } else {
175 fmtMain(argc, argv) catch |e| {
176 std.debug.warn("{}\n", .{@errorName(e)});
177 return -1;
178 };
179 }
180 return 0;
181}
182
183fn argvToArrayList(allocator: *Allocator, argc: c_int, argv: [*]const [*:0]const u8) !ArrayList([]const u8) {
184 var args_list = std.ArrayList([]const u8).init(allocator);
185 const argc_usize = @intCast(usize, argc);
186 var arg_i: usize = 0;
187 while (arg_i < argc_usize) : (arg_i += 1) {
188 try args_list.append(mem.spanZ(argv[arg_i]));
189 }
190
191 return args_list;
192}
193
194fn fmtMain(argc: c_int, argv: [*]const [*:0]const u8) !void {
195 const allocator = std.heap.c_allocator;
196
197 var args_list = try argvToArrayList(allocator, argc, argv);
198 defer args_list.deinit();
199
200 const args = args_list.span()[2..];
201 return self_hosted_main.cmdFmt(allocator, args);
202}
203
204export fn stage2_DepTokenizer_init(input: [*]const u8, len: usize) stage2_DepTokenizer {
205 const t = std.heap.c_allocator.create(DepTokenizer) catch @panic("failed to create .d tokenizer");
206 t.* = DepTokenizer.init(std.heap.c_allocator, input[0..len]);
207 return stage2_DepTokenizer{
208 .handle = t,
209 };
210}
211
212export fn stage2_DepTokenizer_deinit(self: *stage2_DepTokenizer) void {
213 self.handle.deinit();
214}
215
216export fn stage2_DepTokenizer_next(self: *stage2_DepTokenizer) stage2_DepNextResult {
217 const otoken = self.handle.next() catch {
218 const textz = std.ArrayListSentineled(u8, 0).init(&self.handle.arena.allocator, self.handle.error_text) catch @panic("failed to create .d tokenizer error text");
219 return stage2_DepNextResult{
220 .type_id = .error_,
221 .textz = textz.span().ptr,
222 };
223 };
224 const token = otoken orelse {
225 return stage2_DepNextResult{
226 .type_id = .null_,
227 .textz = undefined,
228 };
229 };
230 const textz = std.ArrayListSentineled(u8, 0).init(&self.handle.arena.allocator, token.bytes) catch @panic("failed to create .d tokenizer token text");
231 return stage2_DepNextResult{
232 .type_id = switch (token.id) {
233 .target => .target,
234 .prereq => .prereq,
235 },
236 .textz = textz.span().ptr,
237 };
238}
239
240const stage2_DepTokenizer = extern struct {
241 handle: *DepTokenizer,
242};
243
244const stage2_DepNextResult = extern struct {
245 type_id: TypeId,
246
247 // when type_id == error --> error text
248 // when type_id == null --> undefined
249 // when type_id == target --> target pathname
250 // when type_id == prereq --> prereq pathname
251 textz: [*]const u8,
252
253 const TypeId = extern enum {
254 error_,
255 null_,
256 target,
257 prereq,
258 };
259};
260
261// ABI warning
262export fn stage2_attach_segfault_handler() void {
263 if (std.debug.runtime_safety and std.debug.have_segfault_handling_support) {
264 std.debug.attachSegfaultHandler();
265 }
266}
267
268// ABI warning
269export fn stage2_progress_create() *std.Progress {
270 const ptr = std.heap.c_allocator.create(std.Progress) catch @panic("out of memory");
271 ptr.* = std.Progress{};
272 return ptr;
273}
274
275// ABI warning
276export fn stage2_progress_destroy(progress: *std.Progress) void {
277 std.heap.c_allocator.destroy(progress);
278}
279
280// ABI warning
281export fn stage2_progress_start_root(
282 progress: *std.Progress,
283 name_ptr: [*]const u8,
284 name_len: usize,
285 estimated_total_items: usize,
286) *std.Progress.Node {
287 return progress.start(
288 name_ptr[0..name_len],
289 if (estimated_total_items == 0) null else estimated_total_items,
290 ) catch @panic("timer unsupported");
291}
292
293// ABI warning
294export fn stage2_progress_disable_tty(progress: *std.Progress) void {
295 progress.terminal = null;
296}
297
298// ABI warning
299export fn stage2_progress_start(
300 node: *std.Progress.Node,
301 name_ptr: [*]const u8,
302 name_len: usize,
303 estimated_total_items: usize,
304) *std.Progress.Node {
305 const child_node = std.heap.c_allocator.create(std.Progress.Node) catch @panic("out of memory");
306 child_node.* = node.start(
307 name_ptr[0..name_len],
308 if (estimated_total_items == 0) null else estimated_total_items,
309 );
310 child_node.activate();
311 return child_node;
312}
313
314// ABI warning
315export fn stage2_progress_end(node: *std.Progress.Node) void {
316 node.end();
317 if (&node.context.root != node) {
318 std.heap.c_allocator.destroy(node);
319 }
320}
321
322// ABI warning
323export fn stage2_progress_complete_one(node: *std.Progress.Node) void {
324 node.completeOne();
325}
326
327// ABI warning
328export fn stage2_progress_update_node(node: *std.Progress.Node, done_count: usize, total_count: usize) void {
329 node.completed_items = done_count;
330 node.estimated_total_items = total_count;
331 node.activate();
332 node.context.maybeRefresh();
333}
334
335fn detectNativeCpuWithLLVM(
336 arch: Target.Cpu.Arch,
337 llvm_cpu_name_z: ?[*:0]const u8,
338 llvm_cpu_features_opt: ?[*:0]const u8,
339) !Target.Cpu {
340 var result = Target.Cpu.baseline(arch);
341
342 if (llvm_cpu_name_z) |cpu_name_z| {
343 const llvm_cpu_name = mem.spanZ(cpu_name_z);
344
345 for (arch.allCpuModels()) |model| {
346 const this_llvm_name = model.llvm_name orelse continue;
347 if (mem.eql(u8, this_llvm_name, llvm_cpu_name)) {
348 // Here we use the non-dependencies-populated set,
349 // so that subtracting features later in this function
350 // affect the prepopulated set.
351 result = Target.Cpu{
352 .arch = arch,
353 .model = model,
354 .features = model.features,
355 };
356 break;
357 }
358 }
359 }
360
361 const all_features = arch.allFeaturesList();
362
363 if (llvm_cpu_features_opt) |llvm_cpu_features| {
364 var it = mem.tokenize(mem.spanZ(llvm_cpu_features), ",");
365 while (it.next()) |decorated_llvm_feat| {
366 var op: enum {
367 add,
368 sub,
369 } = undefined;
370 var llvm_feat: []const u8 = undefined;
371 if (mem.startsWith(u8, decorated_llvm_feat, "+")) {
372 op = .add;
373 llvm_feat = decorated_llvm_feat[1..];
374 } else if (mem.startsWith(u8, decorated_llvm_feat, "-")) {
375 op = .sub;
376 llvm_feat = decorated_llvm_feat[1..];
377 } else {
378 return error.InvalidLlvmCpuFeaturesFormat;
379 }
380 for (all_features) |feature, index_usize| {
381 const this_llvm_name = feature.llvm_name orelse continue;
382 if (mem.eql(u8, llvm_feat, this_llvm_name)) {
383 const index = @intCast(Target.Cpu.Feature.Set.Index, index_usize);
384 switch (op) {
385 .add => result.features.addFeature(index),
386 .sub => result.features.removeFeature(index),
387 }
388 break;
389 }
390 }
391 }
392 }
393
394 result.features.populateDependencies(all_features);
395 return result;
396}
397
398export fn stage2_env(argc: c_int, argv: [*]const [*:0]const u8) c_int {
399 const allocator = std.heap.c_allocator;
400
401 var args_list = argvToArrayList(allocator, argc, argv) catch |err| {
402 std.debug.print("unable to parse arguments: {}\n", .{@errorName(err)});
403 return -1;
404 };
405 defer args_list.deinit();
406
407 const args = args_list.span()[2..];
408
409 @import("print_env.zig").cmdEnv(allocator, args, std.io.getStdOut().outStream()) catch |err| {
410 std.debug.print("unable to print info: {}\n", .{@errorName(err)});
411 return -1;
412 };
413
414 return 0;
415}
416
417export fn stage2_cc(argc: c_int, argv: [*]const [*:0]const u8, is_cpp: bool) c_int {
418 const allocator = std.heap.c_allocator;
419
420 var args_list = argvToArrayList(allocator, argc, argv) catch |err| {
421 std.debug.print("unable to parse arguments: {}\n", .{@errorName(err)});
422 return -1;
423 };
424 defer args_list.deinit();
425
426 self_hosted_main.buildOutputType(allocator, allocator, args_list.items, if (is_cpp) .cpp else .cc) catch |err| {
427 std.debug.print("zig cc failure: {}\n", .{@errorName(err)});
428 return -1;
429 };
430
431 return 0;
432}
433
434// ABI warning
435export fn stage2_cmd_targets(
436 zig_triple: ?[*:0]const u8,
437 mcpu: ?[*:0]const u8,
438 dynamic_linker: ?[*:0]const u8,
439) c_int {
440 cmdTargets(zig_triple, mcpu, dynamic_linker) catch |err| {
441 std.debug.warn("unable to list targets: {}\n", .{@errorName(err)});
442 return -1;
443 };
444 return 0;
445}
446
447fn cmdTargets(
448 zig_triple_oz: ?[*:0]const u8,
449 mcpu_oz: ?[*:0]const u8,
450 dynamic_linker_oz: ?[*:0]const u8,
451) !void {
452 const cross_target = try stage2CrossTarget(zig_triple_oz, mcpu_oz, dynamic_linker_oz);
453 var dynamic_linker: ?[*:0]u8 = null;
454 const target = try crossTargetToTarget(cross_target, &dynamic_linker);
455 return @import("print_targets.zig").cmdTargets(
456 std.heap.c_allocator,
457 &[0][]u8{},
458 std.io.getStdOut().outStream(),
459 target,
460 );
461}
462
463// ABI warning
464export fn stage2_target_parse(
465 target: *Stage2Target,
466 zig_triple: ?[*:0]const u8,
467 mcpu: ?[*:0]const u8,
468 dynamic_linker: ?[*:0]const u8,
469) Error {
470 stage2TargetParse(target, zig_triple, mcpu, dynamic_linker) catch |err| switch (err) {
471 error.OutOfMemory => return .OutOfMemory,
472 error.UnknownArchitecture => return .UnknownArchitecture,
473 error.UnknownOperatingSystem => return .UnknownOperatingSystem,
474 error.UnknownApplicationBinaryInterface => return .UnknownApplicationBinaryInterface,
475 error.MissingOperatingSystem => return .MissingOperatingSystem,
476 error.InvalidLlvmCpuFeaturesFormat => return .InvalidLlvmCpuFeaturesFormat,
477 error.UnexpectedExtraField => return .SemanticAnalyzeFail,
478 error.InvalidAbiVersion => return .InvalidAbiVersion,
479 error.InvalidOperatingSystemVersion => return .InvalidOperatingSystemVersion,
480 error.FileSystem => return .FileSystem,
481 error.SymLinkLoop => return .SymLinkLoop,
482 error.SystemResources => return .SystemResources,
483 error.ProcessFdQuotaExceeded => return .ProcessFdQuotaExceeded,
484 error.SystemFdQuotaExceeded => return .SystemFdQuotaExceeded,
485 error.DeviceBusy => return .DeviceBusy,
486 };
487 return .None;
488}
489
490fn stage2CrossTarget(
491 zig_triple_oz: ?[*:0]const u8,
492 mcpu_oz: ?[*:0]const u8,
493 dynamic_linker_oz: ?[*:0]const u8,
494) !CrossTarget {
495 const mcpu = mem.spanZ(mcpu_oz);
496 const dynamic_linker = mem.spanZ(dynamic_linker_oz);
497 var diags: CrossTarget.ParseOptions.Diagnostics = .{};
498 const target: CrossTarget = CrossTarget.parse(.{
499 .arch_os_abi = mem.spanZ(zig_triple_oz) orelse "native",
500 .cpu_features = mcpu,
501 .dynamic_linker = dynamic_linker,
502 .diagnostics = &diags,
503 }) catch |err| switch (err) {
504 error.UnknownCpuModel => {
505 std.debug.warn("Unknown CPU: '{}'\nAvailable CPUs for architecture '{}':\n", .{
506 diags.cpu_name.?,
507 @tagName(diags.arch.?),
508 });
509 for (diags.arch.?.allCpuModels()) |cpu| {
510 std.debug.warn(" {}\n", .{cpu.name});
511 }
512 process.exit(1);
513 },
514 error.UnknownCpuFeature => {
515 std.debug.warn(
516 \\Unknown CPU feature: '{}'
517 \\Available CPU features for architecture '{}':
518 \\
519 , .{
520 diags.unknown_feature_name,
521 @tagName(diags.arch.?),
522 });
523 for (diags.arch.?.allFeaturesList()) |feature| {
524 std.debug.warn(" {}: {}\n", .{ feature.name, feature.description });
525 }
526 process.exit(1);
527 },
528 else => |e| return e,
529 };
530
531 return target;
532}
533
534fn stage2TargetParse(
535 stage1_target: *Stage2Target,
536 zig_triple_oz: ?[*:0]const u8,
537 mcpu_oz: ?[*:0]const u8,
538 dynamic_linker_oz: ?[*:0]const u8,
539) !void {
540 const target = try stage2CrossTarget(zig_triple_oz, mcpu_oz, dynamic_linker_oz);
541 try stage1_target.fromTarget(target);
542}
543
544// ABI warning
545const Stage2LibCInstallation = extern struct {
546 include_dir: [*]const u8,
547 include_dir_len: usize,
548 sys_include_dir: [*]const u8,
549 sys_include_dir_len: usize,
550 crt_dir: [*]const u8,
551 crt_dir_len: usize,
552 msvc_lib_dir: [*]const u8,
553 msvc_lib_dir_len: usize,
554 kernel32_lib_dir: [*]const u8,
555 kernel32_lib_dir_len: usize,
556
557 fn initFromStage2(self: *Stage2LibCInstallation, libc: LibCInstallation) void {
558 if (libc.include_dir) |s| {
559 self.include_dir = s.ptr;
560 self.include_dir_len = s.len;
561 } else {
562 self.include_dir = "";
563 self.include_dir_len = 0;
564 }
565 if (libc.sys_include_dir) |s| {
566 self.sys_include_dir = s.ptr;
567 self.sys_include_dir_len = s.len;
568 } else {
569 self.sys_include_dir = "";
570 self.sys_include_dir_len = 0;
571 }
572 if (libc.crt_dir) |s| {
573 self.crt_dir = s.ptr;
574 self.crt_dir_len = s.len;
575 } else {
576 self.crt_dir = "";
577 self.crt_dir_len = 0;
578 }
579 if (libc.msvc_lib_dir) |s| {
580 self.msvc_lib_dir = s.ptr;
581 self.msvc_lib_dir_len = s.len;
582 } else {
583 self.msvc_lib_dir = "";
584 self.msvc_lib_dir_len = 0;
585 }
586 if (libc.kernel32_lib_dir) |s| {
587 self.kernel32_lib_dir = s.ptr;
588 self.kernel32_lib_dir_len = s.len;
589 } else {
590 self.kernel32_lib_dir = "";
591 self.kernel32_lib_dir_len = 0;
592 }
593 }
594
595 fn toStage2(self: Stage2LibCInstallation) LibCInstallation {
596 var libc: LibCInstallation = .{};
597 if (self.include_dir_len != 0) {
598 libc.include_dir = self.include_dir[0..self.include_dir_len];
599 }
600 if (self.sys_include_dir_len != 0) {
601 libc.sys_include_dir = self.sys_include_dir[0..self.sys_include_dir_len];
602 }
603 if (self.crt_dir_len != 0) {
604 libc.crt_dir = self.crt_dir[0..self.crt_dir_len];
605 }
606 if (self.msvc_lib_dir_len != 0) {
607 libc.msvc_lib_dir = self.msvc_lib_dir[0..self.msvc_lib_dir_len];
608 }
609 if (self.kernel32_lib_dir_len != 0) {
610 libc.kernel32_lib_dir = self.kernel32_lib_dir[0..self.kernel32_lib_dir_len];
611 }
612 return libc;
613 }
614};
615
616// ABI warning
617export fn stage2_libc_parse(stage1_libc: *Stage2LibCInstallation, libc_file_z: [*:0]const u8) Error {
618 const libc_file = mem.spanZ(libc_file_z);
619 var libc = LibCInstallation.parse(std.heap.c_allocator, libc_file) catch |err| switch (err) {
620 error.ParseError => return .SemanticAnalyzeFail,
621 error.FileTooBig => return .FileTooBig,
622 error.InputOutput => return .FileSystem,
623 error.NoSpaceLeft => return .NoSpaceLeft,
624 error.AccessDenied => return .AccessDenied,
625 error.BrokenPipe => return .BrokenPipe,
626 error.SystemResources => return .SystemResources,
627 error.OperationAborted => return .OperationAborted,
628 error.WouldBlock => unreachable,
629 error.NotOpenForReading => unreachable,
630 error.Unexpected => return .Unexpected,
631 error.IsDir => return .IsDir,
632 error.ConnectionResetByPeer => unreachable,
633 error.ConnectionTimedOut => unreachable,
634 error.OutOfMemory => return .OutOfMemory,
635 error.Unseekable => unreachable,
636 error.SharingViolation => return .SharingViolation,
637 error.PathAlreadyExists => unreachable,
638 error.FileNotFound => return .FileNotFound,
639 error.PipeBusy => return .PipeBusy,
640 error.NameTooLong => return .PathTooLong,
641 error.InvalidUtf8 => return .BadPathName,
642 error.BadPathName => return .BadPathName,
643 error.SymLinkLoop => return .SymLinkLoop,
644 error.ProcessFdQuotaExceeded => return .ProcessFdQuotaExceeded,
645 error.SystemFdQuotaExceeded => return .SystemFdQuotaExceeded,
646 error.NoDevice => return .NoDevice,
647 error.NotDir => return .NotDir,
648 error.DeviceBusy => return .DeviceBusy,
649 error.FileLocksNotSupported => unreachable,
650 };
651 stage1_libc.initFromStage2(libc);
652 return .None;
653}
654
655// ABI warning
656export fn stage2_libc_find_native(stage1_libc: *Stage2LibCInstallation) Error {
657 var libc = LibCInstallation.findNative(.{
658 .allocator = std.heap.c_allocator,
659 .verbose = true,
660 }) catch |err| switch (err) {
661 error.OutOfMemory => return .OutOfMemory,
662 error.FileSystem => return .FileSystem,
663 error.UnableToSpawnCCompiler => return .UnableToSpawnCCompiler,
664 error.CCompilerExitCode => return .CCompilerExitCode,
665 error.CCompilerCrashed => return .CCompilerCrashed,
666 error.CCompilerCannotFindHeaders => return .CCompilerCannotFindHeaders,
667 error.LibCRuntimeNotFound => return .LibCRuntimeNotFound,
668 error.LibCStdLibHeaderNotFound => return .LibCStdLibHeaderNotFound,
669 error.LibCKernel32LibNotFound => return .LibCKernel32LibNotFound,
670 error.UnsupportedArchitecture => return .UnsupportedArchitecture,
671 error.WindowsSdkNotFound => return .WindowsSdkNotFound,
672 error.ZigIsTheCCompiler => return .ZigIsTheCCompiler,
673 };
674 stage1_libc.initFromStage2(libc);
675 return .None;
676}
677
678// ABI warning
679export fn stage2_libc_render(stage1_libc: *Stage2LibCInstallation, output_file: *FILE) Error {
680 var libc = stage1_libc.toStage2();
681 const c_out_stream = std.io.cOutStream(output_file);
682 libc.render(c_out_stream) catch |err| switch (err) {
683 error.WouldBlock => unreachable, // stage1 opens stuff in exclusively blocking mode
684 error.NotOpenForWriting => unreachable,
685 error.SystemResources => return .SystemResources,
686 error.OperationAborted => return .OperationAborted,
687 error.BrokenPipe => return .BrokenPipe,
688 error.DiskQuota => return .DiskQuota,
689 error.FileTooBig => return .FileTooBig,
690 error.NoSpaceLeft => return .NoSpaceLeft,
691 error.AccessDenied => return .AccessDenied,
692 error.Unexpected => return .Unexpected,
693 error.InputOutput => return .FileSystem,
694 };
695 return .None;
696}
697
698// ABI warning
699const Stage2Target = extern struct {
700 arch: c_int,
701 vendor: c_int,
702
703 abi: c_int,
704 os: c_int,
705
706 is_native_os: bool,
707 is_native_cpu: bool,
708
709 glibc_or_darwin_version: ?*Stage2SemVer,
710
711 llvm_cpu_name: ?[*:0]const u8,
712 llvm_cpu_features: ?[*:0]const u8,
713 cpu_builtin_str: ?[*:0]const u8,
714 cache_hash: ?[*:0]const u8,
715 cache_hash_len: usize,
716 os_builtin_str: ?[*:0]const u8,
717
718 dynamic_linker: ?[*:0]const u8,
719 standard_dynamic_linker_path: ?[*:0]const u8,
720
721 llvm_cpu_features_asm_ptr: [*]const [*:0]const u8,
722 llvm_cpu_features_asm_len: usize,
723
724 fn fromTarget(self: *Stage2Target, cross_target: CrossTarget) !void {
725 const allocator = std.heap.c_allocator;
726
727 var dynamic_linker: ?[*:0]u8 = null;
728 const target = try crossTargetToTarget(cross_target, &dynamic_linker);
729
730 var cache_hash = try std.ArrayListSentineled(u8, 0).allocPrint(allocator, "{}\n{}\n", .{
731 target.cpu.model.name,
732 target.cpu.features.asBytes(),
733 });
734 defer cache_hash.deinit();
735
736 const generic_arch_name = target.cpu.arch.genericName();
737 var cpu_builtin_str_buffer = try std.ArrayListSentineled(u8, 0).allocPrint(allocator,
738 \\Cpu{{
739 \\ .arch = .{},
740 \\ .model = &Target.{}.cpu.{},
741 \\ .features = Target.{}.featureSet(&[_]Target.{}.Feature{{
742 \\
743 , .{
744 @tagName(target.cpu.arch),
745 generic_arch_name,
746 target.cpu.model.name,
747 generic_arch_name,
748 generic_arch_name,
749 });
750 defer cpu_builtin_str_buffer.deinit();
751
752 var llvm_features_buffer = try std.ArrayListSentineled(u8, 0).initSize(allocator, 0);
753 defer llvm_features_buffer.deinit();
754
755 // Unfortunately we have to do the work twice, because Clang does not support
756 // the same command line parameters for CPU features when assembling code as it does
757 // when compiling C code.
758 var asm_features_list = std.ArrayList([*:0]const u8).init(allocator);
759 defer asm_features_list.deinit();
760
761 for (target.cpu.arch.allFeaturesList()) |feature, index_usize| {
762 const index = @intCast(Target.Cpu.Feature.Set.Index, index_usize);
763 const is_enabled = target.cpu.features.isEnabled(index);
764
765 if (feature.llvm_name) |llvm_name| {
766 const plus_or_minus = "-+"[@boolToInt(is_enabled)];
767 try llvm_features_buffer.append(plus_or_minus);
768 try llvm_features_buffer.appendSlice(llvm_name);
769 try llvm_features_buffer.appendSlice(",");
770 }
771
772 if (is_enabled) {
773 // TODO some kind of "zig identifier escape" function rather than
774 // unconditionally using @"" syntax
775 try cpu_builtin_str_buffer.appendSlice(" .@\"");
776 try cpu_builtin_str_buffer.appendSlice(feature.name);
777 try cpu_builtin_str_buffer.appendSlice("\",\n");
778 }
779 }
780
781 switch (target.cpu.arch) {
782 .riscv32, .riscv64 => {
783 if (std.Target.riscv.featureSetHas(target.cpu.features, .relax)) {
784 try asm_features_list.append("-mrelax");
785 } else {
786 try asm_features_list.append("-mno-relax");
787 }
788 },
789 else => {
790 // TODO
791 // Argh, why doesn't the assembler accept the list of CPU features?!
792 // I don't see a way to do this other than hard coding everything.
793 },
794 }
795
796 try cpu_builtin_str_buffer.appendSlice(
797 \\ }),
798 \\};
799 \\
800 );
801
802 assert(mem.endsWith(u8, llvm_features_buffer.span(), ","));
803 llvm_features_buffer.shrink(llvm_features_buffer.len() - 1);
804
805 var os_builtin_str_buffer = try std.ArrayListSentineled(u8, 0).allocPrint(allocator,
806 \\Os{{
807 \\ .tag = .{},
808 \\ .version_range = .{{
809 , .{@tagName(target.os.tag)});
810 defer os_builtin_str_buffer.deinit();
811
812 // We'll re-use the OS version range builtin string for the cache hash.
813 const os_builtin_str_ver_start_index = os_builtin_str_buffer.len();
814
815 @setEvalBranchQuota(2000);
816 switch (target.os.tag) {
817 .freestanding,
818 .ananas,
819 .cloudabi,
820 .dragonfly,
821 .fuchsia,
822 .ios,
823 .kfreebsd,
824 .lv2,
825 .solaris,
826 .haiku,
827 .minix,
828 .rtems,
829 .nacl,
830 .cnk,
831 .aix,
832 .cuda,
833 .nvcl,
834 .amdhsa,
835 .ps4,
836 .elfiamcu,
837 .tvos,
838 .watchos,
839 .mesa3d,
840 .contiki,
841 .amdpal,
842 .hermit,
843 .hurd,
844 .wasi,
845 .emscripten,
846 .uefi,
847 .other,
848 => try os_builtin_str_buffer.appendSlice(" .none = {} }\n"),
849
850 .freebsd,
851 .macosx,
852 .netbsd,
853 .openbsd,
854 => try os_builtin_str_buffer.outStream().print(
855 \\ .semver = .{{
856 \\ .min = .{{
857 \\ .major = {},
858 \\ .minor = {},
859 \\ .patch = {},
860 \\ }},
861 \\ .max = .{{
862 \\ .major = {},
863 \\ .minor = {},
864 \\ .patch = {},
865 \\ }},
866 \\ }}}},
867 \\
868 , .{
869 target.os.version_range.semver.min.major,
870 target.os.version_range.semver.min.minor,
871 target.os.version_range.semver.min.patch,
872
873 target.os.version_range.semver.max.major,
874 target.os.version_range.semver.max.minor,
875 target.os.version_range.semver.max.patch,
876 }),
877
878 .linux => try os_builtin_str_buffer.outStream().print(
879 \\ .linux = .{{
880 \\ .range = .{{
881 \\ .min = .{{
882 \\ .major = {},
883 \\ .minor = {},
884 \\ .patch = {},
885 \\ }},
886 \\ .max = .{{
887 \\ .major = {},
888 \\ .minor = {},
889 \\ .patch = {},
890 \\ }},
891 \\ }},
892 \\ .glibc = .{{
893 \\ .major = {},
894 \\ .minor = {},
895 \\ .patch = {},
896 \\ }},
897 \\ }}}},
898 \\
899 , .{
900 target.os.version_range.linux.range.min.major,
901 target.os.version_range.linux.range.min.minor,
902 target.os.version_range.linux.range.min.patch,
903
904 target.os.version_range.linux.range.max.major,
905 target.os.version_range.linux.range.max.minor,
906 target.os.version_range.linux.range.max.patch,
907
908 target.os.version_range.linux.glibc.major,
909 target.os.version_range.linux.glibc.minor,
910 target.os.version_range.linux.glibc.patch,
911 }),
912
913 .windows => try os_builtin_str_buffer.outStream().print(
914 \\ .windows = .{{
915 \\ .min = {s},
916 \\ .max = {s},
917 \\ }}}},
918 \\
919 , .{
920 target.os.version_range.windows.min,
921 target.os.version_range.windows.max,
922 }),
923 }
924 try os_builtin_str_buffer.appendSlice("};\n");
925
926 try cache_hash.appendSlice(
927 os_builtin_str_buffer.span()[os_builtin_str_ver_start_index..os_builtin_str_buffer.len()],
928 );
929
930 const glibc_or_darwin_version = blk: {
931 if (target.isGnuLibC()) {
932 const stage1_glibc = try std.heap.c_allocator.create(Stage2SemVer);
933 const stage2_glibc = target.os.version_range.linux.glibc;
934 stage1_glibc.* = .{
935 .major = stage2_glibc.major,
936 .minor = stage2_glibc.minor,
937 .patch = stage2_glibc.patch,
938 };
939 break :blk stage1_glibc;
940 } else if (target.isDarwin()) {
941 const stage1_semver = try std.heap.c_allocator.create(Stage2SemVer);
942 const stage2_semver = target.os.version_range.semver.min;
943 stage1_semver.* = .{
944 .major = stage2_semver.major,
945 .minor = stage2_semver.minor,
946 .patch = stage2_semver.patch,
947 };
948 break :blk stage1_semver;
949 } else {
950 break :blk null;
951 }
952 };
953
954 const std_dl = target.standardDynamicLinkerPath();
955 const std_dl_z = if (std_dl.get()) |dl|
956 (try mem.dupeZ(std.heap.c_allocator, u8, dl)).ptr
957 else
958 null;
959
960 const cache_hash_slice = cache_hash.toOwnedSlice();
961 const asm_features = asm_features_list.toOwnedSlice();
962 self.* = .{
963 .arch = @enumToInt(target.cpu.arch) + 1, // skip over ZigLLVM_UnknownArch
964 .vendor = 0,
965 .os = @enumToInt(target.os.tag),
966 .abi = @enumToInt(target.abi),
967 .llvm_cpu_name = if (target.cpu.model.llvm_name) |s| s.ptr else null,
968 .llvm_cpu_features = llvm_features_buffer.toOwnedSlice().ptr,
969 .llvm_cpu_features_asm_ptr = asm_features.ptr,
970 .llvm_cpu_features_asm_len = asm_features.len,
971 .cpu_builtin_str = cpu_builtin_str_buffer.toOwnedSlice().ptr,
972 .os_builtin_str = os_builtin_str_buffer.toOwnedSlice().ptr,
973 .cache_hash = cache_hash_slice.ptr,
974 .cache_hash_len = cache_hash_slice.len,
975 .is_native_os = cross_target.isNativeOs(),
976 .is_native_cpu = cross_target.isNativeCpu(),
977 .glibc_or_darwin_version = glibc_or_darwin_version,
978 .dynamic_linker = dynamic_linker,
979 .standard_dynamic_linker_path = std_dl_z,
980 };
981 }
982};
983
984fn enumInt(comptime Enum: type, int: c_int) Enum {
985 return @intToEnum(Enum, @intCast(@TagType(Enum), int));
986}
987
988fn crossTargetToTarget(cross_target: CrossTarget, dynamic_linker_ptr: *?[*:0]u8) !Target {
989 var info = try std.zig.system.NativeTargetInfo.detect(std.heap.c_allocator, cross_target);
990 if (info.cpu_detection_unimplemented) {
991 // TODO We want to just use detected_info.target but implementing
992 // CPU model & feature detection is todo so here we rely on LLVM.
993 const llvm = @import("llvm.zig");
994 const llvm_cpu_name = llvm.GetHostCPUName();
995 const llvm_cpu_features = llvm.GetNativeFeatures();
996 const arch = std.Target.current.cpu.arch;
997 info.target.cpu = try detectNativeCpuWithLLVM(arch, llvm_cpu_name, llvm_cpu_features);
998 cross_target.updateCpuFeatures(&info.target.cpu.features);
999 info.target.cpu.arch = cross_target.getCpuArch();
1000 }
1001 if (info.dynamic_linker.get()) |dl| {
1002 dynamic_linker_ptr.* = try mem.dupeZ(std.heap.c_allocator, u8, dl);
1003 } else {
1004 dynamic_linker_ptr.* = null;
1005 }
1006 return info.target;
1007}
1008
1009// ABI warning
1010const Stage2SemVer = extern struct {
1011 major: u32,
1012 minor: u32,
1013 patch: u32,
1014};
1015
1016// ABI warning
1017const Stage2NativePaths = extern struct {
1018 include_dirs_ptr: [*][*:0]u8,
1019 include_dirs_len: usize,
1020 lib_dirs_ptr: [*][*:0]u8,
1021 lib_dirs_len: usize,
1022 rpaths_ptr: [*][*:0]u8,
1023 rpaths_len: usize,
1024 warnings_ptr: [*][*:0]u8,
1025 warnings_len: usize,
1026};
1027// ABI warning
1028export fn stage2_detect_native_paths(stage1_paths: *Stage2NativePaths) Error {
1029 stage2DetectNativePaths(stage1_paths) catch |err| switch (err) {
1030 error.OutOfMemory => return .OutOfMemory,
1031 };
1032 return .None;
1033}
1034
1035fn stage2DetectNativePaths(stage1_paths: *Stage2NativePaths) !void {
1036 var paths = try std.zig.system.NativePaths.detect(std.heap.c_allocator);
1037 errdefer paths.deinit();
1038
1039 try convertSlice(paths.include_dirs.span(), &stage1_paths.include_dirs_ptr, &stage1_paths.include_dirs_len);
1040 try convertSlice(paths.lib_dirs.span(), &stage1_paths.lib_dirs_ptr, &stage1_paths.lib_dirs_len);
1041 try convertSlice(paths.rpaths.span(), &stage1_paths.rpaths_ptr, &stage1_paths.rpaths_len);
1042 try convertSlice(paths.warnings.span(), &stage1_paths.warnings_ptr, &stage1_paths.warnings_len);
1043}
1044
1045fn convertSlice(slice: [][:0]u8, ptr: *[*][*:0]u8, len: *usize) !void {
1046 len.* = slice.len;
1047 const new_slice = try std.heap.c_allocator.alloc([*:0]u8, slice.len);
1048 for (slice) |item, i| {
1049 new_slice[i] = item.ptr;
1050 }
1051 ptr.* = new_slice.ptr;
1052}
1053
1054export const stage2_is_zig0 = false;
src/all_types.hpp+9-126
...@@ -10,7 +10,6 @@...@@ -10,7 +10,6 @@
1010
11#include "list.hpp"11#include "list.hpp"
12#include "buffer.hpp"12#include "buffer.hpp"
13#include "cache_hash.hpp"
14#include "zig_llvm.h"13#include "zig_llvm.h"
15#include "hash_map.hpp"14#include "hash_map.hpp"
16#include "errmsg.hpp"15#include "errmsg.hpp"
...@@ -1639,8 +1638,6 @@ struct ZigType {...@@ -1639,8 +1638,6 @@ struct ZigType {
1639 size_t abi_size;1638 size_t abi_size;
1640 // Number of bits of information in this type. Known after ResolveStatusSizeKnown.1639 // Number of bits of information in this type. Known after ResolveStatusSizeKnown.
1641 size_t size_in_bits;1640 size_t size_in_bits;
1642
1643 bool gen_h_loop_flag;
1644};1641};
16451642
1646enum FnAnalState {1643enum FnAnalState {
...@@ -1976,67 +1973,16 @@ struct TimeEvent {...@@ -1976,67 +1973,16 @@ struct TimeEvent {
1976 const char *name;1973 const char *name;
1977};1974};
19781975
1979enum BuildMode {
1980 BuildModeDebug,
1981 BuildModeFastRelease,
1982 BuildModeSafeRelease,
1983 BuildModeSmallRelease,
1984};
1985
1986enum CodeModel {
1987 CodeModelDefault,
1988 CodeModelTiny,
1989 CodeModelSmall,
1990 CodeModelKernel,
1991 CodeModelMedium,
1992 CodeModelLarge,
1993};
1994
1995struct LinkLib {
1996 Buf *name;
1997 Buf *path;
1998 ZigList<Buf *> symbols; // the list of symbols that we depend on from this lib
1999 bool provided_explicitly;
2000};
2001
2002enum ValgrindSupport {
2003 ValgrindSupportAuto,
2004 ValgrindSupportDisabled,
2005 ValgrindSupportEnabled,
2006};
2007
2008enum WantPIC {
2009 WantPICAuto,
2010 WantPICDisabled,
2011 WantPICEnabled,
2012};
2013
2014enum WantStackCheck {
2015 WantStackCheckAuto,
2016 WantStackCheckDisabled,
2017 WantStackCheckEnabled,
2018};
2019
2020enum WantCSanitize {
2021 WantCSanitizeAuto,
2022 WantCSanitizeDisabled,
2023 WantCSanitizeEnabled,
2024};
2025
2026enum OptionalBool {
2027 OptionalBoolNull,
2028 OptionalBoolFalse,
2029 OptionalBoolTrue,
2030};
2031
2032struct CFile {1976struct CFile {
2033 ZigList<const char *> args;1977 ZigList<const char *> args;
2034 const char *source_path;1978 const char *source_path;
2035 const char *preprocessor_only_basename;1979 const char *preprocessor_only_basename;
2036};1980};
20371981
2038// When adding fields, check if they should be added to the hash computation in build_with_cache
2039struct CodeGen {1982struct CodeGen {
1983 // Other code depends on this being first.
1984 ZigStage1 stage1;
1985
2040 // arena allocator destroyed just prior to codegen emit1986 // arena allocator destroyed just prior to codegen emit
2041 heap::ArenaAllocator *pass1_arena;1987 heap::ArenaAllocator *pass1_arena;
20421988
...@@ -2048,8 +1994,6 @@ struct CodeGen {...@@ -2048,8 +1994,6 @@ struct CodeGen {
2048 ZigLLVMDIBuilder *dbuilder;1994 ZigLLVMDIBuilder *dbuilder;
2049 ZigLLVMDICompileUnit *compile_unit;1995 ZigLLVMDICompileUnit *compile_unit;
2050 ZigLLVMDIFile *compile_unit_file;1996 ZigLLVMDIFile *compile_unit_file;
2051 LinkLib *libc_link_lib;
2052 LinkLib *libcpp_link_lib;
2053 LLVMTargetDataRef target_data_ref;1997 LLVMTargetDataRef target_data_ref;
2054 LLVMTargetMachineRef target_machine;1998 LLVMTargetMachineRef target_machine;
2055 ZigLLVMDIFile *dummy_di_file;1999 ZigLLVMDIFile *dummy_di_file;
...@@ -2104,7 +2048,6 @@ struct CodeGen {...@@ -2104,7 +2048,6 @@ struct CodeGen {
2104 ZigList<ZigFn *> inline_fns;2048 ZigList<ZigFn *> inline_fns;
2105 ZigList<ZigFn *> test_fns;2049 ZigList<ZigFn *> test_fns;
2106 ZigList<ErrorTableEntry *> errors_by_index;2050 ZigList<ErrorTableEntry *> errors_by_index;
2107 ZigList<CacheHash *> caches_to_release;
2108 size_t largest_err_name_len;2051 size_t largest_err_name_len;
2109 ZigList<ZigType *> type_resolve_stack;2052 ZigList<ZigType *> type_resolve_stack;
21102053
...@@ -2173,7 +2116,6 @@ struct CodeGen {...@@ -2173,7 +2116,6 @@ struct CodeGen {
2173 Buf llvm_triple_str;2116 Buf llvm_triple_str;
2174 Buf global_asm;2117 Buf global_asm;
2175 Buf o_file_output_path;2118 Buf o_file_output_path;
2176 Buf bin_file_output_path;
2177 Buf asm_file_output_path;2119 Buf asm_file_output_path;
2178 Buf llvm_ir_file_output_path;2120 Buf llvm_ir_file_output_path;
2179 Buf *cache_dir;2121 Buf *cache_dir;
...@@ -2184,7 +2126,7 @@ struct CodeGen {...@@ -2184,7 +2126,7 @@ struct CodeGen {
2184 const char **libc_include_dir_list;2126 const char **libc_include_dir_list;
2185 size_t libc_include_dir_len;2127 size_t libc_include_dir_len;
21862128
2187 Buf *zig_c_headers_dir; // Cannot be overridden; derived from zig_lib_dir.2129 Buf *builtin_zig_path;
2188 Buf *zig_std_special_dir; // Cannot be overridden; derived from zig_lib_dir.2130 Buf *zig_std_special_dir; // Cannot be overridden; derived from zig_lib_dir.
21892131
2190 IrInstSrc *invalid_inst_src;2132 IrInstSrc *invalid_inst_src;
...@@ -2206,18 +2148,9 @@ struct CodeGen {...@@ -2206,18 +2148,9 @@ struct CodeGen {
2206 Stage2ProgressNode *main_progress_node;2148 Stage2ProgressNode *main_progress_node;
2207 Stage2ProgressNode *sub_progress_node;2149 Stage2ProgressNode *sub_progress_node;
22082150
2209 WantPIC want_pic;
2210 WantStackCheck want_stack_check;
2211 WantCSanitize want_sanitize_c;
2212 CacheHash cache_hash;
2213 ErrColor err_color;2151 ErrColor err_color;
2214 uint32_t next_unresolved_index;2152 uint32_t next_unresolved_index;
2215 unsigned pointer_size_bytes;2153 unsigned pointer_size_bytes;
2216 uint32_t target_os_index;
2217 uint32_t target_arch_index;
2218 uint32_t target_sub_arch_index;
2219 uint32_t target_abi_index;
2220 uint32_t target_oformat_index;
2221 bool is_big_endian;2154 bool is_big_endian;
2222 bool have_c_main;2155 bool have_c_main;
2223 bool have_winmain;2156 bool have_winmain;
...@@ -2226,9 +2159,6 @@ struct CodeGen {...@@ -2226,9 +2159,6 @@ struct CodeGen {
2226 bool have_wwinmain_crt_startup;2159 bool have_wwinmain_crt_startup;
2227 bool have_dllmain_crt_startup;2160 bool have_dllmain_crt_startup;
2228 bool have_err_ret_tracing;2161 bool have_err_ret_tracing;
2229 bool link_eh_frame_hdr;
2230 bool c_want_stdint;
2231 bool c_want_stdbool;
2232 bool verbose_tokenize;2162 bool verbose_tokenize;
2233 bool verbose_ast;2163 bool verbose_ast;
2234 bool verbose_link;2164 bool verbose_link;
...@@ -2239,61 +2169,24 @@ struct CodeGen {...@@ -2239,61 +2169,24 @@ struct CodeGen {
2239 bool verbose_llvm_cpu_features;2169 bool verbose_llvm_cpu_features;
2240 bool error_during_imports;2170 bool error_during_imports;
2241 bool generate_error_name_table;2171 bool generate_error_name_table;
2242 bool enable_cache; // mutually exclusive with output_dir
2243 bool enable_time_report;2172 bool enable_time_report;
2244 bool enable_stack_report;2173 bool enable_stack_report;
2245 bool system_linker_hack;
2246 bool reported_bad_link_libc_error;2174 bool reported_bad_link_libc_error;
2247 bool is_dynamic; // shared library rather than static library. dynamic musl rather than static musl.
2248 bool need_frame_size_prefix_data;2175 bool need_frame_size_prefix_data;
2249 bool disable_c_depfile;2176 bool link_libc;
22502177 bool link_libcpp;
2251 //////////////////////////// Participates in Input Parameter Cache Hash
2252 /////// Note: there is a separate cache hash for builtin.zig, when adding fields,
2253 /////// consider if they need to go into both.
2254 ZigList<LinkLib *> link_libs_list;
2255 // add -framework [name] args to linker
2256 ZigList<Buf *> darwin_frameworks;
2257 // add -rpath [name] args to linker
2258 ZigList<Buf *> rpath_list;
2259 ZigList<Buf *> forbidden_libs;
2260 ZigList<Buf *> link_objects;
2261 ZigList<Buf *> assembly_files;
2262 ZigList<CFile *> c_source_files;
2263 ZigList<const char *> lib_dirs;
2264 ZigList<const char *> framework_dirs;
2265
2266 Stage2LibCInstallation *libc;
2267
2268 bool is_versioned;
2269 size_t version_major;
2270 size_t version_minor;
2271 size_t version_patch;
2272 const char *linker_script;
2273 size_t stack_size_override;
22742178
2275 BuildMode build_mode;2179 BuildMode build_mode;
2276 OutType out_type;
2277 const ZigTarget *zig_target;2180 const ZigTarget *zig_target;
2278 TargetSubsystem subsystem; // careful using this directly; see detect_subsystem2181 TargetSubsystem subsystem; // careful using this directly; see detect_subsystem
2279 ValgrindSupport valgrind_support;
2280 CodeModel code_model;2182 CodeModel code_model;
2281 OptionalBool linker_gc_sections;
2282 OptionalBool linker_allow_shlib_undefined;
2283 OptionalBool linker_bind_global_refs_locally;
2284 bool strip_debug_symbols;2183 bool strip_debug_symbols;
2285 bool is_test_build;2184 bool is_test_build;
2286 bool is_single_threaded;2185 bool is_single_threaded;
2287 bool want_single_threaded;
2288 bool linker_rdynamic;
2289 bool each_lib_rpath;
2290 bool is_dummy_so;
2291 bool disable_gen_h;
2292 bool bundle_compiler_rt;
2293 bool have_pic;2186 bool have_pic;
2294 bool have_dynamic_link; // this is whether the final thing will be dynamically linked. see also is_dynamic2187 bool link_mode_dynamic;
2188 bool dll_export_fns;
2295 bool have_stack_probing;2189 bool have_stack_probing;
2296 bool have_sanitize_c;
2297 bool function_sections;2190 bool function_sections;
2298 bool enable_dump_analysis;2191 bool enable_dump_analysis;
2299 bool enable_doc_generation;2192 bool enable_doc_generation;
...@@ -2301,23 +2194,13 @@ struct CodeGen {...@@ -2301,23 +2194,13 @@ struct CodeGen {
2301 bool emit_asm;2194 bool emit_asm;
2302 bool emit_llvm_ir;2195 bool emit_llvm_ir;
2303 bool test_is_evented;2196 bool test_is_evented;
2304 bool linker_z_nodelete;2197 bool valgrind_enabled;
2305 bool linker_z_defs;
23062198
2307 Buf *root_out_name;2199 Buf *root_out_name;
2308 Buf *test_filter;2200 Buf *test_filter;
2309 Buf *test_name_prefix;2201 Buf *test_name_prefix;
2310 Buf *zig_lib_dir;2202 Buf *zig_lib_dir;
2311 Buf *zig_std_dir;2203 Buf *zig_std_dir;
2312 Buf *version_script_path;
2313 Buf *override_soname;
2314 Buf *linker_optimization;
2315
2316 const char **llvm_argv;
2317 size_t llvm_argv_len;
2318
2319 const char **clang_argv;
2320 size_t clang_argv_len;
2321};2204};
23222205
2323struct ZigVar {2206struct ZigVar {
src/analyze.cpp+8-41
...@@ -3496,7 +3496,7 @@ void add_var_export(CodeGen *g, ZigVar *var, const char *symbol_name, GlobalLink...@@ -3496,7 +3496,7 @@ void add_var_export(CodeGen *g, ZigVar *var, const char *symbol_name, GlobalLink
3496}3496}
34973497
3498void add_fn_export(CodeGen *g, ZigFn *fn_table_entry, const char *symbol_name, GlobalLinkageId linkage, CallingConvention cc) {3498void add_fn_export(CodeGen *g, ZigFn *fn_table_entry, const char *symbol_name, GlobalLinkageId linkage, CallingConvention cc) {
3499 if (cc == CallingConventionC && strcmp(symbol_name, "main") == 0 && g->libc_link_lib != nullptr) {3499 if (cc == CallingConventionC && strcmp(symbol_name, "main") == 0 && g->link_libc) {
3500 g->have_c_main = true;3500 g->have_c_main = true;
3501 } else if (cc == CallingConventionStdcall && g->zig_target->os == OsWindows) {3501 } else if (cc == CallingConventionStdcall && g->zig_target->os == OsWindows) {
3502 if (strcmp(symbol_name, "WinMain") == 0) {3502 if (strcmp(symbol_name, "WinMain") == 0) {
...@@ -7863,40 +7863,6 @@ const char *type_id_name(ZigTypeId id) {...@@ -7863,40 +7863,6 @@ const char *type_id_name(ZigTypeId id) {
7863 zig_unreachable();7863 zig_unreachable();
7864}7864}
78657865
7866LinkLib *create_link_lib(Buf *name) {
7867 LinkLib *link_lib = heap::c_allocator.create<LinkLib>();
7868 link_lib->name = name;
7869 return link_lib;
7870}
7871
7872LinkLib *add_link_lib(CodeGen *g, Buf *name) {
7873 bool is_libc = buf_eql_str(name, "c");
7874 bool is_libcpp = buf_eql_str(name, "c++") || buf_eql_str(name, "c++abi");
7875
7876 if (is_libc && g->libc_link_lib != nullptr)
7877 return g->libc_link_lib;
7878
7879 if (is_libcpp && g->libcpp_link_lib != nullptr)
7880 return g->libcpp_link_lib;
7881
7882 for (size_t i = 0; i < g->link_libs_list.length; i += 1) {
7883 LinkLib *existing_lib = g->link_libs_list.at(i);
7884 if (buf_eql_buf(existing_lib->name, name)) {
7885 return existing_lib;
7886 }
7887 }
7888
7889 LinkLib *link_lib = create_link_lib(name);
7890 g->link_libs_list.append(link_lib);
7891
7892 if (is_libc)
7893 g->libc_link_lib = link_lib;
7894 if (is_libcpp)
7895 g->libcpp_link_lib = link_lib;
7896
7897 return link_lib;
7898}
7899
7900ZigType *get_align_amt_type(CodeGen *g) {7866ZigType *get_align_amt_type(CodeGen *g) {
7901 if (g->align_amt_type == nullptr) {7867 if (g->align_amt_type == nullptr) {
7902 // according to LLVM the maximum alignment is 1 << 29.7868 // according to LLVM the maximum alignment is 1 << 29.
...@@ -8017,12 +7983,13 @@ not_integer:...@@ -8017,12 +7983,13 @@ not_integer:
8017 return ErrorNone;7983 return ErrorNone;
8018}7984}
80197985
8020Error file_fetch(CodeGen *g, Buf *resolved_path, Buf *contents) {7986Error file_fetch(CodeGen *g, Buf *resolved_path, Buf *contents_buf) {
8021 if (g->enable_cache) {7987 size_t len;
8022 return cache_add_file_fetch(&g->cache_hash, resolved_path, contents);7988 const char *contents = stage2_fetch_file(&g->stage1, buf_ptr(resolved_path), buf_len(resolved_path), &len);
8023 } else {7989 if (contents == nullptr)
8024 return os_fetch_file_path(resolved_path, contents);7990 return ErrorNoMem;
8025 }7991 buf_init_from_mem(contents_buf, contents, len);
7992 return ErrorNone;
8026}7993}
80277994
8028static X64CABIClass type_windows_abi_x86_64_class(CodeGen *g, ZigType *ty, size_t ty_size) {7995static X64CABIClass type_windows_abi_x86_64_class(CodeGen *g, ZigType *ty, size_t ty_size) {
src/analyze.hpp-3
...@@ -200,8 +200,6 @@ ZigTypeId type_id_at_index(size_t index);...@@ -200,8 +200,6 @@ ZigTypeId type_id_at_index(size_t index);
200size_t type_id_len();200size_t type_id_len();
201size_t type_id_index(ZigType *entry);201size_t type_id_index(ZigType *entry);
202ZigType *get_generic_fn_type(CodeGen *g, FnTypeId *fn_type_id);202ZigType *get_generic_fn_type(CodeGen *g, FnTypeId *fn_type_id);
203LinkLib *create_link_lib(Buf *name);
204LinkLib *add_link_lib(CodeGen *codegen, Buf *lib);
205bool optional_value_is_null(ZigValue *val);203bool optional_value_is_null(ZigValue *val);
206204
207uint32_t get_abi_alignment(CodeGen *g, ZigType *type_entry);205uint32_t get_abi_alignment(CodeGen *g, ZigType *type_entry);
...@@ -256,7 +254,6 @@ Error ensure_const_val_repr(IrAnalyze *ira, CodeGen *codegen, AstNode *source_no...@@ -256,7 +254,6 @@ Error ensure_const_val_repr(IrAnalyze *ira, CodeGen *codegen, AstNode *source_no
256void typecheck_panic_fn(CodeGen *g, TldFn *tld_fn, ZigFn *panic_fn);254void typecheck_panic_fn(CodeGen *g, TldFn *tld_fn, ZigFn *panic_fn);
257Buf *type_bare_name(ZigType *t);255Buf *type_bare_name(ZigType *t);
258Buf *type_h_name(ZigType *t);256Buf *type_h_name(ZigType *t);
259Error create_c_object_cache(CodeGen *g, CacheHash **out_cache_hash, bool verbose);
260257
261LLVMTypeRef get_llvm_type(CodeGen *g, ZigType *type);258LLVMTypeRef get_llvm_type(CodeGen *g, ZigType *type);
262ZigLLVMDIType *get_llvm_di_type(CodeGen *g, ZigType *type);259ZigLLVMDIType *get_llvm_di_type(CodeGen *g, ZigType *type);
src/blake2.h deleted-196
...@@ -1,196 +0,0 @@
1/*
2 BLAKE2 reference source code package - reference C implementations
3
4 Copyright 2012, Samuel Neves <sneves@dei.uc.pt>. You may use this under the
5 terms of the CC0, the OpenSSL Licence, or the Apache Public License 2.0, at
6 your option. The terms of these licenses can be found at:
7
8 - CC0 1.0 Universal : http://creativecommons.org/publicdomain/zero/1.0
9 - OpenSSL license : https://www.openssl.org/source/license.html
10 - Apache 2.0 : http://www.apache.org/licenses/LICENSE-2.0
11
12 More information about the BLAKE2 hash function can be found at
13 https://blake2.net.
14*/
15#ifndef BLAKE2_H
16#define BLAKE2_H
17
18#include <stddef.h>
19#include <stdint.h>
20
21#if defined(_MSC_VER)
22#define BLAKE2_PACKED(x) __pragma(pack(push, 1)) x __pragma(pack(pop))
23#else
24#define BLAKE2_PACKED(x) x __attribute__((packed))
25#endif
26
27#if defined(__cplusplus)
28extern "C" {
29#endif
30
31 enum blake2s_constant
32 {
33 BLAKE2S_BLOCKBYTES = 64,
34 BLAKE2S_OUTBYTES = 32,
35 BLAKE2S_KEYBYTES = 32,
36 BLAKE2S_SALTBYTES = 8,
37 BLAKE2S_PERSONALBYTES = 8
38 };
39
40 enum blake2b_constant
41 {
42 BLAKE2B_BLOCKBYTES = 128,
43 BLAKE2B_OUTBYTES = 64,
44 BLAKE2B_KEYBYTES = 64,
45 BLAKE2B_SALTBYTES = 16,
46 BLAKE2B_PERSONALBYTES = 16
47 };
48
49 typedef struct blake2s_state__
50 {
51 uint32_t h[8];
52 uint32_t t[2];
53 uint32_t f[2];
54 uint8_t buf[BLAKE2S_BLOCKBYTES];
55 size_t buflen;
56 size_t outlen;
57 uint8_t last_node;
58 } blake2s_state;
59
60 typedef struct blake2b_state__
61 {
62 uint64_t h[8];
63 uint64_t t[2];
64 uint64_t f[2];
65 uint8_t buf[BLAKE2B_BLOCKBYTES];
66 size_t buflen;
67 size_t outlen;
68 uint8_t last_node;
69 } blake2b_state;
70
71 typedef struct blake2sp_state__
72 {
73 blake2s_state S[8][1];
74 blake2s_state R[1];
75 uint8_t buf[8 * BLAKE2S_BLOCKBYTES];
76 size_t buflen;
77 size_t outlen;
78 } blake2sp_state;
79
80 typedef struct blake2bp_state__
81 {
82 blake2b_state S[4][1];
83 blake2b_state R[1];
84 uint8_t buf[4 * BLAKE2B_BLOCKBYTES];
85 size_t buflen;
86 size_t outlen;
87 } blake2bp_state;
88
89
90 BLAKE2_PACKED(struct blake2s_param__
91 {
92 uint8_t digest_length; /* 1 */
93 uint8_t key_length; /* 2 */
94 uint8_t fanout; /* 3 */
95 uint8_t depth; /* 4 */
96 uint32_t leaf_length; /* 8 */
97 uint32_t node_offset; /* 12 */
98 uint16_t xof_length; /* 14 */
99 uint8_t node_depth; /* 15 */
100 uint8_t inner_length; /* 16 */
101 /* uint8_t reserved[0]; */
102 uint8_t salt[BLAKE2S_SALTBYTES]; /* 24 */
103 uint8_t personal[BLAKE2S_PERSONALBYTES]; /* 32 */
104 });
105
106 typedef struct blake2s_param__ blake2s_param;
107
108 BLAKE2_PACKED(struct blake2b_param__
109 {
110 uint8_t digest_length; /* 1 */
111 uint8_t key_length; /* 2 */
112 uint8_t fanout; /* 3 */
113 uint8_t depth; /* 4 */
114 uint32_t leaf_length; /* 8 */
115 uint32_t node_offset; /* 12 */
116 uint32_t xof_length; /* 16 */
117 uint8_t node_depth; /* 17 */
118 uint8_t inner_length; /* 18 */
119 uint8_t reserved[14]; /* 32 */
120 uint8_t salt[BLAKE2B_SALTBYTES]; /* 48 */
121 uint8_t personal[BLAKE2B_PERSONALBYTES]; /* 64 */
122 });
123
124 typedef struct blake2b_param__ blake2b_param;
125
126 typedef struct blake2xs_state__
127 {
128 blake2s_state S[1];
129 blake2s_param P[1];
130 } blake2xs_state;
131
132 typedef struct blake2xb_state__
133 {
134 blake2b_state S[1];
135 blake2b_param P[1];
136 } blake2xb_state;
137
138 /* Padded structs result in a compile-time error */
139 enum {
140 BLAKE2_DUMMY_1 = 1/(sizeof(blake2s_param) == BLAKE2S_OUTBYTES),
141 BLAKE2_DUMMY_2 = 1/(sizeof(blake2b_param) == BLAKE2B_OUTBYTES)
142 };
143
144 /* Streaming API */
145 int blake2s_init( blake2s_state *S, size_t outlen );
146 int blake2s_init_key( blake2s_state *S, size_t outlen, const void *key, size_t keylen );
147 int blake2s_init_param( blake2s_state *S, const blake2s_param *P );
148 int blake2s_update( blake2s_state *S, const void *in, size_t inlen );
149 int blake2s_final( blake2s_state *S, void *out, size_t outlen );
150
151 int blake2b_init( blake2b_state *S, size_t outlen );
152 int blake2b_init_key( blake2b_state *S, size_t outlen, const void *key, size_t keylen );
153 int blake2b_init_param( blake2b_state *S, const blake2b_param *P );
154 int blake2b_update( blake2b_state *S, const void *in, size_t inlen );
155 int blake2b_final( blake2b_state *S, void *out, size_t outlen );
156
157 int blake2sp_init( blake2sp_state *S, size_t outlen );
158 int blake2sp_init_key( blake2sp_state *S, size_t outlen, const void *key, size_t keylen );
159 int blake2sp_update( blake2sp_state *S, const void *in, size_t inlen );
160 int blake2sp_final( blake2sp_state *S, void *out, size_t outlen );
161
162 int blake2bp_init( blake2bp_state *S, size_t outlen );
163 int blake2bp_init_key( blake2bp_state *S, size_t outlen, const void *key, size_t keylen );
164 int blake2bp_update( blake2bp_state *S, const void *in, size_t inlen );
165 int blake2bp_final( blake2bp_state *S, void *out, size_t outlen );
166
167 /* Variable output length API */
168 int blake2xs_init( blake2xs_state *S, const size_t outlen );
169 int blake2xs_init_key( blake2xs_state *S, const size_t outlen, const void *key, size_t keylen );
170 int blake2xs_update( blake2xs_state *S, const void *in, size_t inlen );
171 int blake2xs_final(blake2xs_state *S, void *out, size_t outlen);
172
173 int blake2xb_init( blake2xb_state *S, const size_t outlen );
174 int blake2xb_init_key( blake2xb_state *S, const size_t outlen, const void *key, size_t keylen );
175 int blake2xb_update( blake2xb_state *S, const void *in, size_t inlen );
176 int blake2xb_final(blake2xb_state *S, void *out, size_t outlen);
177
178 /* Simple API */
179 int blake2s( void *out, size_t outlen, const void *in, size_t inlen, const void *key, size_t keylen );
180 int blake2b( void *out, size_t outlen, const void *in, size_t inlen, const void *key, size_t keylen );
181
182 int blake2sp( void *out, size_t outlen, const void *in, size_t inlen, const void *key, size_t keylen );
183 int blake2bp( void *out, size_t outlen, const void *in, size_t inlen, const void *key, size_t keylen );
184
185 int blake2xs( void *out, size_t outlen, const void *in, size_t inlen, const void *key, size_t keylen );
186 int blake2xb( void *out, size_t outlen, const void *in, size_t inlen, const void *key, size_t keylen );
187
188 /* This is simply an alias for blake2b */
189 int blake2( void *out, size_t outlen, const void *in, size_t inlen, const void *key, size_t keylen );
190
191#if defined(__cplusplus)
192}
193#endif
194
195#endif
196
src/blake2b.c deleted-539
...@@ -1,539 +0,0 @@
1/*
2 BLAKE2 reference source code package - reference C implementations
3
4 Copyright 2012, Samuel Neves <sneves@dei.uc.pt>. You may use this under the
5 terms of the CC0, the OpenSSL Licence, or the Apache Public License 2.0, at
6 your option. The terms of these licenses can be found at:
7
8 - CC0 1.0 Universal : http://creativecommons.org/publicdomain/zero/1.0
9 - OpenSSL license : https://www.openssl.org/source/license.html
10 - Apache 2.0 : http://www.apache.org/licenses/LICENSE-2.0
11
12 More information about the BLAKE2 hash function can be found at
13 https://blake2.net.
14*/
15
16#include <stdint.h>
17#include <string.h>
18#include <stdio.h>
19
20#include "blake2.h"
21/*
22 BLAKE2 reference source code package - reference C implementations
23
24 Copyright 2012, Samuel Neves <sneves@dei.uc.pt>. You may use this under the
25 terms of the CC0, the OpenSSL Licence, or the Apache Public License 2.0, at
26 your option. The terms of these licenses can be found at:
27
28 - CC0 1.0 Universal : http://creativecommons.org/publicdomain/zero/1.0
29 - OpenSSL license : https://www.openssl.org/source/license.html
30 - Apache 2.0 : http://www.apache.org/licenses/LICENSE-2.0
31
32 More information about the BLAKE2 hash function can be found at
33 https://blake2.net.
34*/
35#ifndef BLAKE2_IMPL_H
36#define BLAKE2_IMPL_H
37
38#include <stdint.h>
39#include <string.h>
40
41#if !defined(__cplusplus) && (!defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L)
42 #if defined(_MSC_VER)
43 #define BLAKE2_INLINE __inline
44 #elif defined(__GNUC__)
45 #define BLAKE2_INLINE __inline__
46 #else
47 #define BLAKE2_INLINE
48 #endif
49#else
50 #define BLAKE2_INLINE inline
51#endif
52
53static BLAKE2_INLINE uint32_t load32( const void *src )
54{
55#if defined(NATIVE_LITTLE_ENDIAN)
56 uint32_t w;
57 memcpy(&w, src, sizeof w);
58 return w;
59#else
60 const uint8_t *p = ( const uint8_t * )src;
61 return (( uint32_t )( p[0] ) << 0) |
62 (( uint32_t )( p[1] ) << 8) |
63 (( uint32_t )( p[2] ) << 16) |
64 (( uint32_t )( p[3] ) << 24) ;
65#endif
66}
67
68static BLAKE2_INLINE uint64_t load64( const void *src )
69{
70#if defined(NATIVE_LITTLE_ENDIAN)
71 uint64_t w;
72 memcpy(&w, src, sizeof w);
73 return w;
74#else
75 const uint8_t *p = ( const uint8_t * )src;
76 return (( uint64_t )( p[0] ) << 0) |
77 (( uint64_t )( p[1] ) << 8) |
78 (( uint64_t )( p[2] ) << 16) |
79 (( uint64_t )( p[3] ) << 24) |
80 (( uint64_t )( p[4] ) << 32) |
81 (( uint64_t )( p[5] ) << 40) |
82 (( uint64_t )( p[6] ) << 48) |
83 (( uint64_t )( p[7] ) << 56) ;
84#endif
85}
86
87static BLAKE2_INLINE uint16_t load16( const void *src )
88{
89#if defined(NATIVE_LITTLE_ENDIAN)
90 uint16_t w;
91 memcpy(&w, src, sizeof w);
92 return w;
93#else
94 const uint8_t *p = ( const uint8_t * )src;
95 return ( uint16_t )((( uint32_t )( p[0] ) << 0) |
96 (( uint32_t )( p[1] ) << 8));
97#endif
98}
99
100static BLAKE2_INLINE void store16( void *dst, uint16_t w )
101{
102#if defined(NATIVE_LITTLE_ENDIAN)
103 memcpy(dst, &w, sizeof w);
104#else
105 uint8_t *p = ( uint8_t * )dst;
106 *p++ = ( uint8_t )w; w >>= 8;
107 *p++ = ( uint8_t )w;
108#endif
109}
110
111static BLAKE2_INLINE void store32( void *dst, uint32_t w )
112{
113#if defined(NATIVE_LITTLE_ENDIAN)
114 memcpy(dst, &w, sizeof w);
115#else
116 uint8_t *p = ( uint8_t * )dst;
117 p[0] = (uint8_t)(w >> 0);
118 p[1] = (uint8_t)(w >> 8);
119 p[2] = (uint8_t)(w >> 16);
120 p[3] = (uint8_t)(w >> 24);
121#endif
122}
123
124static BLAKE2_INLINE void store64( void *dst, uint64_t w )
125{
126#if defined(NATIVE_LITTLE_ENDIAN)
127 memcpy(dst, &w, sizeof w);
128#else
129 uint8_t *p = ( uint8_t * )dst;
130 p[0] = (uint8_t)(w >> 0);
131 p[1] = (uint8_t)(w >> 8);
132 p[2] = (uint8_t)(w >> 16);
133 p[3] = (uint8_t)(w >> 24);
134 p[4] = (uint8_t)(w >> 32);
135 p[5] = (uint8_t)(w >> 40);
136 p[6] = (uint8_t)(w >> 48);
137 p[7] = (uint8_t)(w >> 56);
138#endif
139}
140
141static BLAKE2_INLINE uint64_t load48( const void *src )
142{
143 const uint8_t *p = ( const uint8_t * )src;
144 return (( uint64_t )( p[0] ) << 0) |
145 (( uint64_t )( p[1] ) << 8) |
146 (( uint64_t )( p[2] ) << 16) |
147 (( uint64_t )( p[3] ) << 24) |
148 (( uint64_t )( p[4] ) << 32) |
149 (( uint64_t )( p[5] ) << 40) ;
150}
151
152static BLAKE2_INLINE void store48( void *dst, uint64_t w )
153{
154 uint8_t *p = ( uint8_t * )dst;
155 p[0] = (uint8_t)(w >> 0);
156 p[1] = (uint8_t)(w >> 8);
157 p[2] = (uint8_t)(w >> 16);
158 p[3] = (uint8_t)(w >> 24);
159 p[4] = (uint8_t)(w >> 32);
160 p[5] = (uint8_t)(w >> 40);
161}
162
163static BLAKE2_INLINE uint32_t rotr32( const uint32_t w, const unsigned c )
164{
165 return ( w >> c ) | ( w << ( 32 - c ) );
166}
167
168static BLAKE2_INLINE uint64_t rotr64( const uint64_t w, const unsigned c )
169{
170 return ( w >> c ) | ( w << ( 64 - c ) );
171}
172
173/* prevents compiler optimizing out memset() */
174static BLAKE2_INLINE void secure_zero_memory(void *v, size_t n)
175{
176 static void *(*const volatile memset_v)(void *, int, size_t) = &memset;
177 memset_v(v, 0, n);
178}
179
180#endif
181
182static const uint64_t blake2b_IV[8] =
183{
184 0x6a09e667f3bcc908ULL, 0xbb67ae8584caa73bULL,
185 0x3c6ef372fe94f82bULL, 0xa54ff53a5f1d36f1ULL,
186 0x510e527fade682d1ULL, 0x9b05688c2b3e6c1fULL,
187 0x1f83d9abfb41bd6bULL, 0x5be0cd19137e2179ULL
188};
189
190static const uint8_t blake2b_sigma[12][16] =
191{
192 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 } ,
193 { 14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3 } ,
194 { 11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4 } ,
195 { 7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8 } ,
196 { 9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13 } ,
197 { 2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9 } ,
198 { 12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11 } ,
199 { 13, 11, 7, 14, 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10 } ,
200 { 6, 15, 14, 9, 11, 3, 0, 8, 12, 2, 13, 7, 1, 4, 10, 5 } ,
201 { 10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13 , 0 } ,
202 { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 } ,
203 { 14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3 }
204};
205
206
207static void blake2b_set_lastnode( blake2b_state *S )
208{
209 S->f[1] = (uint64_t)-1;
210}
211
212/* Some helper functions, not necessarily useful */
213static int blake2b_is_lastblock( const blake2b_state *S )
214{
215 return S->f[0] != 0;
216}
217
218static void blake2b_set_lastblock( blake2b_state *S )
219{
220 if( S->last_node ) blake2b_set_lastnode( S );
221
222 S->f[0] = (uint64_t)-1;
223}
224
225static void blake2b_increment_counter( blake2b_state *S, const uint64_t inc )
226{
227 S->t[0] += inc;
228 S->t[1] += ( S->t[0] < inc );
229}
230
231static void blake2b_init0( blake2b_state *S )
232{
233 size_t i;
234 memset( S, 0, sizeof( blake2b_state ) );
235
236 for( i = 0; i < 8; ++i ) S->h[i] = blake2b_IV[i];
237}
238
239/* init xors IV with input parameter block */
240int blake2b_init_param( blake2b_state *S, const blake2b_param *P )
241{
242 const uint8_t *p = ( const uint8_t * )( P );
243 size_t i;
244
245 blake2b_init0( S );
246
247 /* IV XOR ParamBlock */
248 for( i = 0; i < 8; ++i )
249 S->h[i] ^= load64( p + sizeof( S->h[i] ) * i );
250
251 S->outlen = P->digest_length;
252 return 0;
253}
254
255
256
257int blake2b_init( blake2b_state *S, size_t outlen )
258{
259 blake2b_param P[1];
260
261 if ( ( !outlen ) || ( outlen > BLAKE2B_OUTBYTES ) ) return -1;
262
263 P->digest_length = (uint8_t)outlen;
264 P->key_length = 0;
265 P->fanout = 1;
266 P->depth = 1;
267 store32( &P->leaf_length, 0 );
268 store32( &P->node_offset, 0 );
269 store32( &P->xof_length, 0 );
270 P->node_depth = 0;
271 P->inner_length = 0;
272 memset( P->reserved, 0, sizeof( P->reserved ) );
273 memset( P->salt, 0, sizeof( P->salt ) );
274 memset( P->personal, 0, sizeof( P->personal ) );
275 return blake2b_init_param( S, P );
276}
277
278
279int blake2b_init_key( blake2b_state *S, size_t outlen, const void *key, size_t keylen )
280{
281 blake2b_param P[1];
282
283 if ( ( !outlen ) || ( outlen > BLAKE2B_OUTBYTES ) ) return -1;
284
285 if ( !key || !keylen || keylen > BLAKE2B_KEYBYTES ) return -1;
286
287 P->digest_length = (uint8_t)outlen;
288 P->key_length = (uint8_t)keylen;
289 P->fanout = 1;
290 P->depth = 1;
291 store32( &P->leaf_length, 0 );
292 store32( &P->node_offset, 0 );
293 store32( &P->xof_length, 0 );
294 P->node_depth = 0;
295 P->inner_length = 0;
296 memset( P->reserved, 0, sizeof( P->reserved ) );
297 memset( P->salt, 0, sizeof( P->salt ) );
298 memset( P->personal, 0, sizeof( P->personal ) );
299
300 if( blake2b_init_param( S, P ) < 0 ) return -1;
301
302 {
303 uint8_t block[BLAKE2B_BLOCKBYTES];
304 memset( block, 0, BLAKE2B_BLOCKBYTES );
305 memcpy( block, key, keylen );
306 blake2b_update( S, block, BLAKE2B_BLOCKBYTES );
307 secure_zero_memory( block, BLAKE2B_BLOCKBYTES ); /* Burn the key from stack */
308 }
309 return 0;
310}
311
312#define G(r,i,a,b,c,d) \
313 do { \
314 a = a + b + m[blake2b_sigma[r][2*i+0]]; \
315 d = rotr64(d ^ a, 32); \
316 c = c + d; \
317 b = rotr64(b ^ c, 24); \
318 a = a + b + m[blake2b_sigma[r][2*i+1]]; \
319 d = rotr64(d ^ a, 16); \
320 c = c + d; \
321 b = rotr64(b ^ c, 63); \
322 } while(0)
323
324#define ROUND(r) \
325 do { \
326 G(r,0,v[ 0],v[ 4],v[ 8],v[12]); \
327 G(r,1,v[ 1],v[ 5],v[ 9],v[13]); \
328 G(r,2,v[ 2],v[ 6],v[10],v[14]); \
329 G(r,3,v[ 3],v[ 7],v[11],v[15]); \
330 G(r,4,v[ 0],v[ 5],v[10],v[15]); \
331 G(r,5,v[ 1],v[ 6],v[11],v[12]); \
332 G(r,6,v[ 2],v[ 7],v[ 8],v[13]); \
333 G(r,7,v[ 3],v[ 4],v[ 9],v[14]); \
334 } while(0)
335
336static void blake2b_compress( blake2b_state *S, const uint8_t block[BLAKE2B_BLOCKBYTES] )
337{
338 uint64_t m[16];
339 uint64_t v[16];
340 size_t i;
341
342 for( i = 0; i < 16; ++i ) {
343 m[i] = load64( block + i * sizeof( m[i] ) );
344 }
345
346 for( i = 0; i < 8; ++i ) {
347 v[i] = S->h[i];
348 }
349
350 v[ 8] = blake2b_IV[0];
351 v[ 9] = blake2b_IV[1];
352 v[10] = blake2b_IV[2];
353 v[11] = blake2b_IV[3];
354 v[12] = blake2b_IV[4] ^ S->t[0];
355 v[13] = blake2b_IV[5] ^ S->t[1];
356 v[14] = blake2b_IV[6] ^ S->f[0];
357 v[15] = blake2b_IV[7] ^ S->f[1];
358
359 ROUND( 0 );
360 ROUND( 1 );
361 ROUND( 2 );
362 ROUND( 3 );
363 ROUND( 4 );
364 ROUND( 5 );
365 ROUND( 6 );
366 ROUND( 7 );
367 ROUND( 8 );
368 ROUND( 9 );
369 ROUND( 10 );
370 ROUND( 11 );
371
372 for( i = 0; i < 8; ++i ) {
373 S->h[i] = S->h[i] ^ v[i] ^ v[i + 8];
374 }
375}
376
377#undef G
378#undef ROUND
379
380int blake2b_update( blake2b_state *S, const void *pin, size_t inlen )
381{
382 const unsigned char * in = (const unsigned char *)pin;
383 if( inlen > 0 )
384 {
385 size_t left = S->buflen;
386 size_t fill = BLAKE2B_BLOCKBYTES - left;
387 if( inlen > fill )
388 {
389 S->buflen = 0;
390 memcpy( S->buf + left, in, fill ); /* Fill buffer */
391 blake2b_increment_counter( S, BLAKE2B_BLOCKBYTES );
392 blake2b_compress( S, S->buf ); /* Compress */
393 in += fill; inlen -= fill;
394 while(inlen > BLAKE2B_BLOCKBYTES) {
395 blake2b_increment_counter(S, BLAKE2B_BLOCKBYTES);
396 blake2b_compress( S, in );
397 in += BLAKE2B_BLOCKBYTES;
398 inlen -= BLAKE2B_BLOCKBYTES;
399 }
400 }
401 memcpy( S->buf + S->buflen, in, inlen );
402 S->buflen += inlen;
403 }
404 return 0;
405}
406
407int blake2b_final( blake2b_state *S, void *out, size_t outlen )
408{
409 uint8_t buffer[BLAKE2B_OUTBYTES] = {0};
410 size_t i;
411
412 if( out == NULL || outlen < S->outlen )
413 return -1;
414
415 if( blake2b_is_lastblock( S ) )
416 return -1;
417
418 blake2b_increment_counter( S, S->buflen );
419 blake2b_set_lastblock( S );
420 memset( S->buf + S->buflen, 0, BLAKE2B_BLOCKBYTES - S->buflen ); /* Padding */
421 blake2b_compress( S, S->buf );
422
423 for( i = 0; i < 8; ++i ) /* Output full hash to temp buffer */
424 store64( buffer + sizeof( S->h[i] ) * i, S->h[i] );
425
426 memcpy( out, buffer, S->outlen );
427 secure_zero_memory(buffer, sizeof(buffer));
428 return 0;
429}
430
431/* inlen, at least, should be uint64_t. Others can be size_t. */
432int blake2b( void *out, size_t outlen, const void *in, size_t inlen, const void *key, size_t keylen )
433{
434 blake2b_state S[1];
435
436 /* Verify parameters */
437 if ( NULL == in && inlen > 0 ) return -1;
438
439 if ( NULL == out ) return -1;
440
441 if( NULL == key && keylen > 0 ) return -1;
442
443 if( !outlen || outlen > BLAKE2B_OUTBYTES ) return -1;
444
445 if( keylen > BLAKE2B_KEYBYTES ) return -1;
446
447 if( keylen > 0 )
448 {
449 if( blake2b_init_key( S, outlen, key, keylen ) < 0 ) return -1;
450 }
451 else
452 {
453 if( blake2b_init( S, outlen ) < 0 ) return -1;
454 }
455
456 blake2b_update( S, ( const uint8_t * )in, inlen );
457 blake2b_final( S, out, outlen );
458 return 0;
459}
460
461int blake2( void *out, size_t outlen, const void *in, size_t inlen, const void *key, size_t keylen ) {
462 return blake2b(out, outlen, in, inlen, key, keylen);
463}
464
465#if defined(SUPERCOP)
466int crypto_hash( unsigned char *out, unsigned char *in, unsigned long long inlen )
467{
468 return blake2b( out, BLAKE2B_OUTBYTES, in, inlen, NULL, 0 );
469}
470#endif
471
472#if defined(BLAKE2B_SELFTEST)
473#include <string.h>
474#include "blake2-kat.h"
475int main( void )
476{
477 uint8_t key[BLAKE2B_KEYBYTES];
478 uint8_t buf[BLAKE2_KAT_LENGTH];
479 size_t i, step;
480
481 for( i = 0; i < BLAKE2B_KEYBYTES; ++i )
482 key[i] = ( uint8_t )i;
483
484 for( i = 0; i < BLAKE2_KAT_LENGTH; ++i )
485 buf[i] = ( uint8_t )i;
486
487 /* Test simple API */
488 for( i = 0; i < BLAKE2_KAT_LENGTH; ++i )
489 {
490 uint8_t hash[BLAKE2B_OUTBYTES];
491 blake2b( hash, BLAKE2B_OUTBYTES, buf, i, key, BLAKE2B_KEYBYTES );
492
493 if( 0 != memcmp( hash, blake2b_keyed_kat[i], BLAKE2B_OUTBYTES ) )
494 {
495 goto fail;
496 }
497 }
498
499 /* Test streaming API */
500 for(step = 1; step < BLAKE2B_BLOCKBYTES; ++step) {
501 for (i = 0; i < BLAKE2_KAT_LENGTH; ++i) {
502 uint8_t hash[BLAKE2B_OUTBYTES];
503 blake2b_state S;
504 uint8_t * p = buf;
505 size_t mlen = i;
506 int err = 0;
507
508 if( (err = blake2b_init_key(&S, BLAKE2B_OUTBYTES, key, BLAKE2B_KEYBYTES)) < 0 ) {
509 goto fail;
510 }
511
512 while (mlen >= step) {
513 if ( (err = blake2b_update(&S, p, step)) < 0 ) {
514 goto fail;
515 }
516 mlen -= step;
517 p += step;
518 }
519 if ( (err = blake2b_update(&S, p, mlen)) < 0) {
520 goto fail;
521 }
522 if ( (err = blake2b_final(&S, hash, BLAKE2B_OUTBYTES)) < 0) {
523 goto fail;
524 }
525
526 if (0 != memcmp(hash, blake2b_keyed_kat[i], BLAKE2B_OUTBYTES)) {
527 goto fail;
528 }
529 }
530 }
531
532 puts( "ok" );
533 return 0;
534fail:
535 puts("error");
536 return -1;
537}
538#endif
539
src/cache_hash.cpp deleted-595
...@@ -1,595 +0,0 @@
1/*
2 * Copyright (c) 2018 Andrew Kelley
3 *
4 * This file is part of zig, which is MIT licensed.
5 * See http://opensource.org/licenses/MIT
6 */
7
8#include "stage2.h"
9#include "cache_hash.hpp"
10#include "all_types.hpp"
11#include "buffer.hpp"
12#include "os.hpp"
13
14#include <stdio.h>
15
16void cache_init(CacheHash *ch, Buf *manifest_dir) {
17 int rc = blake2b_init(&ch->blake, 48);
18 assert(rc == 0);
19 ch->files = {};
20 ch->manifest_dir = manifest_dir;
21 ch->manifest_file_path = nullptr;
22 ch->manifest_dirty = false;
23 ch->force_check_manifest = false;
24 ch->b64_digest = BUF_INIT;
25}
26
27void cache_mem(CacheHash *ch, const char *ptr, size_t len) {
28 assert(ch->manifest_file_path == nullptr);
29 assert(ptr != nullptr);
30 blake2b_update(&ch->blake, ptr, len);
31}
32
33void cache_slice(CacheHash *ch, Slice<const char> slice) {
34 // mix the length into the hash so that two juxtaposed cached slices can't collide
35 cache_usize(ch, slice.len);
36 cache_mem(ch, slice.ptr, slice.len);
37}
38
39void cache_str(CacheHash *ch, const char *ptr) {
40 // + 1 to include the null byte
41 cache_mem(ch, ptr, strlen(ptr) + 1);
42}
43
44void cache_int(CacheHash *ch, int x) {
45 assert(ch->manifest_file_path == nullptr);
46 // + 1 to include the null byte
47 uint8_t buf[sizeof(int) + 1];
48 memcpy(buf, &x, sizeof(int));
49 buf[sizeof(int)] = 0;
50 blake2b_update(&ch->blake, buf, sizeof(int) + 1);
51}
52
53void cache_usize(CacheHash *ch, size_t x) {
54 assert(ch->manifest_file_path == nullptr);
55 // + 1 to include the null byte
56 uint8_t buf[sizeof(size_t) + 1];
57 memcpy(buf, &x, sizeof(size_t));
58 buf[sizeof(size_t)] = 0;
59 blake2b_update(&ch->blake, buf, sizeof(size_t) + 1);
60}
61
62void cache_bool(CacheHash *ch, bool x) {
63 assert(ch->manifest_file_path == nullptr);
64 blake2b_update(&ch->blake, &x, 1);
65}
66
67void cache_buf(CacheHash *ch, Buf *buf) {
68 assert(ch->manifest_file_path == nullptr);
69 assert(buf != nullptr);
70 // + 1 to include the null byte
71 blake2b_update(&ch->blake, buf_ptr(buf), buf_len(buf) + 1);
72}
73
74void cache_buf_opt(CacheHash *ch, Buf *buf) {
75 assert(ch->manifest_file_path == nullptr);
76 if (buf == nullptr) {
77 cache_str(ch, "");
78 cache_str(ch, "");
79 } else {
80 cache_buf(ch, buf);
81 }
82}
83
84void cache_list_of_link_lib(CacheHash *ch, LinkLib **ptr, size_t len) {
85 assert(ch->manifest_file_path == nullptr);
86 for (size_t i = 0; i < len; i += 1) {
87 LinkLib *lib = ptr[i];
88 if (lib->provided_explicitly) {
89 cache_buf(ch, lib->name);
90 }
91 }
92 cache_str(ch, "");
93}
94
95void cache_list_of_buf(CacheHash *ch, Buf **ptr, size_t len) {
96 assert(ch->manifest_file_path == nullptr);
97 for (size_t i = 0; i < len; i += 1) {
98 Buf *buf = ptr[i];
99 cache_buf(ch, buf);
100 }
101 cache_str(ch, "");
102}
103
104void cache_list_of_file(CacheHash *ch, Buf **ptr, size_t len) {
105 assert(ch->manifest_file_path == nullptr);
106
107 for (size_t i = 0; i < len; i += 1) {
108 Buf *buf = ptr[i];
109 cache_file(ch, buf);
110 }
111 cache_str(ch, "");
112}
113
114void cache_list_of_str(CacheHash *ch, const char **ptr, size_t len) {
115 assert(ch->manifest_file_path == nullptr);
116
117 for (size_t i = 0; i < len; i += 1) {
118 const char *s = ptr[i];
119 cache_str(ch, s);
120 }
121 cache_str(ch, "");
122}
123
124void cache_file(CacheHash *ch, Buf *file_path) {
125 assert(ch->manifest_file_path == nullptr);
126 assert(file_path != nullptr);
127 Buf *resolved_path = buf_alloc();
128 *resolved_path = os_path_resolve(&file_path, 1);
129 CacheHashFile *chf = ch->files.add_one();
130 chf->path = resolved_path;
131 cache_buf(ch, resolved_path);
132}
133
134void cache_file_opt(CacheHash *ch, Buf *file_path) {
135 assert(ch->manifest_file_path == nullptr);
136 if (file_path == nullptr) {
137 cache_str(ch, "");
138 cache_str(ch, "");
139 } else {
140 cache_file(ch, file_path);
141 }
142}
143
144// Ported from std/base64.zig
145static uint8_t base64_fs_alphabet[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
146static void base64_encode(Slice<uint8_t> dest, Slice<uint8_t> source) {
147 size_t dest_len = ((source.len + 2) / 3) * 4;
148 assert(dest.len == dest_len);
149
150 size_t i = 0;
151 size_t out_index = 0;
152 for (; i + 2 < source.len; i += 3) {
153 dest.ptr[out_index] = base64_fs_alphabet[(source.ptr[i] >> 2) & 0x3f];
154 out_index += 1;
155
156 dest.ptr[out_index] = base64_fs_alphabet[((source.ptr[i] & 0x3) << 4) | ((source.ptr[i + 1] & 0xf0) >> 4)];
157 out_index += 1;
158
159 dest.ptr[out_index] = base64_fs_alphabet[((source.ptr[i + 1] & 0xf) << 2) | ((source.ptr[i + 2] & 0xc0) >> 6)];
160 out_index += 1;
161
162 dest.ptr[out_index] = base64_fs_alphabet[source.ptr[i + 2] & 0x3f];
163 out_index += 1;
164 }
165
166 // Assert that we never need pad characters.
167 assert(i == source.len);
168}
169
170// Ported from std/base64.zig
171static Error base64_decode(Slice<uint8_t> dest, Slice<uint8_t> source) {
172 if (source.len % 4 != 0)
173 return ErrorInvalidFormat;
174 if (dest.len != (source.len / 4) * 3)
175 return ErrorInvalidFormat;
176
177 // In Zig this is comptime computed. In C++ it's not worth it to do that.
178 uint8_t char_to_index[256];
179 bool char_in_alphabet[256] = {0};
180 for (size_t i = 0; i < 64; i += 1) {
181 uint8_t c = base64_fs_alphabet[i];
182 assert(!char_in_alphabet[c]);
183 char_in_alphabet[c] = true;
184 char_to_index[c] = i;
185 }
186
187 size_t src_cursor = 0;
188 size_t dest_cursor = 0;
189
190 for (;src_cursor < source.len; src_cursor += 4) {
191 if (!char_in_alphabet[source.ptr[src_cursor + 0]]) return ErrorInvalidFormat;
192 if (!char_in_alphabet[source.ptr[src_cursor + 1]]) return ErrorInvalidFormat;
193 if (!char_in_alphabet[source.ptr[src_cursor + 2]]) return ErrorInvalidFormat;
194 if (!char_in_alphabet[source.ptr[src_cursor + 3]]) return ErrorInvalidFormat;
195 dest.ptr[dest_cursor + 0] = (char_to_index[source.ptr[src_cursor + 0]] << 2) | (char_to_index[source.ptr[src_cursor + 1]] >> 4);
196 dest.ptr[dest_cursor + 1] = (char_to_index[source.ptr[src_cursor + 1]] << 4) | (char_to_index[source.ptr[src_cursor + 2]] >> 2);
197 dest.ptr[dest_cursor + 2] = (char_to_index[source.ptr[src_cursor + 2]] << 6) | (char_to_index[source.ptr[src_cursor + 3]]);
198 dest_cursor += 3;
199 }
200
201 assert(src_cursor == source.len);
202 assert(dest_cursor == dest.len);
203 return ErrorNone;
204}
205
206static Error hash_file(uint8_t *digest, OsFile handle, Buf *contents) {
207 Error err;
208
209 if (contents) {
210 buf_resize(contents, 0);
211 }
212
213 blake2b_state blake;
214 int rc = blake2b_init(&blake, 48);
215 assert(rc == 0);
216
217 for (;;) {
218 uint8_t buf[4096];
219 size_t amt = 4096;
220 if ((err = os_file_read(handle, buf, &amt)))
221 return err;
222 if (amt == 0) {
223 rc = blake2b_final(&blake, digest, 48);
224 assert(rc == 0);
225 return ErrorNone;
226 }
227 blake2b_update(&blake, buf, amt);
228 if (contents) {
229 buf_append_mem(contents, (char*)buf, amt);
230 }
231 }
232}
233
234// If the wall clock time, rounded to the same precision as the
235// mtime, is equal to the mtime, then we cannot rely on this mtime
236// yet. We will instead save an mtime value that indicates the hash
237// must be unconditionally computed.
238static bool is_problematic_timestamp(const OsTimeStamp *fs_clock) {
239 OsTimeStamp wall_clock = os_timestamp_calendar();
240 // First make all the least significant zero bits in the fs_clock, also zero bits in the wall clock.
241 if (fs_clock->nsec == 0) {
242 wall_clock.nsec = 0;
243 if (fs_clock->sec == 0) {
244 wall_clock.sec = 0;
245 } else {
246 wall_clock.sec &= (-1ull) << ctzll(fs_clock->sec);
247 }
248 } else {
249 wall_clock.nsec &= (-1ull) << ctzll(fs_clock->nsec);
250 }
251 return wall_clock.nsec == fs_clock->nsec && wall_clock.sec == fs_clock->sec;
252}
253
254static Error populate_file_hash(CacheHash *ch, CacheHashFile *chf, Buf *contents) {
255 Error err;
256
257 assert(chf->path != nullptr);
258
259 OsFile this_file;
260 if ((err = os_file_open_r(chf->path, &this_file, &chf->attr)))
261 return err;
262
263 if (is_problematic_timestamp(&chf->attr.mtime)) {
264 chf->attr.mtime.sec = 0;
265 chf->attr.mtime.nsec = 0;
266 chf->attr.inode = 0;
267 }
268
269 if ((err = hash_file(chf->bin_digest, this_file, contents))) {
270 os_file_close(&this_file);
271 return err;
272 }
273 os_file_close(&this_file);
274
275 blake2b_update(&ch->blake, chf->bin_digest, 48);
276
277 return ErrorNone;
278}
279
280Error cache_hit(CacheHash *ch, Buf *out_digest) {
281 Error err;
282
283 uint8_t bin_digest[48];
284 int rc = blake2b_final(&ch->blake, bin_digest, 48);
285 assert(rc == 0);
286
287 buf_resize(&ch->b64_digest, 64);
288 base64_encode(buf_to_slice(&ch->b64_digest), {bin_digest, 48});
289
290 if (ch->files.length == 0 && !ch->force_check_manifest) {
291 buf_resize(out_digest, 64);
292 base64_encode(buf_to_slice(out_digest), {bin_digest, 48});
293 return ErrorNone;
294 }
295
296 rc = blake2b_init(&ch->blake, 48);
297 assert(rc == 0);
298 blake2b_update(&ch->blake, bin_digest, 48);
299
300 ch->manifest_file_path = buf_alloc();
301 os_path_join(ch->manifest_dir, &ch->b64_digest, ch->manifest_file_path);
302
303 buf_append_str(ch->manifest_file_path, ".txt");
304
305 if ((err = os_make_path(ch->manifest_dir)))
306 return err;
307
308 if ((err = os_file_open_lock_rw(ch->manifest_file_path, &ch->manifest_file)))
309 return err;
310
311 Buf line_buf = BUF_INIT;
312 buf_resize(&line_buf, 512);
313 if ((err = os_file_read_all(ch->manifest_file, &line_buf))) {
314 os_file_close(&ch->manifest_file);
315 return err;
316 }
317
318 size_t input_file_count = ch->files.length;
319 bool any_file_changed = false;
320 Error return_code = ErrorNone;
321 size_t file_i = 0;
322 SplitIterator line_it = memSplit(buf_to_slice(&line_buf), str("\n"));
323 for (;; file_i += 1) {
324 Optional<Slice<uint8_t>> opt_line = SplitIterator_next(&line_it);
325
326 CacheHashFile *chf;
327 if (file_i < input_file_count) {
328 chf = &ch->files.at(file_i);
329 } else if (any_file_changed) {
330 // cache miss.
331 // keep the manifest file open with the rw lock
332 // reset the hash
333 rc = blake2b_init(&ch->blake, 48);
334 assert(rc == 0);
335 blake2b_update(&ch->blake, bin_digest, 48);
336 ch->files.resize(input_file_count);
337 // bring the hash up to the input file hashes
338 for (file_i = 0; file_i < input_file_count; file_i += 1) {
339 blake2b_update(&ch->blake, ch->files.at(file_i).bin_digest, 48);
340 }
341 // caller can notice that out_digest is unmodified.
342 return return_code;
343 } else if (!opt_line.is_some) {
344 break;
345 } else {
346 chf = ch->files.add_one();
347 chf->path = nullptr;
348 }
349
350 if (!opt_line.is_some)
351 break;
352
353 SplitIterator it = memSplit(opt_line.value, str(" "));
354
355 Optional<Slice<uint8_t>> opt_inode = SplitIterator_next(&it);
356 if (!opt_inode.is_some) {
357 return_code = ErrorInvalidFormat;
358 break;
359 }
360 chf->attr.inode = strtoull((const char *)opt_inode.value.ptr, nullptr, 10);
361
362 Optional<Slice<uint8_t>> opt_mtime_sec = SplitIterator_next(&it);
363 if (!opt_mtime_sec.is_some) {
364 return_code = ErrorInvalidFormat;
365 break;
366 }
367 chf->attr.mtime.sec = strtoull((const char *)opt_mtime_sec.value.ptr, nullptr, 10);
368
369 Optional<Slice<uint8_t>> opt_mtime_nsec = SplitIterator_next(&it);
370 if (!opt_mtime_nsec.is_some) {
371 return_code = ErrorInvalidFormat;
372 break;
373 }
374 chf->attr.mtime.nsec = strtoull((const char *)opt_mtime_nsec.value.ptr, nullptr, 10);
375
376 Optional<Slice<uint8_t>> opt_digest = SplitIterator_next(&it);
377 if (!opt_digest.is_some) {
378 return_code = ErrorInvalidFormat;
379 break;
380 }
381 if ((err = base64_decode({chf->bin_digest, 48}, opt_digest.value))) {
382 return_code = ErrorInvalidFormat;
383 break;
384 }
385
386 Slice<uint8_t> file_path = SplitIterator_rest(&it);
387 if (file_path.len == 0) {
388 return_code = ErrorInvalidFormat;
389 break;
390 }
391 Buf *this_path = buf_create_from_slice(file_path);
392 if (chf->path != nullptr && !buf_eql_buf(this_path, chf->path)) {
393 return_code = ErrorInvalidFormat;
394 break;
395 }
396 chf->path = this_path;
397
398 // if the mtime matches we can trust the digest
399 OsFile this_file;
400 OsFileAttr actual_attr;
401 if ((err = os_file_open_r(chf->path, &this_file, &actual_attr))) {
402 fprintf(stderr, "Unable to open %s\n: %s", buf_ptr(chf->path), err_str(err));
403 os_file_close(&ch->manifest_file);
404 return ErrorCacheUnavailable;
405 }
406 if (chf->attr.mtime.sec == actual_attr.mtime.sec &&
407 chf->attr.mtime.nsec == actual_attr.mtime.nsec &&
408 chf->attr.inode == actual_attr.inode)
409 {
410 os_file_close(&this_file);
411 } else {
412 // we have to recompute the digest.
413 // later we'll rewrite the manifest with the new mtime/digest values
414 ch->manifest_dirty = true;
415 chf->attr = actual_attr;
416
417 if (is_problematic_timestamp(&actual_attr.mtime)) {
418 chf->attr.mtime.sec = 0;
419 chf->attr.mtime.nsec = 0;
420 chf->attr.inode = 0;
421 }
422
423 uint8_t actual_digest[48];
424 if ((err = hash_file(actual_digest, this_file, nullptr))) {
425 os_file_close(&this_file);
426 os_file_close(&ch->manifest_file);
427 return err;
428 }
429 os_file_close(&this_file);
430 if (memcmp(chf->bin_digest, actual_digest, 48) != 0) {
431 memcpy(chf->bin_digest, actual_digest, 48);
432 // keep going until we have the input file digests
433 any_file_changed = true;
434 }
435 }
436 if (!any_file_changed) {
437 blake2b_update(&ch->blake, chf->bin_digest, 48);
438 }
439 }
440 if (file_i < input_file_count || file_i == 0 || return_code != ErrorNone) {
441 // manifest file is empty or missing entries, so this is a cache miss
442 ch->manifest_dirty = true;
443 for (; file_i < input_file_count; file_i += 1) {
444 CacheHashFile *chf = &ch->files.at(file_i);
445 if ((err = populate_file_hash(ch, chf, nullptr))) {
446 fprintf(stderr, "Unable to hash %s: %s\n", buf_ptr(chf->path), err_str(err));
447 os_file_close(&ch->manifest_file);
448 return ErrorCacheUnavailable;
449 }
450 }
451 if (return_code != ErrorNone && return_code != ErrorInvalidFormat) {
452 os_file_close(&ch->manifest_file);
453 }
454 return return_code;
455 }
456 // Cache Hit
457 return cache_final(ch, out_digest);
458}
459
460Error cache_add_file_fetch(CacheHash *ch, Buf *resolved_path, Buf *contents) {
461 Error err;
462
463 assert(ch->manifest_file_path != nullptr);
464 CacheHashFile *chf = ch->files.add_one();
465 chf->path = resolved_path;
466 if ((err = populate_file_hash(ch, chf, contents))) {
467 os_file_close(&ch->manifest_file);
468 return err;
469 }
470
471 return ErrorNone;
472}
473
474Error cache_add_file(CacheHash *ch, Buf *path) {
475 Buf *resolved_path = buf_alloc();
476 *resolved_path = os_path_resolve(&path, 1);
477 return cache_add_file_fetch(ch, resolved_path, nullptr);
478}
479
480Error cache_add_dep_file(CacheHash *ch, Buf *dep_file_path, bool verbose) {
481 Error err;
482 Buf *contents = buf_alloc();
483 if ((err = os_fetch_file_path(dep_file_path, contents))) {
484 if (err == ErrorFileNotFound)
485 return err;
486 if (verbose) {
487 fprintf(stderr, "%s: unable to read .d file: %s\n", err_str(err), buf_ptr(dep_file_path));
488 }
489 return ErrorReadingDepFile;
490 }
491 auto it = stage2_DepTokenizer_init(buf_ptr(contents), buf_len(contents));
492 // skip first token: target
493 {
494 auto result = stage2_DepTokenizer_next(&it);
495 switch (result.type_id) {
496 case stage2_DepNextResult::error:
497 if (verbose) {
498 fprintf(stderr, "%s: failed processing .d file: %s\n", result.textz, buf_ptr(dep_file_path));
499 }
500 err = ErrorInvalidDepFile;
501 goto finish;
502 case stage2_DepNextResult::null:
503 err = ErrorNone;
504 goto finish;
505 case stage2_DepNextResult::target:
506 case stage2_DepNextResult::prereq:
507 err = ErrorNone;
508 break;
509 }
510 }
511 // Process 0+ preqreqs.
512 // clang is invoked in single-source mode so we never get more targets.
513 for (;;) {
514 auto result = stage2_DepTokenizer_next(&it);
515 switch (result.type_id) {
516 case stage2_DepNextResult::error:
517 if (verbose) {
518 fprintf(stderr, "%s: failed processing .d file: %s\n", result.textz, buf_ptr(dep_file_path));
519 }
520 err = ErrorInvalidDepFile;
521 goto finish;
522 case stage2_DepNextResult::null:
523 case stage2_DepNextResult::target:
524 err = ErrorNone;
525 goto finish;
526 case stage2_DepNextResult::prereq:
527 break;
528 }
529 auto textbuf = buf_alloc();
530 buf_init_from_str(textbuf, result.textz);
531 if ((err = cache_add_file(ch, textbuf))) {
532 if (verbose) {
533 fprintf(stderr, "unable to add %s to cache: %s\n", result.textz, err_str(err));
534 fprintf(stderr, "when processing .d file: %s\n", buf_ptr(dep_file_path));
535 }
536 goto finish;
537 }
538 }
539
540 finish:
541 stage2_DepTokenizer_deinit(&it);
542 return err;
543}
544
545static Error write_manifest_file(CacheHash *ch) {
546 Error err;
547 Buf contents = BUF_INIT;
548 buf_resize(&contents, 0);
549 uint8_t encoded_digest[65];
550 encoded_digest[64] = 0;
551 for (size_t i = 0; i < ch->files.length; i += 1) {
552 CacheHashFile *chf = &ch->files.at(i);
553 base64_encode({encoded_digest, 64}, {chf->bin_digest, 48});
554 buf_appendf(&contents, "%" ZIG_PRI_u64 " %" ZIG_PRI_u64 " %" ZIG_PRI_u64 " %s %s\n",
555 chf->attr.inode, chf->attr.mtime.sec, chf->attr.mtime.nsec, encoded_digest, buf_ptr(chf->path));
556 }
557 if ((err = os_file_overwrite(ch->manifest_file, &contents)))
558 return err;
559
560 return ErrorNone;
561}
562
563Error cache_final(CacheHash *ch, Buf *out_digest) {
564 assert(ch->manifest_file_path != nullptr);
565
566 // We don't close the manifest file yet, because we want to
567 // keep it locked until the API user is done using it.
568 // We also don't write out the manifest yet, because until
569 // cache_release is called we still might be working on creating
570 // the artifacts to cache.
571
572 uint8_t bin_digest[48];
573 int rc = blake2b_final(&ch->blake, bin_digest, 48);
574 assert(rc == 0);
575 buf_resize(out_digest, 64);
576 base64_encode(buf_to_slice(out_digest), {bin_digest, 48});
577
578 return ErrorNone;
579}
580
581void cache_release(CacheHash *ch) {
582 assert(ch->manifest_file_path != nullptr);
583
584 Error err;
585
586 if (ch->manifest_dirty) {
587 if ((err = write_manifest_file(ch))) {
588 fprintf(stderr, "Warning: Unable to write cache file '%s': %s\n",
589 buf_ptr(ch->manifest_file_path), err_str(err));
590 }
591 }
592
593 os_file_close(&ch->manifest_file);
594}
595
src/cache_hash.hpp deleted-83
...@@ -1,83 +0,0 @@
1/*
2 * Copyright (c) 2018 Andrew Kelley
3 *
4 * This file is part of zig, which is MIT licensed.
5 * See http://opensource.org/licenses/MIT
6 */
7
8#ifndef ZIG_CACHE_HASH_HPP
9#define ZIG_CACHE_HASH_HPP
10
11#include "blake2.h"
12#include "os.hpp"
13
14struct LinkLib;
15
16struct CacheHashFile {
17 Buf *path;
18 OsFileAttr attr;
19 uint8_t bin_digest[48];
20 Buf *contents;
21};
22
23struct CacheHash {
24 blake2b_state blake;
25 ZigList<CacheHashFile> files;
26 Buf *manifest_dir;
27 Buf *manifest_file_path;
28 Buf b64_digest;
29 OsFile manifest_file;
30 bool manifest_dirty;
31 bool force_check_manifest;
32};
33
34// Always call this first to set up.
35void cache_init(CacheHash *ch, Buf *manifest_dir);
36
37// Next, use the hash population functions to add the initial parameters.
38void cache_mem(CacheHash *ch, const char *ptr, size_t len);
39void cache_slice(CacheHash *ch, Slice<const char> slice);
40void cache_str(CacheHash *ch, const char *ptr);
41void cache_int(CacheHash *ch, int x);
42void cache_bool(CacheHash *ch, bool x);
43void cache_usize(CacheHash *ch, size_t x);
44void cache_buf(CacheHash *ch, Buf *buf);
45void cache_buf_opt(CacheHash *ch, Buf *buf);
46void cache_list_of_link_lib(CacheHash *ch, LinkLib **ptr, size_t len);
47void cache_list_of_buf(CacheHash *ch, Buf **ptr, size_t len);
48void cache_list_of_file(CacheHash *ch, Buf **ptr, size_t len);
49void cache_list_of_str(CacheHash *ch, const char **ptr, size_t len);
50void cache_file(CacheHash *ch, Buf *path);
51void cache_file_opt(CacheHash *ch, Buf *path);
52
53// Then call cache_hit when you're ready to see if you can skip the next step.
54// out_b64_digest will be left unchanged if it was a cache miss.
55// If you got a cache hit, the next step is cache_release.
56// From this point on, there is a lock on the input params. Release
57// the lock with cache_release.
58// Set force_check_manifest if you plan to add files later, but have not
59// added any files before calling cache_hit. CacheHash::b64_digest becomes
60// available for use after this call, even in the case of a miss, and it
61// is a hash of the input parameters only.
62// If this function returns ErrorInvalidFormat, that error may be treated
63// as a cache miss.
64Error ATTRIBUTE_MUST_USE cache_hit(CacheHash *ch, Buf *out_b64_digest);
65
66// If you did not get a cache hit, call this function for every file
67// that is depended on, and then finish with cache_final.
68Error ATTRIBUTE_MUST_USE cache_add_file(CacheHash *ch, Buf *path);
69// This opens a file created by -MD -MF args to Clang
70Error ATTRIBUTE_MUST_USE cache_add_dep_file(CacheHash *ch, Buf *path, bool verbose);
71
72// This variant of cache_add_file returns the file contents.
73// Also the file path argument must be already resolved.
74Error ATTRIBUTE_MUST_USE cache_add_file_fetch(CacheHash *ch, Buf *resolved_path, Buf *contents);
75
76// out_b64_digest will be the same thing that cache_hit returns if you got a cache hit
77Error ATTRIBUTE_MUST_USE cache_final(CacheHash *ch, Buf *out_b64_digest);
78
79// Until this function is called, no one will be able to get a lock on your input params.
80void cache_release(CacheHash *ch);
81
82
83#endif
src/codegen.cpp+204-2027
...@@ -8,7 +8,6 @@...@@ -8,7 +8,6 @@
8#include "analyze.hpp"8#include "analyze.hpp"
9#include "ast_render.hpp"9#include "ast_render.hpp"
10#include "codegen.hpp"10#include "codegen.hpp"
11#include "compiler.hpp"
12#include "config.h"11#include "config.h"
13#include "errmsg.hpp"12#include "errmsg.hpp"
14#include "error.hpp"13#include "error.hpp"
...@@ -21,7 +20,6 @@...@@ -21,7 +20,6 @@
21#include "stage2.h"20#include "stage2.h"
22#include "dump_analysis.hpp"21#include "dump_analysis.hpp"
23#include "softfloat.hpp"22#include "softfloat.hpp"
24#include "mem_profile.hpp"
2523
26#include <stdio.h>24#include <stdio.h>
27#include <errno.h>25#include <errno.h>
...@@ -72,39 +70,6 @@ static const char *symbols_that_llvm_depends_on[] = {...@@ -72,39 +70,6 @@ static const char *symbols_that_llvm_depends_on[] = {
72 // TODO probably all of compiler-rt needs to go here70 // TODO probably all of compiler-rt needs to go here
73};71};
7472
75void codegen_set_clang_argv(CodeGen *g, const char **args, size_t len) {
76 g->clang_argv = args;
77 g->clang_argv_len = len;
78}
79
80void codegen_set_llvm_argv(CodeGen *g, const char **args, size_t len) {
81 g->llvm_argv = args;
82 g->llvm_argv_len = len;
83}
84
85void codegen_set_test_filter(CodeGen *g, Buf *filter) {
86 g->test_filter = filter;
87}
88
89void codegen_set_test_name_prefix(CodeGen *g, Buf *prefix) {
90 g->test_name_prefix = prefix;
91}
92
93void codegen_set_lib_version(CodeGen *g, bool is_versioned, size_t major, size_t minor, size_t patch) {
94 g->is_versioned = is_versioned;
95 g->version_major = major;
96 g->version_minor = minor;
97 g->version_patch = patch;
98}
99
100void codegen_set_each_lib_rpath(CodeGen *g, bool each_lib_rpath) {
101 g->each_lib_rpath = each_lib_rpath;
102}
103
104void codegen_set_errmsg_color(CodeGen *g, ErrColor err_color) {
105 g->err_color = err_color;
106}
107
108void codegen_set_strip(CodeGen *g, bool strip) {73void codegen_set_strip(CodeGen *g, bool strip) {
109 g->strip_debug_symbols = strip;74 g->strip_debug_symbols = strip;
110 if (!target_has_debug_info(g->zig_target)) {75 if (!target_has_debug_info(g->zig_target)) {
...@@ -112,39 +77,6 @@ void codegen_set_strip(CodeGen *g, bool strip) {...@@ -112,39 +77,6 @@ void codegen_set_strip(CodeGen *g, bool strip) {
112 }77 }
113}78}
11479
115void codegen_set_out_name(CodeGen *g, Buf *out_name) {
116 g->root_out_name = out_name;
117}
118
119void codegen_add_lib_dir(CodeGen *g, const char *dir) {
120 g->lib_dirs.append(dir);
121}
122
123void codegen_add_rpath(CodeGen *g, const char *name) {
124 g->rpath_list.append(buf_create_from_str(name));
125}
126
127LinkLib *codegen_add_link_lib(CodeGen *g, Buf *name) {
128 return add_link_lib(g, name);
129}
130
131void codegen_add_forbidden_lib(CodeGen *codegen, Buf *lib) {
132 codegen->forbidden_libs.append(lib);
133}
134
135void codegen_add_framework(CodeGen *g, const char *framework) {
136 g->darwin_frameworks.append(buf_create_from_str(framework));
137}
138
139void codegen_set_rdynamic(CodeGen *g, bool rdynamic) {
140 g->linker_rdynamic = rdynamic;
141}
142
143void codegen_set_linker_script(CodeGen *g, const char *linker_script) {
144 g->linker_script = linker_script;
145}
146
147
148static void render_const_val(CodeGen *g, ZigValue *const_val, const char *name);80static void render_const_val(CodeGen *g, ZigValue *const_val, const char *name);
149static void render_const_val_global(CodeGen *g, ZigValue *const_val, const char *name);81static void render_const_val_global(CodeGen *g, ZigValue *const_val, const char *name);
150static LLVMValueRef gen_const_val(CodeGen *g, ZigValue *const_val, const char *name);82static LLVMValueRef gen_const_val(CodeGen *g, ZigValue *const_val, const char *name);
...@@ -155,7 +87,6 @@ static LLVMValueRef build_alloca(CodeGen *g, ZigType *type_entry, const char *na...@@ -155,7 +87,6 @@ static LLVMValueRef build_alloca(CodeGen *g, ZigType *type_entry, const char *na
155static LLVMValueRef gen_await_early_return(CodeGen *g, IrInstGen *source_instr,87static LLVMValueRef gen_await_early_return(CodeGen *g, IrInstGen *source_instr,
156 LLVMValueRef target_frame_ptr, ZigType *result_type, ZigType *ptr_result_type,88 LLVMValueRef target_frame_ptr, ZigType *result_type, ZigType *ptr_result_type,
157 LLVMValueRef result_loc, bool non_async);89 LLVMValueRef result_loc, bool non_async);
158static Error get_tmp_filename(CodeGen *g, Buf *out, Buf *suffix);
15990
160static void addLLVMAttr(LLVMValueRef val, LLVMAttributeIndex attr_index, const char *attr_name) {91static void addLLVMAttr(LLVMValueRef val, LLVMAttributeIndex attr_index, const char *attr_name) {
161 unsigned kind_id = LLVMGetEnumAttributeKindForName(attr_name, strlen(attr_name));92 unsigned kind_id = LLVMGetEnumAttributeKindForName(attr_name, strlen(attr_name));
...@@ -389,7 +320,7 @@ static uint32_t get_err_ret_trace_arg_index(CodeGen *g, ZigFn *fn_table_entry) {...@@ -389,7 +320,7 @@ static uint32_t get_err_ret_trace_arg_index(CodeGen *g, ZigFn *fn_table_entry) {
389}320}
390321
391static void maybe_export_dll(CodeGen *g, LLVMValueRef global_value, GlobalLinkageId linkage) {322static void maybe_export_dll(CodeGen *g, LLVMValueRef global_value, GlobalLinkageId linkage) {
392 if (linkage != GlobalLinkageIdInternal && g->zig_target->os == OsWindows && g->is_dynamic) {323 if (linkage != GlobalLinkageIdInternal && g->zig_target->os == OsWindows && g->dll_export_fns) {
393 LLVMSetDLLStorageClass(global_value, LLVMDLLExportStorageClass);324 LLVMSetDLLStorageClass(global_value, LLVMDLLExportStorageClass);
394 }325 }
395}326}
...@@ -541,7 +472,7 @@ static LLVMValueRef make_fn_llvm_value(CodeGen *g, ZigFn *fn) {...@@ -541,7 +472,7 @@ static LLVMValueRef make_fn_llvm_value(CodeGen *g, ZigFn *fn) {
541 g->build_mode != BuildModeSmallRelease &&472 g->build_mode != BuildModeSmallRelease &&
542 !fn->def_scope->safety_off;473 !fn->def_scope->safety_off;
543 if (want_fn_safety) {474 if (want_fn_safety) {
544 if (g->libc_link_lib != nullptr) {475 if (g->link_libc) {
545 addLLVMFnAttr(llvm_fn, "sspstrong");476 addLLVMFnAttr(llvm_fn, "sspstrong");
546 addLLVMFnAttrStr(llvm_fn, "stack-protector-buffer-size", "4");477 addLLVMFnAttrStr(llvm_fn, "stack-protector-buffer-size", "4");
547 }478 }
...@@ -3859,20 +3790,6 @@ static LLVMValueRef gen_valgrind_client_request(CodeGen *g, LLVMValueRef default...@@ -3859,20 +3790,6 @@ static LLVMValueRef gen_valgrind_client_request(CodeGen *g, LLVMValueRef default
3859 zig_unreachable();3790 zig_unreachable();
3860}3791}
38613792
3862static bool want_valgrind_support(CodeGen *g) {
3863 if (!target_has_valgrind_support(g->zig_target))
3864 return false;
3865 switch (g->valgrind_support) {
3866 case ValgrindSupportDisabled:
3867 return false;
3868 case ValgrindSupportEnabled:
3869 return true;
3870 case ValgrindSupportAuto:
3871 return g->build_mode == BuildModeDebug;
3872 }
3873 zig_unreachable();
3874}
3875
3876static void gen_valgrind_undef(CodeGen *g, LLVMValueRef dest_ptr, LLVMValueRef byte_count) {3793static void gen_valgrind_undef(CodeGen *g, LLVMValueRef dest_ptr, LLVMValueRef byte_count) {
3877 static const uint32_t VG_USERREQ__MAKE_MEM_UNDEFINED = 1296236545;3794 static const uint32_t VG_USERREQ__MAKE_MEM_UNDEFINED = 1296236545;
3878 ZigType *usize = g->builtin_types.entry_usize;3795 ZigType *usize = g->builtin_types.entry_usize;
...@@ -3895,7 +3812,7 @@ static void gen_undef_init(CodeGen *g, uint32_t ptr_align_bytes, ZigType *value_...@@ -3895,7 +3812,7 @@ static void gen_undef_init(CodeGen *g, uint32_t ptr_align_bytes, ZigType *value_
3895 LLVMValueRef byte_count = LLVMConstInt(usize->llvm_type, size_bytes, false);3812 LLVMValueRef byte_count = LLVMConstInt(usize->llvm_type, size_bytes, false);
3896 ZigLLVMBuildMemSet(g->builder, dest_ptr, fill_char, byte_count, ptr_align_bytes, false);3813 ZigLLVMBuildMemSet(g->builder, dest_ptr, fill_char, byte_count, ptr_align_bytes, false);
3897 // then tell valgrind that the memory is undefined even though we just memset it3814 // then tell valgrind that the memory is undefined even though we just memset it
3898 if (want_valgrind_support(g)) {3815 if (g->valgrind_enabled) {
3899 gen_valgrind_undef(g, dest_ptr, byte_count);3816 gen_valgrind_undef(g, dest_ptr, byte_count);
3900 }3817 }
3901}3818}
...@@ -5598,7 +5515,7 @@ static LLVMValueRef ir_render_memset(CodeGen *g, IrExecutableGen *executable, Ir...@@ -5598,7 +5515,7 @@ static LLVMValueRef ir_render_memset(CodeGen *g, IrExecutableGen *executable, Ir
5598 ZigLLVMBuildMemSet(g->builder, dest_ptr_casted, fill_char, len_val, get_ptr_align(g, ptr_type),5515 ZigLLVMBuildMemSet(g->builder, dest_ptr_casted, fill_char, len_val, get_ptr_align(g, ptr_type),
5599 ptr_type->data.pointer.is_volatile);5516 ptr_type->data.pointer.is_volatile);
56005517
5601 if (val_is_undef && want_valgrind_support(g)) {5518 if (val_is_undef && g->valgrind_enabled) {
5602 gen_valgrind_undef(g, dest_ptr_casted, len_val);5519 gen_valgrind_undef(g, dest_ptr_casted, len_val);
5603 }5520 }
5604 return nullptr;5521 return nullptr;
...@@ -8350,13 +8267,6 @@ static void zig_llvm_emit_output(CodeGen *g) {...@@ -8350,13 +8267,6 @@ static void zig_llvm_emit_output(CodeGen *g) {
8350 exit(1);8267 exit(1);
8351 }8268 }
83528269
8353 if (g->emit_bin) {
8354 g->link_objects.append(&g->o_file_output_path);
8355 if (g->bundle_compiler_rt && (g->out_type == OutTypeObj || (g->out_type == OutTypeLib && !g->is_dynamic))) {
8356 zig_link_add_compiler_rt(g, g->sub_progress_node);
8357 }
8358 }
8359
8360 LLVMDisposeModule(g->module);8270 LLVMDisposeModule(g->module);
8361 g->module = nullptr;8271 g->module = nullptr;
8362 LLVMDisposeTargetData(g->target_data_ref);8272 LLVMDisposeTargetData(g->target_data_ref);
...@@ -8751,75 +8661,12 @@ static const char *subsystem_to_str(TargetSubsystem subsystem) {...@@ -8751,75 +8661,12 @@ static const char *subsystem_to_str(TargetSubsystem subsystem) {
8751 zig_unreachable();8661 zig_unreachable();
8752}8662}
87538663
8754static bool detect_dynamic_link(CodeGen *g) {
8755 if (g->is_dynamic)
8756 return true;
8757 if (g->zig_target->os == OsFreestanding)
8758 return false;
8759 if (target_os_requires_libc(g->zig_target->os))
8760 return true;
8761 if (g->libc_link_lib != nullptr && target_is_glibc(g->zig_target))
8762 return true;
8763 // If there are no dynamic libraries then we can disable dynamic linking.
8764 for (size_t i = 0; i < g->link_libs_list.length; i += 1) {
8765 LinkLib *link_lib = g->link_libs_list.at(i);
8766 if (target_is_libc_lib_name(g->zig_target, buf_ptr(link_lib->name)))
8767 continue;
8768 if (target_is_libcpp_lib_name(g->zig_target, buf_ptr(link_lib->name)))
8769 continue;
8770 return true;
8771 }
8772 return false;
8773}
8774
8775static bool detect_pic(CodeGen *g) {
8776 if (target_requires_pic(g->zig_target, g->libc_link_lib != nullptr))
8777 return true;
8778 switch (g->want_pic) {
8779 case WantPICDisabled:
8780 return false;
8781 case WantPICEnabled:
8782 return true;
8783 case WantPICAuto:
8784 return g->have_dynamic_link;
8785 }
8786 zig_unreachable();
8787}
8788
8789static bool detect_stack_probing(CodeGen *g) {
8790 if (!target_supports_stack_probing(g->zig_target))
8791 return false;
8792 switch (g->want_stack_check) {
8793 case WantStackCheckDisabled:
8794 return false;
8795 case WantStackCheckEnabled:
8796 return true;
8797 case WantStackCheckAuto:
8798 return g->build_mode == BuildModeSafeRelease || g->build_mode == BuildModeDebug;
8799 }
8800 zig_unreachable();
8801}
8802
8803static bool detect_sanitize_c(CodeGen *g) {
8804 if (!target_supports_sanitize_c(g->zig_target))
8805 return false;
8806 switch (g->want_sanitize_c) {
8807 case WantCSanitizeDisabled:
8808 return false;
8809 case WantCSanitizeEnabled:
8810 return true;
8811 case WantCSanitizeAuto:
8812 return g->build_mode == BuildModeSafeRelease || g->build_mode == BuildModeDebug;
8813 }
8814 zig_unreachable();
8815}
8816
8817// Returns TargetSubsystemAuto to mean "no subsystem"8664// Returns TargetSubsystemAuto to mean "no subsystem"
8818TargetSubsystem detect_subsystem(CodeGen *g) {8665TargetSubsystem detect_subsystem(CodeGen *g) {
8819 if (g->subsystem != TargetSubsystemAuto)8666 if (g->subsystem != TargetSubsystemAuto)
8820 return g->subsystem;8667 return g->subsystem;
8821 if (g->zig_target->os == OsWindows) {8668 if (g->zig_target->os == OsWindows) {
8822 if (g->have_dllmain_crt_startup || (g->out_type == OutTypeLib && g->is_dynamic))8669 if (g->have_dllmain_crt_startup)
8823 return TargetSubsystemAuto;8670 return TargetSubsystemAuto;
8824 if (g->have_c_main || g->is_test_build || g->have_winmain_crt_startup || g->have_wwinmain_crt_startup)8671 if (g->have_c_main || g->is_test_build || g->have_winmain_crt_startup || g->have_wwinmain_crt_startup)
8825 return TargetSubsystemConsole;8672 return TargetSubsystemConsole;
...@@ -8831,15 +8678,6 @@ TargetSubsystem detect_subsystem(CodeGen *g) {...@@ -8831,15 +8678,6 @@ TargetSubsystem detect_subsystem(CodeGen *g) {
8831 return TargetSubsystemAuto;8678 return TargetSubsystemAuto;
8832}8679}
88338680
8834static bool detect_single_threaded(CodeGen *g) {
8835 if (g->want_single_threaded)
8836 return true;
8837 if (target_is_single_threaded(g->zig_target)) {
8838 return true;
8839 }
8840 return false;
8841}
8842
8843static bool detect_err_ret_tracing(CodeGen *g) {8681static bool detect_err_ret_tracing(CodeGen *g) {
8844 return !g->strip_debug_symbols &&8682 return !g->strip_debug_symbols &&
8845 g->build_mode != BuildModeFastRelease &&8683 g->build_mode != BuildModeFastRelease &&
...@@ -8847,30 +8685,30 @@ static bool detect_err_ret_tracing(CodeGen *g) {...@@ -8847,30 +8685,30 @@ static bool detect_err_ret_tracing(CodeGen *g) {
8847}8685}
88488686
8849static LLVMCodeModel to_llvm_code_model(CodeGen *g) {8687static LLVMCodeModel to_llvm_code_model(CodeGen *g) {
8850 switch (g->code_model) {8688 switch (g->code_model) {
8851 case CodeModelDefault:8689 case CodeModelDefault:
8852 return LLVMCodeModelDefault;8690 return LLVMCodeModelDefault;
8853 case CodeModelTiny:8691 case CodeModelTiny:
8854 return LLVMCodeModelTiny;8692 return LLVMCodeModelTiny;
8855 case CodeModelSmall:8693 case CodeModelSmall:
8856 return LLVMCodeModelSmall;8694 return LLVMCodeModelSmall;
8857 case CodeModelKernel:8695 case CodeModelKernel:
8858 return LLVMCodeModelKernel;8696 return LLVMCodeModelKernel;
8859 case CodeModelMedium:8697 case CodeModelMedium:
8860 return LLVMCodeModelMedium;8698 return LLVMCodeModelMedium;
8861 case CodeModelLarge:8699 case CodeModelLarge:
8862 return LLVMCodeModelLarge;8700 return LLVMCodeModelLarge;
8863 }8701 }
88648702
8865 zig_unreachable();8703 zig_unreachable();
8866}8704}
88678705
8868Buf *codegen_generate_builtin_source(CodeGen *g) {8706Buf *codegen_generate_builtin_source(CodeGen *g) {
8869 g->have_dynamic_link = detect_dynamic_link(g);8707 // Note that this only runs when zig0 is building the self-hosted zig compiler code,
8870 g->have_pic = detect_pic(g);8708 // so it makes a few assumption that are always true for that case. Once we have
8871 g->have_stack_probing = detect_stack_probing(g);8709 // built the stage2 zig components then zig is in charge of generating the builtin.zig
8872 g->have_sanitize_c = detect_sanitize_c(g);8710 // file.
8873 g->is_single_threaded = detect_single_threaded(g);8711
8874 g->have_err_ret_tracing = detect_err_ret_tracing(g);8712 g->have_err_ret_tracing = detect_err_ret_tracing(g);
88758713
8876 Buf *contents = buf_alloc();8714 Buf *contents = buf_alloc();
...@@ -8884,7 +8722,6 @@ Buf *codegen_generate_builtin_source(CodeGen *g) {...@@ -8884,7 +8722,6 @@ Buf *codegen_generate_builtin_source(CodeGen *g) {
8884 const char *name = target_os_name(os_type);8722 const char *name = target_os_name(os_type);
88858723
8886 if (os_type == g->zig_target->os) {8724 if (os_type == g->zig_target->os) {
8887 g->target_os_index = i;
8888 cur_os = name;8725 cur_os = name;
8889 }8726 }
8890 }8727 }
...@@ -8898,7 +8735,6 @@ Buf *codegen_generate_builtin_source(CodeGen *g) {...@@ -8898,7 +8735,6 @@ Buf *codegen_generate_builtin_source(CodeGen *g) {
8898 ZigLLVM_ArchType arch = target_arch_enum(arch_i);8735 ZigLLVM_ArchType arch = target_arch_enum(arch_i);
8899 const char *arch_name = target_arch_name(arch);8736 const char *arch_name = target_arch_name(arch);
8900 if (arch == g->zig_target->arch) {8737 if (arch == g->zig_target->arch) {
8901 g->target_arch_index = arch_i;
8902 cur_arch = arch_name;8738 cur_arch = arch_name;
8903 }8739 }
8904 }8740 }
...@@ -8913,7 +8749,6 @@ Buf *codegen_generate_builtin_source(CodeGen *g) {...@@ -8913,7 +8749,6 @@ Buf *codegen_generate_builtin_source(CodeGen *g) {
8913 const char *name = target_abi_name(abi);8749 const char *name = target_abi_name(abi);
89148750
8915 if (abi == g->zig_target->abi) {8751 if (abi == g->zig_target->abi) {
8916 g->target_abi_index = i;
8917 cur_abi = name;8752 cur_abi = name;
8918 }8753 }
8919 }8754 }
...@@ -8929,7 +8764,6 @@ Buf *codegen_generate_builtin_source(CodeGen *g) {...@@ -8929,7 +8764,6 @@ Buf *codegen_generate_builtin_source(CodeGen *g) {
89298764
8930 ZigLLVM_ObjectFormatType target_oformat = target_object_format(g->zig_target);8765 ZigLLVM_ObjectFormatType target_oformat = target_object_format(g->zig_target);
8931 if (oformat == target_oformat) {8766 if (oformat == target_oformat) {
8932 g->target_oformat_index = i;
8933 cur_obj_fmt = name;8767 cur_obj_fmt = name;
8934 }8768 }
8935 }8769 }
...@@ -8979,23 +8813,9 @@ Buf *codegen_generate_builtin_source(CodeGen *g) {...@@ -8979,23 +8813,9 @@ Buf *codegen_generate_builtin_source(CodeGen *g) {
8979 const char *endian_str = g->is_big_endian ? "Endian.Big" : "Endian.Little";8813 const char *endian_str = g->is_big_endian ? "Endian.Big" : "Endian.Little";
8980 buf_appendf(contents, "pub const endian = %s;\n", endian_str);8814 buf_appendf(contents, "pub const endian = %s;\n", endian_str);
8981 }8815 }
8982 const char *out_type = nullptr;8816 buf_appendf(contents, "pub const output_mode = OutputMode.Obj;\n");
8983 switch (g->out_type) {8817 buf_appendf(contents, "pub const link_mode = LinkMode.Static;\n");
8984 case OutTypeExe:8818 buf_appendf(contents, "pub const is_test = false;\n");
8985 out_type = "Exe";
8986 break;
8987 case OutTypeLib:
8988 out_type = "Lib";
8989 break;
8990 case OutTypeObj:
8991 case OutTypeUnknown: // This happens when running the `zig builtin` command.
8992 out_type = "Obj";
8993 break;
8994 }
8995 buf_appendf(contents, "pub const output_mode = OutputMode.%s;\n", out_type);
8996 const char *link_type = g->have_dynamic_link ? "Dynamic" : "Static";
8997 buf_appendf(contents, "pub const link_mode = LinkMode.%s;\n", link_type);
8998 buf_appendf(contents, "pub const is_test = %s;\n", bool_to_str(g->is_test_build));
8999 buf_appendf(contents, "pub const single_threaded = %s;\n", bool_to_str(g->is_single_threaded));8819 buf_appendf(contents, "pub const single_threaded = %s;\n", bool_to_str(g->is_single_threaded));
9000 buf_append_str(contents, "/// Deprecated: use `std.Target.cpu.arch`\n");8820 buf_append_str(contents, "/// Deprecated: use `std.Target.cpu.arch`\n");
9001 buf_appendf(contents, "pub const arch = Arch.%s;\n", cur_arch);8821 buf_appendf(contents, "pub const arch = Arch.%s;\n", cur_arch);
...@@ -9018,40 +8838,13 @@ Buf *codegen_generate_builtin_source(CodeGen *g) {...@@ -9018,40 +8838,13 @@ Buf *codegen_generate_builtin_source(CodeGen *g) {
9018 }8838 }
9019 buf_appendf(contents, "pub const object_format = ObjectFormat.%s;\n", cur_obj_fmt);8839 buf_appendf(contents, "pub const object_format = ObjectFormat.%s;\n", cur_obj_fmt);
9020 buf_appendf(contents, "pub const mode = %s;\n", build_mode_to_str(g->build_mode));8840 buf_appendf(contents, "pub const mode = %s;\n", build_mode_to_str(g->build_mode));
9021 buf_appendf(contents, "pub const link_libc = %s;\n", bool_to_str(g->libc_link_lib != nullptr));8841 buf_appendf(contents, "pub const link_libc = %s;\n", bool_to_str(g->link_libc));
9022 buf_appendf(contents, "pub const link_libcpp = %s;\n", bool_to_str(g->libcpp_link_lib != nullptr));8842 buf_appendf(contents, "pub const link_libcpp = %s;\n", bool_to_str(g->link_libcpp));
9023 buf_appendf(contents, "pub const have_error_return_tracing = %s;\n", bool_to_str(g->have_err_ret_tracing));8843 buf_appendf(contents, "pub const have_error_return_tracing = %s;\n", bool_to_str(g->have_err_ret_tracing));
9024 buf_appendf(contents, "pub const valgrind_support = %s;\n", bool_to_str(want_valgrind_support(g)));8844 buf_appendf(contents, "pub const valgrind_support = false;\n");
9025 buf_appendf(contents, "pub const position_independent_code = %s;\n", bool_to_str(g->have_pic));8845 buf_appendf(contents, "pub const position_independent_code = %s;\n", bool_to_str(g->have_pic));
9026 buf_appendf(contents, "pub const strip_debug_info = %s;\n", bool_to_str(g->strip_debug_symbols));8846 buf_appendf(contents, "pub const strip_debug_info = %s;\n", bool_to_str(g->strip_debug_symbols));
90278847 buf_appendf(contents, "pub const code_model = CodeModel.default;\n");
9028 {
9029 const char *code_model;
9030 switch (g->code_model) {
9031 case CodeModelDefault:
9032 code_model = "default";
9033 break;
9034 case CodeModelTiny:
9035 code_model = "tiny";
9036 break;
9037 case CodeModelSmall:
9038 code_model = "small";
9039 break;
9040 case CodeModelKernel:
9041 code_model = "kernel";
9042 break;
9043 case CodeModelMedium:
9044 code_model = "medium";
9045 break;
9046 case CodeModelLarge:
9047 code_model = "large";
9048 break;
9049 default:
9050 zig_unreachable();
9051 }
9052
9053 buf_appendf(contents, "pub const code_model = CodeModel.%s;\n", code_model);
9054 }
90558848
9056 {8849 {
9057 TargetSubsystem detected_subsystem = detect_subsystem(g);8850 TargetSubsystem detected_subsystem = detect_subsystem(g);
...@@ -9060,15 +8853,6 @@ Buf *codegen_generate_builtin_source(CodeGen *g) {...@@ -9060,15 +8853,6 @@ Buf *codegen_generate_builtin_source(CodeGen *g) {
9060 }8853 }
9061 }8854 }
90628855
9063 if (g->is_test_build) {
9064 buf_appendf(contents,
9065 "pub var test_functions: []TestFn = undefined; // overwritten later\n"
9066 );
9067
9068 buf_appendf(contents, "pub const test_io_mode = %s;\n",
9069 g->test_is_evented ? ".evented" : ".blocking");
9070 }
9071
9072 return contents;8856 return contents;
9073}8857}
90748858
...@@ -9077,95 +8861,35 @@ static ZigPackage *create_test_runner_pkg(CodeGen *g) {...@@ -9077,95 +8861,35 @@ static ZigPackage *create_test_runner_pkg(CodeGen *g) {
9077}8861}
90788862
9079static Error define_builtin_compile_vars(CodeGen *g) {8863static Error define_builtin_compile_vars(CodeGen *g) {
9080 if (g->std_package == nullptr)
9081 return ErrorNone;
9082
9083 Error err;8864 Error err;
90848865
9085 Buf *manifest_dir = buf_alloc();8866 if (g->std_package == nullptr)
9086 os_path_join(get_global_cache_dir(), buf_create_from_str("builtin"), manifest_dir);8867 return ErrorNone;
9087
9088 CacheHash cache_hash;
9089 cache_init(&cache_hash, manifest_dir);
9090
9091 Buf *compiler_id;
9092 if ((err = get_compiler_id(&compiler_id)))
9093 return err;
9094
9095 // Only a few things affect builtin.zig
9096 cache_buf(&cache_hash, compiler_id);
9097 cache_int(&cache_hash, g->build_mode);
9098 cache_bool(&cache_hash, g->strip_debug_symbols);
9099 cache_int(&cache_hash, g->out_type);
9100 cache_bool(&cache_hash, detect_dynamic_link(g));
9101 cache_bool(&cache_hash, g->is_test_build);
9102 cache_bool(&cache_hash, g->is_single_threaded);
9103 cache_bool(&cache_hash, g->test_is_evented);
9104 cache_int(&cache_hash, g->code_model);
9105 cache_int(&cache_hash, g->zig_target->is_native_os);
9106 cache_int(&cache_hash, g->zig_target->is_native_cpu);
9107 cache_int(&cache_hash, g->zig_target->arch);
9108 cache_int(&cache_hash, g->zig_target->vendor);
9109 cache_int(&cache_hash, g->zig_target->os);
9110 cache_int(&cache_hash, g->zig_target->abi);
9111 if (g->zig_target->cache_hash != nullptr) {
9112 cache_mem(&cache_hash, g->zig_target->cache_hash, g->zig_target->cache_hash_len);
9113 }
9114 if (g->zig_target->glibc_or_darwin_version != nullptr) {
9115 cache_int(&cache_hash, g->zig_target->glibc_or_darwin_version->major);
9116 cache_int(&cache_hash, g->zig_target->glibc_or_darwin_version->minor);
9117 cache_int(&cache_hash, g->zig_target->glibc_or_darwin_version->patch);
9118 }
9119 cache_bool(&cache_hash, g->have_err_ret_tracing);
9120 cache_bool(&cache_hash, g->libc_link_lib != nullptr);
9121 cache_bool(&cache_hash, g->libcpp_link_lib != nullptr);
9122 cache_bool(&cache_hash, g->valgrind_support);
9123 cache_bool(&cache_hash, g->link_eh_frame_hdr);
9124 cache_int(&cache_hash, detect_subsystem(g));
9125
9126 Buf digest = BUF_INIT;
9127 buf_resize(&digest, 0);
9128 if ((err = cache_hit(&cache_hash, &digest))) {
9129 // Treat an invalid format error as a cache miss.
9130 if (err != ErrorInvalidFormat)
9131 return err;
9132 }
9133
9134 // We should always get a cache hit because there are no
9135 // files in the input hash.
9136 assert(buf_len(&digest) != 0);
9137
9138 Buf *this_dir = buf_alloc();
9139 os_path_join(manifest_dir, &digest, this_dir);
9140
9141 if ((err = os_make_path(this_dir)))
9142 return err;
91438868
9144 const char *builtin_zig_basename = "builtin.zig";8869 const char *builtin_zig_basename = "builtin.zig";
9145 Buf *builtin_zig_path = buf_alloc();
9146 os_path_join(this_dir, buf_create_from_str(builtin_zig_basename), builtin_zig_path);
91478870
9148 bool hit;
9149 if ((err = os_file_exists(builtin_zig_path, &hit)))
9150 return err;
9151 Buf *contents;8871 Buf *contents;
9152 if (hit) {8872 if (g->builtin_zig_path == nullptr) {
9153 contents = buf_alloc();8873 // Then this is zig0 building stage2. We can make many assumptions about the compilation.
9154 if ((err = os_fetch_file_path(builtin_zig_path, contents))) {8874 g->builtin_zig_path = buf_alloc();
9155 fprintf(stderr, "Unable to open '%s': %s\n", buf_ptr(builtin_zig_path), err_str(err));8875 os_path_join(g->output_dir, buf_create_from_str(builtin_zig_basename), g->builtin_zig_path);
8876
8877 contents = codegen_generate_builtin_source(g);
8878 if ((err = os_write_file(g->builtin_zig_path, contents))) {
8879 fprintf(stderr, "Unable to write file '%s': %s\n", buf_ptr(g->builtin_zig_path), err_str(err));
9156 exit(1);8880 exit(1);
9157 }8881 }
9158 } else {8882 } else {
9159 contents = codegen_generate_builtin_source(g);8883 contents = buf_alloc();
9160 if ((err = os_write_file(builtin_zig_path, contents))) {8884 if ((err = os_fetch_file_path(g->builtin_zig_path, contents))) {
9161 fprintf(stderr, "Unable to write file '%s': %s\n", buf_ptr(builtin_zig_path), err_str(err));8885 fprintf(stderr, "unable to open '%s': %s\n", buf_ptr(g->builtin_zig_path), err_str(err));
9162 exit(1);8886 exit(1);
9163 }8887 }
9164 }8888 }
91658889
9166 assert(g->main_pkg);8890 assert(g->main_pkg);
9167 assert(g->std_package);8891 assert(g->std_package);
9168 g->compile_var_package = new_package(buf_ptr(this_dir), builtin_zig_basename, "builtin");8892 g->compile_var_package = new_package(buf_ptr(g->output_dir), builtin_zig_basename, "builtin");
9169 if (g->is_test_build) {8893 if (g->is_test_build) {
9170 if (g->test_runner_package == nullptr) {8894 if (g->test_runner_package == nullptr) {
9171 g->test_runner_package = create_test_runner_pkg(g);8895 g->test_runner_package = create_test_runner_pkg(g);
...@@ -9180,7 +8904,7 @@ static Error define_builtin_compile_vars(CodeGen *g) {...@@ -9180,7 +8904,7 @@ static Error define_builtin_compile_vars(CodeGen *g) {
9180 g->std_package->package_table.put(buf_create_from_str("builtin"), g->compile_var_package);8904 g->std_package->package_table.put(buf_create_from_str("builtin"), g->compile_var_package);
9181 g->std_package->package_table.put(buf_create_from_str("std"), g->std_package);8905 g->std_package->package_table.put(buf_create_from_str("std"), g->std_package);
9182 g->std_package->package_table.put(buf_create_from_str("root"), g->root_pkg);8906 g->std_package->package_table.put(buf_create_from_str("root"), g->root_pkg);
9183 g->compile_var_import = add_source_file(g, g->compile_var_package, builtin_zig_path, contents,8907 g->compile_var_import = add_source_file(g, g->compile_var_package, g->builtin_zig_path, contents,
9184 SourceKindPkgMain);8908 SourceKindPkgMain);
91858909
9186 return ErrorNone;8910 return ErrorNone;
...@@ -9190,17 +8914,8 @@ static void init(CodeGen *g) {...@@ -9190,17 +8914,8 @@ static void init(CodeGen *g) {
9190 if (g->module)8914 if (g->module)
9191 return;8915 return;
91928916
9193 g->have_dynamic_link = detect_dynamic_link(g);
9194 g->have_pic = detect_pic(g);
9195 g->have_stack_probing = detect_stack_probing(g);
9196 g->have_sanitize_c = detect_sanitize_c(g);
9197 g->is_single_threaded = detect_single_threaded(g);
9198 g->have_err_ret_tracing = detect_err_ret_tracing(g);8917 g->have_err_ret_tracing = detect_err_ret_tracing(g);
91998918
9200 if (target_is_single_threaded(g->zig_target)) {
9201 g->is_single_threaded = true;
9202 }
9203
9204 assert(g->root_out_name);8919 assert(g->root_out_name);
9205 g->module = LLVMModuleCreateWithName(buf_ptr(g->root_out_name));8920 g->module = LLVMModuleCreateWithName(buf_ptr(g->root_out_name));
92068921
...@@ -9230,7 +8945,7 @@ static void init(CodeGen *g) {...@@ -9230,7 +8945,7 @@ static void init(CodeGen *g) {
9230 LLVMRelocMode reloc_mode;8945 LLVMRelocMode reloc_mode;
9231 if (g->have_pic) {8946 if (g->have_pic) {
9232 reloc_mode = LLVMRelocPIC;8947 reloc_mode = LLVMRelocPIC;
9233 } else if (g->have_dynamic_link) {8948 } else if (g->link_mode_dynamic) {
9234 reloc_mode = LLVMRelocDynamicNoPic;8949 reloc_mode = LLVMRelocDynamicNoPic;
9235 } else {8950 } else {
9236 reloc_mode = LLVMRelocStatic;8951 reloc_mode = LLVMRelocStatic;
...@@ -9336,1378 +9051,160 @@ static void init(CodeGen *g) {...@@ -9336,1378 +9051,160 @@ static void init(CodeGen *g) {
9336 }9051 }
9337}9052}
93389053
9339static void detect_libc(CodeGen *g) {9054static void update_test_functions_builtin_decl(CodeGen *g) {
9340 Error err;9055 Error err;
93419056
9342 if (g->libc != nullptr || g->libc_link_lib == nullptr)9057 assert(g->is_test_build);
9343 return;
93449058
9345 if (target_can_build_libc(g->zig_target)) {9059 if (g->test_fns.length == 0) {
9346 const char *generic_name = target_libc_generic_name(g->zig_target);9060 fprintf(stderr, "No tests to run.\n");
9347 const char *arch_name = target_arch_name(g->zig_target->arch);9061 exit(0);
9348 const char *abi_name = target_abi_name(g->zig_target->abi);
9349 if (target_is_musl(g->zig_target)) {
9350 // musl has some overrides. its headers are ABI-agnostic and so they all have the "musl" ABI name.
9351 abi_name = "musl";
9352 // some architectures are handled by the same set of headers
9353 arch_name = target_arch_musl_name(g->zig_target->arch);
9354 }
9355 Buf *arch_include_dir = buf_sprintf("%s" OS_SEP "libc" OS_SEP "include" OS_SEP "%s-%s-%s",
9356 buf_ptr(g->zig_lib_dir), arch_name, target_os_name(g->zig_target->os), abi_name);
9357 Buf *generic_include_dir = buf_sprintf("%s" OS_SEP "libc" OS_SEP "include" OS_SEP "generic-%s",
9358 buf_ptr(g->zig_lib_dir), generic_name);
9359 Buf *arch_os_include_dir = buf_sprintf("%s" OS_SEP "libc" OS_SEP "include" OS_SEP "%s-%s-any",
9360 buf_ptr(g->zig_lib_dir), target_arch_name(g->zig_target->arch), target_os_name(g->zig_target->os));
9361 Buf *generic_os_include_dir = buf_sprintf("%s" OS_SEP "libc" OS_SEP "include" OS_SEP "any-%s-any",
9362 buf_ptr(g->zig_lib_dir), target_os_name(g->zig_target->os));
9363
9364 g->libc_include_dir_len = 4;
9365 g->libc_include_dir_list = heap::c_allocator.allocate<const char*>(g->libc_include_dir_len);
9366 g->libc_include_dir_list[0] = buf_ptr(arch_include_dir);
9367 g->libc_include_dir_list[1] = buf_ptr(generic_include_dir);
9368 g->libc_include_dir_list[2] = buf_ptr(arch_os_include_dir);
9369 g->libc_include_dir_list[3] = buf_ptr(generic_os_include_dir);
9370 return;
9371 }9062 }
93729063
9373 if (g->zig_target->is_native_os) {9064 ZigType *fn_type = get_test_fn_type(g);
9374 g->libc = heap::c_allocator.create<Stage2LibCInstallation>();
9375
9376 if ((err = stage2_libc_find_native(g->libc))) {
9377 fprintf(stderr,
9378 "Unable to link against libc: Unable to find libc installation: %s\n"
9379 "See `zig libc --help` for more details.\n", err_str(err));
9380 exit(1);
9381 }
9382
9383 bool want_sys_dir = !mem_eql_mem(g->libc->include_dir, g->libc->include_dir_len,
9384 g->libc->sys_include_dir, g->libc->sys_include_dir_len);
9385 size_t want_um_and_shared_dirs = (g->zig_target->os == OsWindows) ? 2 : 0;
9386 size_t dir_count = 1 + want_sys_dir + want_um_and_shared_dirs;
9387 g->libc_include_dir_len = 0;
9388 g->libc_include_dir_list = heap::c_allocator.allocate<const char *>(dir_count);
9389
9390 g->libc_include_dir_list[g->libc_include_dir_len] = buf_ptr(buf_create_from_mem(
9391 g->libc->include_dir, g->libc->include_dir_len));
9392 g->libc_include_dir_len += 1;
93939065
9394 if (want_sys_dir) {9066 ZigValue *test_fn_type_val = get_builtin_value(g, "TestFn");
9395 g->libc_include_dir_list[g->libc_include_dir_len] = buf_ptr(buf_create_from_mem(9067 assert(test_fn_type_val->type->id == ZigTypeIdMetaType);
9396 g->libc->sys_include_dir, g->libc->sys_include_dir_len));9068 ZigType *struct_type = test_fn_type_val->data.x_type;
9397 g->libc_include_dir_len += 1;9069 if ((err = type_resolve(g, struct_type, ResolveStatusSizeKnown)))
9398 }9070 zig_unreachable();
93999071
9400 if (want_um_and_shared_dirs != 0) {9072 ZigValue *test_fn_array = g->pass1_arena->create<ZigValue>();
9401 Buf *include_dir_parent = buf_alloc();9073 test_fn_array->type = get_array_type(g, struct_type, g->test_fns.length, nullptr);
9402 os_path_join(buf_create_from_mem(g->libc->include_dir, g->libc->include_dir_len),9074 test_fn_array->special = ConstValSpecialStatic;
9403 buf_create_from_str(".."), include_dir_parent);9075 test_fn_array->data.x_array.data.s_none.elements = g->pass1_arena->allocate<ZigValue>(g->test_fns.length);
94049076
9405 Buf *buff1 = buf_alloc();9077 for (size_t i = 0; i < g->test_fns.length; i += 1) {
9406 os_path_join(include_dir_parent, buf_create_from_str("um"), buff1);9078 ZigFn *test_fn_entry = g->test_fns.at(i);
9407 g->libc_include_dir_list[g->libc_include_dir_len] = buf_ptr(buff1);
9408 g->libc_include_dir_len += 1;
94099079
9410 Buf *buff2 = buf_alloc();9080 ZigValue *this_val = &test_fn_array->data.x_array.data.s_none.elements[i];
9411 os_path_join(include_dir_parent, buf_create_from_str("shared"), buff2);9081 this_val->special = ConstValSpecialStatic;
9412 g->libc_include_dir_list[g->libc_include_dir_len] = buf_ptr(buff2);9082 this_val->type = struct_type;
9413 g->libc_include_dir_len += 1;9083 this_val->parent.id = ConstParentIdArray;
9414 }9084 this_val->parent.data.p_array.array_val = test_fn_array;
9415 assert(g->libc_include_dir_len == dir_count);9085 this_val->parent.data.p_array.elem_index = i;
9416 } else if ((g->out_type == OutTypeExe || (g->out_type == OutTypeLib && g->is_dynamic)) &&9086 this_val->data.x_struct.fields = alloc_const_vals_ptrs(g, 3);
9417 !target_os_is_darwin(g->zig_target->os))
9418 {
9419 Buf triple_buf = BUF_INIT;
9420 target_triple_zig(&triple_buf, g->zig_target);
9421 fprintf(stderr,
9422 "Zig is unable to provide a libc for the chosen target '%s'.\n"
9423 "The target is non-native, so Zig also cannot use the native libc installation.\n"
9424 "Choose a target which has a libc available (see `zig targets`), or\n"
9425 "provide a libc installation text file (see `zig libc --help`).\n", buf_ptr(&triple_buf));
9426 exit(1);
9427 }
9428}
94299087
9430// does not add the "cc" arg9088 ZigValue *name_field = this_val->data.x_struct.fields[0];
9431void add_cc_args(CodeGen *g, ZigList<const char *> &args, const char *out_dep_path,9089 ZigValue *name_array_val = create_const_str_lit(g, &test_fn_entry->symbol_name)->data.x_ptr.data.ref.pointee;
9432 bool translate_c, FileExt source_kind)9090 init_const_slice(g, name_field, name_array_val, 0, buf_len(&test_fn_entry->symbol_name), true);
9433{
9434 if (translate_c) {
9435 args.append("-x");
9436 args.append("c");
9437 }
94389091
9439 args.append("-nostdinc");9092 ZigValue *fn_field = this_val->data.x_struct.fields[1];
9440 if (source_kind == FileExtCpp) {9093 fn_field->type = fn_type;
9441 args.append("-nostdinc++");9094 fn_field->special = ConstValSpecialStatic;
9442 }9095 fn_field->data.x_ptr.special = ConstPtrSpecialFunction;
9443 args.append("-fno-spell-checking");9096 fn_field->data.x_ptr.mut = ConstPtrMutComptimeConst;
9097 fn_field->data.x_ptr.data.fn.fn_entry = test_fn_entry;
94449098
9445 if (g->function_sections) {9099 ZigValue *frame_size_field = this_val->data.x_struct.fields[2];
9446 args.append("-ffunction-sections");9100 frame_size_field->type = get_optional_type(g, g->builtin_types.entry_usize);
9447 }9101 frame_size_field->special = ConstValSpecialStatic;
9102 frame_size_field->data.x_optional = nullptr;
94489103
9449 if (!translate_c) {9104 if (fn_is_async(test_fn_entry)) {
9450 switch (g->err_color) {9105 frame_size_field->data.x_optional = g->pass1_arena->create<ZigValue>();
9451 case ErrColorAuto:9106 frame_size_field->data.x_optional->special = ConstValSpecialStatic;
9452 break;9107 frame_size_field->data.x_optional->type = g->builtin_types.entry_usize;
9453 case ErrColorOff:9108 bigint_init_unsigned(&frame_size_field->data.x_optional->data.x_bigint,
9454 args.append("-fno-color-diagnostics");9109 test_fn_entry->frame_type->abi_size);
9455 args.append("-fno-caret-diagnostics");
9456 break;
9457 case ErrColorOn:
9458 args.append("-fcolor-diagnostics");
9459 args.append("-fcaret-diagnostics");
9460 break;
9461 }9110 }
9462 }9111 }
9112 report_errors_and_maybe_exit(g);
94639113
9464 for (size_t i = 0; i < g->framework_dirs.length; i += 1) {9114 ZigValue *test_fn_slice = create_const_slice(g, test_fn_array, 0, g->test_fns.length, true);
9465 args.append("-iframework");
9466 args.append(g->framework_dirs.at(i));
9467 }
94689115
9469 if (g->libcpp_link_lib != nullptr) {9116 update_compile_var(g, buf_create_from_str("test_functions"), test_fn_slice);
9470 const char *libcxx_include_path = buf_ptr(buf_sprintf("%s" OS_SEP "libcxx" OS_SEP "include",9117 assert(g->test_runner_package != nullptr);
9471 buf_ptr(g->zig_lib_dir)));9118}
94729119
9473 const char *libcxxabi_include_path = buf_ptr(buf_sprintf("%s" OS_SEP "libcxxabi" OS_SEP "include",9120static Buf *get_resolved_root_src_path(CodeGen *g) {
9474 buf_ptr(g->zig_lib_dir)));9121 // TODO memoize
9122 if (buf_len(&g->main_pkg->root_src_path) == 0)
9123 return nullptr;
94759124
9476 args.append("-isystem");9125 Buf rel_full_path = BUF_INIT;
9477 args.append(libcxx_include_path);9126 os_path_join(&g->main_pkg->root_src_dir, &g->main_pkg->root_src_path, &rel_full_path);
94789127
9479 args.append("-isystem");9128 Buf *resolved_path = buf_alloc();
9480 args.append(libcxxabi_include_path);9129 Buf *resolve_paths[] = {&rel_full_path};
9130 *resolved_path = os_path_resolve(resolve_paths, 1);
94819131
9482 if (target_abi_is_musl(g->zig_target->abi)) {9132 return resolved_path;
9483 args.append("-D_LIBCPP_HAS_MUSL_LIBC");9133}
9484 }
9485 args.append("-D_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS");
9486 args.append("-D_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS");
9487 }
94889134
9489 args.append("-target");9135static void gen_root_source(CodeGen *g) {
9490 args.append(buf_ptr(&g->llvm_triple_str));9136 Buf *resolved_path = get_resolved_root_src_path(g);
9137 if (resolved_path == nullptr)
9138 return;
94919139
9492 switch (source_kind) {9140 Buf *source_code = buf_alloc();
9493 case FileExtC:9141 Error err;
9494 case FileExtCpp:9142 // No need for using the caching system for this file fetch because it is handled
9495 case FileExtHeader:9143 // separately.
9496 // According to Rich Felker libc headers are supposed to go before C language headers.9144 if ((err = os_fetch_file_path(resolved_path, source_code))) {
9497 // However as noted by @dimenus, appending libc headers before c_headers breaks intrinsics9145 fprintf(stderr, "unable to open '%s': %s\n", buf_ptr(resolved_path), err_str(err));
9498 // and other compiler specific items.9146 exit(1);
9499 args.append("-isystem");9147 }
9500 args.append(buf_ptr(g->zig_c_headers_dir));
95019148
9502 for (size_t i = 0; i < g->libc_include_dir_len; i += 1) {9149 ZigType *root_import_alias = add_source_file(g, g->main_pkg, resolved_path, source_code, SourceKindRoot);
9503 const char *include_dir = g->libc_include_dir_list[i];9150 assert(root_import_alias == g->root_import);
9504 args.append("-isystem");
9505 args.append(include_dir);
9506 }
95079151
9508 if (g->zig_target->llvm_cpu_name != nullptr) {9152 assert(g->root_out_name);
9509 args.append("-Xclang");
9510 args.append("-target-cpu");
9511 args.append("-Xclang");
9512 args.append(g->zig_target->llvm_cpu_name);
9513 }
9514 if (g->zig_target->llvm_cpu_features != nullptr) {
9515 // https://github.com/ziglang/zig/issues/5017
9516 SplitIterator it = memSplit(str(g->zig_target->llvm_cpu_features), str(","));
9517 Optional<Slice<uint8_t>> flag = SplitIterator_next(&it);
9518 while (flag.is_some) {
9519 args.append("-Xclang");
9520 args.append("-target-feature");
9521 args.append("-Xclang");
9522 args.append(buf_ptr(buf_create_from_slice(flag.value)));
9523 flag = SplitIterator_next(&it);
9524 }
9525 }
9526 if (translate_c) {
9527 // this gives us access to preprocessing entities, presumably at
9528 // the cost of performance
9529 args.append("-Xclang");
9530 args.append("-detailed-preprocessing-record");
9531 }
9532 if (out_dep_path != nullptr) {
9533 args.append("-MD");
9534 args.append("-MV");
9535 args.append("-MF");
9536 args.append(out_dep_path);
9537 }
9538 break;
9539 case FileExtAsm:
9540 case FileExtLLVMIr:
9541 case FileExtLLVMBitCode:
9542 case FileExtUnknown:
9543 break;
9544 }
9545 for (size_t i = 0; i < g->zig_target->llvm_cpu_features_asm_len; i += 1) {
9546 args.append(g->zig_target->llvm_cpu_features_asm_ptr[i]);
9547 }
95489153
9549 if (g->zig_target->os == OsFreestanding) {9154 // Zig has lazy top level definitions. Here we semantically analyze the panic function.
9550 args.append("-ffreestanding");9155 Buf *import_target_path;
9156 Buf full_path = BUF_INIT;
9157 ZigType *std_import;
9158 if ((err = analyze_import(g, g->root_import, buf_create_from_str("std"), &std_import,
9159 &import_target_path, &full_path)))
9160 {
9161 if (err == ErrorFileNotFound) {
9162 fprintf(stderr, "unable to find '%s'", buf_ptr(import_target_path));
9163 } else {
9164 fprintf(stderr, "unable to open '%s': %s\n", buf_ptr(&full_path), err_str(err));
9165 }
9166 exit(1);
9551 }9167 }
95529168
9553 // windows.h has files such as pshpack1.h which do #pragma packing, triggering a clang warning.9169 Tld *builtin_tld = find_decl(g, &get_container_scope(std_import)->base,
9554 // So for this target, we disable this warning.9170 buf_create_from_str("builtin"));
9555 if (g->zig_target->os == OsWindows && target_abi_is_gnu(g->zig_target->abi)) {9171 assert(builtin_tld != nullptr);
9556 args.append("-Wno-pragma-pack");9172 resolve_top_level_decl(g, builtin_tld, nullptr, false);
9557 }9173 report_errors_and_maybe_exit(g);
9174 assert(builtin_tld->id == TldIdVar);
9175 TldVar *builtin_tld_var = (TldVar*)builtin_tld;
9176 ZigValue *builtin_val = builtin_tld_var->var->const_value;
9177 assert(builtin_val->type->id == ZigTypeIdMetaType);
9178 ZigType *builtin_type = builtin_val->data.x_type;
9179
9180 Tld *panic_tld = find_decl(g, &get_container_scope(builtin_type)->base,
9181 buf_create_from_str("panic"));
9182 assert(panic_tld != nullptr);
9183 resolve_top_level_decl(g, panic_tld, nullptr, false);
9184 report_errors_and_maybe_exit(g);
9185 assert(panic_tld->id == TldIdVar);
9186 TldVar *panic_tld_var = (TldVar*)panic_tld;
9187 ZigValue *panic_fn_val = panic_tld_var->var->const_value;
9188 assert(panic_fn_val->type->id == ZigTypeIdFn);
9189 assert(panic_fn_val->data.x_ptr.special == ConstPtrSpecialFunction);
9190 g->panic_fn = panic_fn_val->data.x_ptr.data.fn.fn_entry;
9191 assert(g->panic_fn != nullptr);
95589192
9559 if (!g->strip_debug_symbols) {9193 if (!g->error_during_imports) {
9560 args.append("-g");9194 semantic_analyze(g);
9561 }9195 }
9196 report_errors_and_maybe_exit(g);
95629197
9563 if (codegen_have_frame_pointer(g)) {9198 if (g->is_test_build) {
9564 args.append("-fno-omit-frame-pointer");9199 update_test_functions_builtin_decl(g);
9565 } else {9200 if (!g->error_during_imports) {
9566 args.append("-fomit-frame-pointer");9201 semantic_analyze(g);
9202 }
9567 }9203 }
95689204
9569 if (g->have_sanitize_c) {9205 report_errors_and_maybe_exit(g);
9570 args.append("-fsanitize=undefined");
9571 args.append("-fsanitize-trap=undefined");
9572 }
95739206
9574 switch (g->build_mode) {9207}
9575 case BuildModeDebug:
9576 // windows c runtime requires -D_DEBUG if using debug libraries
9577 args.append("-D_DEBUG");
9578 args.append("-Og");
9579
9580 if (g->libc_link_lib != nullptr) {
9581 args.append("-fstack-protector-strong");
9582 args.append("--param");
9583 args.append("ssp-buffer-size=4");
9584 } else {
9585 args.append("-fno-stack-protector");
9586 }
9587 break;
9588 case BuildModeSafeRelease:
9589 // See the comment in the BuildModeFastRelease case for why we pass -O2 rather
9590 // than -O3 here.
9591 args.append("-O2");
9592 if (g->libc_link_lib != nullptr) {
9593 args.append("-D_FORTIFY_SOURCE=2");
9594 args.append("-fstack-protector-strong");
9595 args.append("--param");
9596 args.append("ssp-buffer-size=4");
9597 } else {
9598 args.append("-fno-stack-protector");
9599 }
9600 break;
9601 case BuildModeFastRelease:
9602 args.append("-DNDEBUG");
9603 // Here we pass -O2 rather than -O3 because, although we do the equivalent of
9604 // -O3 in Zig code, the justification for the difference here is that Zig
9605 // has better detection and prevention of undefined behavior, so -O3 is safer for
9606 // Zig code than it is for C code. Also, C programmers are used to their code
9607 // running in -O2 and thus the -O3 path has been tested less.
9608 args.append("-O2");
9609 args.append("-fno-stack-protector");
9610 break;
9611 case BuildModeSmallRelease:
9612 args.append("-DNDEBUG");
9613 args.append("-Os");
9614 args.append("-fno-stack-protector");
9615 break;
9616 }
9617
9618 if (target_supports_fpic(g->zig_target) && g->have_pic) {
9619 args.append("-fPIC");
9620 }
9621
9622 for (size_t arg_i = 0; arg_i < g->clang_argv_len; arg_i += 1) {
9623 args.append(g->clang_argv[arg_i]);
9624 }
9625
9626}
9627
9628void codegen_translate_c(CodeGen *g, Buf *full_path) {
9629 Error err;
9630
9631 Buf *src_basename = buf_alloc();
9632 Buf *src_dirname = buf_alloc();
9633 os_path_split(full_path, src_dirname, src_basename);
9634
9635 Buf noextname = BUF_INIT;
9636 os_path_extname(src_basename, &noextname, nullptr);
9637
9638 Buf *zig_basename = buf_sprintf("%s.zig", buf_ptr(&noextname));
9639
9640 detect_libc(g);
9641
9642 Buf cache_digest = BUF_INIT;
9643 buf_resize(&cache_digest, 0);
9644
9645 CacheHash *cache_hash = nullptr;
9646 if (g->enable_cache) {
9647 if ((err = create_c_object_cache(g, &cache_hash, true))) {
9648 // Already printed error; verbose = true
9649 exit(1);
9650 }
9651 cache_file(cache_hash, full_path);
9652 // to distinguish from generating a C object
9653 cache_buf(cache_hash, buf_create_from_str("translate-c"));
9654
9655 if ((err = cache_hit(cache_hash, &cache_digest))) {
9656 if (err != ErrorInvalidFormat) {
9657 fprintf(stderr, "unable to check cache: %s\n", err_str(err));
9658 exit(1);
9659 }
9660 }
9661 if (cache_hash->manifest_file_path != nullptr) {
9662 g->caches_to_release.append(cache_hash);
9663 }
9664 }
9665
9666 if (g->enable_cache && buf_len(&cache_digest) != 0) {
9667 // cache hit
9668 Buf *cached_path = buf_sprintf("%s" OS_SEP CACHE_OUT_SUBDIR OS_SEP "%s" OS_SEP "%s",
9669 buf_ptr(g->cache_dir), buf_ptr(&cache_digest), buf_ptr(zig_basename));
9670 fprintf(stdout, "%s\n", buf_ptr(cached_path));
9671 return;
9672 }
9673
9674 // cache miss or cache disabled
9675 init(g);
9676
9677 Buf *out_dep_path = nullptr;
9678 const char *out_dep_path_cstr = nullptr;
9679
9680 if (g->enable_cache) {
9681 buf_alloc();// we can't know the digest until we do the C compiler invocation, so we
9682 // need a tmp filename.
9683 out_dep_path = buf_alloc();
9684 if ((err = get_tmp_filename(g, out_dep_path, buf_sprintf("%s.d", buf_ptr(zig_basename))))) {
9685 fprintf(stderr, "unable to create tmp dir: %s\n", err_str(err));
9686 exit(1);
9687 }
9688 out_dep_path_cstr = buf_ptr(out_dep_path);
9689 }
9690
9691 ZigList<const char *> clang_argv = {0};
9692 add_cc_args(g, clang_argv, out_dep_path_cstr, true, FileExtC);
9693
9694 clang_argv.append(buf_ptr(full_path));
9695
9696 if (g->verbose_cc) {
9697 fprintf(stderr, "clang");
9698 for (size_t i = 0; i < clang_argv.length; i += 1) {
9699 fprintf(stderr, " %s", clang_argv.at(i));
9700 }
9701 fprintf(stderr, "\n");
9702 }
9703
9704 clang_argv.append(nullptr); // to make the [start...end] argument work
9705
9706 const char *resources_path = buf_ptr(g->zig_c_headers_dir);
9707 Stage2ErrorMsg *errors_ptr;
9708 size_t errors_len;
9709 Stage2Ast *ast;
9710
9711 err = stage2_translate_c(&ast, &errors_ptr, &errors_len,
9712 &clang_argv.at(0), &clang_argv.last(), resources_path);
9713
9714 if (err == ErrorCCompileErrors && errors_len > 0) {
9715 for (size_t i = 0; i < errors_len; i += 1) {
9716 Stage2ErrorMsg *clang_err = &errors_ptr[i];
9717
9718 ErrorMsg *err_msg = err_msg_create_with_offset(
9719 clang_err->filename_ptr ?
9720 buf_create_from_mem(clang_err->filename_ptr, clang_err->filename_len) : nullptr,
9721 clang_err->line, clang_err->column, clang_err->offset, clang_err->source,
9722 buf_create_from_mem(clang_err->msg_ptr, clang_err->msg_len));
9723 print_err_msg(err_msg, g->err_color);
9724 }
9725 exit(1);
9726 }
9727
9728 if (err) {
9729 fprintf(stderr, "unable to parse C file: %s\n", err_str(err));
9730 exit(1);
9731 }
9732
9733 if (!g->enable_cache) {
9734 stage2_render_ast(ast, stdout);
9735 return;
9736 }
9737
9738 // add the files depended on to the cache system
9739 if ((err = cache_add_dep_file(cache_hash, out_dep_path, true))) {
9740 // Don't treat the absence of the .d file as a fatal error, the
9741 // compiler may not produce one eg. when compiling .s files
9742 if (err != ErrorFileNotFound) {
9743 fprintf(stderr, "Failed to add C source dependencies to cache: %s\n", err_str(err));
9744 exit(1);
9745 }
9746 }
9747 if (err != ErrorFileNotFound) {
9748 os_delete_file(out_dep_path);
9749 }
9750
9751 if ((err = cache_final(cache_hash, &cache_digest))) {
9752 fprintf(stderr, "Unable to finalize cache hash: %s\n", err_str(err));
9753 exit(1);
9754 }
9755
9756 Buf *artifact_dir = buf_sprintf("%s" OS_SEP CACHE_OUT_SUBDIR OS_SEP "%s",
9757 buf_ptr(g->cache_dir), buf_ptr(&cache_digest));
9758
9759 if ((err = os_make_path(artifact_dir))) {
9760 fprintf(stderr, "Unable to make dir: %s\n", err_str(err));
9761 exit(1);
9762 }
9763
9764 Buf *cached_path = buf_sprintf("%s" OS_SEP "%s", buf_ptr(artifact_dir), buf_ptr(zig_basename));
9765
9766 FILE *out_file = fopen(buf_ptr(cached_path), "wb");
9767 if (out_file == nullptr) {
9768 fprintf(stderr, "Unable to open output file: %s\n", strerror(errno));
9769 exit(1);
9770 }
9771 stage2_render_ast(ast, out_file);
9772 if (fclose(out_file) != 0) {
9773 fprintf(stderr, "Unable to write to output file: %s\n", strerror(errno));
9774 exit(1);
9775 }
9776 fprintf(stdout, "%s\n", buf_ptr(cached_path));
9777}
9778
9779static void update_test_functions_builtin_decl(CodeGen *g) {
9780 Error err;
9781
9782 assert(g->is_test_build);
9783
9784 if (g->test_fns.length == 0) {
9785 fprintf(stderr, "No tests to run.\n");
9786 exit(0);
9787 }
9788
9789 ZigType *fn_type = get_test_fn_type(g);
9790
9791 ZigValue *test_fn_type_val = get_builtin_value(g, "TestFn");
9792 assert(test_fn_type_val->type->id == ZigTypeIdMetaType);
9793 ZigType *struct_type = test_fn_type_val->data.x_type;
9794 if ((err = type_resolve(g, struct_type, ResolveStatusSizeKnown)))
9795 zig_unreachable();
9796
9797 ZigValue *test_fn_array = g->pass1_arena->create<ZigValue>();
9798 test_fn_array->type = get_array_type(g, struct_type, g->test_fns.length, nullptr);
9799 test_fn_array->special = ConstValSpecialStatic;
9800 test_fn_array->data.x_array.data.s_none.elements = g->pass1_arena->allocate<ZigValue>(g->test_fns.length);
9801
9802 for (size_t i = 0; i < g->test_fns.length; i += 1) {
9803 ZigFn *test_fn_entry = g->test_fns.at(i);
9804
9805 ZigValue *this_val = &test_fn_array->data.x_array.data.s_none.elements[i];
9806 this_val->special = ConstValSpecialStatic;
9807 this_val->type = struct_type;
9808 this_val->parent.id = ConstParentIdArray;
9809 this_val->parent.data.p_array.array_val = test_fn_array;
9810 this_val->parent.data.p_array.elem_index = i;
9811 this_val->data.x_struct.fields = alloc_const_vals_ptrs(g, 3);
9812
9813 ZigValue *name_field = this_val->data.x_struct.fields[0];
9814 ZigValue *name_array_val = create_const_str_lit(g, &test_fn_entry->symbol_name)->data.x_ptr.data.ref.pointee;
9815 init_const_slice(g, name_field, name_array_val, 0, buf_len(&test_fn_entry->symbol_name), true);
9816
9817 ZigValue *fn_field = this_val->data.x_struct.fields[1];
9818 fn_field->type = fn_type;
9819 fn_field->special = ConstValSpecialStatic;
9820 fn_field->data.x_ptr.special = ConstPtrSpecialFunction;
9821 fn_field->data.x_ptr.mut = ConstPtrMutComptimeConst;
9822 fn_field->data.x_ptr.data.fn.fn_entry = test_fn_entry;
9823
9824 ZigValue *frame_size_field = this_val->data.x_struct.fields[2];
9825 frame_size_field->type = get_optional_type(g, g->builtin_types.entry_usize);
9826 frame_size_field->special = ConstValSpecialStatic;
9827 frame_size_field->data.x_optional = nullptr;
9828
9829 if (fn_is_async(test_fn_entry)) {
9830 frame_size_field->data.x_optional = g->pass1_arena->create<ZigValue>();
9831 frame_size_field->data.x_optional->special = ConstValSpecialStatic;
9832 frame_size_field->data.x_optional->type = g->builtin_types.entry_usize;
9833 bigint_init_unsigned(&frame_size_field->data.x_optional->data.x_bigint,
9834 test_fn_entry->frame_type->abi_size);
9835 }
9836 }
9837 report_errors_and_maybe_exit(g);
9838
9839 ZigValue *test_fn_slice = create_const_slice(g, test_fn_array, 0, g->test_fns.length, true);
9840
9841 update_compile_var(g, buf_create_from_str("test_functions"), test_fn_slice);
9842 assert(g->test_runner_package != nullptr);
9843}
9844
9845static Buf *get_resolved_root_src_path(CodeGen *g) {
9846 // TODO memoize
9847 if (buf_len(&g->main_pkg->root_src_path) == 0)
9848 return nullptr;
9849
9850 Buf rel_full_path = BUF_INIT;
9851 os_path_join(&g->main_pkg->root_src_dir, &g->main_pkg->root_src_path, &rel_full_path);
9852
9853 Buf *resolved_path = buf_alloc();
9854 Buf *resolve_paths[] = {&rel_full_path};
9855 *resolved_path = os_path_resolve(resolve_paths, 1);
9856
9857 return resolved_path;
9858}
9859
9860static void gen_root_source(CodeGen *g) {
9861 Buf *resolved_path = get_resolved_root_src_path(g);
9862 if (resolved_path == nullptr)
9863 return;
9864
9865 Buf *source_code = buf_alloc();
9866 Error err;
9867 // No need for using the caching system for this file fetch because it is handled
9868 // separately.
9869 if ((err = os_fetch_file_path(resolved_path, source_code))) {
9870 fprintf(stderr, "unable to open '%s': %s\n", buf_ptr(resolved_path), err_str(err));
9871 exit(1);
9872 }
9873
9874 ZigType *root_import_alias = add_source_file(g, g->main_pkg, resolved_path, source_code, SourceKindRoot);
9875 assert(root_import_alias == g->root_import);
9876
9877 assert(g->root_out_name);
9878 assert(g->out_type != OutTypeUnknown);
9879
9880 if (!g->is_dummy_so) {
9881 // Zig has lazy top level definitions. Here we semantically analyze the panic function.
9882 Buf *import_target_path;
9883 Buf full_path = BUF_INIT;
9884 ZigType *std_import;
9885 if ((err = analyze_import(g, g->root_import, buf_create_from_str("std"), &std_import,
9886 &import_target_path, &full_path)))
9887 {
9888 if (err == ErrorFileNotFound) {
9889 fprintf(stderr, "unable to find '%s'", buf_ptr(import_target_path));
9890 } else {
9891 fprintf(stderr, "unable to open '%s': %s\n", buf_ptr(&full_path), err_str(err));
9892 }
9893 exit(1);
9894 }
9895
9896 Tld *builtin_tld = find_decl(g, &get_container_scope(std_import)->base,
9897 buf_create_from_str("builtin"));
9898 assert(builtin_tld != nullptr);
9899 resolve_top_level_decl(g, builtin_tld, nullptr, false);
9900 report_errors_and_maybe_exit(g);
9901 assert(builtin_tld->id == TldIdVar);
9902 TldVar *builtin_tld_var = (TldVar*)builtin_tld;
9903 ZigValue *builtin_val = builtin_tld_var->var->const_value;
9904 assert(builtin_val->type->id == ZigTypeIdMetaType);
9905 ZigType *builtin_type = builtin_val->data.x_type;
9906
9907 Tld *panic_tld = find_decl(g, &get_container_scope(builtin_type)->base,
9908 buf_create_from_str("panic"));
9909 assert(panic_tld != nullptr);
9910 resolve_top_level_decl(g, panic_tld, nullptr, false);
9911 report_errors_and_maybe_exit(g);
9912 assert(panic_tld->id == TldIdVar);
9913 TldVar *panic_tld_var = (TldVar*)panic_tld;
9914 ZigValue *panic_fn_val = panic_tld_var->var->const_value;
9915 assert(panic_fn_val->type->id == ZigTypeIdFn);
9916 assert(panic_fn_val->data.x_ptr.special == ConstPtrSpecialFunction);
9917 g->panic_fn = panic_fn_val->data.x_ptr.data.fn.fn_entry;
9918 assert(g->panic_fn != nullptr);
9919 }
9920
9921 if (!g->error_during_imports) {
9922 semantic_analyze(g);
9923 }
9924 report_errors_and_maybe_exit(g);
9925
9926 if (g->is_test_build) {
9927 update_test_functions_builtin_decl(g);
9928 if (!g->error_during_imports) {
9929 semantic_analyze(g);
9930 }
9931 }
9932
9933 report_errors_and_maybe_exit(g);
9934
9935}
9936
9937static void print_zig_cc_cmd(ZigList<const char *> *args) {
9938 for (size_t arg_i = 0; arg_i < args->length; arg_i += 1) {
9939 const char *space_str = (arg_i == 0) ? "" : " ";
9940 fprintf(stderr, "%s%s", space_str, args->at(arg_i));
9941 }
9942 fprintf(stderr, "\n");
9943}
9944
9945// Caller should delete the file when done or rename it into a better location.
9946static Error get_tmp_filename(CodeGen *g, Buf *out, Buf *suffix) {
9947 Error err;
9948 buf_resize(out, 0);
9949 os_path_join(g->cache_dir, buf_create_from_str("tmp" OS_SEP), out);
9950 if ((err = os_make_path(out))) {
9951 return err;
9952 }
9953 const char base64[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_";
9954 assert(array_length(base64) == 64 + 1);
9955 for (size_t i = 0; i < 12; i += 1) {
9956 buf_append_char(out, base64[rand() % 64]);
9957 }
9958 buf_append_char(out, '-');
9959 buf_append_buf(out, suffix);
9960 return ErrorNone;
9961}
9962
9963Error create_c_object_cache(CodeGen *g, CacheHash **out_cache_hash, bool verbose) {
9964 Error err;
9965 CacheHash *cache_hash = heap::c_allocator.create<CacheHash>();
9966 Buf *manifest_dir = buf_sprintf("%s" OS_SEP CACHE_HASH_SUBDIR, buf_ptr(g->cache_dir));
9967 cache_init(cache_hash, manifest_dir);
9968
9969 Buf *compiler_id;
9970 if ((err = get_compiler_id(&compiler_id))) {
9971 if (verbose) {
9972 fprintf(stderr, "unable to get compiler id: %s\n", err_str(err));
9973 }
9974 return err;
9975 }
9976 cache_buf(cache_hash, compiler_id);
9977 cache_int(cache_hash, g->err_color);
9978 cache_list_of_str(cache_hash, g->framework_dirs.items, g->framework_dirs.length);
9979 cache_bool(cache_hash, g->libcpp_link_lib != nullptr);
9980 cache_buf(cache_hash, g->zig_lib_dir);
9981 cache_buf(cache_hash, g->zig_c_headers_dir);
9982 cache_list_of_str(cache_hash, g->libc_include_dir_list, g->libc_include_dir_len);
9983 cache_int(cache_hash, g->zig_target->is_native_os);
9984 cache_int(cache_hash, g->zig_target->is_native_cpu);
9985 cache_int(cache_hash, g->zig_target->arch);
9986 cache_int(cache_hash, g->zig_target->vendor);
9987 cache_int(cache_hash, g->zig_target->os);
9988 cache_int(cache_hash, g->zig_target->abi);
9989 cache_bool(cache_hash, g->strip_debug_symbols);
9990 cache_int(cache_hash, g->build_mode);
9991 cache_bool(cache_hash, g->have_pic);
9992 cache_bool(cache_hash, g->have_sanitize_c);
9993 cache_bool(cache_hash, want_valgrind_support(g));
9994 cache_bool(cache_hash, g->function_sections);
9995 cache_int(cache_hash, g->code_model);
9996 cache_bool(cache_hash, codegen_have_frame_pointer(g));
9997 cache_bool(cache_hash, g->libc_link_lib);
9998 if (g->zig_target->cache_hash != nullptr) {
9999 cache_mem(cache_hash, g->zig_target->cache_hash, g->zig_target->cache_hash_len);
10000 }
10001
10002 for (size_t arg_i = 0; arg_i < g->clang_argv_len; arg_i += 1) {
10003 cache_str(cache_hash, g->clang_argv[arg_i]);
10004 }
10005
10006 *out_cache_hash = cache_hash;
10007 return ErrorNone;
10008}
10009
10010static bool need_llvm_module(CodeGen *g) {
10011 return buf_len(&g->main_pkg->root_src_path) != 0;
10012}
10013
10014// before gen_c_objects
10015static bool main_output_dir_is_just_one_c_object_pre(CodeGen *g) {
10016 return g->enable_cache && g->c_source_files.length == 1 && !need_llvm_module(g) &&
10017 g->out_type == OutTypeObj && g->link_objects.length == 0;
10018}
10019
10020// after gen_c_objects
10021static bool main_output_dir_is_just_one_c_object_post(CodeGen *g) {
10022 return g->enable_cache && g->link_objects.length == 1 && !need_llvm_module(g) && g->out_type == OutTypeObj;
10023}
10024
10025// returns true if it was a cache miss
10026static void gen_c_object(CodeGen *g, Buf *self_exe_path, CFile *c_file) {
10027 Error err;
10028
10029 Buf *artifact_dir;
10030 Buf *o_final_path;
10031
10032 Buf *o_dir = buf_sprintf("%s" OS_SEP CACHE_OUT_SUBDIR, buf_ptr(g->cache_dir));
10033
10034 Buf *c_source_file = buf_create_from_str(c_file->source_path);
10035 Buf *c_source_basename = buf_alloc();
10036 os_path_split(c_source_file, nullptr, c_source_basename);
10037
10038 Stage2ProgressNode *child_prog_node = stage2_progress_start(g->sub_progress_node, buf_ptr(c_source_basename),
10039 buf_len(c_source_basename), 0);
10040
10041 Buf *final_o_basename = buf_alloc();
10042 if (c_file->preprocessor_only_basename == nullptr) {
10043 // We special case when doing build-obj for just one C file
10044 if (main_output_dir_is_just_one_c_object_pre(g)) {
10045 buf_init_from_buf(final_o_basename, g->root_out_name);
10046 } else {
10047 os_path_extname(c_source_basename, final_o_basename, nullptr);
10048 }
10049 buf_append_str(final_o_basename, target_o_file_ext(g->zig_target));
10050 } else {
10051 buf_init_from_str(final_o_basename, c_file->preprocessor_only_basename);
10052 }
10053
10054 CacheHash *cache_hash;
10055 if ((err = create_c_object_cache(g, &cache_hash, true))) {
10056 // Already printed error; verbose = true
10057 exit(1);
10058 }
10059 cache_file(cache_hash, c_source_file);
10060
10061 // Note: not directory args, just args that always have a file next
10062 static const char *file_args[] = {
10063 "-include",
10064 };
10065 for (size_t arg_i = 0; arg_i < c_file->args.length; arg_i += 1) {
10066 const char *arg = c_file->args.at(arg_i);
10067 cache_str(cache_hash, arg);
10068 for (size_t file_arg_i = 0; file_arg_i < array_length(file_args); file_arg_i += 1) {
10069 if (strcmp(arg, file_args[file_arg_i]) == 0 && arg_i + 1 < c_file->args.length) {
10070 arg_i += 1;
10071 cache_file(cache_hash, buf_create_from_str(c_file->args.at(arg_i)));
10072 }
10073 }
10074 }
10075
10076 Buf digest = BUF_INIT;
10077 buf_resize(&digest, 0);
10078 if ((err = cache_hit(cache_hash, &digest))) {
10079 if (err != ErrorInvalidFormat) {
10080 if (err == ErrorCacheUnavailable) {
10081 // already printed error
10082 } else {
10083 fprintf(stderr, "unable to check cache when compiling C object: %s\n", err_str(err));
10084 }
10085 exit(1);
10086 }
10087 }
10088 bool is_cache_miss = g->disable_c_depfile || (buf_len(&digest) == 0);
10089 if (is_cache_miss) {
10090 // we can't know the digest until we do the C compiler invocation, so we
10091 // need a tmp filename.
10092 Buf *out_obj_path = buf_alloc();
10093 if ((err = get_tmp_filename(g, out_obj_path, final_o_basename))) {
10094 fprintf(stderr, "unable to create tmp dir: %s\n", err_str(err));
10095 exit(1);
10096 }
10097
10098 Termination term;
10099 ZigList<const char *> args = {};
10100 args.append(buf_ptr(self_exe_path));
10101 args.append("clang");
10102
10103 if (c_file->preprocessor_only_basename == nullptr) {
10104 args.append("-c");
10105 }
10106
10107 Buf *out_dep_path = g->disable_c_depfile ? nullptr : buf_sprintf("%s.d", buf_ptr(out_obj_path));
10108 const char *out_dep_path_cstr = (out_dep_path == nullptr) ? nullptr : buf_ptr(out_dep_path);
10109 FileExt ext = classify_file_ext(buf_ptr(c_source_basename), buf_len(c_source_basename));
10110 add_cc_args(g, args, out_dep_path_cstr, false, ext);
10111
10112 args.append("-o");
10113 args.append(buf_ptr(out_obj_path));
10114
10115 args.append(buf_ptr(c_source_file));
10116
10117 for (size_t arg_i = 0; arg_i < c_file->args.length; arg_i += 1) {
10118 args.append(c_file->args.at(arg_i));
10119 }
10120
10121 if (g->verbose_cc) {
10122 print_zig_cc_cmd(&args);
10123 }
10124 os_spawn_process(args, &term);
10125 if (term.how != TerminationIdClean || term.code != 0) {
10126 fprintf(stderr, "\nThe following command failed:\n");
10127 print_zig_cc_cmd(&args);
10128 exit(1);
10129 }
10130
10131 if (out_dep_path != nullptr) {
10132 // add the files depended on to the cache system
10133 if ((err = cache_add_dep_file(cache_hash, out_dep_path, true))) {
10134 // Don't treat the absence of the .d file as a fatal error, the
10135 // compiler may not produce one eg. when compiling .s files
10136 if (err != ErrorFileNotFound) {
10137 fprintf(stderr, "Failed to add C source dependencies to cache: %s\n", err_str(err));
10138 exit(1);
10139 }
10140 }
10141 if (err != ErrorFileNotFound) {
10142 os_delete_file(out_dep_path);
10143 }
10144
10145 if ((err = cache_final(cache_hash, &digest))) {
10146 fprintf(stderr, "Unable to finalize cache hash: %s\n", err_str(err));
10147 exit(1);
10148 }
10149 }
10150 artifact_dir = buf_alloc();
10151 os_path_join(o_dir, &digest, artifact_dir);
10152 if ((err = os_make_path(artifact_dir))) {
10153 fprintf(stderr, "Unable to create output directory '%s': %s",
10154 buf_ptr(artifact_dir), err_str(err));
10155 exit(1);
10156 }
10157 o_final_path = buf_alloc();
10158 os_path_join(artifact_dir, final_o_basename, o_final_path);
10159 if ((err = os_rename(out_obj_path, o_final_path))) {
10160 fprintf(stderr, "Unable to rename object: %s\n", err_str(err));
10161 exit(1);
10162 }
10163 } else {
10164 // cache hit
10165 artifact_dir = buf_alloc();
10166 os_path_join(o_dir, &digest, artifact_dir);
10167 o_final_path = buf_alloc();
10168 os_path_join(artifact_dir, final_o_basename, o_final_path);
10169 }
10170
10171 g->c_artifact_dir = artifact_dir;
10172 g->link_objects.append(o_final_path);
10173 g->caches_to_release.append(cache_hash);
10174
10175 stage2_progress_end(child_prog_node);
10176}
10177
10178// returns true if we had any cache misses
10179static void gen_c_objects(CodeGen *g) {
10180 Error err;
10181
10182 if (g->c_source_files.length == 0)
10183 return;
10184
10185 Buf *self_exe_path = buf_alloc();
10186 if ((err = os_self_exe_path(self_exe_path))) {
10187 fprintf(stderr, "Unable to get self exe path: %s\n", err_str(err));
10188 exit(1);
10189 }
10190
10191 codegen_add_time_event(g, "Compile C Objects");
10192 const char *c_prog_name = "Compile C Objects";
10193 codegen_switch_sub_prog_node(g, stage2_progress_start(g->main_progress_node, c_prog_name, strlen(c_prog_name),
10194 g->c_source_files.length));
10195
10196 for (size_t c_file_i = 0; c_file_i < g->c_source_files.length; c_file_i += 1) {
10197 CFile *c_file = g->c_source_files.at(c_file_i);
10198 gen_c_object(g, self_exe_path, c_file);
10199 }
10200}
10201
10202void codegen_add_object(CodeGen *g, Buf *object_path) {
10203 g->link_objects.append(object_path);
10204}
10205
10206// Must be coordinated with with CIntType enum
10207static const char *c_int_type_names[] = {
10208 "short",
10209 "unsigned short",
10210 "int",
10211 "unsigned int",
10212 "long",
10213 "unsigned long",
10214 "long long",
10215 "unsigned long long",
10216};
10217
10218struct GenH {
10219 ZigList<ZigType *> types_to_declare;
10220};
10221
10222static void prepend_c_type_to_decl_list(CodeGen *g, GenH *gen_h, ZigType *type_entry) {
10223 if (type_entry->gen_h_loop_flag)
10224 return;
10225 type_entry->gen_h_loop_flag = true;
10226
10227 switch (type_entry->id) {
10228 case ZigTypeIdInvalid:
10229 case ZigTypeIdMetaType:
10230 case ZigTypeIdComptimeFloat:
10231 case ZigTypeIdComptimeInt:
10232 case ZigTypeIdEnumLiteral:
10233 case ZigTypeIdUndefined:
10234 case ZigTypeIdNull:
10235 case ZigTypeIdBoundFn:
10236 case ZigTypeIdErrorUnion:
10237 case ZigTypeIdErrorSet:
10238 case ZigTypeIdFnFrame:
10239 case ZigTypeIdAnyFrame:
10240 zig_unreachable();
10241 case ZigTypeIdVoid:
10242 case ZigTypeIdUnreachable:
10243 return;
10244 case ZigTypeIdBool:
10245 g->c_want_stdbool = true;
10246 return;
10247 case ZigTypeIdInt:
10248 g->c_want_stdint = true;
10249 return;
10250 case ZigTypeIdFloat:
10251 return;
10252 case ZigTypeIdOpaque:
10253 gen_h->types_to_declare.append(type_entry);
10254 return;
10255 case ZigTypeIdStruct:
10256 if(type_entry->data.structure.layout == ContainerLayoutExtern) {
10257 for (uint32_t i = 0; i < type_entry->data.structure.src_field_count; i += 1) {
10258 TypeStructField *field = type_entry->data.structure.fields[i];
10259 prepend_c_type_to_decl_list(g, gen_h, field->type_entry);
10260 }
10261 }
10262 gen_h->types_to_declare.append(type_entry);
10263 return;
10264 case ZigTypeIdUnion:
10265 for (uint32_t i = 0; i < type_entry->data.unionation.src_field_count; i += 1) {
10266 TypeUnionField *field = &type_entry->data.unionation.fields[i];
10267 prepend_c_type_to_decl_list(g, gen_h, field->type_entry);
10268 }
10269 gen_h->types_to_declare.append(type_entry);
10270 return;
10271 case ZigTypeIdEnum:
10272 prepend_c_type_to_decl_list(g, gen_h, type_entry->data.enumeration.tag_int_type);
10273 gen_h->types_to_declare.append(type_entry);
10274 return;
10275 case ZigTypeIdPointer:
10276 prepend_c_type_to_decl_list(g, gen_h, type_entry->data.pointer.child_type);
10277 return;
10278 case ZigTypeIdArray:
10279 prepend_c_type_to_decl_list(g, gen_h, type_entry->data.array.child_type);
10280 return;
10281 case ZigTypeIdVector:
10282 prepend_c_type_to_decl_list(g, gen_h, type_entry->data.vector.elem_type);
10283 return;
10284 case ZigTypeIdOptional:
10285 prepend_c_type_to_decl_list(g, gen_h, type_entry->data.maybe.child_type);
10286 return;
10287 case ZigTypeIdFn:
10288 for (size_t i = 0; i < type_entry->data.fn.fn_type_id.param_count; i += 1) {
10289 prepend_c_type_to_decl_list(g, gen_h, type_entry->data.fn.fn_type_id.param_info[i].type);
10290 }
10291 prepend_c_type_to_decl_list(g, gen_h, type_entry->data.fn.fn_type_id.return_type);
10292 return;
10293 }
10294}
10295
10296static void get_c_type(CodeGen *g, GenH *gen_h, ZigType *type_entry, Buf *out_buf) {
10297 assert(type_entry);
10298
10299 for (size_t i = 0; i < array_length(c_int_type_names); i += 1) {
10300 if (type_entry == g->builtin_types.entry_c_int[i]) {
10301 buf_init_from_str(out_buf, c_int_type_names[i]);
10302 return;
10303 }
10304 }
10305 if (type_entry == g->builtin_types.entry_c_longdouble) {
10306 buf_init_from_str(out_buf, "long double");
10307 return;
10308 }
10309 if (type_entry == g->builtin_types.entry_c_void) {
10310 buf_init_from_str(out_buf, "void");
10311 return;
10312 }
10313 if (type_entry == g->builtin_types.entry_isize) {
10314 g->c_want_stdint = true;
10315 buf_init_from_str(out_buf, "intptr_t");
10316 return;
10317 }
10318 if (type_entry == g->builtin_types.entry_usize) {
10319 g->c_want_stdint = true;
10320 buf_init_from_str(out_buf, "uintptr_t");
10321 return;
10322 }
10323
10324 prepend_c_type_to_decl_list(g, gen_h, type_entry);
10325
10326 switch (type_entry->id) {
10327 case ZigTypeIdVoid:
10328 buf_init_from_str(out_buf, "void");
10329 break;
10330 case ZigTypeIdBool:
10331 buf_init_from_str(out_buf, "bool");
10332 break;
10333 case ZigTypeIdUnreachable:
10334 buf_init_from_str(out_buf, "__attribute__((__noreturn__)) void");
10335 break;
10336 case ZigTypeIdFloat:
10337 switch (type_entry->data.floating.bit_count) {
10338 case 32:
10339 buf_init_from_str(out_buf, "float");
10340 break;
10341 case 64:
10342 buf_init_from_str(out_buf, "double");
10343 break;
10344 case 80:
10345 buf_init_from_str(out_buf, "__float80");
10346 break;
10347 case 128:
10348 buf_init_from_str(out_buf, "__float128");
10349 break;
10350 default:
10351 zig_unreachable();
10352 }
10353 break;
10354 case ZigTypeIdInt:
10355 buf_resize(out_buf, 0);
10356 buf_appendf(out_buf, "%sint%" PRIu32 "_t",
10357 type_entry->data.integral.is_signed ? "" : "u",
10358 type_entry->data.integral.bit_count);
10359 break;
10360 case ZigTypeIdPointer:
10361 {
10362 Buf child_buf = BUF_INIT;
10363 ZigType *child_type = type_entry->data.pointer.child_type;
10364 get_c_type(g, gen_h, child_type, &child_buf);
10365
10366 const char *const_str = type_entry->data.pointer.is_const ? "const " : "";
10367 buf_resize(out_buf, 0);
10368 buf_appendf(out_buf, "%s%s *", const_str, buf_ptr(&child_buf));
10369 break;
10370 }
10371 case ZigTypeIdOptional:
10372 {
10373 ZigType *child_type = type_entry->data.maybe.child_type;
10374 if (!type_has_bits(g, child_type)) {
10375 buf_init_from_str(out_buf, "bool");
10376 return;
10377 } else if (type_is_nonnull_ptr(g, child_type)) {
10378 return get_c_type(g, gen_h, child_type, out_buf);
10379 } else {
10380 zig_unreachable();
10381 }
10382 }
10383 case ZigTypeIdStruct:
10384 case ZigTypeIdOpaque:
10385 {
10386 buf_init_from_str(out_buf, "struct ");
10387 buf_append_buf(out_buf, type_h_name(type_entry));
10388 return;
10389 }
10390 case ZigTypeIdUnion:
10391 {
10392 buf_init_from_str(out_buf, "union ");
10393 buf_append_buf(out_buf, type_h_name(type_entry));
10394 return;
10395 }
10396 case ZigTypeIdEnum:
10397 {
10398 buf_init_from_str(out_buf, "enum ");
10399 buf_append_buf(out_buf, type_h_name(type_entry));
10400 return;
10401 }
10402 case ZigTypeIdArray:
10403 {
10404 ZigTypeArray *array_data = &type_entry->data.array;
10405
10406 Buf *child_buf = buf_alloc();
10407 get_c_type(g, gen_h, array_data->child_type, child_buf);
10408
10409 buf_resize(out_buf, 0);
10410 buf_appendf(out_buf, "%s", buf_ptr(child_buf));
10411 return;
10412 }
10413 case ZigTypeIdVector:
10414 zig_panic("TODO implement get_c_type for vector types");
10415 case ZigTypeIdErrorUnion:
10416 case ZigTypeIdErrorSet:
10417 case ZigTypeIdFn:
10418 zig_panic("TODO implement get_c_type for more types");
10419 case ZigTypeIdInvalid:
10420 case ZigTypeIdMetaType:
10421 case ZigTypeIdBoundFn:
10422 case ZigTypeIdComptimeFloat:
10423 case ZigTypeIdComptimeInt:
10424 case ZigTypeIdEnumLiteral:
10425 case ZigTypeIdUndefined:
10426 case ZigTypeIdNull:
10427 case ZigTypeIdFnFrame:
10428 case ZigTypeIdAnyFrame:
10429 zig_unreachable();
10430 }
10431}
10432
10433static const char *preprocessor_alphabet1 = "_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
10434static const char *preprocessor_alphabet2 = "_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
10435
10436static bool need_to_preprocessor_mangle(Buf *src) {
10437 for (size_t i = 0; i < buf_len(src); i += 1) {
10438 const char *alphabet = (i == 0) ? preprocessor_alphabet1 : preprocessor_alphabet2;
10439 uint8_t byte = buf_ptr(src)[i];
10440 if (strchr(alphabet, byte) == nullptr) {
10441 return true;
10442 }
10443 }
10444 return false;
10445}
10446
10447static Buf *preprocessor_mangle(Buf *src) {
10448 if (!need_to_preprocessor_mangle(src)) {
10449 return buf_create_from_buf(src);
10450 }
10451 Buf *result = buf_alloc();
10452 for (size_t i = 0; i < buf_len(src); i += 1) {
10453 const char *alphabet = (i == 0) ? preprocessor_alphabet1 : preprocessor_alphabet2;
10454 uint8_t byte = buf_ptr(src)[i];
10455 if (strchr(alphabet, byte) == nullptr) {
10456 // perform escape
10457 buf_appendf(result, "_%02x_", byte);
10458 } else {
10459 buf_append_char(result, byte);
10460 }
10461 }
10462 return result;
10463}
10464
10465static void gen_h_file_types(CodeGen* g, GenH* gen_h, Buf* out_buf) {
10466 for (size_t type_i = 0; type_i < gen_h->types_to_declare.length; type_i += 1) {
10467 ZigType *type_entry = gen_h->types_to_declare.at(type_i);
10468 switch (type_entry->id) {
10469 case ZigTypeIdInvalid:
10470 case ZigTypeIdMetaType:
10471 case ZigTypeIdVoid:
10472 case ZigTypeIdBool:
10473 case ZigTypeIdUnreachable:
10474 case ZigTypeIdInt:
10475 case ZigTypeIdFloat:
10476 case ZigTypeIdPointer:
10477 case ZigTypeIdComptimeFloat:
10478 case ZigTypeIdComptimeInt:
10479 case ZigTypeIdEnumLiteral:
10480 case ZigTypeIdArray:
10481 case ZigTypeIdUndefined:
10482 case ZigTypeIdNull:
10483 case ZigTypeIdErrorUnion:
10484 case ZigTypeIdErrorSet:
10485 case ZigTypeIdBoundFn:
10486 case ZigTypeIdOptional:
10487 case ZigTypeIdFn:
10488 case ZigTypeIdVector:
10489 case ZigTypeIdFnFrame:
10490 case ZigTypeIdAnyFrame:
10491 zig_unreachable();
10492
10493 case ZigTypeIdEnum:
10494 if (type_entry->data.enumeration.layout == ContainerLayoutExtern) {
10495 buf_appendf(out_buf, "enum %s {\n", buf_ptr(type_h_name(type_entry)));
10496 for (uint32_t field_i = 0; field_i < type_entry->data.enumeration.src_field_count; field_i += 1) {
10497 TypeEnumField *enum_field = &type_entry->data.enumeration.fields[field_i];
10498 Buf *value_buf = buf_alloc();
10499 bigint_append_buf(value_buf, &enum_field->value, 10);
10500 buf_appendf(out_buf, " %s = %s", buf_ptr(enum_field->name), buf_ptr(value_buf));
10501 if (field_i != type_entry->data.enumeration.src_field_count - 1) {
10502 buf_appendf(out_buf, ",");
10503 }
10504 buf_appendf(out_buf, "\n");
10505 }
10506 buf_appendf(out_buf, "};\n\n");
10507 } else {
10508 buf_appendf(out_buf, "enum %s;\n\n", buf_ptr(type_h_name(type_entry)));
10509 }
10510 break;
10511 case ZigTypeIdStruct:
10512 if (type_entry->data.structure.layout == ContainerLayoutExtern) {
10513 buf_appendf(out_buf, "struct %s {\n", buf_ptr(type_h_name(type_entry)));
10514 for (uint32_t field_i = 0; field_i < type_entry->data.structure.src_field_count; field_i += 1) {
10515 TypeStructField *struct_field = type_entry->data.structure.fields[field_i];
10516
10517 Buf *type_name_buf = buf_alloc();
10518 get_c_type(g, gen_h, struct_field->type_entry, type_name_buf);
10519
10520 if (struct_field->type_entry->id == ZigTypeIdArray) {
10521 buf_appendf(out_buf, " %s %s[%" ZIG_PRI_u64 "];\n", buf_ptr(type_name_buf),
10522 buf_ptr(struct_field->name),
10523 struct_field->type_entry->data.array.len);
10524 } else {
10525 buf_appendf(out_buf, " %s %s;\n", buf_ptr(type_name_buf), buf_ptr(struct_field->name));
10526 }
10527
10528 }
10529 buf_appendf(out_buf, "};\n\n");
10530 } else {
10531 buf_appendf(out_buf, "struct %s;\n\n", buf_ptr(type_h_name(type_entry)));
10532 }
10533 break;
10534 case ZigTypeIdUnion:
10535 if (type_entry->data.unionation.layout == ContainerLayoutExtern) {
10536 buf_appendf(out_buf, "union %s {\n", buf_ptr(type_h_name(type_entry)));
10537 for (uint32_t field_i = 0; field_i < type_entry->data.unionation.src_field_count; field_i += 1) {
10538 TypeUnionField *union_field = &type_entry->data.unionation.fields[field_i];
10539
10540 Buf *type_name_buf = buf_alloc();
10541 get_c_type(g, gen_h, union_field->type_entry, type_name_buf);
10542 buf_appendf(out_buf, " %s %s;\n", buf_ptr(type_name_buf), buf_ptr(union_field->name));
10543 }
10544 buf_appendf(out_buf, "};\n\n");
10545 } else {
10546 buf_appendf(out_buf, "union %s;\n\n", buf_ptr(type_h_name(type_entry)));
10547 }
10548 break;
10549 case ZigTypeIdOpaque:
10550 buf_appendf(out_buf, "struct %s;\n\n", buf_ptr(type_h_name(type_entry)));
10551 break;
10552 }
10553 }
10554}
10555
10556static void gen_h_file_functions(CodeGen* g, GenH* gen_h, Buf* out_buf, Buf* export_macro) {
10557 for (size_t fn_def_i = 0; fn_def_i < g->fn_defs.length; fn_def_i += 1) {
10558 ZigFn *fn_table_entry = g->fn_defs.at(fn_def_i);
10559
10560 if (fn_table_entry->export_list.length == 0)
10561 continue;
10562
10563 FnTypeId *fn_type_id = &fn_table_entry->type_entry->data.fn.fn_type_id;
10564
10565 Buf return_type_c = BUF_INIT;
10566 get_c_type(g, gen_h, fn_type_id->return_type, &return_type_c);
10567
10568 Buf *symbol_name;
10569 if (fn_table_entry->export_list.length == 0) {
10570 symbol_name = &fn_table_entry->symbol_name;
10571 } else {
10572 GlobalExport *fn_export = &fn_table_entry->export_list.items[0];
10573 symbol_name = &fn_export->name;
10574 }
10575
10576 if (export_macro != nullptr) {
10577 buf_appendf(out_buf, "%s %s %s(",
10578 buf_ptr(export_macro),
10579 buf_ptr(&return_type_c),
10580 buf_ptr(symbol_name));
10581 } else {
10582 buf_appendf(out_buf, "%s %s(",
10583 buf_ptr(&return_type_c),
10584 buf_ptr(symbol_name));
10585 }
10586
10587 Buf param_type_c = BUF_INIT;
10588 if (fn_type_id->param_count > 0) {
10589 for (size_t param_i = 0; param_i < fn_type_id->param_count; param_i += 1) {
10590 FnTypeParamInfo *param_info = &fn_type_id->param_info[param_i];
10591 AstNode *param_decl_node = get_param_decl_node(fn_table_entry, param_i);
10592 Buf *param_name = param_decl_node->data.param_decl.name;
10593
10594 const char *comma_str = (param_i == 0) ? "" : ", ";
10595 const char *restrict_str = param_info->is_noalias ? "restrict" : "";
10596 get_c_type(g, gen_h, param_info->type, &param_type_c);
10597
10598 if (param_info->type->id == ZigTypeIdArray) {
10599 // Arrays decay to pointers
10600 buf_appendf(out_buf, "%s%s%s %s[]", comma_str, buf_ptr(&param_type_c),
10601 restrict_str, buf_ptr(param_name));
10602 } else {
10603 buf_appendf(out_buf, "%s%s%s %s", comma_str, buf_ptr(&param_type_c),
10604 restrict_str, buf_ptr(param_name));
10605 }
10606 }
10607 buf_appendf(out_buf, ")");
10608 } else {
10609 buf_appendf(out_buf, "void)");
10610 }
10611
10612 buf_appendf(out_buf, ";\n");
10613 }
10614}
10615
10616static void gen_h_file_variables(CodeGen* g, GenH* gen_h, Buf* h_buf, Buf* export_macro) {
10617 for (size_t exp_var_i = 0; exp_var_i < g->global_vars.length; exp_var_i += 1) {
10618 ZigVar* var = g->global_vars.at(exp_var_i)->var;
10619 if (var->export_list.length == 0)
10620 continue;
10621
10622 Buf var_type_c = BUF_INIT;
10623 get_c_type(g, gen_h, var->var_type, &var_type_c);
10624
10625 if (export_macro != nullptr) {
10626 buf_appendf(h_buf, "extern %s %s %s;\n",
10627 buf_ptr(export_macro),
10628 buf_ptr(&var_type_c),
10629 var->name);
10630 } else {
10631 buf_appendf(h_buf, "extern %s %s;\n",
10632 buf_ptr(&var_type_c),
10633 var->name);
10634 }
10635 }
10636}
10637
10638static void gen_h_file(CodeGen *g) {
10639 GenH gen_h_data = {0};
10640 GenH *gen_h = &gen_h_data;
10641
10642 assert(!g->is_test_build);
10643 assert(!g->disable_gen_h);
10644
10645 Buf *out_h_path = buf_sprintf("%s" OS_SEP "%s.h", buf_ptr(g->output_dir), buf_ptr(g->root_out_name));
10646
10647 FILE *out_h = fopen(buf_ptr(out_h_path), "wb");
10648 if (!out_h)
10649 zig_panic("unable to open %s: %s\n", buf_ptr(out_h_path), strerror(errno));
10650
10651 Buf *export_macro = nullptr;
10652 if (g->is_dynamic) {
10653 export_macro = preprocessor_mangle(buf_sprintf("%s_EXPORT", buf_ptr(g->root_out_name)));
10654 buf_upcase(export_macro);
10655 }
10656
10657 Buf fns_buf = BUF_INIT;
10658 buf_resize(&fns_buf, 0);
10659 gen_h_file_functions(g, gen_h, &fns_buf, export_macro);
10660
10661 Buf vars_buf = BUF_INIT;
10662 buf_resize(&vars_buf, 0);
10663 gen_h_file_variables(g, gen_h, &vars_buf, export_macro);
10664
10665 // Types will be populated by exported functions and variables so it has to run last.
10666 Buf types_buf = BUF_INIT;
10667 buf_resize(&types_buf, 0);
10668 gen_h_file_types(g, gen_h, &types_buf);
10669
10670 Buf *ifdef_dance_name = preprocessor_mangle(buf_sprintf("%s_H", buf_ptr(g->root_out_name)));
10671 buf_upcase(ifdef_dance_name);
10672
10673 fprintf(out_h, "#ifndef %s\n", buf_ptr(ifdef_dance_name));
10674 fprintf(out_h, "#define %s\n\n", buf_ptr(ifdef_dance_name));
10675
10676 if (g->c_want_stdbool)
10677 fprintf(out_h, "#include <stdbool.h>\n");
10678 if (g->c_want_stdint)
10679 fprintf(out_h, "#include <stdint.h>\n");
10680
10681 fprintf(out_h, "\n");
10682
10683 if (g->is_dynamic) {
10684 fprintf(out_h, "#if defined(_WIN32)\n");
10685 fprintf(out_h, "#define %s __declspec(dllimport)\n", buf_ptr(export_macro));
10686 fprintf(out_h, "#else\n");
10687 fprintf(out_h, "#define %s __attribute__((visibility (\"default\")))\n",
10688 buf_ptr(export_macro));
10689 fprintf(out_h, "#endif\n");
10690 fprintf(out_h, "\n");
10691 }
10692
10693 fprintf(out_h, "#ifdef __cplusplus\n");
10694 fprintf(out_h, "extern \"C\" {\n");
10695 fprintf(out_h, "#endif\n");
10696 fprintf(out_h, "\n");
10697
10698 fprintf(out_h, "%s", buf_ptr(&types_buf));
10699 fprintf(out_h, "%s\n", buf_ptr(&fns_buf));
10700 fprintf(out_h, "%s\n", buf_ptr(&vars_buf));
10701
10702 fprintf(out_h, "#ifdef __cplusplus\n");
10703 fprintf(out_h, "} // extern \"C\"\n");
10704 fprintf(out_h, "#endif\n\n");
10705
10706 fprintf(out_h, "#endif // %s\n", buf_ptr(ifdef_dance_name));
10707
10708 if (fclose(out_h))
10709 zig_panic("unable to close h file: %s", strerror(errno));
10710}
107119208
10712void codegen_print_timing_report(CodeGen *g, FILE *f) {9209void codegen_print_timing_report(CodeGen *g, FILE *f) {
10713 double start_time = g->timing_events.at(0).time;9210 double start_time = g->timing_events.at(0).time;
...@@ -10733,174 +9230,14 @@ void codegen_add_time_event(CodeGen *g, const char *name) {...@@ -10733,174 +9230,14 @@ void codegen_add_time_event(CodeGen *g, const char *name) {
10733 g->timing_events.append({seconds, name});9230 g->timing_events.append({seconds, name});
10734}9231}
107359232
10736static void add_cache_pkg(CodeGen *g, CacheHash *ch, ZigPackage *pkg) {
10737 if (buf_len(&pkg->root_src_path) == 0)
10738 return;
10739 pkg->added_to_cache = true;
10740
10741 Buf *rel_full_path = buf_alloc();
10742 os_path_join(&pkg->root_src_dir, &pkg->root_src_path, rel_full_path);
10743 cache_file(ch, rel_full_path);
10744
10745 auto it = pkg->package_table.entry_iterator();
10746 for (;;) {
10747 auto *entry = it.next();
10748 if (!entry)
10749 break;
10750
10751 if (!pkg->added_to_cache) {
10752 cache_buf(ch, entry->key);
10753 add_cache_pkg(g, ch, entry->value);
10754 }
10755 }
10756}
10757
10758// Called before init()
10759// is_cache_hit takes into account gen_c_objects
10760static Error check_cache(CodeGen *g, Buf *manifest_dir, Buf *digest) {
10761 Error err;
10762
10763 Buf *compiler_id;
10764 if ((err = get_compiler_id(&compiler_id)))
10765 return err;
10766
10767 CacheHash *ch = &g->cache_hash;
10768 cache_init(ch, manifest_dir);
10769
10770 add_cache_pkg(g, ch, g->main_pkg);
10771 if (g->linker_script != nullptr) {
10772 cache_file(ch, buf_create_from_str(g->linker_script));
10773 }
10774 cache_buf(ch, compiler_id);
10775 cache_buf(ch, g->root_out_name);
10776 cache_buf(ch, g->zig_lib_dir);
10777 cache_buf(ch, g->zig_std_dir);
10778 cache_list_of_link_lib(ch, g->link_libs_list.items, g->link_libs_list.length);
10779 cache_list_of_buf(ch, g->darwin_frameworks.items, g->darwin_frameworks.length);
10780 cache_list_of_buf(ch, g->rpath_list.items, g->rpath_list.length);
10781 cache_list_of_buf(ch, g->forbidden_libs.items, g->forbidden_libs.length);
10782 cache_int(ch, g->build_mode);
10783 cache_int(ch, g->out_type);
10784 cache_bool(ch, g->zig_target->is_native_os);
10785 cache_bool(ch, g->zig_target->is_native_cpu);
10786 cache_int(ch, g->zig_target->arch);
10787 cache_int(ch, g->zig_target->vendor);
10788 cache_int(ch, g->zig_target->os);
10789 cache_int(ch, g->zig_target->abi);
10790 if (g->zig_target->cache_hash != nullptr) {
10791 cache_mem(ch, g->zig_target->cache_hash, g->zig_target->cache_hash_len);
10792 }
10793 if (g->zig_target->glibc_or_darwin_version != nullptr) {
10794 cache_int(ch, g->zig_target->glibc_or_darwin_version->major);
10795 cache_int(ch, g->zig_target->glibc_or_darwin_version->minor);
10796 cache_int(ch, g->zig_target->glibc_or_darwin_version->patch);
10797 }
10798 if (g->zig_target->dynamic_linker != nullptr) {
10799 cache_str(ch, g->zig_target->dynamic_linker);
10800 }
10801 cache_int(ch, detect_subsystem(g));
10802 cache_bool(ch, g->strip_debug_symbols);
10803 cache_bool(ch, g->is_test_build);
10804 if (g->is_test_build) {
10805 cache_buf_opt(ch, g->test_filter);
10806 cache_buf_opt(ch, g->test_name_prefix);
10807 cache_bool(ch, g->test_is_evented);
10808 }
10809 cache_bool(ch, g->link_eh_frame_hdr);
10810 cache_bool(ch, g->is_single_threaded);
10811 cache_bool(ch, g->linker_rdynamic);
10812 cache_bool(ch, g->each_lib_rpath);
10813 cache_bool(ch, g->disable_gen_h);
10814 cache_bool(ch, g->bundle_compiler_rt);
10815 cache_bool(ch, want_valgrind_support(g));
10816 cache_bool(ch, g->have_pic);
10817 cache_bool(ch, g->have_dynamic_link);
10818 cache_bool(ch, g->have_stack_probing);
10819 cache_bool(ch, g->have_sanitize_c);
10820 cache_bool(ch, g->is_dummy_so);
10821 cache_bool(ch, g->function_sections);
10822 cache_bool(ch, g->enable_dump_analysis);
10823 cache_bool(ch, g->enable_doc_generation);
10824 cache_bool(ch, g->emit_bin);
10825 cache_bool(ch, g->emit_llvm_ir);
10826 cache_bool(ch, g->emit_asm);
10827 cache_bool(ch, g->is_versioned);
10828 cache_usize(ch, g->version_major);
10829 cache_usize(ch, g->version_minor);
10830 cache_usize(ch, g->version_patch);
10831 cache_list_of_str(ch, g->llvm_argv, g->llvm_argv_len);
10832 cache_list_of_str(ch, g->clang_argv, g->clang_argv_len);
10833 cache_list_of_str(ch, g->lib_dirs.items, g->lib_dirs.length);
10834 cache_list_of_str(ch, g->framework_dirs.items, g->framework_dirs.length);
10835 if (g->libc) {
10836 cache_slice(ch, Slice<const char>{g->libc->include_dir, g->libc->include_dir_len});
10837 cache_slice(ch, Slice<const char>{g->libc->sys_include_dir, g->libc->sys_include_dir_len});
10838 cache_slice(ch, Slice<const char>{g->libc->crt_dir, g->libc->crt_dir_len});
10839 cache_slice(ch, Slice<const char>{g->libc->msvc_lib_dir, g->libc->msvc_lib_dir_len});
10840 cache_slice(ch, Slice<const char>{g->libc->kernel32_lib_dir, g->libc->kernel32_lib_dir_len});
10841 }
10842 cache_buf_opt(ch, g->version_script_path);
10843 cache_buf_opt(ch, g->override_soname);
10844 cache_buf_opt(ch, g->linker_optimization);
10845 cache_int(ch, g->linker_gc_sections);
10846 cache_int(ch, g->linker_allow_shlib_undefined);
10847 cache_int(ch, g->linker_bind_global_refs_locally);
10848 cache_bool(ch, g->linker_z_nodelete);
10849 cache_bool(ch, g->linker_z_defs);
10850 cache_usize(ch, g->stack_size_override);
10851
10852 // gen_c_objects appends objects to g->link_objects which we want to include in the hash
10853 gen_c_objects(g);
10854 cache_list_of_file(ch, g->link_objects.items, g->link_objects.length);
10855
10856 buf_resize(digest, 0);
10857 if ((err = cache_hit(ch, digest))) {
10858 if (err != ErrorInvalidFormat)
10859 return err;
10860 }
10861
10862 if (ch->manifest_file_path != nullptr) {
10863 g->caches_to_release.append(ch);
10864 }
10865
10866 return ErrorNone;
10867}
10868
10869static void resolve_out_paths(CodeGen *g) {9233static void resolve_out_paths(CodeGen *g) {
10870 assert(g->output_dir != nullptr);9234 assert(g->output_dir != nullptr);
10871 assert(g->root_out_name != nullptr);9235 assert(g->root_out_name != nullptr);
108729236
10873 if (g->emit_bin) {9237 if (g->emit_bin) {
10874 Buf *out_basename = buf_create_from_buf(g->root_out_name);
10875 Buf *o_basename = buf_create_from_buf(g->root_out_name);9238 Buf *o_basename = buf_create_from_buf(g->root_out_name);
10876 switch (g->out_type) {9239 buf_append_str(o_basename, target_o_file_ext(g->zig_target));
10877 case OutTypeUnknown:
10878 zig_unreachable();
10879 case OutTypeObj:
10880 if (need_llvm_module(g) && g->link_objects.length != 0 && !g->enable_cache &&
10881 buf_eql_buf(o_basename, out_basename))
10882 {
10883 // make it not collide with main output object
10884 buf_append_str(o_basename, ".root");
10885 }
10886 buf_append_str(o_basename, target_o_file_ext(g->zig_target));
10887 buf_append_str(out_basename, target_o_file_ext(g->zig_target));
10888 break;
10889 case OutTypeExe:
10890 buf_append_str(o_basename, target_o_file_ext(g->zig_target));
10891 buf_append_str(out_basename, target_exe_file_ext(g->zig_target));
10892 break;
10893 case OutTypeLib:
10894 buf_append_str(o_basename, target_o_file_ext(g->zig_target));
10895 buf_resize(out_basename, 0);
10896 buf_append_str(out_basename, target_lib_file_prefix(g->zig_target));
10897 buf_append_buf(out_basename, g->root_out_name);
10898 buf_append_str(out_basename, target_lib_file_ext(g->zig_target, !g->is_dynamic, g->is_versioned,
10899 g->version_major, g->version_minor, g->version_patch));
10900 break;
10901 }
10902 os_path_join(g->output_dir, o_basename, &g->o_file_output_path);9240 os_path_join(g->output_dir, o_basename, &g->o_file_output_path);
10903 os_path_join(g->output_dir, out_basename, &g->bin_file_output_path);
10904 }9241 }
10905 if (g->emit_asm) {9242 if (g->emit_asm) {
10906 Buf *asm_basename = buf_create_from_buf(g->root_out_name);9243 Buf *asm_basename = buf_create_from_buf(g->root_out_name);
...@@ -10971,144 +9308,46 @@ static void output_type_information(CodeGen *g) {...@@ -10971,144 +9308,46 @@ static void output_type_information(CodeGen *g) {
10971 }9308 }
10972}9309}
109739310
10974static void init_output_dir(CodeGen *g, Buf *digest) {9311void codegen_build_object(CodeGen *g) {
10975 if (main_output_dir_is_just_one_c_object_post(g)) {9312 assert(g->output_dir != nullptr);
10976 g->output_dir = buf_alloc();
10977 os_path_dirname(g->link_objects.at(0), g->output_dir);
10978 } else {
10979 g->output_dir = buf_sprintf("%s" OS_SEP CACHE_OUT_SUBDIR OS_SEP "%s",
10980 buf_ptr(g->cache_dir), buf_ptr(digest));
10981 }
10982}
10983
10984void codegen_build_and_link(CodeGen *g) {
10985 Error err;
10986 assert(g->out_type != OutTypeUnknown);
10987
10988 if (!g->enable_cache) {
10989 if (g->output_dir == nullptr) {
10990 g->output_dir = buf_create_from_str(".");
10991 } else if ((err = os_make_path(g->output_dir))) {
10992 fprintf(stderr, "Unable to create output directory: %s\n", err_str(err));
10993 exit(1);
10994 }
10995 }
109969313
10997 g->have_dynamic_link = detect_dynamic_link(g);
10998 g->have_pic = detect_pic(g);
10999 g->is_single_threaded = detect_single_threaded(g);
11000 g->have_err_ret_tracing = detect_err_ret_tracing(g);9314 g->have_err_ret_tracing = detect_err_ret_tracing(g);
11001 g->have_sanitize_c = detect_sanitize_c(g);
11002 detect_libc(g);
11003
11004 Buf digest = BUF_INIT;
11005 if (g->enable_cache) {
11006 Buf *manifest_dir = buf_alloc();
11007 os_path_join(g->cache_dir, buf_create_from_str(CACHE_HASH_SUBDIR), manifest_dir);
11008
11009 if ((err = check_cache(g, manifest_dir, &digest))) {
11010 if (err == ErrorCacheUnavailable) {
11011 // message already printed
11012 } else if (err == ErrorNotDir) {
11013 fprintf(stderr, "Unable to check cache: %s is not a directory\n",
11014 buf_ptr(manifest_dir));
11015 } else {
11016 fprintf(stderr, "Unable to check cache: %s: %s\n", buf_ptr(manifest_dir), err_str(err));
11017 }
11018 exit(1);
11019 }
11020 } else {
11021 // There is a call to this in check_cache
11022 gen_c_objects(g);
11023 }
110249315
11025 if (g->enable_cache && buf_len(&digest) != 0) {9316 init(g);
11026 init_output_dir(g, &digest);
11027 resolve_out_paths(g);
11028 } else {
11029 if (need_llvm_module(g)) {
11030 init(g);
11031
11032 codegen_add_time_event(g, "Semantic Analysis");
11033 const char *progress_name = "Semantic Analysis";
11034 codegen_switch_sub_prog_node(g, stage2_progress_start(g->main_progress_node,
11035 progress_name, strlen(progress_name), 0));
11036
11037 gen_root_source(g);
11038
11039 }
11040 if (g->enable_cache) {
11041 if (buf_len(&digest) == 0) {
11042 if ((err = cache_final(&g->cache_hash, &digest))) {
11043 fprintf(stderr, "Unable to finalize cache hash: %s\n", err_str(err));
11044 exit(1);
11045 }
11046 }
11047 init_output_dir(g, &digest);
110489317
11049 if ((err = os_make_path(g->output_dir))) {9318 codegen_add_time_event(g, "Semantic Analysis");
11050 fprintf(stderr, "Unable to create output directory: %s\n", err_str(err));9319 const char *progress_name = "Semantic Analysis";
11051 exit(1);9320 codegen_switch_sub_prog_node(g, stage2_progress_start(g->main_progress_node,
11052 }9321 progress_name, strlen(progress_name), 0));
11053 }
11054 resolve_out_paths(g);
110559322
11056 if (g->enable_dump_analysis || g->enable_doc_generation) {9323 gen_root_source(g);
11057 output_type_information(g);
11058 }
110599324
11060 if (need_llvm_module(g)) {9325 resolve_out_paths(g);
11061 codegen_add_time_event(g, "Code Generation");
11062 {
11063 const char *progress_name = "Code Generation";
11064 codegen_switch_sub_prog_node(g, stage2_progress_start(g->main_progress_node,
11065 progress_name, strlen(progress_name), 0));
11066 }
110679326
11068 do_code_gen(g);9327 if (g->enable_dump_analysis || g->enable_doc_generation) {
11069 codegen_add_time_event(g, "LLVM Emit Output");9328 output_type_information(g);
11070 {9329 }
11071 const char *progress_name = "LLVM Emit Output";
11072 codegen_switch_sub_prog_node(g, stage2_progress_start(g->main_progress_node,
11073 progress_name, strlen(progress_name), 0));
11074 }
11075 zig_llvm_emit_output(g);
110769330
11077 if (!g->disable_gen_h && (g->out_type == OutTypeObj || g->out_type == OutTypeLib)) {9331 codegen_add_time_event(g, "Code Generation");
11078 codegen_add_time_event(g, "Generate .h");9332 {
11079 {9333 const char *progress_name = "Code Generation";
11080 const char *progress_name = "Generate .h";9334 codegen_switch_sub_prog_node(g, stage2_progress_start(g->main_progress_node,
11081 codegen_switch_sub_prog_node(g, stage2_progress_start(g->main_progress_node,9335 progress_name, strlen(progress_name), 0));
11082 progress_name, strlen(progress_name), 0));9336 }
11083 }
11084 gen_h_file(g);
11085 }
11086 }
110879337
11088 // If we're outputting assembly or llvm IR we skip linking.9338 do_code_gen(g);
11089 // If we're making a library or executable we must link.9339 codegen_add_time_event(g, "LLVM Emit Output");
11090 // If there is more than one object, we have to link them (with -r).9340 {
11091 // Finally, if we didn't make an object from zig source, and we don't have caching enabled,9341 const char *progress_name = "LLVM Emit Output";
11092 // then we have an object from C source that we must copy to the output dir which we do with a -r link.9342 codegen_switch_sub_prog_node(g, stage2_progress_start(g->main_progress_node,
11093 if (g->emit_bin &&9343 progress_name, strlen(progress_name), 0));
11094 (g->out_type != OutTypeObj || g->link_objects.length > 1 ||
11095 (!need_llvm_module(g) && !g->enable_cache)))
11096 {
11097 codegen_link(g);
11098 }
11099 }9344 }
9345 zig_llvm_emit_output(g);
111009346
11101 codegen_release_caches(g);
11102 codegen_add_time_event(g, "Done");9347 codegen_add_time_event(g, "Done");
11103 codegen_switch_sub_prog_node(g, nullptr);9348 codegen_switch_sub_prog_node(g, nullptr);
11104}9349}
111059350
11106void codegen_release_caches(CodeGen *g) {
11107 while (g->caches_to_release.length != 0) {
11108 cache_release(g->caches_to_release.pop());
11109 }
11110}
11111
11112ZigPackage *codegen_create_package(CodeGen *g, const char *root_src_dir, const char *root_src_path,9351ZigPackage *codegen_create_package(CodeGen *g, const char *root_src_dir, const char *root_src_path,
11113 const char *pkg_path)9352 const char *pkg_path)
11114{9353{
...@@ -11125,43 +9364,17 @@ ZigPackage *codegen_create_package(CodeGen *g, const char *root_src_dir, const c...@@ -11125,43 +9364,17 @@ ZigPackage *codegen_create_package(CodeGen *g, const char *root_src_dir, const c
11125 return pkg;9364 return pkg;
11126}9365}
111279366
11128CodeGen *create_child_codegen(CodeGen *parent_gen, Buf *root_src_path, OutType out_type,9367void codegen_destroy(CodeGen *g) {
11129 Stage2LibCInstallation *libc, const char *name, Stage2ProgressNode *parent_progress_node)9368 if (g->pass1_arena != nullptr) {
11130{9369 g->pass1_arena->destruct(&heap::c_allocator);
11131 Stage2ProgressNode *child_progress_node = stage2_progress_start(9370 g->pass1_arena = nullptr;
11132 parent_progress_node ? parent_progress_node : parent_gen->sub_progress_node,9371 }
11133 name, strlen(name), 0);9372 heap::c_allocator.destroy<CodeGen>(g);
11134
11135 CodeGen *child_gen = codegen_create(nullptr, root_src_path, parent_gen->zig_target, out_type,
11136 parent_gen->build_mode, parent_gen->zig_lib_dir, libc, get_global_cache_dir(), false, child_progress_node);
11137 child_gen->root_out_name = buf_create_from_str(name);
11138 child_gen->disable_gen_h = true;
11139 child_gen->want_stack_check = WantStackCheckDisabled;
11140 child_gen->want_sanitize_c = WantCSanitizeDisabled;
11141 child_gen->verbose_tokenize = parent_gen->verbose_tokenize;
11142 child_gen->verbose_ast = parent_gen->verbose_ast;
11143 child_gen->verbose_link = parent_gen->verbose_link;
11144 child_gen->verbose_ir = parent_gen->verbose_ir;
11145 child_gen->verbose_llvm_ir = parent_gen->verbose_llvm_ir;
11146 child_gen->verbose_cimport = parent_gen->verbose_cimport;
11147 child_gen->verbose_cc = parent_gen->verbose_cc;
11148 child_gen->verbose_llvm_cpu_features = parent_gen->verbose_llvm_cpu_features;
11149 child_gen->llvm_argv = parent_gen->llvm_argv;
11150
11151 codegen_set_strip(child_gen, parent_gen->strip_debug_symbols);
11152 child_gen->want_pic = parent_gen->have_pic ? WantPICEnabled : WantPICDisabled;
11153 child_gen->valgrind_support = ValgrindSupportDisabled;
11154
11155 codegen_set_errmsg_color(child_gen, parent_gen->err_color);
11156
11157 child_gen->enable_cache = true;
11158
11159 return child_gen;
11160}9373}
111619374
11162CodeGen *codegen_create(Buf *main_pkg_path, Buf *root_src_path, const ZigTarget *target,9375CodeGen *codegen_create(Buf *main_pkg_path, Buf *root_src_path, const ZigTarget *target,
11163 OutType out_type, BuildMode build_mode, Buf *override_lib_dir,9376 BuildMode build_mode, Buf *override_lib_dir,
11164 Stage2LibCInstallation *libc, Buf *cache_dir, bool is_test_build, Stage2ProgressNode *progress_node)9377 bool is_test_build, Stage2ProgressNode *progress_node)
11165{9378{
11166 CodeGen *g = heap::c_allocator.create<CodeGen>();9379 CodeGen *g = heap::c_allocator.create<CodeGen>();
11167 g->emit_bin = true;9380 g->emit_bin = true;
...@@ -11176,24 +9389,15 @@ CodeGen *codegen_create(Buf *main_pkg_path, Buf *root_src_path, const ZigTarget...@@ -11176,24 +9389,15 @@ CodeGen *codegen_create(Buf *main_pkg_path, Buf *root_src_path, const ZigTarget
11176 }9389 }
111779390
11178 g->subsystem = TargetSubsystemAuto;9391 g->subsystem = TargetSubsystemAuto;
11179 g->libc = libc;
11180 g->zig_target = target;9392 g->zig_target = target;
11181 g->cache_dir = cache_dir;
111829393
11183 if (override_lib_dir == nullptr) {9394 assert(override_lib_dir != nullptr);
11184 g->zig_lib_dir = get_zig_lib_dir();9395 g->zig_lib_dir = override_lib_dir;
11185 } else {
11186 g->zig_lib_dir = override_lib_dir;
11187 }
111889396
11189 g->zig_std_dir = buf_alloc();9397 g->zig_std_dir = buf_alloc();
11190 os_path_join(g->zig_lib_dir, buf_create_from_str("std"), g->zig_std_dir);9398 os_path_join(g->zig_lib_dir, buf_create_from_str("std"), g->zig_std_dir);
111919399
11192 g->zig_c_headers_dir = buf_alloc();
11193 os_path_join(g->zig_lib_dir, buf_create_from_str("include"), g->zig_c_headers_dir);
11194
11195 g->build_mode = build_mode;9400 g->build_mode = build_mode;
11196 g->out_type = out_type;
11197 g->import_table.init(32);9401 g->import_table.init(32);
11198 g->builtin_fn_table.init(32);9402 g->builtin_fn_table.init(32);
11199 g->primitive_type_table.init(32);9403 g->primitive_type_table.init(32);
...@@ -11256,18 +9460,6 @@ CodeGen *codegen_create(Buf *main_pkg_path, Buf *root_src_path, const ZigTarget...@@ -11256,18 +9460,6 @@ CodeGen *codegen_create(Buf *main_pkg_path, Buf *root_src_path, const ZigTarget
11256 g->zig_std_special_dir = buf_alloc();9460 g->zig_std_special_dir = buf_alloc();
11257 os_path_join(g->zig_std_dir, buf_sprintf("special"), g->zig_std_special_dir);9461 os_path_join(g->zig_std_dir, buf_sprintf("special"), g->zig_std_special_dir);
112589462
11259 assert(target != nullptr);
11260 if (!target->is_native_os) {
11261 g->each_lib_rpath = false;
11262 } else {
11263 g->each_lib_rpath = true;
11264 }
11265
11266 if (target_os_requires_libc(g->zig_target->os)) {
11267 g->libc_link_lib = create_link_lib(buf_create_from_str("c"));
11268 g->link_libs_list.append(g->libc_link_lib);
11269 }
11270
11271 target_triple_llvm(&g->llvm_triple_str, g->zig_target);9463 target_triple_llvm(&g->llvm_triple_str, g->zig_target);
11272 g->pointer_size_bytes = target_arch_pointer_bit_width(g->zig_target->arch) / 8;9464 g->pointer_size_bytes = target_arch_pointer_bit_width(g->zig_target->arch) / 8;
112739465
...@@ -11302,36 +9494,21 @@ void codegen_switch_sub_prog_node(CodeGen *g, Stage2ProgressNode *node) {...@@ -11302,36 +9494,21 @@ void codegen_switch_sub_prog_node(CodeGen *g, Stage2ProgressNode *node) {
11302}9494}
113039495
11304ZigValue *CodeGen::Intern::for_undefined() {9496ZigValue *CodeGen::Intern::for_undefined() {
11305#ifdef ZIG_ENABLE_MEM_PROFILE
11306 mem::intern_counters.x_undefined += 1;
11307#endif
11308 return &this->x_undefined;9497 return &this->x_undefined;
11309}9498}
113109499
11311ZigValue *CodeGen::Intern::for_void() {9500ZigValue *CodeGen::Intern::for_void() {
11312#ifdef ZIG_ENABLE_MEM_PROFILE
11313 mem::intern_counters.x_void += 1;
11314#endif
11315 return &this->x_void;9501 return &this->x_void;
11316}9502}
113179503
11318ZigValue *CodeGen::Intern::for_null() {9504ZigValue *CodeGen::Intern::for_null() {
11319#ifdef ZIG_ENABLE_MEM_PROFILE
11320 mem::intern_counters.x_null += 1;
11321#endif
11322 return &this->x_null;9505 return &this->x_null;
11323}9506}
113249507
11325ZigValue *CodeGen::Intern::for_unreachable() {9508ZigValue *CodeGen::Intern::for_unreachable() {
11326#ifdef ZIG_ENABLE_MEM_PROFILE
11327 mem::intern_counters.x_unreachable += 1;
11328#endif
11329 return &this->x_unreachable;9509 return &this->x_unreachable;
11330}9510}
113319511
11332ZigValue *CodeGen::Intern::for_zero_byte() {9512ZigValue *CodeGen::Intern::for_zero_byte() {
11333#ifdef ZIG_ENABLE_MEM_PROFILE
11334 mem::intern_counters.zero_byte += 1;
11335#endif
11336 return &this->zero_byte;9513 return &this->zero_byte;
11337}9514}
src/codegen.hpp+4-31
...@@ -16,47 +16,20 @@...@@ -16,47 +16,20 @@
16#include <stdio.h>16#include <stdio.h>
1717
18CodeGen *codegen_create(Buf *main_pkg_path, Buf *root_src_path, const ZigTarget *target,18CodeGen *codegen_create(Buf *main_pkg_path, Buf *root_src_path, const ZigTarget *target,
19 OutType out_type, BuildMode build_mode, Buf *zig_lib_dir,19 BuildMode build_mode, Buf *zig_lib_dir,
20 Stage2LibCInstallation *libc, Buf *cache_dir, bool is_test_build, Stage2ProgressNode *progress_node);20 bool is_test_build, Stage2ProgressNode *progress_node);
2121
22CodeGen *create_child_codegen(CodeGen *parent_gen, Buf *root_src_path, OutType out_type,22void codegen_build_object(CodeGen *g);
23 Stage2LibCInstallation *libc, const char *name, Stage2ProgressNode *progress_node);23void codegen_destroy(CodeGen *);
2424
25void codegen_set_clang_argv(CodeGen *codegen, const char **args, size_t len);
26void codegen_set_llvm_argv(CodeGen *codegen, const char **args, size_t len);
27void codegen_set_each_lib_rpath(CodeGen *codegen, bool each_lib_rpath);
28
29void codegen_set_strip(CodeGen *codegen, bool strip);
30void codegen_set_errmsg_color(CodeGen *codegen, ErrColor err_color);
31void codegen_set_out_name(CodeGen *codegen, Buf *out_name);
32void codegen_add_lib_dir(CodeGen *codegen, const char *dir);
33void codegen_add_forbidden_lib(CodeGen *codegen, Buf *lib);
34LinkLib *codegen_add_link_lib(CodeGen *codegen, Buf *lib);
35void codegen_add_framework(CodeGen *codegen, const char *name);
36void codegen_add_rpath(CodeGen *codegen, const char *name);
37void codegen_set_rdynamic(CodeGen *g, bool rdynamic);
38void codegen_set_linker_script(CodeGen *g, const char *linker_script);
39void codegen_set_test_filter(CodeGen *g, Buf *filter);
40void codegen_set_test_name_prefix(CodeGen *g, Buf *prefix);
41void codegen_set_lib_version(CodeGen *g, bool is_versioned, size_t major, size_t minor, size_t patch);
42void codegen_add_time_event(CodeGen *g, const char *name);25void codegen_add_time_event(CodeGen *g, const char *name);
43void codegen_print_timing_report(CodeGen *g, FILE *f);26void codegen_print_timing_report(CodeGen *g, FILE *f);
44void codegen_link(CodeGen *g);
45void zig_link_add_compiler_rt(CodeGen *g, Stage2ProgressNode *progress_node);
46void codegen_build_and_link(CodeGen *g);
4727
48ZigPackage *codegen_create_package(CodeGen *g, const char *root_src_dir, const char *root_src_path,28ZigPackage *codegen_create_package(CodeGen *g, const char *root_src_dir, const char *root_src_path,
49 const char *pkg_path);29 const char *pkg_path);
50void codegen_add_assembly(CodeGen *g, Buf *path);
51void codegen_add_object(CodeGen *g, Buf *object_path);
52
53void codegen_translate_c(CodeGen *g, Buf *full_path);
54
55Buf *codegen_generate_builtin_source(CodeGen *g);
5630
57TargetSubsystem detect_subsystem(CodeGen *g);31TargetSubsystem detect_subsystem(CodeGen *g);
5832
59void codegen_release_caches(CodeGen *codegen);
60bool codegen_fn_has_err_ret_tracing_arg(CodeGen *g, ZigType *return_type);33bool codegen_fn_has_err_ret_tracing_arg(CodeGen *g, ZigType *return_type);
61bool codegen_fn_has_err_ret_tracing_stack(CodeGen *g, ZigFn *fn, bool is_async);34bool codegen_fn_has_err_ret_tracing_stack(CodeGen *g, ZigFn *fn, bool is_async);
6235
src/compiler.cpp deleted-196
...@@ -1,196 +0,0 @@
1#include "cache_hash.hpp"
2#include "os.hpp"
3#include "compiler.hpp"
4
5#include <stdio.h>
6
7Error get_compiler_id(Buf **result) {
8 static Buf saved_compiler_id = BUF_INIT;
9
10 if (saved_compiler_id.list.length != 0) {
11 *result = &saved_compiler_id;
12 return ErrorNone;
13 }
14
15 Error err;
16 Buf *manifest_dir = buf_alloc();
17 os_path_join(get_global_cache_dir(), buf_create_from_str("exe"), manifest_dir);
18
19 CacheHash cache_hash;
20 CacheHash *ch = &cache_hash;
21 cache_init(ch, manifest_dir);
22 Buf self_exe_path = BUF_INIT;
23 if ((err = os_self_exe_path(&self_exe_path)))
24 return err;
25
26 cache_file(ch, &self_exe_path);
27
28 buf_resize(&saved_compiler_id, 0);
29 if ((err = cache_hit(ch, &saved_compiler_id))) {
30 if (err != ErrorInvalidFormat)
31 return err;
32 }
33 if (buf_len(&saved_compiler_id) != 0) {
34 cache_release(ch);
35 *result = &saved_compiler_id;
36 return ErrorNone;
37 }
38 ZigList<Buf *> lib_paths = {};
39 if ((err = os_self_exe_shared_libs(lib_paths)))
40 return err;
41 #if defined(ZIG_OS_DARWIN)
42 // only add the self exe path on mac os
43 Buf *lib_path = lib_paths.at(0);
44 if ((err = cache_add_file(ch, lib_path)))
45 return err;
46 #else
47 for (size_t i = 0; i < lib_paths.length; i += 1) {
48 Buf *lib_path = lib_paths.at(i);
49 if ((err = cache_add_file(ch, lib_path)))
50 return err;
51 }
52 #endif
53
54 if ((err = cache_final(ch, &saved_compiler_id)))
55 return err;
56
57 cache_release(ch);
58
59 *result = &saved_compiler_id;
60 return ErrorNone;
61}
62
63static bool test_zig_install_prefix(Buf *test_path, Buf *out_zig_lib_dir) {
64 {
65 Buf *test_zig_dir = buf_sprintf("%s" OS_SEP "lib" OS_SEP "zig", buf_ptr(test_path));
66 Buf *test_index_file = buf_sprintf("%s" OS_SEP "std" OS_SEP "std.zig", buf_ptr(test_zig_dir));
67 int err;
68 bool exists;
69 if ((err = os_file_exists(test_index_file, &exists))) {
70 exists = false;
71 }
72 if (exists) {
73 buf_init_from_buf(out_zig_lib_dir, test_zig_dir);
74 return true;
75 }
76 }
77
78 // Also try without "zig"
79 {
80 Buf *test_zig_dir = buf_sprintf("%s" OS_SEP "lib", buf_ptr(test_path));
81 Buf *test_index_file = buf_sprintf("%s" OS_SEP "std" OS_SEP "std.zig", buf_ptr(test_zig_dir));
82 int err;
83 bool exists;
84 if ((err = os_file_exists(test_index_file, &exists))) {
85 exists = false;
86 }
87 if (exists) {
88 buf_init_from_buf(out_zig_lib_dir, test_zig_dir);
89 return true;
90 }
91 }
92
93 return false;
94}
95
96static int find_zig_lib_dir(Buf *out_path) {
97 int err;
98
99 Buf self_exe_path = BUF_INIT;
100 buf_resize(&self_exe_path, 0);
101 if (!(err = os_self_exe_path(&self_exe_path))) {
102 Buf *cur_path = &self_exe_path;
103
104 for (;;) {
105 Buf *test_dir = buf_alloc();
106 os_path_dirname(cur_path, test_dir);
107
108 if (buf_eql_buf(test_dir, cur_path)) {
109 break;
110 }
111
112 if (test_zig_install_prefix(test_dir, out_path)) {
113 return 0;
114 }
115
116 cur_path = test_dir;
117 }
118 }
119
120 return ErrorFileNotFound;
121}
122
123Buf *get_zig_lib_dir(void) {
124 static Buf saved_lib_dir = BUF_INIT;
125 if (saved_lib_dir.list.length != 0)
126 return &saved_lib_dir;
127 buf_resize(&saved_lib_dir, 0);
128
129 int err;
130 if ((err = find_zig_lib_dir(&saved_lib_dir))) {
131 fprintf(stderr, "Unable to find zig lib directory\n");
132 exit(EXIT_FAILURE);
133 }
134 return &saved_lib_dir;
135}
136
137Buf *get_zig_std_dir(Buf *zig_lib_dir) {
138 static Buf saved_std_dir = BUF_INIT;
139 if (saved_std_dir.list.length != 0)
140 return &saved_std_dir;
141 buf_resize(&saved_std_dir, 0);
142
143 os_path_join(zig_lib_dir, buf_create_from_str("std"), &saved_std_dir);
144
145 return &saved_std_dir;
146}
147
148Buf *get_zig_special_dir(Buf *zig_lib_dir) {
149 static Buf saved_special_dir = BUF_INIT;
150 if (saved_special_dir.list.length != 0)
151 return &saved_special_dir;
152 buf_resize(&saved_special_dir, 0);
153
154 os_path_join(get_zig_std_dir(zig_lib_dir), buf_sprintf("special"), &saved_special_dir);
155
156 return &saved_special_dir;
157}
158
159Buf *get_global_cache_dir(void) {
160 static Buf saved_global_cache_dir = BUF_INIT;
161 if (saved_global_cache_dir.list.length != 0)
162 return &saved_global_cache_dir;
163 buf_resize(&saved_global_cache_dir, 0);
164
165 Buf app_data_dir = BUF_INIT;
166 Error err;
167 if ((err = os_get_app_data_dir(&app_data_dir, "zig"))) {
168 fprintf(stderr, "Unable to get application data dir: %s\n", err_str(err));
169 exit(1);
170 }
171 os_path_join(&app_data_dir, buf_create_from_str("stage1"), &saved_global_cache_dir);
172 buf_deinit(&app_data_dir);
173 return &saved_global_cache_dir;
174}
175
176FileExt classify_file_ext(const char *filename_ptr, size_t filename_len) {
177 if (mem_ends_with_str(filename_ptr, filename_len, ".c")) {
178 return FileExtC;
179 } else if (mem_ends_with_str(filename_ptr, filename_len, ".C") ||
180 mem_ends_with_str(filename_ptr, filename_len, ".cc") ||
181 mem_ends_with_str(filename_ptr, filename_len, ".cpp") ||
182 mem_ends_with_str(filename_ptr, filename_len, ".cxx"))
183 {
184 return FileExtCpp;
185 } else if (mem_ends_with_str(filename_ptr, filename_len, ".ll")) {
186 return FileExtLLVMIr;
187 } else if (mem_ends_with_str(filename_ptr, filename_len, ".bc")) {
188 return FileExtLLVMBitCode;
189 } else if (mem_ends_with_str(filename_ptr, filename_len, ".s") ||
190 mem_ends_with_str(filename_ptr, filename_len, ".S"))
191 {
192 return FileExtAsm;
193 }
194 // TODO look for .so, .so.X, .so.X.Y, .so.X.Y.Z
195 return FileExtUnknown;
196}
src/compiler.hpp deleted-24
...@@ -1,24 +0,0 @@
1/*
2 * Copyright (c) 2018 Andrew Kelley
3 *
4 * This file is part of zig, which is MIT licensed.
5 * See http://opensource.org/licenses/MIT
6 */
7
8#ifndef ZIG_COMPILER_HPP
9#define ZIG_COMPILER_HPP
10
11#include "all_types.hpp"
12
13Error get_compiler_id(Buf **result);
14
15Buf *get_zig_lib_dir(void);
16Buf *get_zig_special_dir(Buf *zig_lib_dir);
17Buf *get_zig_std_dir(Buf *zig_lib_dir);
18
19Buf *get_global_cache_dir(void);
20
21
22FileExt classify_file_ext(const char *filename_ptr, size_t filename_len);
23
24#endif
src/config.h.in-2
...@@ -22,6 +22,4 @@...@@ -22,6 +22,4 @@
22#define ZIG_LLVM_CONFIG_EXE "@LLVM_CONFIG_EXE@"22#define ZIG_LLVM_CONFIG_EXE "@LLVM_CONFIG_EXE@"
23#define ZIG_DIA_GUIDS_LIB "@ZIG_DIA_GUIDS_LIB_ESCAPED@"23#define ZIG_DIA_GUIDS_LIB "@ZIG_DIA_GUIDS_LIB_ESCAPED@"
2424
25#cmakedefine ZIG_ENABLE_MEM_PROFILE
26
27#endif25#endif
src/config.zig.in+1
...@@ -3,3 +3,4 @@ pub const version: []const u8 = "@ZIG_VERSION@";...@@ -3,3 +3,4 @@ pub const version: []const u8 = "@ZIG_VERSION@";
3pub const log_scopes: []const []const u8 = &[_][]const u8{};3pub const log_scopes: []const []const u8 = &[_][]const u8{};
4pub const zir_dumps: []const []const u8 = &[_][]const u8{};4pub const zir_dumps: []const []const u8 = &[_][]const u8{};
5pub const enable_tracy = false;5pub const enable_tracy = false;
6pub const is_stage1 = true;
src/dump_analysis.cpp+1-11
...@@ -6,11 +6,11 @@...@@ -6,11 +6,11 @@
6 */6 */
77
8#include "dump_analysis.hpp"8#include "dump_analysis.hpp"
9#include "compiler.hpp"
10#include "analyze.hpp"9#include "analyze.hpp"
11#include "config.h"10#include "config.h"
12#include "ir.hpp"11#include "ir.hpp"
13#include "codegen.hpp"12#include "codegen.hpp"
13#include "os.hpp"
1414
15enum JsonWriterState {15enum JsonWriterState {
16 JsonWriterStateInvalid,16 JsonWriterStateInvalid,
...@@ -1173,7 +1173,6 @@ static void anal_dump_fn(AnalDumpCtx *ctx, ZigFn *fn) {...@@ -1173,7 +1173,6 @@ static void anal_dump_fn(AnalDumpCtx *ctx, ZigFn *fn) {
1173}1173}
11741174
1175void zig_print_analysis_dump(CodeGen *g, FILE *f, const char *one_indent, const char *nl) {1175void zig_print_analysis_dump(CodeGen *g, FILE *f, const char *one_indent, const char *nl) {
1176 Error err;
1177 AnalDumpCtx ctx = {};1176 AnalDumpCtx ctx = {};
1178 ctx.g = g;1177 ctx.g = g;
1179 JsonWriter *jw = &ctx.jw;1178 JsonWriter *jw = &ctx.jw;
...@@ -1199,15 +1198,6 @@ void zig_print_analysis_dump(CodeGen *g, FILE *f, const char *one_indent, const...@@ -1199,15 +1198,6 @@ void zig_print_analysis_dump(CodeGen *g, FILE *f, const char *one_indent, const
1199 jw_object_field(jw, "params");1198 jw_object_field(jw, "params");
1200 jw_begin_object(jw);1199 jw_begin_object(jw);
1201 {1200 {
1202 jw_object_field(jw, "zigId");
1203
1204 Buf *compiler_id;
1205 if ((err = get_compiler_id(&compiler_id))) {
1206 fprintf(stderr, "Unable to determine compiler id: %s\n", err_str(err));
1207 exit(1);
1208 }
1209 jw_string(jw, buf_ptr(compiler_id));
1210
1211 jw_object_field(jw, "zigVersion");1201 jw_object_field(jw, "zigVersion");
1212 jw_string(jw, ZIG_VERSION_STRING);1202 jw_string(jw, ZIG_VERSION_STRING);
12131203
src/empty.cpp created
src/errmsg.hpp+1-6
...@@ -10,12 +10,7 @@...@@ -10,12 +10,7 @@
1010
11#include "buffer.hpp"11#include "buffer.hpp"
12#include "list.hpp"12#include "list.hpp"
1313#include "stage1.h"
14enum ErrColor {
15 ErrColorAuto,
16 ErrColorOff,
17 ErrColorOn,
18};
1914
20struct ErrorMsg {15struct ErrorMsg {
21 size_t line_start;16 size_t line_start;
src/glibc.cpp deleted-392
...@@ -1,392 +0,0 @@
1/*
2 * Copyright (c) 2019 Andrew Kelley
3 *
4 * This file is part of zig, which is MIT licensed.
5 * See http://opensource.org/licenses/MIT
6 */
7
8#include "glibc.hpp"
9#include "compiler.hpp"
10#include "cache_hash.hpp"
11#include "codegen.hpp"
12
13static const ZigGLibCLib glibc_libs[] = {
14 {"c", 6},
15 {"m", 6},
16 {"pthread", 0},
17 {"dl", 2},
18 {"rt", 1},
19 {"ld", 2},
20 {"util", 1},
21};
22
23Error glibc_load_metadata(ZigGLibCAbi **out_result, Buf *zig_lib_dir, bool verbose) {
24 Error err;
25
26 ZigGLibCAbi *glibc_abi = heap::c_allocator.create<ZigGLibCAbi>();
27 glibc_abi->vers_txt_path = buf_sprintf("%s" OS_SEP "libc" OS_SEP "glibc" OS_SEP "vers.txt", buf_ptr(zig_lib_dir));
28 glibc_abi->fns_txt_path = buf_sprintf("%s" OS_SEP "libc" OS_SEP "glibc" OS_SEP "fns.txt", buf_ptr(zig_lib_dir));
29 glibc_abi->abi_txt_path = buf_sprintf("%s" OS_SEP "libc" OS_SEP "glibc" OS_SEP "abi.txt", buf_ptr(zig_lib_dir));
30 glibc_abi->version_table.init(16);
31
32 Buf *vers_txt_contents = buf_alloc();
33 if ((err = os_fetch_file_path(glibc_abi->vers_txt_path, vers_txt_contents))) {
34 if (verbose) {
35 fprintf(stderr, "Unable to read %s: %s\n", buf_ptr(glibc_abi->vers_txt_path), err_str(err));
36 }
37 return err;
38 }
39 Buf *fns_txt_contents = buf_alloc();
40 if ((err = os_fetch_file_path(glibc_abi->fns_txt_path, fns_txt_contents))) {
41 if (verbose) {
42 fprintf(stderr, "Unable to read %s: %s\n", buf_ptr(glibc_abi->fns_txt_path), err_str(err));
43 }
44 return err;
45 }
46 Buf *abi_txt_contents = buf_alloc();
47 if ((err = os_fetch_file_path(glibc_abi->abi_txt_path, abi_txt_contents))) {
48 if (verbose) {
49 fprintf(stderr, "Unable to read %s: %s\n", buf_ptr(glibc_abi->abi_txt_path), err_str(err));
50 }
51 return err;
52 }
53
54 {
55 SplitIterator it = memSplit(buf_to_slice(vers_txt_contents), str("\r\n"));
56 for (;;) {
57 Optional<Slice<uint8_t>> opt_component = SplitIterator_next(&it);
58 if (!opt_component.is_some) break;
59 Buf *ver_buf = buf_create_from_slice(opt_component.value);
60 Stage2SemVer *this_ver = glibc_abi->all_versions.add_one();
61 if ((err = target_parse_glibc_version(this_ver, buf_ptr(ver_buf)))) {
62 if (verbose) {
63 fprintf(stderr, "Unable to parse glibc version '%s': %s\n", buf_ptr(ver_buf), err_str(err));
64 }
65 return err;
66 }
67 }
68 }
69 {
70 SplitIterator it = memSplit(buf_to_slice(fns_txt_contents), str("\r\n"));
71 for (;;) {
72 Optional<Slice<uint8_t>> opt_component = SplitIterator_next(&it);
73 if (!opt_component.is_some) break;
74 SplitIterator line_it = memSplit(opt_component.value, str(" "));
75 Optional<Slice<uint8_t>> opt_fn_name = SplitIterator_next(&line_it);
76 if (!opt_fn_name.is_some) {
77 if (verbose) {
78 fprintf(stderr, "%s: Expected function name\n", buf_ptr(glibc_abi->fns_txt_path));
79 }
80 return ErrorInvalidFormat;
81 }
82 Optional<Slice<uint8_t>> opt_lib_name = SplitIterator_next(&line_it);
83 if (!opt_lib_name.is_some) {
84 if (verbose) {
85 fprintf(stderr, "%s: Expected lib name\n", buf_ptr(glibc_abi->fns_txt_path));
86 }
87 return ErrorInvalidFormat;
88 }
89
90 Buf *this_fn_name = buf_create_from_slice(opt_fn_name.value);
91 Buf *this_lib_name = buf_create_from_slice(opt_lib_name.value);
92 glibc_abi->all_functions.append({ this_fn_name, glibc_lib_find(buf_ptr(this_lib_name)) });
93 }
94 }
95 {
96 SplitIterator it = memSplit(buf_to_slice(abi_txt_contents), str("\r\n"));
97 ZigGLibCVerList *ver_list_base = nullptr;
98 int line_num = 0;
99 for (;;) {
100 if (ver_list_base == nullptr) {
101 line_num += 1;
102 Optional<Slice<uint8_t>> opt_line = SplitIterator_next_separate(&it);
103 if (!opt_line.is_some) break;
104
105 ver_list_base = heap::c_allocator.allocate<ZigGLibCVerList>(glibc_abi->all_functions.length);
106 SplitIterator line_it = memSplit(opt_line.value, str(" "));
107 for (;;) {
108 ZigTarget *target = heap::c_allocator.create<ZigTarget>();
109 Optional<Slice<uint8_t>> opt_target = SplitIterator_next(&line_it);
110 if (!opt_target.is_some) break;
111
112 SplitIterator component_it = memSplit(opt_target.value, str("-"));
113 Optional<Slice<uint8_t>> opt_arch = SplitIterator_next(&component_it);
114 assert(opt_arch.is_some);
115 Optional<Slice<uint8_t>> opt_os = SplitIterator_next(&component_it);
116 assert(opt_os.is_some); // it's always "linux" so we ignore it
117 Optional<Slice<uint8_t>> opt_abi = SplitIterator_next(&component_it);
118 assert(opt_abi.is_some);
119
120
121 err = target_parse_arch(&target->arch, (char*)opt_arch.value.ptr, opt_arch.value.len);
122 assert(err == ErrorNone);
123
124 target->os = OsLinux;
125
126 err = target_parse_abi(&target->abi, (char*)opt_abi.value.ptr, opt_abi.value.len);
127 if (err != ErrorNone) {
128 fprintf(stderr, "Error parsing %s:%d: %s\n", buf_ptr(glibc_abi->abi_txt_path),
129 line_num, err_str(err));
130 fprintf(stderr, "arch: '%.*s', os: '%.*s', abi: '%.*s'\n",
131 (int)opt_arch.value.len, (const char*)opt_arch.value.ptr,
132 (int)opt_os.value.len, (const char*)opt_os.value.ptr,
133 (int)opt_abi.value.len, (const char*)opt_abi.value.ptr);
134 fprintf(stderr, "parsed from target: '%.*s'\n",
135 (int)opt_target.value.len, (const char*)opt_target.value.ptr);
136 fprintf(stderr, "parsed from line:\n%.*s\n", (int)opt_line.value.len, opt_line.value.ptr);
137 fprintf(stderr, "Zig installation appears to be corrupted.\n");
138 exit(1);
139 }
140
141 glibc_abi->version_table.put(target, ver_list_base);
142 }
143 continue;
144 }
145 for (size_t fn_i = 0; fn_i < glibc_abi->all_functions.length; fn_i += 1) {
146 ZigGLibCVerList *ver_list = &ver_list_base[fn_i];
147 line_num += 1;
148 Optional<Slice<uint8_t>> opt_line = SplitIterator_next_separate(&it);
149 assert(opt_line.is_some);
150
151 SplitIterator line_it = memSplit(opt_line.value, str(" "));
152 for (;;) {
153 Optional<Slice<uint8_t>> opt_ver = SplitIterator_next(&line_it);
154 if (!opt_ver.is_some) break;
155 assert(ver_list->len < 8); // increase the array len in the type
156
157 unsigned long ver_index = strtoul(buf_ptr(buf_create_from_slice(opt_ver.value)), nullptr, 10);
158 assert(ver_index < 255); // use a bigger integer in the type
159 ver_list->versions[ver_list->len] = ver_index;
160 ver_list->len += 1;
161 }
162 }
163 ver_list_base = nullptr;
164 }
165 }
166
167 *out_result = glibc_abi;
168 return ErrorNone;
169}
170
171Error glibc_build_dummies_and_maps(CodeGen *g, const ZigGLibCAbi *glibc_abi, const ZigTarget *target,
172 Buf **out_dir, bool verbose, Stage2ProgressNode *progress_node)
173{
174 Error err;
175
176 Buf *cache_dir = get_global_cache_dir();
177 CacheHash *cache_hash = heap::c_allocator.create<CacheHash>();
178 Buf *manifest_dir = buf_sprintf("%s" OS_SEP CACHE_HASH_SUBDIR, buf_ptr(cache_dir));
179 cache_init(cache_hash, manifest_dir);
180
181 Buf *compiler_id;
182 if ((err = get_compiler_id(&compiler_id))) {
183 if (verbose) {
184 fprintf(stderr, "unable to get compiler id: %s\n", err_str(err));
185 }
186 return err;
187 }
188 cache_buf(cache_hash, compiler_id);
189 cache_int(cache_hash, target->arch);
190 cache_int(cache_hash, target->abi);
191 cache_int(cache_hash, target->glibc_or_darwin_version->major);
192 cache_int(cache_hash, target->glibc_or_darwin_version->minor);
193 cache_int(cache_hash, target->glibc_or_darwin_version->patch);
194
195 Buf digest = BUF_INIT;
196 buf_resize(&digest, 0);
197 if ((err = cache_hit(cache_hash, &digest))) {
198 // Treat an invalid format error as a cache miss.
199 if (err != ErrorInvalidFormat)
200 return err;
201 }
202 // We should always get a cache hit because there are no
203 // files in the input hash.
204 assert(buf_len(&digest) != 0);
205
206 Buf *dummy_dir = buf_alloc();
207 os_path_join(manifest_dir, &digest, dummy_dir);
208
209 if ((err = os_make_path(dummy_dir)))
210 return err;
211
212 Buf *test_if_exists_path = buf_alloc();
213 os_path_join(dummy_dir, buf_create_from_str("ok"), test_if_exists_path);
214
215 bool hit;
216 if ((err = os_file_exists(test_if_exists_path, &hit)))
217 return err;
218
219 if (hit) {
220 *out_dir = dummy_dir;
221 return ErrorNone;
222 }
223
224
225 ZigGLibCVerList *ver_list_base = glibc_abi->version_table.get(target);
226
227 uint8_t target_ver_index = 0;
228 for (;target_ver_index < glibc_abi->all_versions.length; target_ver_index += 1) {
229 const Stage2SemVer *this_ver = &glibc_abi->all_versions.at(target_ver_index);
230 if (this_ver->major == target->glibc_or_darwin_version->major &&
231 this_ver->minor == target->glibc_or_darwin_version->minor &&
232 this_ver->patch == target->glibc_or_darwin_version->patch)
233 {
234 break;
235 }
236 }
237 if (target_ver_index == glibc_abi->all_versions.length) {
238 if (verbose) {
239 fprintf(stderr, "Unrecognized glibc version: %d.%d.%d\n",
240 target->glibc_or_darwin_version->major,
241 target->glibc_or_darwin_version->minor,
242 target->glibc_or_darwin_version->patch);
243 }
244 return ErrorUnknownABI;
245 }
246
247 Buf *map_file_path = buf_sprintf("%s" OS_SEP "all.map", buf_ptr(dummy_dir));
248 Buf *map_contents = buf_alloc();
249
250 for (uint8_t ver_i = 0; ver_i < glibc_abi->all_versions.length; ver_i += 1) {
251 const Stage2SemVer *ver = &glibc_abi->all_versions.at(ver_i);
252 if (ver->patch == 0) {
253 buf_appendf(map_contents, "GLIBC_%d.%d { };\n", ver->major, ver->minor);
254 } else {
255 buf_appendf(map_contents, "GLIBC_%d.%d.%d { };\n", ver->major, ver->minor, ver->patch);
256 }
257 }
258
259 if ((err = os_write_file(map_file_path, map_contents))) {
260 if (verbose) {
261 fprintf(stderr, "unable to write %s: %s", buf_ptr(map_file_path), err_str(err));
262 }
263 return err;
264 }
265
266
267 for (size_t lib_i = 0; lib_i < array_length(glibc_libs); lib_i += 1) {
268 const ZigGLibCLib *lib = &glibc_libs[lib_i];
269 Buf *zig_file_path = buf_sprintf("%s" OS_SEP "%s.zig", buf_ptr(dummy_dir), lib->name);
270 Buf *zig_body = buf_alloc();
271 Buf *zig_footer = buf_alloc();
272
273 buf_appendf(zig_body, "comptime {\n");
274 buf_appendf(zig_body, " asm (\n");
275
276 for (size_t fn_i = 0; fn_i < glibc_abi->all_functions.length; fn_i += 1) {
277 const ZigGLibCFn *libc_fn = &glibc_abi->all_functions.at(fn_i);
278 if (libc_fn->lib != lib) continue;
279 ZigGLibCVerList *ver_list = &ver_list_base[fn_i];
280 // Pick the default symbol version:
281 // - If there are no versions, don't emit it
282 // - Take the greatest one <= than the target one
283 // - If none of them is <= than the
284 // specified one don't pick any default version
285 if (ver_list->len == 0) continue;
286 uint8_t chosen_def_ver_index = 255;
287 for (uint8_t ver_i = 0; ver_i < ver_list->len; ver_i += 1) {
288 uint8_t ver_index = ver_list->versions[ver_i];
289 if ((chosen_def_ver_index == 255 || ver_index > chosen_def_ver_index) &&
290 target_ver_index >= ver_index)
291 {
292 chosen_def_ver_index = ver_index;
293 }
294 }
295 for (uint8_t ver_i = 0; ver_i < ver_list->len; ver_i += 1) {
296 uint8_t ver_index = ver_list->versions[ver_i];
297
298 Buf *stub_name;
299 const Stage2SemVer *ver = &glibc_abi->all_versions.at(ver_index);
300 const char *sym_name = buf_ptr(libc_fn->name);
301 if (ver->patch == 0) {
302 stub_name = buf_sprintf("%s_%d_%d", sym_name, ver->major, ver->minor);
303 } else {
304 stub_name = buf_sprintf("%s_%d_%d_%d", sym_name, ver->major, ver->minor, ver->patch);
305 }
306
307 buf_appendf(zig_footer, "export fn %s() void {}\n", buf_ptr(stub_name));
308
309 // Default symbol version definition vs normal symbol version definition
310 const char *at_sign_str = (chosen_def_ver_index != 255 &&
311 ver_index == chosen_def_ver_index) ? "@@" : "@";
312 if (ver->patch == 0) {
313 buf_appendf(zig_body, " \\\\ .symver %s, %s%sGLIBC_%d.%d\n",
314 buf_ptr(stub_name), sym_name, at_sign_str, ver->major, ver->minor);
315 } else {
316 buf_appendf(zig_body, " \\\\ .symver %s, %s%sGLIBC_%d.%d.%d\n",
317 buf_ptr(stub_name), sym_name, at_sign_str, ver->major, ver->minor, ver->patch);
318 }
319 // Hide the stub to keep the symbol table clean
320 buf_appendf(zig_body, " \\\\ .hidden %s\n", buf_ptr(stub_name));
321 }
322 }
323
324 buf_appendf(zig_body, " );\n");
325 buf_appendf(zig_body, "}\n");
326 buf_append_buf(zig_body, zig_footer);
327
328 if ((err = os_write_file(zig_file_path, zig_body))) {
329 if (verbose) {
330 fprintf(stderr, "unable to write %s: %s", buf_ptr(zig_file_path), err_str(err));
331 }
332 return err;
333 }
334
335 bool is_ld = (strcmp(lib->name, "ld") == 0);
336
337 CodeGen *child_gen = create_child_codegen(g, zig_file_path, OutTypeLib, nullptr, lib->name, progress_node);
338 codegen_set_lib_version(child_gen, true, lib->sover, 0, 0);
339 child_gen->is_dynamic = true;
340 child_gen->is_dummy_so = true;
341 child_gen->version_script_path = map_file_path;
342 child_gen->enable_cache = false;
343 child_gen->output_dir = dummy_dir;
344 if (is_ld) {
345 assert(g->zig_target->standard_dynamic_linker_path != nullptr);
346 Buf *ld_basename = buf_alloc();
347 os_path_split(buf_create_from_str(g->zig_target->standard_dynamic_linker_path),
348 nullptr, ld_basename);
349 child_gen->override_soname = ld_basename;
350 }
351 codegen_build_and_link(child_gen);
352 }
353
354 if ((err = os_write_file(test_if_exists_path, buf_alloc()))) {
355 if (verbose) {
356 fprintf(stderr, "unable to write %s: %s", buf_ptr(test_if_exists_path), err_str(err));
357 }
358 return err;
359 }
360 *out_dir = dummy_dir;
361 return ErrorNone;
362}
363
364uint32_t hash_glibc_target(const ZigTarget *x) {
365 return x->arch * (uint32_t)3250106448 +
366 x->os * (uint32_t)542534372 +
367 x->abi * (uint32_t)59162639;
368}
369
370bool eql_glibc_target(const ZigTarget *a, const ZigTarget *b) {
371 return a->arch == b->arch &&
372 a->os == b->os &&
373 a->abi == b->abi;
374}
375
376size_t glibc_lib_count(void) {
377 return array_length(glibc_libs);
378}
379
380const ZigGLibCLib *glibc_lib_enum(size_t index) {
381 assert(index < array_length(glibc_libs));
382 return &glibc_libs[index];
383}
384
385const ZigGLibCLib *glibc_lib_find(const char *name) {
386 for (size_t i = 0; i < array_length(glibc_libs); i += 1) {
387 if (strcmp(glibc_libs[i].name, name) == 0) {
388 return &glibc_libs[i];
389 }
390 }
391 return nullptr;
392}
src/glibc.hpp deleted-50
...@@ -1,50 +0,0 @@
1/*
2 * Copyright (c) 2019 Andrew Kelley
3 *
4 * This file is part of zig, which is MIT licensed.
5 * See http://opensource.org/licenses/MIT
6 */
7
8#ifndef ZIG_GLIBC_HPP
9#define ZIG_GLIBC_HPP
10
11#include "all_types.hpp"
12
13struct ZigGLibCLib {
14 const char *name;
15 uint8_t sover;
16};
17
18struct ZigGLibCFn {
19 Buf *name;
20 const ZigGLibCLib *lib;
21};
22
23struct ZigGLibCVerList {
24 uint8_t versions[8]; // 8 is just the max number, we know statically it's big enough
25 uint8_t len;
26};
27
28uint32_t hash_glibc_target(const ZigTarget *x);
29bool eql_glibc_target(const ZigTarget *a, const ZigTarget *b);
30
31struct ZigGLibCAbi {
32 Buf *abi_txt_path;
33 Buf *vers_txt_path;
34 Buf *fns_txt_path;
35 ZigList<Stage2SemVer> all_versions;
36 ZigList<ZigGLibCFn> all_functions;
37 // The value is a pointer to all_functions.length items and each item is an index
38 // into all_functions.
39 HashMap<const ZigTarget *, ZigGLibCVerList *, hash_glibc_target, eql_glibc_target> version_table;
40};
41
42Error glibc_load_metadata(ZigGLibCAbi **out_result, Buf *zig_lib_dir, bool verbose);
43Error glibc_build_dummies_and_maps(CodeGen *codegen, const ZigGLibCAbi *glibc_abi, const ZigTarget *target,
44 Buf **out_dir, bool verbose, Stage2ProgressNode *progress_node);
45
46size_t glibc_lib_count(void);
47const ZigGLibCLib *glibc_lib_enum(size_t index);
48const ZigGLibCLib *glibc_lib_find(const char *name);
49
50#endif
src/heap.cpp+2-64
...@@ -10,7 +10,6 @@...@@ -10,7 +10,6 @@
1010
11#include "config.h"11#include "config.h"
12#include "heap.hpp"12#include "heap.hpp"
13#include "mem_profile.hpp"
1413
15namespace heap {14namespace heap {
1615
...@@ -48,21 +47,9 @@ void BootstrapAllocator::internal_deallocate(const mem::TypeInfo &info, void *pt...@@ -48,21 +47,9 @@ void BootstrapAllocator::internal_deallocate(const mem::TypeInfo &info, void *pt
48 mem::os::free(ptr);47 mem::os::free(ptr);
49}48}
5049
51void CAllocator::init(const char *name) {50void CAllocator::init(const char *name) { }
52#ifdef ZIG_ENABLE_MEM_PROFILE
53 this->profile = bootstrap_allocator.create<mem::Profile>();
54 this->profile->init(name, "CAllocator");
55#endif
56}
5751
58void CAllocator::deinit() {52void CAllocator::deinit() { }
59#ifdef ZIG_ENABLE_MEM_PROFILE
60 assert(this->profile);
61 this->profile->deinit();
62 bootstrap_allocator.destroy(this->profile);
63 this->profile = nullptr;
64#endif
65}
6653
67CAllocator *CAllocator::construct(mem::Allocator *allocator, const char *name) {54CAllocator *CAllocator::construct(mem::Allocator *allocator, const char *name) {
68 auto p = new(allocator->create<CAllocator>()) CAllocator();55 auto p = new(allocator->create<CAllocator>()) CAllocator();
...@@ -75,23 +62,11 @@ void CAllocator::destruct(mem::Allocator *allocator) {...@@ -75,23 +62,11 @@ void CAllocator::destruct(mem::Allocator *allocator) {
75 allocator->destroy(this);62 allocator->destroy(this);
76}63}
7764
78#ifdef ZIG_ENABLE_MEM_PROFILE
79void CAllocator::print_report(FILE *file) {
80 this->profile->print_report(file);
81}
82#endif
83
84void *CAllocator::internal_allocate(const mem::TypeInfo &info, size_t count) {65void *CAllocator::internal_allocate(const mem::TypeInfo &info, size_t count) {
85#ifdef ZIG_ENABLE_MEM_PROFILE
86 this->profile->record_alloc(info, count);
87#endif
88 return mem::os::calloc(count, info.size);66 return mem::os::calloc(count, info.size);
89}67}
9068
91void *CAllocator::internal_allocate_nonzero(const mem::TypeInfo &info, size_t count) {69void *CAllocator::internal_allocate_nonzero(const mem::TypeInfo &info, size_t count) {
92#ifdef ZIG_ENABLE_MEM_PROFILE
93 this->profile->record_alloc(info, count);
94#endif
95 return mem::os::malloc(count * info.size);70 return mem::os::malloc(count * info.size);
96}71}
9772
...@@ -103,17 +78,10 @@ void *CAllocator::internal_reallocate(const mem::TypeInfo &info, void *old_ptr,...@@ -103,17 +78,10 @@ void *CAllocator::internal_reallocate(const mem::TypeInfo &info, void *old_ptr,
103}78}
10479
105void *CAllocator::internal_reallocate_nonzero(const mem::TypeInfo &info, void *old_ptr, size_t old_count, size_t new_count) {80void *CAllocator::internal_reallocate_nonzero(const mem::TypeInfo &info, void *old_ptr, size_t old_count, size_t new_count) {
106#ifdef ZIG_ENABLE_MEM_PROFILE
107 this->profile->record_dealloc(info, old_count);
108 this->profile->record_alloc(info, new_count);
109#endif
110 return mem::os::realloc(old_ptr, new_count * info.size);81 return mem::os::realloc(old_ptr, new_count * info.size);
111}82}
11283
113void CAllocator::internal_deallocate(const mem::TypeInfo &info, void *ptr, size_t count) {84void CAllocator::internal_deallocate(const mem::TypeInfo &info, void *ptr, size_t count) {
114#ifdef ZIG_ENABLE_MEM_PROFILE
115 this->profile->record_dealloc(info, count);
116#endif
117 mem::os::free(ptr);85 mem::os::free(ptr);
118}86}
11987
...@@ -249,10 +217,6 @@ void ArenaAllocator::Impl::track_object(Object object) {...@@ -249,10 +217,6 @@ void ArenaAllocator::Impl::track_object(Object object) {
249}217}
250218
251void ArenaAllocator::init(Allocator *backing, const char *name) {219void ArenaAllocator::init(Allocator *backing, const char *name) {
252#ifdef ZIG_ENABLE_MEM_PROFILE
253 this->profile = bootstrap_allocator.create<mem::Profile>();
254 this->profile->init(name, "ArenaAllocator");
255#endif
256 this->impl = bootstrap_allocator.create<Impl>();220 this->impl = bootstrap_allocator.create<Impl>();
257 {221 {
258 auto &r = *this->impl;222 auto &r = *this->impl;
...@@ -309,13 +273,6 @@ void ArenaAllocator::deinit() {...@@ -309,13 +273,6 @@ void ArenaAllocator::deinit() {
309 t = prev;273 t = prev;
310 }274 }
311 }275 }
312
313#ifdef ZIG_ENABLE_MEM_PROFILE
314 assert(this->profile);
315 this->profile->deinit();
316 bootstrap_allocator.destroy(this->profile);
317 this->profile = nullptr;
318#endif
319}276}
320277
321ArenaAllocator *ArenaAllocator::construct(mem::Allocator *allocator, mem::Allocator *backing, const char *name) {278ArenaAllocator *ArenaAllocator::construct(mem::Allocator *allocator, mem::Allocator *backing, const char *name) {
...@@ -329,23 +286,11 @@ void ArenaAllocator::destruct(mem::Allocator *allocator) {...@@ -329,23 +286,11 @@ void ArenaAllocator::destruct(mem::Allocator *allocator) {
329 allocator->destroy(this);286 allocator->destroy(this);
330}287}
331288
332#ifdef ZIG_ENABLE_MEM_PROFILE
333void ArenaAllocator::print_report(FILE *file) {
334 this->profile->print_report(file);
335}
336#endif
337
338void *ArenaAllocator::internal_allocate(const mem::TypeInfo &info, size_t count) {289void *ArenaAllocator::internal_allocate(const mem::TypeInfo &info, size_t count) {
339#ifdef ZIG_ENABLE_MEM_PROFILE
340 this->profile->record_alloc(info, count);
341#endif
342 return this->impl->allocate(info, count);290 return this->impl->allocate(info, count);
343}291}
344292
345void *ArenaAllocator::internal_allocate_nonzero(const mem::TypeInfo &info, size_t count) {293void *ArenaAllocator::internal_allocate_nonzero(const mem::TypeInfo &info, size_t count) {
346#ifdef ZIG_ENABLE_MEM_PROFILE
347 this->profile->record_alloc(info, count);
348#endif
349 return this->impl->allocate(info, count);294 return this->impl->allocate(info, count);
350}295}
351296
...@@ -354,17 +299,10 @@ void *ArenaAllocator::internal_reallocate(const mem::TypeInfo &info, void *old_p...@@ -354,17 +299,10 @@ void *ArenaAllocator::internal_reallocate(const mem::TypeInfo &info, void *old_p
354}299}
355300
356void *ArenaAllocator::internal_reallocate_nonzero(const mem::TypeInfo &info, void *old_ptr, size_t old_count, size_t new_count) {301void *ArenaAllocator::internal_reallocate_nonzero(const mem::TypeInfo &info, void *old_ptr, size_t old_count, size_t new_count) {
357#ifdef ZIG_ENABLE_MEM_PROFILE
358 this->profile->record_dealloc(info, old_count);
359 this->profile->record_alloc(info, new_count);
360#endif
361 return this->impl->reallocate(info, old_ptr, old_count, new_count);302 return this->impl->reallocate(info, old_ptr, old_count, new_count);
362}303}
363304
364void ArenaAllocator::internal_deallocate(const mem::TypeInfo &info, void *ptr, size_t count) {305void ArenaAllocator::internal_deallocate(const mem::TypeInfo &info, void *ptr, size_t count) {
365#ifdef ZIG_ENABLE_MEM_PROFILE
366 this->profile->record_dealloc(info, count);
367#endif
368 // noop306 // noop
369}307}
370308
src/heap.hpp-19
...@@ -12,12 +12,6 @@...@@ -12,12 +12,6 @@
12#include "util_base.hpp"12#include "util_base.hpp"
13#include "mem.hpp"13#include "mem.hpp"
1414
15#ifdef ZIG_ENABLE_MEM_PROFILE
16namespace mem {
17 struct Profile;
18}
19#endif
20
21namespace heap {15namespace heap {
2216
23struct BootstrapAllocator final : mem::Allocator {17struct BootstrapAllocator final : mem::Allocator {
...@@ -40,9 +34,6 @@ struct CAllocator final : mem::Allocator {...@@ -40,9 +34,6 @@ struct CAllocator final : mem::Allocator {
40 static CAllocator *construct(mem::Allocator *allocator, const char *name);34 static CAllocator *construct(mem::Allocator *allocator, const char *name);
41 void destruct(mem::Allocator *allocator) final;35 void destruct(mem::Allocator *allocator) final;
4236
43#ifdef ZIG_ENABLE_MEM_PROFILE
44 void print_report(FILE *file = nullptr);
45#endif
4637
47private:38private:
48 ATTRIBUTE_RETURNS_NOALIAS void *internal_allocate(const mem::TypeInfo &info, size_t count) final;39 ATTRIBUTE_RETURNS_NOALIAS void *internal_allocate(const mem::TypeInfo &info, size_t count) final;
...@@ -51,9 +42,6 @@ private:...@@ -51,9 +42,6 @@ private:
51 void *internal_reallocate_nonzero(const mem::TypeInfo &info, void *old_ptr, size_t old_count, size_t new_count) final;42 void *internal_reallocate_nonzero(const mem::TypeInfo &info, void *old_ptr, size_t old_count, size_t new_count) final;
52 void internal_deallocate(const mem::TypeInfo &info, void *ptr, size_t count) final;43 void internal_deallocate(const mem::TypeInfo &info, void *ptr, size_t count) final;
5344
54#ifdef ZIG_ENABLE_MEM_PROFILE
55 mem::Profile *profile;
56#endif
57};45};
5846
59//47//
...@@ -71,9 +59,6 @@ struct ArenaAllocator final : mem::Allocator {...@@ -71,9 +59,6 @@ struct ArenaAllocator final : mem::Allocator {
71 static ArenaAllocator *construct(mem::Allocator *allocator, mem::Allocator *backing, const char *name);59 static ArenaAllocator *construct(mem::Allocator *allocator, mem::Allocator *backing, const char *name);
72 void destruct(mem::Allocator *allocator) final;60 void destruct(mem::Allocator *allocator) final;
7361
74#ifdef ZIG_ENABLE_MEM_PROFILE
75 void print_report(FILE *file = nullptr);
76#endif
7762
78private:63private:
79 ATTRIBUTE_RETURNS_NOALIAS void *internal_allocate(const mem::TypeInfo &info, size_t count) final;64 ATTRIBUTE_RETURNS_NOALIAS void *internal_allocate(const mem::TypeInfo &info, size_t count) final;
...@@ -82,10 +67,6 @@ private:...@@ -82,10 +67,6 @@ private:
82 void *internal_reallocate_nonzero(const mem::TypeInfo &info, void *old_ptr, size_t old_count, size_t new_count) final;67 void *internal_reallocate_nonzero(const mem::TypeInfo &info, void *old_ptr, size_t old_count, size_t new_count) final;
83 void internal_deallocate(const mem::TypeInfo &info, void *ptr, size_t count) final;68 void internal_deallocate(const mem::TypeInfo &info, void *ptr, size_t count) final;
8469
85#ifdef ZIG_ENABLE_MEM_PROFILE
86 mem::Profile *profile;
87#endif
88
89 struct Impl;70 struct Impl;
90 Impl *impl;71 Impl *impl;
91};72};
src/install_files.h deleted-1907
...@@ -1,1907 +0,0 @@
1#ifndef ZIG_INSTALL_FILES_H
2#define ZIG_INSTALL_FILES_H
3static const char *ZIG_MUSL_SRC_FILES[] = {
4"musl/src/aio/aio.c",
5"musl/src/aio/aio_suspend.c",
6"musl/src/aio/lio_listio.c",
7"musl/src/complex/__cexp.c",
8"musl/src/complex/__cexpf.c",
9"musl/src/complex/cabs.c",
10"musl/src/complex/cabsf.c",
11"musl/src/complex/cabsl.c",
12"musl/src/complex/cacos.c",
13"musl/src/complex/cacosf.c",
14"musl/src/complex/cacosh.c",
15"musl/src/complex/cacoshf.c",
16"musl/src/complex/cacoshl.c",
17"musl/src/complex/cacosl.c",
18"musl/src/complex/carg.c",
19"musl/src/complex/cargf.c",
20"musl/src/complex/cargl.c",
21"musl/src/complex/casin.c",
22"musl/src/complex/casinf.c",
23"musl/src/complex/casinh.c",
24"musl/src/complex/casinhf.c",
25"musl/src/complex/casinhl.c",
26"musl/src/complex/casinl.c",
27"musl/src/complex/catan.c",
28"musl/src/complex/catanf.c",
29"musl/src/complex/catanh.c",
30"musl/src/complex/catanhf.c",
31"musl/src/complex/catanhl.c",
32"musl/src/complex/catanl.c",
33"musl/src/complex/ccos.c",
34"musl/src/complex/ccosf.c",
35"musl/src/complex/ccosh.c",
36"musl/src/complex/ccoshf.c",
37"musl/src/complex/ccoshl.c",
38"musl/src/complex/ccosl.c",
39"musl/src/complex/cexp.c",
40"musl/src/complex/cexpf.c",
41"musl/src/complex/cexpl.c",
42"musl/src/complex/cimag.c",
43"musl/src/complex/cimagf.c",
44"musl/src/complex/cimagl.c",
45"musl/src/complex/clog.c",
46"musl/src/complex/clogf.c",
47"musl/src/complex/clogl.c",
48"musl/src/complex/conj.c",
49"musl/src/complex/conjf.c",
50"musl/src/complex/conjl.c",
51"musl/src/complex/cpow.c",
52"musl/src/complex/cpowf.c",
53"musl/src/complex/cpowl.c",
54"musl/src/complex/cproj.c",
55"musl/src/complex/cprojf.c",
56"musl/src/complex/cprojl.c",
57"musl/src/complex/creal.c",
58"musl/src/complex/crealf.c",
59"musl/src/complex/creall.c",
60"musl/src/complex/csin.c",
61"musl/src/complex/csinf.c",
62"musl/src/complex/csinh.c",
63"musl/src/complex/csinhf.c",
64"musl/src/complex/csinhl.c",
65"musl/src/complex/csinl.c",
66"musl/src/complex/csqrt.c",
67"musl/src/complex/csqrtf.c",
68"musl/src/complex/csqrtl.c",
69"musl/src/complex/ctan.c",
70"musl/src/complex/ctanf.c",
71"musl/src/complex/ctanh.c",
72"musl/src/complex/ctanhf.c",
73"musl/src/complex/ctanhl.c",
74"musl/src/complex/ctanl.c",
75"musl/src/conf/confstr.c",
76"musl/src/conf/fpathconf.c",
77"musl/src/conf/legacy.c",
78"musl/src/conf/pathconf.c",
79"musl/src/conf/sysconf.c",
80"musl/src/crypt/crypt.c",
81"musl/src/crypt/crypt_blowfish.c",
82"musl/src/crypt/crypt_des.c",
83"musl/src/crypt/crypt_md5.c",
84"musl/src/crypt/crypt_r.c",
85"musl/src/crypt/crypt_sha256.c",
86"musl/src/crypt/crypt_sha512.c",
87"musl/src/crypt/encrypt.c",
88"musl/src/ctype/__ctype_b_loc.c",
89"musl/src/ctype/__ctype_get_mb_cur_max.c",
90"musl/src/ctype/__ctype_tolower_loc.c",
91"musl/src/ctype/__ctype_toupper_loc.c",
92"musl/src/ctype/isalnum.c",
93"musl/src/ctype/isalpha.c",
94"musl/src/ctype/isascii.c",
95"musl/src/ctype/isblank.c",
96"musl/src/ctype/iscntrl.c",
97"musl/src/ctype/isdigit.c",
98"musl/src/ctype/isgraph.c",
99"musl/src/ctype/islower.c",
100"musl/src/ctype/isprint.c",
101"musl/src/ctype/ispunct.c",
102"musl/src/ctype/isspace.c",
103"musl/src/ctype/isupper.c",
104"musl/src/ctype/iswalnum.c",
105"musl/src/ctype/iswalpha.c",
106"musl/src/ctype/iswblank.c",
107"musl/src/ctype/iswcntrl.c",
108"musl/src/ctype/iswctype.c",
109"musl/src/ctype/iswdigit.c",
110"musl/src/ctype/iswgraph.c",
111"musl/src/ctype/iswlower.c",
112"musl/src/ctype/iswprint.c",
113"musl/src/ctype/iswpunct.c",
114"musl/src/ctype/iswspace.c",
115"musl/src/ctype/iswupper.c",
116"musl/src/ctype/iswxdigit.c",
117"musl/src/ctype/isxdigit.c",
118"musl/src/ctype/toascii.c",
119"musl/src/ctype/tolower.c",
120"musl/src/ctype/toupper.c",
121"musl/src/ctype/towctrans.c",
122"musl/src/ctype/wcswidth.c",
123"musl/src/ctype/wctrans.c",
124"musl/src/ctype/wcwidth.c",
125"musl/src/dirent/alphasort.c",
126"musl/src/dirent/closedir.c",
127"musl/src/dirent/dirfd.c",
128"musl/src/dirent/fdopendir.c",
129"musl/src/dirent/opendir.c",
130"musl/src/dirent/readdir.c",
131"musl/src/dirent/readdir_r.c",
132"musl/src/dirent/rewinddir.c",
133"musl/src/dirent/scandir.c",
134"musl/src/dirent/seekdir.c",
135"musl/src/dirent/telldir.c",
136"musl/src/dirent/versionsort.c",
137"musl/src/env/__environ.c",
138"musl/src/env/__init_tls.c",
139"musl/src/env/__libc_start_main.c",
140"musl/src/env/__reset_tls.c",
141"musl/src/env/__stack_chk_fail.c",
142"musl/src/env/clearenv.c",
143"musl/src/env/getenv.c",
144"musl/src/env/putenv.c",
145"musl/src/env/secure_getenv.c",
146"musl/src/env/setenv.c",
147"musl/src/env/unsetenv.c",
148"musl/src/errno/__errno_location.c",
149"musl/src/errno/strerror.c",
150"musl/src/exit/_Exit.c",
151"musl/src/exit/abort.c",
152"musl/src/exit/arm/__aeabi_atexit.c",
153"musl/src/exit/assert.c",
154"musl/src/exit/at_quick_exit.c",
155"musl/src/exit/atexit.c",
156"musl/src/exit/exit.c",
157"musl/src/exit/quick_exit.c",
158"musl/src/fcntl/creat.c",
159"musl/src/fcntl/fcntl.c",
160"musl/src/fcntl/open.c",
161"musl/src/fcntl/openat.c",
162"musl/src/fcntl/posix_fadvise.c",
163"musl/src/fcntl/posix_fallocate.c",
164"musl/src/fenv/__flt_rounds.c",
165"musl/src/fenv/aarch64/fenv.s",
166"musl/src/fenv/arm/fenv-hf.S",
167"musl/src/fenv/arm/fenv.c",
168"musl/src/fenv/fegetexceptflag.c",
169"musl/src/fenv/feholdexcept.c",
170"musl/src/fenv/fenv.c",
171"musl/src/fenv/fesetexceptflag.c",
172"musl/src/fenv/fesetround.c",
173"musl/src/fenv/feupdateenv.c",
174"musl/src/fenv/i386/fenv.s",
175"musl/src/fenv/m68k/fenv.c",
176"musl/src/fenv/mips/fenv-sf.c",
177"musl/src/fenv/mips/fenv.S",
178"musl/src/fenv/mips64/fenv-sf.c",
179"musl/src/fenv/mips64/fenv.S",
180"musl/src/fenv/mipsn32/fenv-sf.c",
181"musl/src/fenv/mipsn32/fenv.S",
182"musl/src/fenv/powerpc/fenv-sf.c",
183"musl/src/fenv/powerpc/fenv.S",
184"musl/src/fenv/powerpc64/fenv.c",
185"musl/src/fenv/riscv64/fenv-sf.c",
186"musl/src/fenv/riscv64/fenv.S",
187"musl/src/fenv/s390x/fenv.c",
188"musl/src/fenv/sh/fenv-nofpu.c",
189"musl/src/fenv/sh/fenv.S",
190"musl/src/fenv/x32/fenv.s",
191"musl/src/fenv/x86_64/fenv.s",
192"musl/src/internal/defsysinfo.c",
193"musl/src/internal/floatscan.c",
194"musl/src/internal/i386/defsysinfo.s",
195"musl/src/internal/intscan.c",
196"musl/src/internal/libc.c",
197"musl/src/internal/procfdname.c",
198"musl/src/internal/sh/__shcall.c",
199"musl/src/internal/shgetc.c",
200"musl/src/internal/syscall_ret.c",
201"musl/src/internal/vdso.c",
202"musl/src/internal/version.c",
203"musl/src/ipc/ftok.c",
204"musl/src/ipc/msgctl.c",
205"musl/src/ipc/msgget.c",
206"musl/src/ipc/msgrcv.c",
207"musl/src/ipc/msgsnd.c",
208"musl/src/ipc/semctl.c",
209"musl/src/ipc/semget.c",
210"musl/src/ipc/semop.c",
211"musl/src/ipc/semtimedop.c",
212"musl/src/ipc/shmat.c",
213"musl/src/ipc/shmctl.c",
214"musl/src/ipc/shmdt.c",
215"musl/src/ipc/shmget.c",
216"musl/src/ldso/__dlsym.c",
217"musl/src/ldso/aarch64/dlsym.s",
218"musl/src/ldso/aarch64/tlsdesc.s",
219"musl/src/ldso/arm/dlsym.s",
220"musl/src/ldso/arm/dlsym_time64.S",
221"musl/src/ldso/arm/find_exidx.c",
222"musl/src/ldso/arm/tlsdesc.S",
223"musl/src/ldso/dl_iterate_phdr.c",
224"musl/src/ldso/dladdr.c",
225"musl/src/ldso/dlclose.c",
226"musl/src/ldso/dlerror.c",
227"musl/src/ldso/dlinfo.c",
228"musl/src/ldso/dlopen.c",
229"musl/src/ldso/dlsym.c",
230"musl/src/ldso/i386/dlsym.s",
231"musl/src/ldso/i386/dlsym_time64.S",
232"musl/src/ldso/i386/tlsdesc.s",
233"musl/src/ldso/m68k/dlsym.s",
234"musl/src/ldso/m68k/dlsym_time64.S",
235"musl/src/ldso/microblaze/dlsym.s",
236"musl/src/ldso/microblaze/dlsym_time64.S",
237"musl/src/ldso/mips/dlsym.s",
238"musl/src/ldso/mips/dlsym_time64.S",
239"musl/src/ldso/mips64/dlsym.s",
240"musl/src/ldso/mipsn32/dlsym.s",
241"musl/src/ldso/mipsn32/dlsym_time64.S",
242"musl/src/ldso/or1k/dlsym.s",
243"musl/src/ldso/or1k/dlsym_time64.S",
244"musl/src/ldso/powerpc/dlsym.s",
245"musl/src/ldso/powerpc/dlsym_time64.S",
246"musl/src/ldso/powerpc64/dlsym.s",
247"musl/src/ldso/riscv64/dlsym.s",
248"musl/src/ldso/s390x/dlsym.s",
249"musl/src/ldso/sh/dlsym.s",
250"musl/src/ldso/sh/dlsym_time64.S",
251"musl/src/ldso/tlsdesc.c",
252"musl/src/ldso/x32/dlsym.s",
253"musl/src/ldso/x86_64/dlsym.s",
254"musl/src/ldso/x86_64/tlsdesc.s",
255"musl/src/legacy/cuserid.c",
256"musl/src/legacy/daemon.c",
257"musl/src/legacy/err.c",
258"musl/src/legacy/euidaccess.c",
259"musl/src/legacy/ftw.c",
260"musl/src/legacy/futimes.c",
261"musl/src/legacy/getdtablesize.c",
262"musl/src/legacy/getloadavg.c",
263"musl/src/legacy/getpagesize.c",
264"musl/src/legacy/getpass.c",
265"musl/src/legacy/getusershell.c",
266"musl/src/legacy/isastream.c",
267"musl/src/legacy/lutimes.c",
268"musl/src/legacy/ulimit.c",
269"musl/src/legacy/utmpx.c",
270"musl/src/legacy/valloc.c",
271"musl/src/linux/adjtime.c",
272"musl/src/linux/adjtimex.c",
273"musl/src/linux/arch_prctl.c",
274"musl/src/linux/brk.c",
275"musl/src/linux/cache.c",
276"musl/src/linux/cap.c",
277"musl/src/linux/chroot.c",
278"musl/src/linux/clock_adjtime.c",
279"musl/src/linux/clone.c",
280"musl/src/linux/copy_file_range.c",
281"musl/src/linux/epoll.c",
282"musl/src/linux/eventfd.c",
283"musl/src/linux/fallocate.c",
284"musl/src/linux/fanotify.c",
285"musl/src/linux/flock.c",
286"musl/src/linux/getdents.c",
287"musl/src/linux/getrandom.c",
288"musl/src/linux/inotify.c",
289"musl/src/linux/ioperm.c",
290"musl/src/linux/iopl.c",
291"musl/src/linux/klogctl.c",
292"musl/src/linux/membarrier.c",
293"musl/src/linux/memfd_create.c",
294"musl/src/linux/mlock2.c",
295"musl/src/linux/module.c",
296"musl/src/linux/mount.c",
297"musl/src/linux/name_to_handle_at.c",
298"musl/src/linux/open_by_handle_at.c",
299"musl/src/linux/personality.c",
300"musl/src/linux/pivot_root.c",
301"musl/src/linux/ppoll.c",
302"musl/src/linux/prctl.c",
303"musl/src/linux/prlimit.c",
304"musl/src/linux/process_vm.c",
305"musl/src/linux/ptrace.c",
306"musl/src/linux/quotactl.c",
307"musl/src/linux/readahead.c",
308"musl/src/linux/reboot.c",
309"musl/src/linux/remap_file_pages.c",
310"musl/src/linux/sbrk.c",
311"musl/src/linux/sendfile.c",
312"musl/src/linux/setfsgid.c",
313"musl/src/linux/setfsuid.c",
314"musl/src/linux/setgroups.c",
315"musl/src/linux/sethostname.c",
316"musl/src/linux/setns.c",
317"musl/src/linux/settimeofday.c",
318"musl/src/linux/signalfd.c",
319"musl/src/linux/splice.c",
320"musl/src/linux/stime.c",
321"musl/src/linux/swap.c",
322"musl/src/linux/sync_file_range.c",
323"musl/src/linux/syncfs.c",
324"musl/src/linux/sysinfo.c",
325"musl/src/linux/tee.c",
326"musl/src/linux/timerfd.c",
327"musl/src/linux/unshare.c",
328"musl/src/linux/utimes.c",
329"musl/src/linux/vhangup.c",
330"musl/src/linux/vmsplice.c",
331"musl/src/linux/wait3.c",
332"musl/src/linux/wait4.c",
333"musl/src/linux/x32/sysinfo.c",
334"musl/src/linux/xattr.c",
335"musl/src/locale/__lctrans.c",
336"musl/src/locale/__mo_lookup.c",
337"musl/src/locale/bind_textdomain_codeset.c",
338"musl/src/locale/c_locale.c",
339"musl/src/locale/catclose.c",
340"musl/src/locale/catgets.c",
341"musl/src/locale/catopen.c",
342"musl/src/locale/dcngettext.c",
343"musl/src/locale/duplocale.c",
344"musl/src/locale/freelocale.c",
345"musl/src/locale/iconv.c",
346"musl/src/locale/iconv_close.c",
347"musl/src/locale/langinfo.c",
348"musl/src/locale/locale_map.c",
349"musl/src/locale/localeconv.c",
350"musl/src/locale/newlocale.c",
351"musl/src/locale/pleval.c",
352"musl/src/locale/setlocale.c",
353"musl/src/locale/strcoll.c",
354"musl/src/locale/strfmon.c",
355"musl/src/locale/strxfrm.c",
356"musl/src/locale/textdomain.c",
357"musl/src/locale/uselocale.c",
358"musl/src/locale/wcscoll.c",
359"musl/src/locale/wcsxfrm.c",
360"musl/src/malloc/aligned_alloc.c",
361"musl/src/malloc/expand_heap.c",
362"musl/src/malloc/lite_malloc.c",
363"musl/src/malloc/malloc.c",
364"musl/src/malloc/malloc_usable_size.c",
365"musl/src/malloc/memalign.c",
366"musl/src/malloc/posix_memalign.c",
367"musl/src/math/__cos.c",
368"musl/src/math/__cosdf.c",
369"musl/src/math/__cosl.c",
370"musl/src/math/__expo2.c",
371"musl/src/math/__expo2f.c",
372"musl/src/math/__fpclassify.c",
373"musl/src/math/__fpclassifyf.c",
374"musl/src/math/__fpclassifyl.c",
375"musl/src/math/__invtrigl.c",
376"musl/src/math/__math_divzero.c",
377"musl/src/math/__math_divzerof.c",
378"musl/src/math/__math_invalid.c",
379"musl/src/math/__math_invalidf.c",
380"musl/src/math/__math_oflow.c",
381"musl/src/math/__math_oflowf.c",
382"musl/src/math/__math_uflow.c",
383"musl/src/math/__math_uflowf.c",
384"musl/src/math/__math_xflow.c",
385"musl/src/math/__math_xflowf.c",
386"musl/src/math/__polevll.c",
387"musl/src/math/__rem_pio2.c",
388"musl/src/math/__rem_pio2_large.c",
389"musl/src/math/__rem_pio2f.c",
390"musl/src/math/__rem_pio2l.c",
391"musl/src/math/__signbit.c",
392"musl/src/math/__signbitf.c",
393"musl/src/math/__signbitl.c",
394"musl/src/math/__sin.c",
395"musl/src/math/__sindf.c",
396"musl/src/math/__sinl.c",
397"musl/src/math/__tan.c",
398"musl/src/math/__tandf.c",
399"musl/src/math/__tanl.c",
400"musl/src/math/aarch64/ceil.c",
401"musl/src/math/aarch64/ceilf.c",
402"musl/src/math/aarch64/fabs.c",
403"musl/src/math/aarch64/fabsf.c",
404"musl/src/math/aarch64/floor.c",
405"musl/src/math/aarch64/floorf.c",
406"musl/src/math/aarch64/fma.c",
407"musl/src/math/aarch64/fmaf.c",
408"musl/src/math/aarch64/fmax.c",
409"musl/src/math/aarch64/fmaxf.c",
410"musl/src/math/aarch64/fmin.c",
411"musl/src/math/aarch64/fminf.c",
412"musl/src/math/aarch64/llrint.c",
413"musl/src/math/aarch64/llrintf.c",
414"musl/src/math/aarch64/llround.c",
415"musl/src/math/aarch64/llroundf.c",
416"musl/src/math/aarch64/lrint.c",
417"musl/src/math/aarch64/lrintf.c",
418"musl/src/math/aarch64/lround.c",
419"musl/src/math/aarch64/lroundf.c",
420"musl/src/math/aarch64/nearbyint.c",
421"musl/src/math/aarch64/nearbyintf.c",
422"musl/src/math/aarch64/rint.c",
423"musl/src/math/aarch64/rintf.c",
424"musl/src/math/aarch64/round.c",
425"musl/src/math/aarch64/roundf.c",
426"musl/src/math/aarch64/sqrt.c",
427"musl/src/math/aarch64/sqrtf.c",
428"musl/src/math/aarch64/trunc.c",
429"musl/src/math/aarch64/truncf.c",
430"musl/src/math/acos.c",
431"musl/src/math/acosf.c",
432"musl/src/math/acosh.c",
433"musl/src/math/acoshf.c",
434"musl/src/math/acoshl.c",
435"musl/src/math/acosl.c",
436"musl/src/math/arm/fabs.c",
437"musl/src/math/arm/fabsf.c",
438"musl/src/math/arm/fma.c",
439"musl/src/math/arm/fmaf.c",
440"musl/src/math/arm/sqrt.c",
441"musl/src/math/arm/sqrtf.c",
442"musl/src/math/asin.c",
443"musl/src/math/asinf.c",
444"musl/src/math/asinh.c",
445"musl/src/math/asinhf.c",
446"musl/src/math/asinhl.c",
447"musl/src/math/asinl.c",
448"musl/src/math/atan.c",
449"musl/src/math/atan2.c",
450"musl/src/math/atan2f.c",
451"musl/src/math/atan2l.c",
452"musl/src/math/atanf.c",
453"musl/src/math/atanh.c",
454"musl/src/math/atanhf.c",
455"musl/src/math/atanhl.c",
456"musl/src/math/atanl.c",
457"musl/src/math/cbrt.c",
458"musl/src/math/cbrtf.c",
459"musl/src/math/cbrtl.c",
460"musl/src/math/ceil.c",
461"musl/src/math/ceilf.c",
462"musl/src/math/ceill.c",
463"musl/src/math/copysign.c",
464"musl/src/math/copysignf.c",
465"musl/src/math/copysignl.c",
466"musl/src/math/cos.c",
467"musl/src/math/cosf.c",
468"musl/src/math/cosh.c",
469"musl/src/math/coshf.c",
470"musl/src/math/coshl.c",
471"musl/src/math/cosl.c",
472"musl/src/math/erf.c",
473"musl/src/math/erff.c",
474"musl/src/math/erfl.c",
475"musl/src/math/exp.c",
476"musl/src/math/exp10.c",
477"musl/src/math/exp10f.c",
478"musl/src/math/exp10l.c",
479"musl/src/math/exp2.c",
480"musl/src/math/exp2f.c",
481"musl/src/math/exp2f_data.c",
482"musl/src/math/exp2l.c",
483"musl/src/math/exp_data.c",
484"musl/src/math/expf.c",
485"musl/src/math/expl.c",
486"musl/src/math/expm1.c",
487"musl/src/math/expm1f.c",
488"musl/src/math/expm1l.c",
489"musl/src/math/fabs.c",
490"musl/src/math/fabsf.c",
491"musl/src/math/fabsl.c",
492"musl/src/math/fdim.c",
493"musl/src/math/fdimf.c",
494"musl/src/math/fdiml.c",
495"musl/src/math/finite.c",
496"musl/src/math/finitef.c",
497"musl/src/math/floor.c",
498"musl/src/math/floorf.c",
499"musl/src/math/floorl.c",
500"musl/src/math/fma.c",
501"musl/src/math/fmaf.c",
502"musl/src/math/fmal.c",
503"musl/src/math/fmax.c",
504"musl/src/math/fmaxf.c",
505"musl/src/math/fmaxl.c",
506"musl/src/math/fmin.c",
507"musl/src/math/fminf.c",
508"musl/src/math/fminl.c",
509"musl/src/math/fmod.c",
510"musl/src/math/fmodf.c",
511"musl/src/math/fmodl.c",
512"musl/src/math/frexp.c",
513"musl/src/math/frexpf.c",
514"musl/src/math/frexpl.c",
515"musl/src/math/hypot.c",
516"musl/src/math/hypotf.c",
517"musl/src/math/hypotl.c",
518"musl/src/math/i386/__invtrigl.s",
519"musl/src/math/i386/acos.s",
520"musl/src/math/i386/acosf.s",
521"musl/src/math/i386/acosl.s",
522"musl/src/math/i386/asin.s",
523"musl/src/math/i386/asinf.s",
524"musl/src/math/i386/asinl.s",
525"musl/src/math/i386/atan.s",
526"musl/src/math/i386/atan2.s",
527"musl/src/math/i386/atan2f.s",
528"musl/src/math/i386/atan2l.s",
529"musl/src/math/i386/atanf.s",
530"musl/src/math/i386/atanl.s",
531"musl/src/math/i386/ceil.s",
532"musl/src/math/i386/ceilf.s",
533"musl/src/math/i386/ceill.s",
534"musl/src/math/i386/exp2l.s",
535"musl/src/math/i386/exp_ld.s",
536"musl/src/math/i386/expl.s",
537"musl/src/math/i386/expm1l.s",
538"musl/src/math/i386/fabs.s",
539"musl/src/math/i386/fabsf.s",
540"musl/src/math/i386/fabsl.s",
541"musl/src/math/i386/floor.s",
542"musl/src/math/i386/floorf.s",
543"musl/src/math/i386/floorl.s",
544"musl/src/math/i386/fmod.s",
545"musl/src/math/i386/fmodf.s",
546"musl/src/math/i386/fmodl.s",
547"musl/src/math/i386/hypot.s",
548"musl/src/math/i386/hypotf.s",
549"musl/src/math/i386/ldexp.s",
550"musl/src/math/i386/ldexpf.s",
551"musl/src/math/i386/ldexpl.s",
552"musl/src/math/i386/llrint.s",
553"musl/src/math/i386/llrintf.s",
554"musl/src/math/i386/llrintl.s",
555"musl/src/math/i386/log.s",
556"musl/src/math/i386/log10.s",
557"musl/src/math/i386/log10f.s",
558"musl/src/math/i386/log10l.s",
559"musl/src/math/i386/log1p.s",
560"musl/src/math/i386/log1pf.s",
561"musl/src/math/i386/log1pl.s",
562"musl/src/math/i386/log2.s",
563"musl/src/math/i386/log2f.s",
564"musl/src/math/i386/log2l.s",
565"musl/src/math/i386/logf.s",
566"musl/src/math/i386/logl.s",
567"musl/src/math/i386/lrint.s",
568"musl/src/math/i386/lrintf.s",
569"musl/src/math/i386/lrintl.s",
570"musl/src/math/i386/remainder.s",
571"musl/src/math/i386/remainderf.s",
572"musl/src/math/i386/remainderl.s",
573"musl/src/math/i386/remquo.s",
574"musl/src/math/i386/remquof.s",
575"musl/src/math/i386/remquol.s",
576"musl/src/math/i386/rint.s",
577"musl/src/math/i386/rintf.s",
578"musl/src/math/i386/rintl.s",
579"musl/src/math/i386/scalbln.s",
580"musl/src/math/i386/scalblnf.s",
581"musl/src/math/i386/scalblnl.s",
582"musl/src/math/i386/scalbn.s",
583"musl/src/math/i386/scalbnf.s",
584"musl/src/math/i386/scalbnl.s",
585"musl/src/math/i386/sqrt.s",
586"musl/src/math/i386/sqrtf.s",
587"musl/src/math/i386/sqrtl.s",
588"musl/src/math/i386/trunc.s",
589"musl/src/math/i386/truncf.s",
590"musl/src/math/i386/truncl.s",
591"musl/src/math/ilogb.c",
592"musl/src/math/ilogbf.c",
593"musl/src/math/ilogbl.c",
594"musl/src/math/j0.c",
595"musl/src/math/j0f.c",
596"musl/src/math/j1.c",
597"musl/src/math/j1f.c",
598"musl/src/math/jn.c",
599"musl/src/math/jnf.c",
600"musl/src/math/ldexp.c",
601"musl/src/math/ldexpf.c",
602"musl/src/math/ldexpl.c",
603"musl/src/math/lgamma.c",
604"musl/src/math/lgamma_r.c",
605"musl/src/math/lgammaf.c",
606"musl/src/math/lgammaf_r.c",
607"musl/src/math/lgammal.c",
608"musl/src/math/llrint.c",
609"musl/src/math/llrintf.c",
610"musl/src/math/llrintl.c",
611"musl/src/math/llround.c",
612"musl/src/math/llroundf.c",
613"musl/src/math/llroundl.c",
614"musl/src/math/log.c",
615"musl/src/math/log10.c",
616"musl/src/math/log10f.c",
617"musl/src/math/log10l.c",
618"musl/src/math/log1p.c",
619"musl/src/math/log1pf.c",
620"musl/src/math/log1pl.c",
621"musl/src/math/log2.c",
622"musl/src/math/log2_data.c",
623"musl/src/math/log2f.c",
624"musl/src/math/log2f_data.c",
625"musl/src/math/log2l.c",
626"musl/src/math/log_data.c",
627"musl/src/math/logb.c",
628"musl/src/math/logbf.c",
629"musl/src/math/logbl.c",
630"musl/src/math/logf.c",
631"musl/src/math/logf_data.c",
632"musl/src/math/logl.c",
633"musl/src/math/lrint.c",
634"musl/src/math/lrintf.c",
635"musl/src/math/lrintl.c",
636"musl/src/math/lround.c",
637"musl/src/math/lroundf.c",
638"musl/src/math/lroundl.c",
639"musl/src/math/mips/fabs.c",
640"musl/src/math/mips/fabsf.c",
641"musl/src/math/mips/sqrt.c",
642"musl/src/math/mips/sqrtf.c",
643"musl/src/math/modf.c",
644"musl/src/math/modff.c",
645"musl/src/math/modfl.c",
646"musl/src/math/nan.c",
647"musl/src/math/nanf.c",
648"musl/src/math/nanl.c",
649"musl/src/math/nearbyint.c",
650"musl/src/math/nearbyintf.c",
651"musl/src/math/nearbyintl.c",
652"musl/src/math/nextafter.c",
653"musl/src/math/nextafterf.c",
654"musl/src/math/nextafterl.c",
655"musl/src/math/nexttoward.c",
656"musl/src/math/nexttowardf.c",
657"musl/src/math/nexttowardl.c",
658"musl/src/math/pow.c",
659"musl/src/math/pow_data.c",
660"musl/src/math/powerpc/fabs.c",
661"musl/src/math/powerpc/fabsf.c",
662"musl/src/math/powerpc/fma.c",
663"musl/src/math/powerpc/fmaf.c",
664"musl/src/math/powerpc/sqrt.c",
665"musl/src/math/powerpc/sqrtf.c",
666"musl/src/math/powerpc64/ceil.c",
667"musl/src/math/powerpc64/ceilf.c",
668"musl/src/math/powerpc64/fabs.c",
669"musl/src/math/powerpc64/fabsf.c",
670"musl/src/math/powerpc64/floor.c",
671"musl/src/math/powerpc64/floorf.c",
672"musl/src/math/powerpc64/fma.c",
673"musl/src/math/powerpc64/fmaf.c",
674"musl/src/math/powerpc64/fmax.c",
675"musl/src/math/powerpc64/fmaxf.c",
676"musl/src/math/powerpc64/fmin.c",
677"musl/src/math/powerpc64/fminf.c",
678"musl/src/math/powerpc64/lrint.c",
679"musl/src/math/powerpc64/lrintf.c",
680"musl/src/math/powerpc64/lround.c",
681"musl/src/math/powerpc64/lroundf.c",
682"musl/src/math/powerpc64/round.c",
683"musl/src/math/powerpc64/roundf.c",
684"musl/src/math/powerpc64/sqrt.c",
685"musl/src/math/powerpc64/sqrtf.c",
686"musl/src/math/powerpc64/trunc.c",
687"musl/src/math/powerpc64/truncf.c",
688"musl/src/math/powf.c",
689"musl/src/math/powf_data.c",
690"musl/src/math/powl.c",
691"musl/src/math/remainder.c",
692"musl/src/math/remainderf.c",
693"musl/src/math/remainderl.c",
694"musl/src/math/remquo.c",
695"musl/src/math/remquof.c",
696"musl/src/math/remquol.c",
697"musl/src/math/rint.c",
698"musl/src/math/rintf.c",
699"musl/src/math/rintl.c",
700"musl/src/math/riscv64/copysign.c",
701"musl/src/math/riscv64/copysignf.c",
702"musl/src/math/riscv64/fabs.c",
703"musl/src/math/riscv64/fabsf.c",
704"musl/src/math/riscv64/fma.c",
705"musl/src/math/riscv64/fmaf.c",
706"musl/src/math/riscv64/fmax.c",
707"musl/src/math/riscv64/fmaxf.c",
708"musl/src/math/riscv64/fmin.c",
709"musl/src/math/riscv64/fminf.c",
710"musl/src/math/riscv64/sqrt.c",
711"musl/src/math/riscv64/sqrtf.c",
712"musl/src/math/round.c",
713"musl/src/math/roundf.c",
714"musl/src/math/roundl.c",
715"musl/src/math/s390x/ceil.c",
716"musl/src/math/s390x/ceilf.c",
717"musl/src/math/s390x/ceill.c",
718"musl/src/math/s390x/fabs.c",
719"musl/src/math/s390x/fabsf.c",
720"musl/src/math/s390x/fabsl.c",
721"musl/src/math/s390x/floor.c",
722"musl/src/math/s390x/floorf.c",
723"musl/src/math/s390x/floorl.c",
724"musl/src/math/s390x/fma.c",
725"musl/src/math/s390x/fmaf.c",
726"musl/src/math/s390x/nearbyint.c",
727"musl/src/math/s390x/nearbyintf.c",
728"musl/src/math/s390x/nearbyintl.c",
729"musl/src/math/s390x/rint.c",
730"musl/src/math/s390x/rintf.c",
731"musl/src/math/s390x/rintl.c",
732"musl/src/math/s390x/round.c",
733"musl/src/math/s390x/roundf.c",
734"musl/src/math/s390x/roundl.c",
735"musl/src/math/s390x/sqrt.c",
736"musl/src/math/s390x/sqrtf.c",
737"musl/src/math/s390x/sqrtl.c",
738"musl/src/math/s390x/trunc.c",
739"musl/src/math/s390x/truncf.c",
740"musl/src/math/s390x/truncl.c",
741"musl/src/math/scalb.c",
742"musl/src/math/scalbf.c",
743"musl/src/math/scalbln.c",
744"musl/src/math/scalblnf.c",
745"musl/src/math/scalblnl.c",
746"musl/src/math/scalbn.c",
747"musl/src/math/scalbnf.c",
748"musl/src/math/scalbnl.c",
749"musl/src/math/signgam.c",
750"musl/src/math/significand.c",
751"musl/src/math/significandf.c",
752"musl/src/math/sin.c",
753"musl/src/math/sincos.c",
754"musl/src/math/sincosf.c",
755"musl/src/math/sincosl.c",
756"musl/src/math/sinf.c",
757"musl/src/math/sinh.c",
758"musl/src/math/sinhf.c",
759"musl/src/math/sinhl.c",
760"musl/src/math/sinl.c",
761"musl/src/math/sqrt.c",
762"musl/src/math/sqrtf.c",
763"musl/src/math/sqrtl.c",
764"musl/src/math/tan.c",
765"musl/src/math/tanf.c",
766"musl/src/math/tanh.c",
767"musl/src/math/tanhf.c",
768"musl/src/math/tanhl.c",
769"musl/src/math/tanl.c",
770"musl/src/math/tgamma.c",
771"musl/src/math/tgammaf.c",
772"musl/src/math/tgammal.c",
773"musl/src/math/trunc.c",
774"musl/src/math/truncf.c",
775"musl/src/math/truncl.c",
776"musl/src/math/x32/__invtrigl.s",
777"musl/src/math/x32/acosl.s",
778"musl/src/math/x32/asinl.s",
779"musl/src/math/x32/atan2l.s",
780"musl/src/math/x32/atanl.s",
781"musl/src/math/x32/ceill.s",
782"musl/src/math/x32/exp2l.s",
783"musl/src/math/x32/expl.s",
784"musl/src/math/x32/expm1l.s",
785"musl/src/math/x32/fabs.s",
786"musl/src/math/x32/fabsf.s",
787"musl/src/math/x32/fabsl.s",
788"musl/src/math/x32/floorl.s",
789"musl/src/math/x32/fma.c",
790"musl/src/math/x32/fmaf.c",
791"musl/src/math/x32/fmodl.s",
792"musl/src/math/x32/llrint.s",
793"musl/src/math/x32/llrintf.s",
794"musl/src/math/x32/llrintl.s",
795"musl/src/math/x32/log10l.s",
796"musl/src/math/x32/log1pl.s",
797"musl/src/math/x32/log2l.s",
798"musl/src/math/x32/logl.s",
799"musl/src/math/x32/lrint.s",
800"musl/src/math/x32/lrintf.s",
801"musl/src/math/x32/lrintl.s",
802"musl/src/math/x32/remainderl.s",
803"musl/src/math/x32/rintl.s",
804"musl/src/math/x32/sqrt.s",
805"musl/src/math/x32/sqrtf.s",
806"musl/src/math/x32/sqrtl.s",
807"musl/src/math/x32/truncl.s",
808"musl/src/math/x86_64/__invtrigl.s",
809"musl/src/math/x86_64/acosl.s",
810"musl/src/math/x86_64/asinl.s",
811"musl/src/math/x86_64/atan2l.s",
812"musl/src/math/x86_64/atanl.s",
813"musl/src/math/x86_64/ceill.s",
814"musl/src/math/x86_64/exp2l.s",
815"musl/src/math/x86_64/expl.s",
816"musl/src/math/x86_64/expm1l.s",
817"musl/src/math/x86_64/fabs.s",
818"musl/src/math/x86_64/fabsf.s",
819"musl/src/math/x86_64/fabsl.s",
820"musl/src/math/x86_64/floorl.s",
821"musl/src/math/x86_64/fma.c",
822"musl/src/math/x86_64/fmaf.c",
823"musl/src/math/x86_64/fmodl.s",
824"musl/src/math/x86_64/llrint.s",
825"musl/src/math/x86_64/llrintf.s",
826"musl/src/math/x86_64/llrintl.s",
827"musl/src/math/x86_64/log10l.s",
828"musl/src/math/x86_64/log1pl.s",
829"musl/src/math/x86_64/log2l.s",
830"musl/src/math/x86_64/logl.s",
831"musl/src/math/x86_64/lrint.s",
832"musl/src/math/x86_64/lrintf.s",
833"musl/src/math/x86_64/lrintl.s",
834"musl/src/math/x86_64/remainderl.s",
835"musl/src/math/x86_64/rintl.s",
836"musl/src/math/x86_64/sqrt.s",
837"musl/src/math/x86_64/sqrtf.s",
838"musl/src/math/x86_64/sqrtl.s",
839"musl/src/math/x86_64/truncl.s",
840"musl/src/misc/a64l.c",
841"musl/src/misc/basename.c",
842"musl/src/misc/dirname.c",
843"musl/src/misc/ffs.c",
844"musl/src/misc/ffsl.c",
845"musl/src/misc/ffsll.c",
846"musl/src/misc/fmtmsg.c",
847"musl/src/misc/forkpty.c",
848"musl/src/misc/get_current_dir_name.c",
849"musl/src/misc/getauxval.c",
850"musl/src/misc/getdomainname.c",
851"musl/src/misc/getentropy.c",
852"musl/src/misc/gethostid.c",
853"musl/src/misc/getopt.c",
854"musl/src/misc/getopt_long.c",
855"musl/src/misc/getpriority.c",
856"musl/src/misc/getresgid.c",
857"musl/src/misc/getresuid.c",
858"musl/src/misc/getrlimit.c",
859"musl/src/misc/getrusage.c",
860"musl/src/misc/getsubopt.c",
861"musl/src/misc/initgroups.c",
862"musl/src/misc/ioctl.c",
863"musl/src/misc/issetugid.c",
864"musl/src/misc/lockf.c",
865"musl/src/misc/login_tty.c",
866"musl/src/misc/mntent.c",
867"musl/src/misc/nftw.c",
868"musl/src/misc/openpty.c",
869"musl/src/misc/ptsname.c",
870"musl/src/misc/pty.c",
871"musl/src/misc/realpath.c",
872"musl/src/misc/setdomainname.c",
873"musl/src/misc/setpriority.c",
874"musl/src/misc/setrlimit.c",
875"musl/src/misc/syscall.c",
876"musl/src/misc/syslog.c",
877"musl/src/misc/uname.c",
878"musl/src/misc/wordexp.c",
879"musl/src/mman/madvise.c",
880"musl/src/mman/mincore.c",
881"musl/src/mman/mlock.c",
882"musl/src/mman/mlockall.c",
883"musl/src/mman/mmap.c",
884"musl/src/mman/mprotect.c",
885"musl/src/mman/mremap.c",
886"musl/src/mman/msync.c",
887"musl/src/mman/munlock.c",
888"musl/src/mman/munlockall.c",
889"musl/src/mman/munmap.c",
890"musl/src/mman/posix_madvise.c",
891"musl/src/mman/shm_open.c",
892"musl/src/mq/mq_close.c",
893"musl/src/mq/mq_getattr.c",
894"musl/src/mq/mq_notify.c",
895"musl/src/mq/mq_open.c",
896"musl/src/mq/mq_receive.c",
897"musl/src/mq/mq_send.c",
898"musl/src/mq/mq_setattr.c",
899"musl/src/mq/mq_timedreceive.c",
900"musl/src/mq/mq_timedsend.c",
901"musl/src/mq/mq_unlink.c",
902"musl/src/multibyte/btowc.c",
903"musl/src/multibyte/c16rtomb.c",
904"musl/src/multibyte/c32rtomb.c",
905"musl/src/multibyte/internal.c",
906"musl/src/multibyte/mblen.c",
907"musl/src/multibyte/mbrlen.c",
908"musl/src/multibyte/mbrtoc16.c",
909"musl/src/multibyte/mbrtoc32.c",
910"musl/src/multibyte/mbrtowc.c",
911"musl/src/multibyte/mbsinit.c",
912"musl/src/multibyte/mbsnrtowcs.c",
913"musl/src/multibyte/mbsrtowcs.c",
914"musl/src/multibyte/mbstowcs.c",
915"musl/src/multibyte/mbtowc.c",
916"musl/src/multibyte/wcrtomb.c",
917"musl/src/multibyte/wcsnrtombs.c",
918"musl/src/multibyte/wcsrtombs.c",
919"musl/src/multibyte/wcstombs.c",
920"musl/src/multibyte/wctob.c",
921"musl/src/multibyte/wctomb.c",
922"musl/src/network/accept.c",
923"musl/src/network/accept4.c",
924"musl/src/network/bind.c",
925"musl/src/network/connect.c",
926"musl/src/network/dn_comp.c",
927"musl/src/network/dn_expand.c",
928"musl/src/network/dn_skipname.c",
929"musl/src/network/dns_parse.c",
930"musl/src/network/ent.c",
931"musl/src/network/ether.c",
932"musl/src/network/freeaddrinfo.c",
933"musl/src/network/gai_strerror.c",
934"musl/src/network/getaddrinfo.c",
935"musl/src/network/gethostbyaddr.c",
936"musl/src/network/gethostbyaddr_r.c",
937"musl/src/network/gethostbyname.c",
938"musl/src/network/gethostbyname2.c",
939"musl/src/network/gethostbyname2_r.c",
940"musl/src/network/gethostbyname_r.c",
941"musl/src/network/getifaddrs.c",
942"musl/src/network/getnameinfo.c",
943"musl/src/network/getpeername.c",
944"musl/src/network/getservbyname.c",
945"musl/src/network/getservbyname_r.c",
946"musl/src/network/getservbyport.c",
947"musl/src/network/getservbyport_r.c",
948"musl/src/network/getsockname.c",
949"musl/src/network/getsockopt.c",
950"musl/src/network/h_errno.c",
951"musl/src/network/herror.c",
952"musl/src/network/hstrerror.c",
953"musl/src/network/htonl.c",
954"musl/src/network/htons.c",
955"musl/src/network/if_freenameindex.c",
956"musl/src/network/if_indextoname.c",
957"musl/src/network/if_nameindex.c",
958"musl/src/network/if_nametoindex.c",
959"musl/src/network/in6addr_any.c",
960"musl/src/network/in6addr_loopback.c",
961"musl/src/network/inet_addr.c",
962"musl/src/network/inet_aton.c",
963"musl/src/network/inet_legacy.c",
964"musl/src/network/inet_ntoa.c",
965"musl/src/network/inet_ntop.c",
966"musl/src/network/inet_pton.c",
967"musl/src/network/listen.c",
968"musl/src/network/lookup_ipliteral.c",
969"musl/src/network/lookup_name.c",
970"musl/src/network/lookup_serv.c",
971"musl/src/network/netlink.c",
972"musl/src/network/netname.c",
973"musl/src/network/ns_parse.c",
974"musl/src/network/ntohl.c",
975"musl/src/network/ntohs.c",
976"musl/src/network/proto.c",
977"musl/src/network/recv.c",
978"musl/src/network/recvfrom.c",
979"musl/src/network/recvmmsg.c",
980"musl/src/network/recvmsg.c",
981"musl/src/network/res_init.c",
982"musl/src/network/res_mkquery.c",
983"musl/src/network/res_msend.c",
984"musl/src/network/res_query.c",
985"musl/src/network/res_querydomain.c",
986"musl/src/network/res_send.c",
987"musl/src/network/res_state.c",
988"musl/src/network/resolvconf.c",
989"musl/src/network/send.c",
990"musl/src/network/sendmmsg.c",
991"musl/src/network/sendmsg.c",
992"musl/src/network/sendto.c",
993"musl/src/network/serv.c",
994"musl/src/network/setsockopt.c",
995"musl/src/network/shutdown.c",
996"musl/src/network/sockatmark.c",
997"musl/src/network/socket.c",
998"musl/src/network/socketpair.c",
999"musl/src/passwd/fgetgrent.c",
1000"musl/src/passwd/fgetpwent.c",
1001"musl/src/passwd/fgetspent.c",
1002"musl/src/passwd/getgr_a.c",
1003"musl/src/passwd/getgr_r.c",
1004"musl/src/passwd/getgrent.c",
1005"musl/src/passwd/getgrent_a.c",
1006"musl/src/passwd/getgrouplist.c",
1007"musl/src/passwd/getpw_a.c",
1008"musl/src/passwd/getpw_r.c",
1009"musl/src/passwd/getpwent.c",
1010"musl/src/passwd/getpwent_a.c",
1011"musl/src/passwd/getspent.c",
1012"musl/src/passwd/getspnam.c",
1013"musl/src/passwd/getspnam_r.c",
1014"musl/src/passwd/lckpwdf.c",
1015"musl/src/passwd/nscd_query.c",
1016"musl/src/passwd/putgrent.c",
1017"musl/src/passwd/putpwent.c",
1018"musl/src/passwd/putspent.c",
1019"musl/src/prng/__rand48_step.c",
1020"musl/src/prng/__seed48.c",
1021"musl/src/prng/drand48.c",
1022"musl/src/prng/lcong48.c",
1023"musl/src/prng/lrand48.c",
1024"musl/src/prng/mrand48.c",
1025"musl/src/prng/rand.c",
1026"musl/src/prng/rand_r.c",
1027"musl/src/prng/random.c",
1028"musl/src/prng/seed48.c",
1029"musl/src/prng/srand48.c",
1030"musl/src/process/arm/vfork.s",
1031"musl/src/process/execl.c",
1032"musl/src/process/execle.c",
1033"musl/src/process/execlp.c",
1034"musl/src/process/execv.c",
1035"musl/src/process/execve.c",
1036"musl/src/process/execvp.c",
1037"musl/src/process/fexecve.c",
1038"musl/src/process/fork.c",
1039"musl/src/process/i386/vfork.s",
1040"musl/src/process/posix_spawn.c",
1041"musl/src/process/posix_spawn_file_actions_addchdir.c",
1042"musl/src/process/posix_spawn_file_actions_addclose.c",
1043"musl/src/process/posix_spawn_file_actions_adddup2.c",
1044"musl/src/process/posix_spawn_file_actions_addfchdir.c",
1045"musl/src/process/posix_spawn_file_actions_addopen.c",
1046"musl/src/process/posix_spawn_file_actions_destroy.c",
1047"musl/src/process/posix_spawn_file_actions_init.c",
1048"musl/src/process/posix_spawnattr_destroy.c",
1049"musl/src/process/posix_spawnattr_getflags.c",
1050"musl/src/process/posix_spawnattr_getpgroup.c",
1051"musl/src/process/posix_spawnattr_getsigdefault.c",
1052"musl/src/process/posix_spawnattr_getsigmask.c",
1053"musl/src/process/posix_spawnattr_init.c",
1054"musl/src/process/posix_spawnattr_sched.c",
1055"musl/src/process/posix_spawnattr_setflags.c",
1056"musl/src/process/posix_spawnattr_setpgroup.c",
1057"musl/src/process/posix_spawnattr_setsigdefault.c",
1058"musl/src/process/posix_spawnattr_setsigmask.c",
1059"musl/src/process/posix_spawnp.c",
1060"musl/src/process/s390x/vfork.s",
1061"musl/src/process/sh/vfork.s",
1062"musl/src/process/system.c",
1063"musl/src/process/vfork.c",
1064"musl/src/process/wait.c",
1065"musl/src/process/waitid.c",
1066"musl/src/process/waitpid.c",
1067"musl/src/process/x32/vfork.s",
1068"musl/src/process/x86_64/vfork.s",
1069"musl/src/regex/fnmatch.c",
1070"musl/src/regex/glob.c",
1071"musl/src/regex/regcomp.c",
1072"musl/src/regex/regerror.c",
1073"musl/src/regex/regexec.c",
1074"musl/src/regex/tre-mem.c",
1075"musl/src/sched/affinity.c",
1076"musl/src/sched/sched_cpucount.c",
1077"musl/src/sched/sched_get_priority_max.c",
1078"musl/src/sched/sched_getcpu.c",
1079"musl/src/sched/sched_getparam.c",
1080"musl/src/sched/sched_getscheduler.c",
1081"musl/src/sched/sched_rr_get_interval.c",
1082"musl/src/sched/sched_setparam.c",
1083"musl/src/sched/sched_setscheduler.c",
1084"musl/src/sched/sched_yield.c",
1085"musl/src/search/hsearch.c",
1086"musl/src/search/insque.c",
1087"musl/src/search/lsearch.c",
1088"musl/src/search/tdelete.c",
1089"musl/src/search/tdestroy.c",
1090"musl/src/search/tfind.c",
1091"musl/src/search/tsearch.c",
1092"musl/src/search/twalk.c",
1093"musl/src/select/poll.c",
1094"musl/src/select/pselect.c",
1095"musl/src/select/select.c",
1096"musl/src/setjmp/aarch64/longjmp.s",
1097"musl/src/setjmp/aarch64/setjmp.s",
1098"musl/src/setjmp/arm/longjmp.S",
1099"musl/src/setjmp/arm/setjmp.S",
1100"musl/src/setjmp/i386/longjmp.s",
1101"musl/src/setjmp/i386/setjmp.s",
1102"musl/src/setjmp/longjmp.c",
1103"musl/src/setjmp/m68k/longjmp.s",
1104"musl/src/setjmp/m68k/setjmp.s",
1105"musl/src/setjmp/microblaze/longjmp.s",
1106"musl/src/setjmp/microblaze/setjmp.s",
1107"musl/src/setjmp/mips/longjmp.S",
1108"musl/src/setjmp/mips/setjmp.S",
1109"musl/src/setjmp/mips64/longjmp.S",
1110"musl/src/setjmp/mips64/setjmp.S",
1111"musl/src/setjmp/mipsn32/longjmp.S",
1112"musl/src/setjmp/mipsn32/setjmp.S",
1113"musl/src/setjmp/or1k/longjmp.s",
1114"musl/src/setjmp/or1k/setjmp.s",
1115"musl/src/setjmp/powerpc/longjmp.S",
1116"musl/src/setjmp/powerpc/setjmp.S",
1117"musl/src/setjmp/powerpc64/longjmp.s",
1118"musl/src/setjmp/powerpc64/setjmp.s",
1119"musl/src/setjmp/riscv64/longjmp.S",
1120"musl/src/setjmp/riscv64/setjmp.S",
1121"musl/src/setjmp/s390x/longjmp.s",
1122"musl/src/setjmp/s390x/setjmp.s",
1123"musl/src/setjmp/setjmp.c",
1124"musl/src/setjmp/sh/longjmp.S",
1125"musl/src/setjmp/sh/setjmp.S",
1126"musl/src/setjmp/x32/longjmp.s",
1127"musl/src/setjmp/x32/setjmp.s",
1128"musl/src/setjmp/x86_64/longjmp.s",
1129"musl/src/setjmp/x86_64/setjmp.s",
1130"musl/src/signal/aarch64/restore.s",
1131"musl/src/signal/aarch64/sigsetjmp.s",
1132"musl/src/signal/arm/restore.s",
1133"musl/src/signal/arm/sigsetjmp.s",
1134"musl/src/signal/block.c",
1135"musl/src/signal/getitimer.c",
1136"musl/src/signal/i386/restore.s",
1137"musl/src/signal/i386/sigsetjmp.s",
1138"musl/src/signal/kill.c",
1139"musl/src/signal/killpg.c",
1140"musl/src/signal/m68k/sigsetjmp.s",
1141"musl/src/signal/microblaze/restore.s",
1142"musl/src/signal/microblaze/sigsetjmp.s",
1143"musl/src/signal/mips/restore.s",
1144"musl/src/signal/mips/sigsetjmp.s",
1145"musl/src/signal/mips64/restore.s",
1146"musl/src/signal/mips64/sigsetjmp.s",
1147"musl/src/signal/mipsn32/restore.s",
1148"musl/src/signal/mipsn32/sigsetjmp.s",
1149"musl/src/signal/or1k/sigsetjmp.s",
1150"musl/src/signal/powerpc/restore.s",
1151"musl/src/signal/powerpc/sigsetjmp.s",
1152"musl/src/signal/powerpc64/restore.s",
1153"musl/src/signal/powerpc64/sigsetjmp.s",
1154"musl/src/signal/psiginfo.c",
1155"musl/src/signal/psignal.c",
1156"musl/src/signal/raise.c",
1157"musl/src/signal/restore.c",
1158"musl/src/signal/riscv64/restore.s",
1159"musl/src/signal/riscv64/sigsetjmp.s",
1160"musl/src/signal/s390x/restore.s",
1161"musl/src/signal/s390x/sigsetjmp.s",
1162"musl/src/signal/setitimer.c",
1163"musl/src/signal/sh/restore.s",
1164"musl/src/signal/sh/sigsetjmp.s",
1165"musl/src/signal/sigaction.c",
1166"musl/src/signal/sigaddset.c",
1167"musl/src/signal/sigaltstack.c",
1168"musl/src/signal/sigandset.c",
1169"musl/src/signal/sigdelset.c",
1170"musl/src/signal/sigemptyset.c",
1171"musl/src/signal/sigfillset.c",
1172"musl/src/signal/sighold.c",
1173"musl/src/signal/sigignore.c",
1174"musl/src/signal/siginterrupt.c",
1175"musl/src/signal/sigisemptyset.c",
1176"musl/src/signal/sigismember.c",
1177"musl/src/signal/siglongjmp.c",
1178"musl/src/signal/signal.c",
1179"musl/src/signal/sigorset.c",
1180"musl/src/signal/sigpause.c",
1181"musl/src/signal/sigpending.c",
1182"musl/src/signal/sigprocmask.c",
1183"musl/src/signal/sigqueue.c",
1184"musl/src/signal/sigrelse.c",
1185"musl/src/signal/sigrtmax.c",
1186"musl/src/signal/sigrtmin.c",
1187"musl/src/signal/sigset.c",
1188"musl/src/signal/sigsetjmp.c",
1189"musl/src/signal/sigsetjmp_tail.c",
1190"musl/src/signal/sigsuspend.c",
1191"musl/src/signal/sigtimedwait.c",
1192"musl/src/signal/sigwait.c",
1193"musl/src/signal/sigwaitinfo.c",
1194"musl/src/signal/x32/getitimer.c",
1195"musl/src/signal/x32/restore.s",
1196"musl/src/signal/x32/setitimer.c",
1197"musl/src/signal/x32/sigsetjmp.s",
1198"musl/src/signal/x86_64/restore.s",
1199"musl/src/signal/x86_64/sigsetjmp.s",
1200"musl/src/stat/__xstat.c",
1201"musl/src/stat/chmod.c",
1202"musl/src/stat/fchmod.c",
1203"musl/src/stat/fchmodat.c",
1204"musl/src/stat/fstat.c",
1205"musl/src/stat/fstatat.c",
1206"musl/src/stat/futimens.c",
1207"musl/src/stat/futimesat.c",
1208"musl/src/stat/lchmod.c",
1209"musl/src/stat/lstat.c",
1210"musl/src/stat/mkdir.c",
1211"musl/src/stat/mkdirat.c",
1212"musl/src/stat/mkfifo.c",
1213"musl/src/stat/mkfifoat.c",
1214"musl/src/stat/mknod.c",
1215"musl/src/stat/mknodat.c",
1216"musl/src/stat/stat.c",
1217"musl/src/stat/statvfs.c",
1218"musl/src/stat/umask.c",
1219"musl/src/stat/utimensat.c",
1220"musl/src/stdio/__fclose_ca.c",
1221"musl/src/stdio/__fdopen.c",
1222"musl/src/stdio/__fmodeflags.c",
1223"musl/src/stdio/__fopen_rb_ca.c",
1224"musl/src/stdio/__lockfile.c",
1225"musl/src/stdio/__overflow.c",
1226"musl/src/stdio/__stdio_close.c",
1227"musl/src/stdio/__stdio_exit.c",
1228"musl/src/stdio/__stdio_read.c",
1229"musl/src/stdio/__stdio_seek.c",
1230"musl/src/stdio/__stdio_write.c",
1231"musl/src/stdio/__stdout_write.c",
1232"musl/src/stdio/__string_read.c",
1233"musl/src/stdio/__toread.c",
1234"musl/src/stdio/__towrite.c",
1235"musl/src/stdio/__uflow.c",
1236"musl/src/stdio/asprintf.c",
1237"musl/src/stdio/clearerr.c",
1238"musl/src/stdio/dprintf.c",
1239"musl/src/stdio/ext.c",
1240"musl/src/stdio/ext2.c",
1241"musl/src/stdio/fclose.c",
1242"musl/src/stdio/feof.c",
1243"musl/src/stdio/ferror.c",
1244"musl/src/stdio/fflush.c",
1245"musl/src/stdio/fgetc.c",
1246"musl/src/stdio/fgetln.c",
1247"musl/src/stdio/fgetpos.c",
1248"musl/src/stdio/fgets.c",
1249"musl/src/stdio/fgetwc.c",
1250"musl/src/stdio/fgetws.c",
1251"musl/src/stdio/fileno.c",
1252"musl/src/stdio/flockfile.c",
1253"musl/src/stdio/fmemopen.c",
1254"musl/src/stdio/fopen.c",
1255"musl/src/stdio/fopencookie.c",
1256"musl/src/stdio/fprintf.c",
1257"musl/src/stdio/fputc.c",
1258"musl/src/stdio/fputs.c",
1259"musl/src/stdio/fputwc.c",
1260"musl/src/stdio/fputws.c",
1261"musl/src/stdio/fread.c",
1262"musl/src/stdio/freopen.c",
1263"musl/src/stdio/fscanf.c",
1264"musl/src/stdio/fseek.c",
1265"musl/src/stdio/fsetpos.c",
1266"musl/src/stdio/ftell.c",
1267"musl/src/stdio/ftrylockfile.c",
1268"musl/src/stdio/funlockfile.c",
1269"musl/src/stdio/fwide.c",
1270"musl/src/stdio/fwprintf.c",
1271"musl/src/stdio/fwrite.c",
1272"musl/src/stdio/fwscanf.c",
1273"musl/src/stdio/getc.c",
1274"musl/src/stdio/getc_unlocked.c",
1275"musl/src/stdio/getchar.c",
1276"musl/src/stdio/getchar_unlocked.c",
1277"musl/src/stdio/getdelim.c",
1278"musl/src/stdio/getline.c",
1279"musl/src/stdio/gets.c",
1280"musl/src/stdio/getw.c",
1281"musl/src/stdio/getwc.c",
1282"musl/src/stdio/getwchar.c",
1283"musl/src/stdio/ofl.c",
1284"musl/src/stdio/ofl_add.c",
1285"musl/src/stdio/open_memstream.c",
1286"musl/src/stdio/open_wmemstream.c",
1287"musl/src/stdio/pclose.c",
1288"musl/src/stdio/perror.c",
1289"musl/src/stdio/popen.c",
1290"musl/src/stdio/printf.c",
1291"musl/src/stdio/putc.c",
1292"musl/src/stdio/putc_unlocked.c",
1293"musl/src/stdio/putchar.c",
1294"musl/src/stdio/putchar_unlocked.c",
1295"musl/src/stdio/puts.c",
1296"musl/src/stdio/putw.c",
1297"musl/src/stdio/putwc.c",
1298"musl/src/stdio/putwchar.c",
1299"musl/src/stdio/remove.c",
1300"musl/src/stdio/rename.c",
1301"musl/src/stdio/rewind.c",
1302"musl/src/stdio/scanf.c",
1303"musl/src/stdio/setbuf.c",
1304"musl/src/stdio/setbuffer.c",
1305"musl/src/stdio/setlinebuf.c",
1306"musl/src/stdio/setvbuf.c",
1307"musl/src/stdio/snprintf.c",
1308"musl/src/stdio/sprintf.c",
1309"musl/src/stdio/sscanf.c",
1310"musl/src/stdio/stderr.c",
1311"musl/src/stdio/stdin.c",
1312"musl/src/stdio/stdout.c",
1313"musl/src/stdio/swprintf.c",
1314"musl/src/stdio/swscanf.c",
1315"musl/src/stdio/tempnam.c",
1316"musl/src/stdio/tmpfile.c",
1317"musl/src/stdio/tmpnam.c",
1318"musl/src/stdio/ungetc.c",
1319"musl/src/stdio/ungetwc.c",
1320"musl/src/stdio/vasprintf.c",
1321"musl/src/stdio/vdprintf.c",
1322"musl/src/stdio/vfprintf.c",
1323"musl/src/stdio/vfscanf.c",
1324"musl/src/stdio/vfwprintf.c",
1325"musl/src/stdio/vfwscanf.c",
1326"musl/src/stdio/vprintf.c",
1327"musl/src/stdio/vscanf.c",
1328"musl/src/stdio/vsnprintf.c",
1329"musl/src/stdio/vsprintf.c",
1330"musl/src/stdio/vsscanf.c",
1331"musl/src/stdio/vswprintf.c",
1332"musl/src/stdio/vswscanf.c",
1333"musl/src/stdio/vwprintf.c",
1334"musl/src/stdio/vwscanf.c",
1335"musl/src/stdio/wprintf.c",
1336"musl/src/stdio/wscanf.c",
1337"musl/src/stdlib/abs.c",
1338"musl/src/stdlib/atof.c",
1339"musl/src/stdlib/atoi.c",
1340"musl/src/stdlib/atol.c",
1341"musl/src/stdlib/atoll.c",
1342"musl/src/stdlib/bsearch.c",
1343"musl/src/stdlib/div.c",
1344"musl/src/stdlib/ecvt.c",
1345"musl/src/stdlib/fcvt.c",
1346"musl/src/stdlib/gcvt.c",
1347"musl/src/stdlib/imaxabs.c",
1348"musl/src/stdlib/imaxdiv.c",
1349"musl/src/stdlib/labs.c",
1350"musl/src/stdlib/ldiv.c",
1351"musl/src/stdlib/llabs.c",
1352"musl/src/stdlib/lldiv.c",
1353"musl/src/stdlib/qsort.c",
1354"musl/src/stdlib/strtod.c",
1355"musl/src/stdlib/strtol.c",
1356"musl/src/stdlib/wcstod.c",
1357"musl/src/stdlib/wcstol.c",
1358"musl/src/string/arm/__aeabi_memcpy.s",
1359"musl/src/string/arm/__aeabi_memset.s",
1360"musl/src/string/arm/memcpy.c",
1361"musl/src/string/arm/memcpy_le.S",
1362"musl/src/string/bcmp.c",
1363"musl/src/string/bcopy.c",
1364"musl/src/string/bzero.c",
1365"musl/src/string/explicit_bzero.c",
1366"musl/src/string/i386/memcpy.s",
1367"musl/src/string/i386/memmove.s",
1368"musl/src/string/i386/memset.s",
1369"musl/src/string/index.c",
1370"musl/src/string/memccpy.c",
1371"musl/src/string/memchr.c",
1372"musl/src/string/memcmp.c",
1373"musl/src/string/memcpy.c",
1374"musl/src/string/memmem.c",
1375"musl/src/string/memmove.c",
1376"musl/src/string/mempcpy.c",
1377"musl/src/string/memrchr.c",
1378"musl/src/string/memset.c",
1379"musl/src/string/rindex.c",
1380"musl/src/string/stpcpy.c",
1381"musl/src/string/stpncpy.c",
1382"musl/src/string/strcasecmp.c",
1383"musl/src/string/strcasestr.c",
1384"musl/src/string/strcat.c",
1385"musl/src/string/strchr.c",
1386"musl/src/string/strchrnul.c",
1387"musl/src/string/strcmp.c",
1388"musl/src/string/strcpy.c",
1389"musl/src/string/strcspn.c",
1390"musl/src/string/strdup.c",
1391"musl/src/string/strerror_r.c",
1392"musl/src/string/strlcat.c",
1393"musl/src/string/strlcpy.c",
1394"musl/src/string/strlen.c",
1395"musl/src/string/strncasecmp.c",
1396"musl/src/string/strncat.c",
1397"musl/src/string/strncmp.c",
1398"musl/src/string/strncpy.c",
1399"musl/src/string/strndup.c",
1400"musl/src/string/strnlen.c",
1401"musl/src/string/strpbrk.c",
1402"musl/src/string/strrchr.c",
1403"musl/src/string/strsep.c",
1404"musl/src/string/strsignal.c",
1405"musl/src/string/strspn.c",
1406"musl/src/string/strstr.c",
1407"musl/src/string/strtok.c",
1408"musl/src/string/strtok_r.c",
1409"musl/src/string/strverscmp.c",
1410"musl/src/string/swab.c",
1411"musl/src/string/wcpcpy.c",
1412"musl/src/string/wcpncpy.c",
1413"musl/src/string/wcscasecmp.c",
1414"musl/src/string/wcscasecmp_l.c",
1415"musl/src/string/wcscat.c",
1416"musl/src/string/wcschr.c",
1417"musl/src/string/wcscmp.c",
1418"musl/src/string/wcscpy.c",
1419"musl/src/string/wcscspn.c",
1420"musl/src/string/wcsdup.c",
1421"musl/src/string/wcslen.c",
1422"musl/src/string/wcsncasecmp.c",
1423"musl/src/string/wcsncasecmp_l.c",
1424"musl/src/string/wcsncat.c",
1425"musl/src/string/wcsncmp.c",
1426"musl/src/string/wcsncpy.c",
1427"musl/src/string/wcsnlen.c",
1428"musl/src/string/wcspbrk.c",
1429"musl/src/string/wcsrchr.c",
1430"musl/src/string/wcsspn.c",
1431"musl/src/string/wcsstr.c",
1432"musl/src/string/wcstok.c",
1433"musl/src/string/wcswcs.c",
1434"musl/src/string/wmemchr.c",
1435"musl/src/string/wmemcmp.c",
1436"musl/src/string/wmemcpy.c",
1437"musl/src/string/wmemmove.c",
1438"musl/src/string/wmemset.c",
1439"musl/src/string/x86_64/memcpy.s",
1440"musl/src/string/x86_64/memmove.s",
1441"musl/src/string/x86_64/memset.s",
1442"musl/src/temp/__randname.c",
1443"musl/src/temp/mkdtemp.c",
1444"musl/src/temp/mkostemp.c",
1445"musl/src/temp/mkostemps.c",
1446"musl/src/temp/mkstemp.c",
1447"musl/src/temp/mkstemps.c",
1448"musl/src/temp/mktemp.c",
1449"musl/src/termios/cfgetospeed.c",
1450"musl/src/termios/cfmakeraw.c",
1451"musl/src/termios/cfsetospeed.c",
1452"musl/src/termios/tcdrain.c",
1453"musl/src/termios/tcflow.c",
1454"musl/src/termios/tcflush.c",
1455"musl/src/termios/tcgetattr.c",
1456"musl/src/termios/tcgetsid.c",
1457"musl/src/termios/tcsendbreak.c",
1458"musl/src/termios/tcsetattr.c",
1459"musl/src/thread/__lock.c",
1460"musl/src/thread/__set_thread_area.c",
1461"musl/src/thread/__syscall_cp.c",
1462"musl/src/thread/__timedwait.c",
1463"musl/src/thread/__tls_get_addr.c",
1464"musl/src/thread/__unmapself.c",
1465"musl/src/thread/__wait.c",
1466"musl/src/thread/aarch64/__set_thread_area.s",
1467"musl/src/thread/aarch64/__unmapself.s",
1468"musl/src/thread/aarch64/clone.s",
1469"musl/src/thread/aarch64/syscall_cp.s",
1470"musl/src/thread/arm/__aeabi_read_tp.s",
1471"musl/src/thread/arm/__set_thread_area.c",
1472"musl/src/thread/arm/__unmapself.s",
1473"musl/src/thread/arm/atomics.s",
1474"musl/src/thread/arm/clone.s",
1475"musl/src/thread/arm/syscall_cp.s",
1476"musl/src/thread/call_once.c",
1477"musl/src/thread/clone.c",
1478"musl/src/thread/cnd_broadcast.c",
1479"musl/src/thread/cnd_destroy.c",
1480"musl/src/thread/cnd_init.c",
1481"musl/src/thread/cnd_signal.c",
1482"musl/src/thread/cnd_timedwait.c",
1483"musl/src/thread/cnd_wait.c",
1484"musl/src/thread/default_attr.c",
1485"musl/src/thread/i386/__set_thread_area.s",
1486"musl/src/thread/i386/__unmapself.s",
1487"musl/src/thread/i386/clone.s",
1488"musl/src/thread/i386/syscall_cp.s",
1489"musl/src/thread/i386/tls.s",
1490"musl/src/thread/lock_ptc.c",
1491"musl/src/thread/m68k/__m68k_read_tp.s",
1492"musl/src/thread/m68k/clone.s",
1493"musl/src/thread/m68k/syscall_cp.s",
1494"musl/src/thread/microblaze/__set_thread_area.s",
1495"musl/src/thread/microblaze/__unmapself.s",
1496"musl/src/thread/microblaze/clone.s",
1497"musl/src/thread/microblaze/syscall_cp.s",
1498"musl/src/thread/mips/__unmapself.s",
1499"musl/src/thread/mips/clone.s",
1500"musl/src/thread/mips/syscall_cp.s",
1501"musl/src/thread/mips64/__unmapself.s",
1502"musl/src/thread/mips64/clone.s",
1503"musl/src/thread/mips64/syscall_cp.s",
1504"musl/src/thread/mipsn32/__unmapself.s",
1505"musl/src/thread/mipsn32/clone.s",
1506"musl/src/thread/mipsn32/syscall_cp.s",
1507"musl/src/thread/mtx_destroy.c",
1508"musl/src/thread/mtx_init.c",
1509"musl/src/thread/mtx_lock.c",
1510"musl/src/thread/mtx_timedlock.c",
1511"musl/src/thread/mtx_trylock.c",
1512"musl/src/thread/mtx_unlock.c",
1513"musl/src/thread/or1k/__set_thread_area.s",
1514"musl/src/thread/or1k/__unmapself.s",
1515"musl/src/thread/or1k/clone.s",
1516"musl/src/thread/or1k/syscall_cp.s",
1517"musl/src/thread/powerpc/__set_thread_area.s",
1518"musl/src/thread/powerpc/__unmapself.s",
1519"musl/src/thread/powerpc/clone.s",
1520"musl/src/thread/powerpc/syscall_cp.s",
1521"musl/src/thread/powerpc64/__set_thread_area.s",
1522"musl/src/thread/powerpc64/__unmapself.s",
1523"musl/src/thread/powerpc64/clone.s",
1524"musl/src/thread/powerpc64/syscall_cp.s",
1525"musl/src/thread/pthread_atfork.c",
1526"musl/src/thread/pthread_attr_destroy.c",
1527"musl/src/thread/pthread_attr_get.c",
1528"musl/src/thread/pthread_attr_init.c",
1529"musl/src/thread/pthread_attr_setdetachstate.c",
1530"musl/src/thread/pthread_attr_setguardsize.c",
1531"musl/src/thread/pthread_attr_setinheritsched.c",
1532"musl/src/thread/pthread_attr_setschedparam.c",
1533"musl/src/thread/pthread_attr_setschedpolicy.c",
1534"musl/src/thread/pthread_attr_setscope.c",
1535"musl/src/thread/pthread_attr_setstack.c",
1536"musl/src/thread/pthread_attr_setstacksize.c",
1537"musl/src/thread/pthread_barrier_destroy.c",
1538"musl/src/thread/pthread_barrier_init.c",
1539"musl/src/thread/pthread_barrier_wait.c",
1540"musl/src/thread/pthread_barrierattr_destroy.c",
1541"musl/src/thread/pthread_barrierattr_init.c",
1542"musl/src/thread/pthread_barrierattr_setpshared.c",
1543"musl/src/thread/pthread_cancel.c",
1544"musl/src/thread/pthread_cleanup_push.c",
1545"musl/src/thread/pthread_cond_broadcast.c",
1546"musl/src/thread/pthread_cond_destroy.c",
1547"musl/src/thread/pthread_cond_init.c",
1548"musl/src/thread/pthread_cond_signal.c",
1549"musl/src/thread/pthread_cond_timedwait.c",
1550"musl/src/thread/pthread_cond_wait.c",
1551"musl/src/thread/pthread_condattr_destroy.c",
1552"musl/src/thread/pthread_condattr_init.c",
1553"musl/src/thread/pthread_condattr_setclock.c",
1554"musl/src/thread/pthread_condattr_setpshared.c",
1555"musl/src/thread/pthread_create.c",
1556"musl/src/thread/pthread_detach.c",
1557"musl/src/thread/pthread_equal.c",
1558"musl/src/thread/pthread_getattr_np.c",
1559"musl/src/thread/pthread_getconcurrency.c",
1560"musl/src/thread/pthread_getcpuclockid.c",
1561"musl/src/thread/pthread_getschedparam.c",
1562"musl/src/thread/pthread_getspecific.c",
1563"musl/src/thread/pthread_join.c",
1564"musl/src/thread/pthread_key_create.c",
1565"musl/src/thread/pthread_kill.c",
1566"musl/src/thread/pthread_mutex_consistent.c",
1567"musl/src/thread/pthread_mutex_destroy.c",
1568"musl/src/thread/pthread_mutex_getprioceiling.c",
1569"musl/src/thread/pthread_mutex_init.c",
1570"musl/src/thread/pthread_mutex_lock.c",
1571"musl/src/thread/pthread_mutex_setprioceiling.c",
1572"musl/src/thread/pthread_mutex_timedlock.c",
1573"musl/src/thread/pthread_mutex_trylock.c",
1574"musl/src/thread/pthread_mutex_unlock.c",
1575"musl/src/thread/pthread_mutexattr_destroy.c",
1576"musl/src/thread/pthread_mutexattr_init.c",
1577"musl/src/thread/pthread_mutexattr_setprotocol.c",
1578"musl/src/thread/pthread_mutexattr_setpshared.c",
1579"musl/src/thread/pthread_mutexattr_setrobust.c",
1580"musl/src/thread/pthread_mutexattr_settype.c",
1581"musl/src/thread/pthread_once.c",
1582"musl/src/thread/pthread_rwlock_destroy.c",
1583"musl/src/thread/pthread_rwlock_init.c",
1584"musl/src/thread/pthread_rwlock_rdlock.c",
1585"musl/src/thread/pthread_rwlock_timedrdlock.c",
1586"musl/src/thread/pthread_rwlock_timedwrlock.c",
1587"musl/src/thread/pthread_rwlock_tryrdlock.c",
1588"musl/src/thread/pthread_rwlock_trywrlock.c",
1589"musl/src/thread/pthread_rwlock_unlock.c",
1590"musl/src/thread/pthread_rwlock_wrlock.c",
1591"musl/src/thread/pthread_rwlockattr_destroy.c",
1592"musl/src/thread/pthread_rwlockattr_init.c",
1593"musl/src/thread/pthread_rwlockattr_setpshared.c",
1594"musl/src/thread/pthread_self.c",
1595"musl/src/thread/pthread_setattr_default_np.c",
1596"musl/src/thread/pthread_setcancelstate.c",
1597"musl/src/thread/pthread_setcanceltype.c",
1598"musl/src/thread/pthread_setconcurrency.c",
1599"musl/src/thread/pthread_setname_np.c",
1600"musl/src/thread/pthread_setschedparam.c",
1601"musl/src/thread/pthread_setschedprio.c",
1602"musl/src/thread/pthread_setspecific.c",
1603"musl/src/thread/pthread_sigmask.c",
1604"musl/src/thread/pthread_spin_destroy.c",
1605"musl/src/thread/pthread_spin_init.c",
1606"musl/src/thread/pthread_spin_lock.c",
1607"musl/src/thread/pthread_spin_trylock.c",
1608"musl/src/thread/pthread_spin_unlock.c",
1609"musl/src/thread/pthread_testcancel.c",
1610"musl/src/thread/riscv64/__set_thread_area.s",
1611"musl/src/thread/riscv64/__unmapself.s",
1612"musl/src/thread/riscv64/clone.s",
1613"musl/src/thread/riscv64/syscall_cp.s",
1614"musl/src/thread/s390x/__set_thread_area.s",
1615"musl/src/thread/s390x/__tls_get_offset.s",
1616"musl/src/thread/s390x/__unmapself.s",
1617"musl/src/thread/s390x/clone.s",
1618"musl/src/thread/s390x/syscall_cp.s",
1619"musl/src/thread/sem_destroy.c",
1620"musl/src/thread/sem_getvalue.c",
1621"musl/src/thread/sem_init.c",
1622"musl/src/thread/sem_open.c",
1623"musl/src/thread/sem_post.c",
1624"musl/src/thread/sem_timedwait.c",
1625"musl/src/thread/sem_trywait.c",
1626"musl/src/thread/sem_unlink.c",
1627"musl/src/thread/sem_wait.c",
1628"musl/src/thread/sh/__set_thread_area.c",
1629"musl/src/thread/sh/__unmapself.c",
1630"musl/src/thread/sh/__unmapself_mmu.s",
1631"musl/src/thread/sh/atomics.s",
1632"musl/src/thread/sh/clone.s",
1633"musl/src/thread/sh/syscall_cp.s",
1634"musl/src/thread/synccall.c",
1635"musl/src/thread/syscall_cp.c",
1636"musl/src/thread/thrd_create.c",
1637"musl/src/thread/thrd_exit.c",
1638"musl/src/thread/thrd_join.c",
1639"musl/src/thread/thrd_sleep.c",
1640"musl/src/thread/thrd_yield.c",
1641"musl/src/thread/tls.c",
1642"musl/src/thread/tss_create.c",
1643"musl/src/thread/tss_delete.c",
1644"musl/src/thread/tss_set.c",
1645"musl/src/thread/vmlock.c",
1646"musl/src/thread/x32/__set_thread_area.s",
1647"musl/src/thread/x32/__unmapself.s",
1648"musl/src/thread/x32/clone.s",
1649"musl/src/thread/x32/syscall_cp.s",
1650"musl/src/thread/x86_64/__set_thread_area.s",
1651"musl/src/thread/x86_64/__unmapself.s",
1652"musl/src/thread/x86_64/clone.s",
1653"musl/src/thread/x86_64/syscall_cp.s",
1654"musl/src/time/__map_file.c",
1655"musl/src/time/__month_to_secs.c",
1656"musl/src/time/__secs_to_tm.c",
1657"musl/src/time/__tm_to_secs.c",
1658"musl/src/time/__tz.c",
1659"musl/src/time/__year_to_secs.c",
1660"musl/src/time/asctime.c",
1661"musl/src/time/asctime_r.c",
1662"musl/src/time/clock.c",
1663"musl/src/time/clock_getcpuclockid.c",
1664"musl/src/time/clock_getres.c",
1665"musl/src/time/clock_gettime.c",
1666"musl/src/time/clock_nanosleep.c",
1667"musl/src/time/clock_settime.c",
1668"musl/src/time/ctime.c",
1669"musl/src/time/ctime_r.c",
1670"musl/src/time/difftime.c",
1671"musl/src/time/ftime.c",
1672"musl/src/time/getdate.c",
1673"musl/src/time/gettimeofday.c",
1674"musl/src/time/gmtime.c",
1675"musl/src/time/gmtime_r.c",
1676"musl/src/time/localtime.c",
1677"musl/src/time/localtime_r.c",
1678"musl/src/time/mktime.c",
1679"musl/src/time/nanosleep.c",
1680"musl/src/time/strftime.c",
1681"musl/src/time/strptime.c",
1682"musl/src/time/time.c",
1683"musl/src/time/timegm.c",
1684"musl/src/time/timer_create.c",
1685"musl/src/time/timer_delete.c",
1686"musl/src/time/timer_getoverrun.c",
1687"musl/src/time/timer_gettime.c",
1688"musl/src/time/timer_settime.c",
1689"musl/src/time/times.c",
1690"musl/src/time/timespec_get.c",
1691"musl/src/time/utime.c",
1692"musl/src/time/wcsftime.c",
1693"musl/src/unistd/_exit.c",
1694"musl/src/unistd/access.c",
1695"musl/src/unistd/acct.c",
1696"musl/src/unistd/alarm.c",
1697"musl/src/unistd/chdir.c",
1698"musl/src/unistd/chown.c",
1699"musl/src/unistd/close.c",
1700"musl/src/unistd/ctermid.c",
1701"musl/src/unistd/dup.c",
1702"musl/src/unistd/dup2.c",
1703"musl/src/unistd/dup3.c",
1704"musl/src/unistd/faccessat.c",
1705"musl/src/unistd/fchdir.c",
1706"musl/src/unistd/fchown.c",
1707"musl/src/unistd/fchownat.c",
1708"musl/src/unistd/fdatasync.c",
1709"musl/src/unistd/fsync.c",
1710"musl/src/unistd/ftruncate.c",
1711"musl/src/unistd/getcwd.c",
1712"musl/src/unistd/getegid.c",
1713"musl/src/unistd/geteuid.c",
1714"musl/src/unistd/getgid.c",
1715"musl/src/unistd/getgroups.c",
1716"musl/src/unistd/gethostname.c",
1717"musl/src/unistd/getlogin.c",
1718"musl/src/unistd/getlogin_r.c",
1719"musl/src/unistd/getpgid.c",
1720"musl/src/unistd/getpgrp.c",
1721"musl/src/unistd/getpid.c",
1722"musl/src/unistd/getppid.c",
1723"musl/src/unistd/getsid.c",
1724"musl/src/unistd/getuid.c",
1725"musl/src/unistd/isatty.c",
1726"musl/src/unistd/lchown.c",
1727"musl/src/unistd/link.c",
1728"musl/src/unistd/linkat.c",
1729"musl/src/unistd/lseek.c",
1730"musl/src/unistd/mips/pipe.s",
1731"musl/src/unistd/mips64/pipe.s",
1732"musl/src/unistd/mipsn32/lseek.c",
1733"musl/src/unistd/mipsn32/pipe.s",
1734"musl/src/unistd/nice.c",
1735"musl/src/unistd/pause.c",
1736"musl/src/unistd/pipe.c",
1737"musl/src/unistd/pipe2.c",
1738"musl/src/unistd/posix_close.c",
1739"musl/src/unistd/pread.c",
1740"musl/src/unistd/preadv.c",
1741"musl/src/unistd/pwrite.c",
1742"musl/src/unistd/pwritev.c",
1743"musl/src/unistd/read.c",
1744"musl/src/unistd/readlink.c",
1745"musl/src/unistd/readlinkat.c",
1746"musl/src/unistd/readv.c",
1747"musl/src/unistd/renameat.c",
1748"musl/src/unistd/rmdir.c",
1749"musl/src/unistd/setegid.c",
1750"musl/src/unistd/seteuid.c",
1751"musl/src/unistd/setgid.c",
1752"musl/src/unistd/setpgid.c",
1753"musl/src/unistd/setpgrp.c",
1754"musl/src/unistd/setregid.c",
1755"musl/src/unistd/setresgid.c",
1756"musl/src/unistd/setresuid.c",
1757"musl/src/unistd/setreuid.c",
1758"musl/src/unistd/setsid.c",
1759"musl/src/unistd/setuid.c",
1760"musl/src/unistd/setxid.c",
1761"musl/src/unistd/sh/pipe.s",
1762"musl/src/unistd/sleep.c",
1763"musl/src/unistd/symlink.c",
1764"musl/src/unistd/symlinkat.c",
1765"musl/src/unistd/sync.c",
1766"musl/src/unistd/tcgetpgrp.c",
1767"musl/src/unistd/tcsetpgrp.c",
1768"musl/src/unistd/truncate.c",
1769"musl/src/unistd/ttyname.c",
1770"musl/src/unistd/ttyname_r.c",
1771"musl/src/unistd/ualarm.c",
1772"musl/src/unistd/unlink.c",
1773"musl/src/unistd/unlinkat.c",
1774"musl/src/unistd/usleep.c",
1775"musl/src/unistd/write.c",
1776"musl/src/unistd/writev.c",
1777"musl/src/unistd/x32/lseek.c",
1778};
1779static const char *ZIG_MUSL_COMPAT_TIME32_FILES[] = {
1780"musl/compat/time32/__xstat.c",
1781"musl/compat/time32/adjtime32.c",
1782"musl/compat/time32/adjtimex_time32.c",
1783"musl/compat/time32/aio_suspend_time32.c",
1784"musl/compat/time32/clock_adjtime32.c",
1785"musl/compat/time32/clock_getres_time32.c",
1786"musl/compat/time32/clock_gettime32.c",
1787"musl/compat/time32/clock_nanosleep_time32.c",
1788"musl/compat/time32/clock_settime32.c",
1789"musl/compat/time32/cnd_timedwait_time32.c",
1790"musl/compat/time32/ctime32.c",
1791"musl/compat/time32/ctime32_r.c",
1792"musl/compat/time32/difftime32.c",
1793"musl/compat/time32/fstat_time32.c",
1794"musl/compat/time32/fstatat_time32.c",
1795"musl/compat/time32/ftime32.c",
1796"musl/compat/time32/futimens_time32.c",
1797"musl/compat/time32/futimes_time32.c",
1798"musl/compat/time32/futimesat_time32.c",
1799"musl/compat/time32/getitimer_time32.c",
1800"musl/compat/time32/getrusage_time32.c",
1801"musl/compat/time32/gettimeofday_time32.c",
1802"musl/compat/time32/gmtime32.c",
1803"musl/compat/time32/gmtime32_r.c",
1804"musl/compat/time32/localtime32.c",
1805"musl/compat/time32/localtime32_r.c",
1806"musl/compat/time32/lstat_time32.c",
1807"musl/compat/time32/lutimes_time32.c",
1808"musl/compat/time32/mktime32.c",
1809"musl/compat/time32/mq_timedreceive_time32.c",
1810"musl/compat/time32/mq_timedsend_time32.c",
1811"musl/compat/time32/mtx_timedlock_time32.c",
1812"musl/compat/time32/nanosleep_time32.c",
1813"musl/compat/time32/ppoll_time32.c",
1814"musl/compat/time32/pselect_time32.c",
1815"musl/compat/time32/pthread_cond_timedwait_time32.c",
1816"musl/compat/time32/pthread_mutex_timedlock_time32.c",
1817"musl/compat/time32/pthread_rwlock_timedrdlock_time32.c",
1818"musl/compat/time32/pthread_rwlock_timedwrlock_time32.c",
1819"musl/compat/time32/pthread_timedjoin_np_time32.c",
1820"musl/compat/time32/recvmmsg_time32.c",
1821"musl/compat/time32/sched_rr_get_interval_time32.c",
1822"musl/compat/time32/select_time32.c",
1823"musl/compat/time32/sem_timedwait_time32.c",
1824"musl/compat/time32/semtimedop_time32.c",
1825"musl/compat/time32/setitimer_time32.c",
1826"musl/compat/time32/settimeofday_time32.c",
1827"musl/compat/time32/sigtimedwait_time32.c",
1828"musl/compat/time32/stat_time32.c",
1829"musl/compat/time32/stime32.c",
1830"musl/compat/time32/thrd_sleep_time32.c",
1831"musl/compat/time32/time32.c",
1832"musl/compat/time32/time32gm.c",
1833"musl/compat/time32/timer_gettime32.c",
1834"musl/compat/time32/timer_settime32.c",
1835"musl/compat/time32/timerfd_gettime32.c",
1836"musl/compat/time32/timerfd_settime32.c",
1837"musl/compat/time32/timespec_get_time32.c",
1838"musl/compat/time32/utime_time32.c",
1839"musl/compat/time32/utimensat_time32.c",
1840"musl/compat/time32/utimes_time32.c",
1841"musl/compat/time32/wait3_time32.c",
1842"musl/compat/time32/wait4_time32.c",
1843};
1844static const char *ZIG_LIBCXXABI_FILES[] = {
1845"src/abort_message.cpp",
1846"src/cxa_aux_runtime.cpp",
1847"src/cxa_default_handlers.cpp",
1848"src/cxa_demangle.cpp",
1849"src/cxa_exception.cpp",
1850"src/cxa_exception_storage.cpp",
1851"src/cxa_guard.cpp",
1852"src/cxa_handlers.cpp",
1853"src/cxa_noexception.cpp",
1854"src/cxa_personality.cpp",
1855"src/cxa_thread_atexit.cpp",
1856"src/cxa_unexpected.cpp",
1857"src/cxa_vector.cpp",
1858"src/cxa_virtual.cpp",
1859"src/fallback_malloc.cpp",
1860"src/private_typeinfo.cpp",
1861"src/stdlib_exception.cpp",
1862"src/stdlib_stdexcept.cpp",
1863"src/stdlib_typeinfo.cpp",
1864};
1865static const char *ZIG_LIBCXX_FILES[] = {
1866"src/algorithm.cpp",
1867"src/any.cpp",
1868"src/bind.cpp",
1869"src/charconv.cpp",
1870"src/chrono.cpp",
1871"src/condition_variable.cpp",
1872"src/condition_variable_destructor.cpp",
1873"src/debug.cpp",
1874"src/exception.cpp",
1875"src/experimental/memory_resource.cpp",
1876"src/filesystem/directory_iterator.cpp",
1877"src/filesystem/operations.cpp",
1878"src/functional.cpp",
1879"src/future.cpp",
1880"src/hash.cpp",
1881"src/ios.cpp",
1882"src/iostream.cpp",
1883"src/locale.cpp",
1884"src/memory.cpp",
1885"src/mutex.cpp",
1886"src/mutex_destructor.cpp",
1887"src/new.cpp",
1888"src/optional.cpp",
1889"src/random.cpp",
1890"src/regex.cpp",
1891"src/shared_mutex.cpp",
1892"src/stdexcept.cpp",
1893"src/string.cpp",
1894"src/strstream.cpp",
1895"src/support/solaris/xlocale.cpp",
1896"src/support/win32/locale_win32.cpp",
1897"src/support/win32/support.cpp",
1898"src/support/win32/thread_win32.cpp",
1899"src/system_error.cpp",
1900"src/thread.cpp",
1901"src/typeinfo.cpp",
1902"src/utility.cpp",
1903"src/valarray.cpp",
1904"src/variant.cpp",
1905"src/vector.cpp",
1906};
1907#endif
src/ir.cpp+5-176
...@@ -22570,38 +22570,12 @@ static IrInstGen *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name...@@ -22570,38 +22570,12 @@ static IrInstGen *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name
22570}22570}
2257122571
22572static void add_link_lib_symbol(IrAnalyze *ira, Buf *lib_name, Buf *symbol_name, AstNode *source_node) {22572static void add_link_lib_symbol(IrAnalyze *ira, Buf *lib_name, Buf *symbol_name, AstNode *source_node) {
22573 bool is_libc = target_is_libc_lib_name(ira->codegen->zig_target, buf_ptr(lib_name));22573 const char *msg = stage2_add_link_lib(&ira->codegen->stage1, buf_ptr(lib_name), buf_len(lib_name),
22574 if (is_libc && ira->codegen->libc_link_lib == nullptr && !ira->codegen->reported_bad_link_libc_error) {22574 buf_ptr(symbol_name), buf_len(symbol_name));
22575 ir_add_error_node(ira, source_node,22575 if (msg != nullptr) {
22576 buf_sprintf("dependency on library c must be explicitly specified in the build command"));22576 ir_add_error_node(ira, source_node, buf_create_from_str(msg));
22577 ira->codegen->reported_bad_link_libc_error = true;
22578 }
22579
22580 LinkLib *link_lib = add_link_lib(ira->codegen, lib_name);
22581 for (size_t i = 0; i < link_lib->symbols.length; i += 1) {
22582 Buf *existing_symbol_name = link_lib->symbols.at(i);
22583 if (buf_eql_buf(existing_symbol_name, symbol_name)) {
22584 return;
22585 }
22586 }
22587
22588 if (!is_libc && !target_is_wasm(ira->codegen->zig_target) && !ira->codegen->have_pic && !ira->codegen->reported_bad_link_libc_error) {
22589 ErrorMsg *msg = ir_add_error_node(ira, source_node,
22590 buf_sprintf("dependency on dynamic library '%s' requires enabling Position Independent Code",
22591 buf_ptr(lib_name)));
22592 add_error_note(ira->codegen, msg, source_node,
22593 buf_sprintf("fixed by `--library %s` or `-fPIC`", buf_ptr(lib_name)));
22594 ira->codegen->reported_bad_link_libc_error = true;22577 ira->codegen->reported_bad_link_libc_error = true;
22595 }22578 }
22596
22597 for (size_t i = 0; i < ira->codegen->forbidden_libs.length; i += 1) {
22598 Buf *forbidden_lib_name = ira->codegen->forbidden_libs.at(i);
22599 if (buf_eql_buf(lib_name, forbidden_lib_name)) {
22600 ir_add_error_node(ira, source_node,
22601 buf_sprintf("linking against forbidden library '%s'", buf_ptr(symbol_name)));
22602 }
22603 }
22604 link_lib->symbols.append(symbol_name);
22605}22579}
2260622580
22607static IrInstGen *ir_error_dependency_loop(IrAnalyze *ira, IrInst* source_instr) {22581static IrInstGen *ir_error_dependency_loop(IrAnalyze *ira, IrInst* source_instr) {
...@@ -26355,13 +26329,6 @@ static IrInstGen *ir_analyze_instruction_type_name(IrAnalyze *ira, IrInstSrcType...@@ -26355,13 +26329,6 @@ static IrInstGen *ir_analyze_instruction_type_name(IrAnalyze *ira, IrInstSrcType
26355 return result;26329 return result;
26356}26330}
2635726331
26358static void ir_cimport_cache_paths(Buf *cache_dir, Buf *tmp_c_file_digest, Buf *out_zig_dir, Buf *out_zig_path) {
26359 buf_resize(out_zig_dir, 0);
26360 buf_resize(out_zig_path, 0);
26361 buf_appendf(out_zig_dir, "%s" OS_SEP "o" OS_SEP "%s",
26362 buf_ptr(cache_dir), buf_ptr(tmp_c_file_digest));
26363 buf_appendf(out_zig_path, "%s" OS_SEP "cimport.zig", buf_ptr(out_zig_dir));
26364}
26365static IrInstGen *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstSrcCImport *instruction) {26332static IrInstGen *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstSrcCImport *instruction) {
26366 Error err;26333 Error err;
26367 AstNode *node = instruction->base.base.source_node;26334 AstNode *node = instruction->base.base.source_node;
...@@ -26393,145 +26360,7 @@ static IrInstGen *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstSrcCImpo...@@ -26393,145 +26360,7 @@ static IrInstGen *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstSrcCImpo
26393 cimport_pkg->package_table.put(buf_create_from_str("std"), ira->codegen->std_package);26360 cimport_pkg->package_table.put(buf_create_from_str("std"), ira->codegen->std_package);
26394 buf_init_from_buf(&cimport_pkg->pkg_path, namespace_name);26361 buf_init_from_buf(&cimport_pkg->pkg_path, namespace_name);
2639526362
26396 CacheHash *cache_hash;26363 Buf *out_zig_path = buf_create_from_str(stage2_cimport(&ira->codegen->stage1));
26397 if ((err = create_c_object_cache(ira->codegen, &cache_hash, false))) {
26398 ir_add_error_node(ira, node, buf_sprintf("C import failed: unable to create cache: %s", err_str(err)));
26399 return ira->codegen->invalid_inst_gen;
26400 }
26401 cache_buf(cache_hash, &cimport_scope->buf);
26402
26403 // Set this because we're not adding any files before checking for a hit.
26404 cache_hash->force_check_manifest = true;
26405
26406 Buf tmp_c_file_digest = BUF_INIT;
26407 buf_resize(&tmp_c_file_digest, 0);
26408 if ((err = cache_hit(cache_hash, &tmp_c_file_digest))) {
26409 if (err != ErrorInvalidFormat) {
26410 ir_add_error_node(ira, node, buf_sprintf("C import failed: unable to check cache: %s", err_str(err)));
26411 return ira->codegen->invalid_inst_gen;
26412 }
26413 }
26414 ira->codegen->caches_to_release.append(cache_hash);
26415
26416 Buf *out_zig_dir = buf_alloc();
26417 Buf *out_zig_path = buf_alloc();
26418 if (buf_len(&tmp_c_file_digest) == 0 || cache_hash->files.length == 0) {
26419 // Cache Miss
26420 Buf *tmp_c_file_dir = buf_sprintf("%s" OS_SEP "o" OS_SEP "%s",
26421 buf_ptr(ira->codegen->cache_dir), buf_ptr(&cache_hash->b64_digest));
26422 Buf *resolve_paths[] = {
26423 tmp_c_file_dir,
26424 buf_create_from_str("cimport.h"),
26425 };
26426 Buf tmp_c_file_path = os_path_resolve(resolve_paths, 2);
26427
26428 if ((err = os_make_path(tmp_c_file_dir))) {
26429 ir_add_error_node(ira, node, buf_sprintf("C import failed: unable to make dir: %s", err_str(err)));
26430 return ira->codegen->invalid_inst_gen;
26431 }
26432
26433 if ((err = os_write_file(&tmp_c_file_path, &cimport_scope->buf))) {
26434 ir_add_error_node(ira, node, buf_sprintf("C import failed: unable to write .h file: %s", err_str(err)));
26435 return ira->codegen->invalid_inst_gen;
26436 }
26437 if (ira->codegen->verbose_cimport) {
26438 fprintf(stderr, "@cImport source: %s\n", buf_ptr(&tmp_c_file_path));
26439 }
26440
26441 Buf *tmp_dep_file = buf_sprintf("%s.d", buf_ptr(&tmp_c_file_path));
26442
26443 ZigList<const char *> clang_argv = {0};
26444
26445 add_cc_args(ira->codegen, clang_argv, buf_ptr(tmp_dep_file), true, FileExtC);
26446
26447 clang_argv.append(buf_ptr(&tmp_c_file_path));
26448
26449 if (ira->codegen->verbose_cc) {
26450 fprintf(stderr, "clang");
26451 for (size_t i = 0; i < clang_argv.length; i += 1) {
26452 fprintf(stderr, " %s", clang_argv.at(i));
26453 }
26454 fprintf(stderr, "\n");
26455 }
26456
26457 clang_argv.append(nullptr); // to make the [start...end] argument work
26458
26459 Stage2ErrorMsg *errors_ptr;
26460 size_t errors_len;
26461 Stage2Ast *ast;
26462
26463 const char *resources_path = buf_ptr(ira->codegen->zig_c_headers_dir);
26464
26465 if ((err = stage2_translate_c(&ast, &errors_ptr, &errors_len,
26466 &clang_argv.at(0), &clang_argv.last(), resources_path)))
26467 {
26468 if (err != ErrorCCompileErrors) {
26469 ir_add_error_node(ira, node, buf_sprintf("C import failed: %s", err_str(err)));
26470 return ira->codegen->invalid_inst_gen;
26471 }
26472
26473 ErrorMsg *parent_err_msg = ir_add_error_node(ira, node, buf_sprintf("C import failed"));
26474 if (ira->codegen->libc_link_lib == nullptr) {
26475 add_error_note(ira->codegen, parent_err_msg, node,
26476 buf_sprintf("libc headers not available; compilation does not link against libc"));
26477 }
26478 for (size_t i = 0; i < errors_len; i += 1) {
26479 Stage2ErrorMsg *clang_err = &errors_ptr[i];
26480 // Clang can emit "too many errors, stopping now", in which case `source` and `filename_ptr` are null
26481 if (clang_err->source && clang_err->filename_ptr) {
26482 ErrorMsg *err_msg = err_msg_create_with_offset(
26483 clang_err->filename_ptr ?
26484 buf_create_from_mem(clang_err->filename_ptr, clang_err->filename_len) : buf_alloc(),
26485 clang_err->line, clang_err->column, clang_err->offset, clang_err->source,
26486 buf_create_from_mem(clang_err->msg_ptr, clang_err->msg_len));
26487 err_msg_add_note(parent_err_msg, err_msg);
26488 }
26489 }
26490
26491 return ira->codegen->invalid_inst_gen;
26492 }
26493 if (ira->codegen->verbose_cimport) {
26494 fprintf(stderr, "@cImport .d file: %s\n", buf_ptr(tmp_dep_file));
26495 }
26496
26497 if ((err = cache_add_dep_file(cache_hash, tmp_dep_file, false))) {
26498 ir_add_error_node(ira, node, buf_sprintf("C import failed: unable to parse .d file: %s", err_str(err)));
26499 return ira->codegen->invalid_inst_gen;
26500 }
26501 if ((err = cache_final(cache_hash, &tmp_c_file_digest))) {
26502 ir_add_error_node(ira, node, buf_sprintf("C import failed: unable to finalize cache: %s", err_str(err)));
26503 return ira->codegen->invalid_inst_gen;
26504 }
26505
26506 ir_cimport_cache_paths(ira->codegen->cache_dir, &tmp_c_file_digest, out_zig_dir, out_zig_path);
26507 if ((err = os_make_path(out_zig_dir))) {
26508 ir_add_error_node(ira, node, buf_sprintf("C import failed: unable to make output dir: %s", err_str(err)));
26509 return ira->codegen->invalid_inst_gen;
26510 }
26511 FILE *out_file = fopen(buf_ptr(out_zig_path), "wb");
26512 if (out_file == nullptr) {
26513 ir_add_error_node(ira, node,
26514 buf_sprintf("C import failed: unable to open output file: %s", strerror(errno)));
26515 return ira->codegen->invalid_inst_gen;
26516 }
26517 stage2_render_ast(ast, out_file);
26518 if (fclose(out_file) != 0) {
26519 ir_add_error_node(ira, node,
26520 buf_sprintf("C import failed: unable to write to output file: %s", strerror(errno)));
26521 return ira->codegen->invalid_inst_gen;
26522 }
26523
26524 if (ira->codegen->verbose_cimport) {
26525 fprintf(stderr, "@cImport output: %s\n", buf_ptr(out_zig_path));
26526 }
26527
26528 } else {
26529 // Cache Hit
26530 ir_cimport_cache_paths(ira->codegen->cache_dir, &tmp_c_file_digest, out_zig_dir, out_zig_path);
26531 if (ira->codegen->verbose_cimport) {
26532 fprintf(stderr, "@cImport cache hit: %s\n", buf_ptr(out_zig_path));
26533 }
26534 }
2653526364
26536 Buf *import_code = buf_alloc();26365 Buf *import_code = buf_alloc();
26537 if ((err = file_fetch(ira->codegen, out_zig_path, import_code))) {26366 if ((err = file_fetch(ira->codegen, out_zig_path, import_code))) {
src/link.cpp deleted-2985
...@@ -1,2985 +0,0 @@
1/*
2 * Copyright (c) 2015 Andrew Kelley
3 *
4 * This file is part of zig, which is MIT licensed.
5 * See http://opensource.org/licenses/MIT
6 */
7
8#include "os.hpp"
9#include "config.h"
10#include "codegen.hpp"
11#include "analyze.hpp"
12#include "compiler.hpp"
13#include "install_files.h"
14#include "glibc.hpp"
15
16static const char *msvcrt_common_src[] = {
17 "misc" OS_SEP "_create_locale.c",
18 "misc" OS_SEP "_free_locale.c",
19 "misc" OS_SEP "onexit_table.c",
20 "misc" OS_SEP "register_tls_atexit.c",
21 "stdio" OS_SEP "acrt_iob_func.c",
22 "misc" OS_SEP "_configthreadlocale.c",
23 "misc" OS_SEP "_get_current_locale.c",
24 "misc" OS_SEP "invalid_parameter_handler.c",
25 "misc" OS_SEP "output_format.c",
26 "misc" OS_SEP "purecall.c",
27 "secapi" OS_SEP "_access_s.c",
28 "secapi" OS_SEP "_cgets_s.c",
29 "secapi" OS_SEP "_cgetws_s.c",
30 "secapi" OS_SEP "_chsize_s.c",
31 "secapi" OS_SEP "_controlfp_s.c",
32 "secapi" OS_SEP "_cprintf_s.c",
33 "secapi" OS_SEP "_cprintf_s_l.c",
34 "secapi" OS_SEP "_ctime32_s.c",
35 "secapi" OS_SEP "_ctime64_s.c",
36 "secapi" OS_SEP "_cwprintf_s.c",
37 "secapi" OS_SEP "_cwprintf_s_l.c",
38 "secapi" OS_SEP "_gmtime32_s.c",
39 "secapi" OS_SEP "_gmtime64_s.c",
40 "secapi" OS_SEP "_localtime32_s.c",
41 "secapi" OS_SEP "_localtime64_s.c",
42 "secapi" OS_SEP "_mktemp_s.c",
43 "secapi" OS_SEP "_sopen_s.c",
44 "secapi" OS_SEP "_strdate_s.c",
45 "secapi" OS_SEP "_strtime_s.c",
46 "secapi" OS_SEP "_umask_s.c",
47 "secapi" OS_SEP "_vcprintf_s.c",
48 "secapi" OS_SEP "_vcprintf_s_l.c",
49 "secapi" OS_SEP "_vcwprintf_s.c",
50 "secapi" OS_SEP "_vcwprintf_s_l.c",
51 "secapi" OS_SEP "_vscprintf_p.c",
52 "secapi" OS_SEP "_vscwprintf_p.c",
53 "secapi" OS_SEP "_vswprintf_p.c",
54 "secapi" OS_SEP "_waccess_s.c",
55 "secapi" OS_SEP "_wasctime_s.c",
56 "secapi" OS_SEP "_wctime32_s.c",
57 "secapi" OS_SEP "_wctime64_s.c",
58 "secapi" OS_SEP "_wstrtime_s.c",
59 "secapi" OS_SEP "_wmktemp_s.c",
60 "secapi" OS_SEP "_wstrdate_s.c",
61 "secapi" OS_SEP "asctime_s.c",
62 "secapi" OS_SEP "memcpy_s.c",
63 "secapi" OS_SEP "memmove_s.c",
64 "secapi" OS_SEP "rand_s.c",
65 "secapi" OS_SEP "sprintf_s.c",
66 "secapi" OS_SEP "strerror_s.c",
67 "secapi" OS_SEP "vsprintf_s.c",
68 "secapi" OS_SEP "wmemcpy_s.c",
69 "secapi" OS_SEP "wmemmove_s.c",
70 "stdio" OS_SEP "mingw_lock.c",
71};
72
73static const char *msvcrt_i386_src[] = {
74 "misc" OS_SEP "lc_locale_func.c",
75 "misc" OS_SEP "___mb_cur_max_func.c",
76};
77
78static const char *msvcrt_other_src[] = {
79 "misc" OS_SEP "__p___argv.c",
80 "misc" OS_SEP "__p__acmdln.c",
81 "misc" OS_SEP "__p__fmode.c",
82 "misc" OS_SEP "__p__wcmdln.c",
83};
84
85static const char *mingwex_generic_src[] = {
86 "complex" OS_SEP "_cabs.c",
87 "complex" OS_SEP "cabs.c",
88 "complex" OS_SEP "cabsf.c",
89 "complex" OS_SEP "cabsl.c",
90 "complex" OS_SEP "cacos.c",
91 "complex" OS_SEP "cacosf.c",
92 "complex" OS_SEP "cacosl.c",
93 "complex" OS_SEP "carg.c",
94 "complex" OS_SEP "cargf.c",
95 "complex" OS_SEP "cargl.c",
96 "complex" OS_SEP "casin.c",
97 "complex" OS_SEP "casinf.c",
98 "complex" OS_SEP "casinl.c",
99 "complex" OS_SEP "catan.c",
100 "complex" OS_SEP "catanf.c",
101 "complex" OS_SEP "catanl.c",
102 "complex" OS_SEP "ccos.c",
103 "complex" OS_SEP "ccosf.c",
104 "complex" OS_SEP "ccosl.c",
105 "complex" OS_SEP "cexp.c",
106 "complex" OS_SEP "cexpf.c",
107 "complex" OS_SEP "cexpl.c",
108 "complex" OS_SEP "cimag.c",
109 "complex" OS_SEP "cimagf.c",
110 "complex" OS_SEP "cimagl.c",
111 "complex" OS_SEP "clog.c",
112 "complex" OS_SEP "clog10.c",
113 "complex" OS_SEP "clog10f.c",
114 "complex" OS_SEP "clog10l.c",
115 "complex" OS_SEP "clogf.c",
116 "complex" OS_SEP "clogl.c",
117 "complex" OS_SEP "conj.c",
118 "complex" OS_SEP "conjf.c",
119 "complex" OS_SEP "conjl.c",
120 "complex" OS_SEP "cpow.c",
121 "complex" OS_SEP "cpowf.c",
122 "complex" OS_SEP "cpowl.c",
123 "complex" OS_SEP "cproj.c",
124 "complex" OS_SEP "cprojf.c",
125 "complex" OS_SEP "cprojl.c",
126 "complex" OS_SEP "creal.c",
127 "complex" OS_SEP "crealf.c",
128 "complex" OS_SEP "creall.c",
129 "complex" OS_SEP "csin.c",
130 "complex" OS_SEP "csinf.c",
131 "complex" OS_SEP "csinl.c",
132 "complex" OS_SEP "csqrt.c",
133 "complex" OS_SEP "csqrtf.c",
134 "complex" OS_SEP "csqrtl.c",
135 "complex" OS_SEP "ctan.c",
136 "complex" OS_SEP "ctanf.c",
137 "complex" OS_SEP "ctanl.c",
138 "crt" OS_SEP "dllentry.c",
139 "crt" OS_SEP "dllmain.c",
140 "gdtoa" OS_SEP "arithchk.c",
141 "gdtoa" OS_SEP "dmisc.c",
142 "gdtoa" OS_SEP "dtoa.c",
143 "gdtoa" OS_SEP "g__fmt.c",
144 "gdtoa" OS_SEP "g_dfmt.c",
145 "gdtoa" OS_SEP "g_ffmt.c",
146 "gdtoa" OS_SEP "g_xfmt.c",
147 "gdtoa" OS_SEP "gdtoa.c",
148 "gdtoa" OS_SEP "gethex.c",
149 "gdtoa" OS_SEP "gmisc.c",
150 "gdtoa" OS_SEP "hd_init.c",
151 "gdtoa" OS_SEP "hexnan.c",
152 "gdtoa" OS_SEP "misc.c",
153 "gdtoa" OS_SEP "qnan.c",
154 "gdtoa" OS_SEP "smisc.c",
155 "gdtoa" OS_SEP "strtodg.c",
156 "gdtoa" OS_SEP "strtodnrp.c",
157 "gdtoa" OS_SEP "strtof.c",
158 "gdtoa" OS_SEP "strtopx.c",
159 "gdtoa" OS_SEP "sum.c",
160 "gdtoa" OS_SEP "ulp.c",
161 "math" OS_SEP "abs64.c",
162 "math" OS_SEP "cbrt.c",
163 "math" OS_SEP "cbrtf.c",
164 "math" OS_SEP "cbrtl.c",
165 "math" OS_SEP "cephes_emath.c",
166 "math" OS_SEP "copysign.c",
167 "math" OS_SEP "copysignf.c",
168 "math" OS_SEP "coshf.c",
169 "math" OS_SEP "coshl.c",
170 "math" OS_SEP "erfl.c",
171 "math" OS_SEP "expf.c",
172 "math" OS_SEP "fabs.c",
173 "math" OS_SEP "fabsf.c",
174 "math" OS_SEP "fabsl.c",
175 "math" OS_SEP "fdim.c",
176 "math" OS_SEP "fdimf.c",
177 "math" OS_SEP "fdiml.c",
178 "math" OS_SEP "fma.c",
179 "math" OS_SEP "fmaf.c",
180 "math" OS_SEP "fmal.c",
181 "math" OS_SEP "fmax.c",
182 "math" OS_SEP "fmaxf.c",
183 "math" OS_SEP "fmaxl.c",
184 "math" OS_SEP "fmin.c",
185 "math" OS_SEP "fminf.c",
186 "math" OS_SEP "fminl.c",
187 "math" OS_SEP "fp_consts.c",
188 "math" OS_SEP "fp_constsf.c",
189 "math" OS_SEP "fp_constsl.c",
190 "math" OS_SEP "fpclassify.c",
191 "math" OS_SEP "fpclassifyf.c",
192 "math" OS_SEP "fpclassifyl.c",
193 "math" OS_SEP "frexpf.c",
194 "math" OS_SEP "hypot.c",
195 "math" OS_SEP "hypotf.c",
196 "math" OS_SEP "hypotl.c",
197 "math" OS_SEP "isnan.c",
198 "math" OS_SEP "isnanf.c",
199 "math" OS_SEP "isnanl.c",
200 "math" OS_SEP "ldexpf.c",
201 "math" OS_SEP "lgamma.c",
202 "math" OS_SEP "lgammaf.c",
203 "math" OS_SEP "lgammal.c",
204 "math" OS_SEP "llrint.c",
205 "math" OS_SEP "llrintf.c",
206 "math" OS_SEP "llrintl.c",
207 "math" OS_SEP "llround.c",
208 "math" OS_SEP "llroundf.c",
209 "math" OS_SEP "llroundl.c",
210 "math" OS_SEP "log10f.c",
211 "math" OS_SEP "logf.c",
212 "math" OS_SEP "lrint.c",
213 "math" OS_SEP "lrintf.c",
214 "math" OS_SEP "lrintl.c",
215 "math" OS_SEP "lround.c",
216 "math" OS_SEP "lroundf.c",
217 "math" OS_SEP "lroundl.c",
218 "math" OS_SEP "modf.c",
219 "math" OS_SEP "modff.c",
220 "math" OS_SEP "modfl.c",
221 "math" OS_SEP "nextafterf.c",
222 "math" OS_SEP "nextafterl.c",
223 "math" OS_SEP "nexttoward.c",
224 "math" OS_SEP "nexttowardf.c",
225 "math" OS_SEP "powf.c",
226 "math" OS_SEP "powi.c",
227 "math" OS_SEP "powif.c",
228 "math" OS_SEP "powil.c",
229 "math" OS_SEP "rint.c",
230 "math" OS_SEP "rintf.c",
231 "math" OS_SEP "rintl.c",
232 "math" OS_SEP "round.c",
233 "math" OS_SEP "roundf.c",
234 "math" OS_SEP "roundl.c",
235 "math" OS_SEP "s_erf.c",
236 "math" OS_SEP "sf_erf.c",
237 "math" OS_SEP "signbit.c",
238 "math" OS_SEP "signbitf.c",
239 "math" OS_SEP "signbitl.c",
240 "math" OS_SEP "signgam.c",
241 "math" OS_SEP "sinhf.c",
242 "math" OS_SEP "sinhl.c",
243 "math" OS_SEP "sqrt.c",
244 "math" OS_SEP "sqrtf.c",
245 "math" OS_SEP "sqrtl.c",
246 "math" OS_SEP "tanhf.c",
247 "math" OS_SEP "tanhl.c",
248 "math" OS_SEP "tgamma.c",
249 "math" OS_SEP "tgammaf.c",
250 "math" OS_SEP "tgammal.c",
251 "math" OS_SEP "truncl.c",
252 "misc" OS_SEP "alarm.c",
253 "misc" OS_SEP "basename.c",
254 "misc" OS_SEP "btowc.c",
255 "misc" OS_SEP "delay-f.c",
256 "misc" OS_SEP "delay-n.c",
257 "misc" OS_SEP "delayimp.c",
258 "misc" OS_SEP "dirent.c",
259 "misc" OS_SEP "dirname.c",
260 "misc" OS_SEP "feclearexcept.c",
261 "misc" OS_SEP "fegetenv.c",
262 "misc" OS_SEP "fegetexceptflag.c",
263 "misc" OS_SEP "fegetround.c",
264 "misc" OS_SEP "feholdexcept.c",
265 "misc" OS_SEP "feraiseexcept.c",
266 "misc" OS_SEP "fesetenv.c",
267 "misc" OS_SEP "fesetexceptflag.c",
268 "misc" OS_SEP "fesetround.c",
269 "misc" OS_SEP "fetestexcept.c",
270 "misc" OS_SEP "feupdateenv.c",
271 "misc" OS_SEP "ftruncate.c",
272 "misc" OS_SEP "ftw.c",
273 "misc" OS_SEP "ftw64.c",
274 "misc" OS_SEP "fwide.c",
275 "misc" OS_SEP "getlogin.c",
276 "misc" OS_SEP "getopt.c",
277 "misc" OS_SEP "gettimeofday.c",
278 "misc" OS_SEP "imaxabs.c",
279 "misc" OS_SEP "imaxdiv.c",
280 "misc" OS_SEP "isblank.c",
281 "misc" OS_SEP "iswblank.c",
282 "misc" OS_SEP "mbrtowc.c",
283 "misc" OS_SEP "mbsinit.c",
284 "misc" OS_SEP "mempcpy.c",
285 "misc" OS_SEP "mingw-aligned-malloc.c",
286 "misc" OS_SEP "mingw-fseek.c",
287 "misc" OS_SEP "mingw_getsp.S",
288 "misc" OS_SEP "mingw_matherr.c",
289 "misc" OS_SEP "mingw_mbwc_convert.c",
290 "misc" OS_SEP "mingw_usleep.c",
291 "misc" OS_SEP "mingw_wcstod.c",
292 "misc" OS_SEP "mingw_wcstof.c",
293 "misc" OS_SEP "mingw_wcstold.c",
294 "misc" OS_SEP "mkstemp.c",
295 "misc" OS_SEP "seterrno.c",
296 "misc" OS_SEP "sleep.c",
297 "misc" OS_SEP "strnlen.c",
298 "misc" OS_SEP "strsafe.c",
299 "misc" OS_SEP "strtoimax.c",
300 "misc" OS_SEP "strtold.c",
301 "misc" OS_SEP "strtoumax.c",
302 "misc" OS_SEP "tdelete.c",
303 "misc" OS_SEP "tfind.c",
304 "misc" OS_SEP "tsearch.c",
305 "misc" OS_SEP "twalk.c",
306 "misc" OS_SEP "uchar_c16rtomb.c",
307 "misc" OS_SEP "uchar_c32rtomb.c",
308 "misc" OS_SEP "uchar_mbrtoc16.c",
309 "misc" OS_SEP "uchar_mbrtoc32.c",
310 "misc" OS_SEP "wassert.c",
311 "misc" OS_SEP "wcrtomb.c",
312 "misc" OS_SEP "wcsnlen.c",
313 "misc" OS_SEP "wcstof.c",
314 "misc" OS_SEP "wcstoimax.c",
315 "misc" OS_SEP "wcstold.c",
316 "misc" OS_SEP "wcstoumax.c",
317 "misc" OS_SEP "wctob.c",
318 "misc" OS_SEP "wctrans.c",
319 "misc" OS_SEP "wctype.c",
320 "misc" OS_SEP "wdirent.c",
321 "misc" OS_SEP "winbs_uint64.c",
322 "misc" OS_SEP "winbs_ulong.c",
323 "misc" OS_SEP "winbs_ushort.c",
324 "misc" OS_SEP "wmemchr.c",
325 "misc" OS_SEP "wmemcmp.c",
326 "misc" OS_SEP "wmemcpy.c",
327 "misc" OS_SEP "wmemmove.c",
328 "misc" OS_SEP "wmempcpy.c",
329 "misc" OS_SEP "wmemset.c",
330 "stdio" OS_SEP "_Exit.c",
331 "stdio" OS_SEP "_findfirst64i32.c",
332 "stdio" OS_SEP "_findnext64i32.c",
333 "stdio" OS_SEP "_fstat.c",
334 "stdio" OS_SEP "_fstat64i32.c",
335 "stdio" OS_SEP "_ftime.c",
336 "stdio" OS_SEP "_getc_nolock.c",
337 "stdio" OS_SEP "_getwc_nolock.c",
338 "stdio" OS_SEP "_putc_nolock.c",
339 "stdio" OS_SEP "_putwc_nolock.c",
340 "stdio" OS_SEP "_stat.c",
341 "stdio" OS_SEP "_stat64i32.c",
342 "stdio" OS_SEP "_wfindfirst64i32.c",
343 "stdio" OS_SEP "_wfindnext64i32.c",
344 "stdio" OS_SEP "_wstat.c",
345 "stdio" OS_SEP "_wstat64i32.c",
346 "stdio" OS_SEP "asprintf.c",
347 "stdio" OS_SEP "atoll.c",
348 "stdio" OS_SEP "fgetpos64.c",
349 "stdio" OS_SEP "fopen64.c",
350 "stdio" OS_SEP "fseeko32.c",
351 "stdio" OS_SEP "fseeko64.c",
352 "stdio" OS_SEP "fsetpos64.c",
353 "stdio" OS_SEP "ftello.c",
354 "stdio" OS_SEP "ftello64.c",
355 "stdio" OS_SEP "ftruncate64.c",
356 "stdio" OS_SEP "lltoa.c",
357 "stdio" OS_SEP "lltow.c",
358 "stdio" OS_SEP "lseek64.c",
359 "stdio" OS_SEP "mingw_asprintf.c",
360 "stdio" OS_SEP "mingw_fprintf.c",
361 "stdio" OS_SEP "mingw_fprintfw.c",
362 "stdio" OS_SEP "mingw_fscanf.c",
363 "stdio" OS_SEP "mingw_fwscanf.c",
364 "stdio" OS_SEP "mingw_pformat.c",
365 "stdio" OS_SEP "mingw_pformatw.c",
366 "stdio" OS_SEP "mingw_printf.c",
367 "stdio" OS_SEP "mingw_printfw.c",
368 "stdio" OS_SEP "mingw_scanf.c",
369 "stdio" OS_SEP "mingw_snprintf.c",
370 "stdio" OS_SEP "mingw_snprintfw.c",
371 "stdio" OS_SEP "mingw_sprintf.c",
372 "stdio" OS_SEP "mingw_sprintfw.c",
373 "stdio" OS_SEP "mingw_sscanf.c",
374 "stdio" OS_SEP "mingw_swscanf.c",
375 "stdio" OS_SEP "mingw_vasprintf.c",
376 "stdio" OS_SEP "mingw_vfprintf.c",
377 "stdio" OS_SEP "mingw_vfprintfw.c",
378 "stdio" OS_SEP "mingw_vfscanf.c",
379 "stdio" OS_SEP "mingw_vprintf.c",
380 "stdio" OS_SEP "mingw_vprintfw.c",
381 "stdio" OS_SEP "mingw_vsnprintf.c",
382 "stdio" OS_SEP "mingw_vsnprintfw.c",
383 "stdio" OS_SEP "mingw_vsprintf.c",
384 "stdio" OS_SEP "mingw_vsprintfw.c",
385 "stdio" OS_SEP "mingw_wscanf.c",
386 "stdio" OS_SEP "mingw_wvfscanf.c",
387 "stdio" OS_SEP "scanf.S",
388 "stdio" OS_SEP "snprintf.c",
389 "stdio" OS_SEP "snwprintf.c",
390 "stdio" OS_SEP "strtof.c",
391 "stdio" OS_SEP "strtok_r.c",
392 "stdio" OS_SEP "truncate.c",
393 "stdio" OS_SEP "ulltoa.c",
394 "stdio" OS_SEP "ulltow.c",
395 "stdio" OS_SEP "vasprintf.c",
396 "stdio" OS_SEP "vfscanf.c",
397 "stdio" OS_SEP "vfscanf2.S",
398 "stdio" OS_SEP "vfwscanf.c",
399 "stdio" OS_SEP "vfwscanf2.S",
400 "stdio" OS_SEP "vscanf.c",
401 "stdio" OS_SEP "vscanf2.S",
402 "stdio" OS_SEP "vsnprintf.c",
403 "stdio" OS_SEP "vsnwprintf.c",
404 "stdio" OS_SEP "vsscanf.c",
405 "stdio" OS_SEP "vsscanf2.S",
406 "stdio" OS_SEP "vswscanf.c",
407 "stdio" OS_SEP "vswscanf2.S",
408 "stdio" OS_SEP "vwscanf.c",
409 "stdio" OS_SEP "vwscanf2.S",
410 "stdio" OS_SEP "wtoll.c",
411};
412
413static const char *mingwex_x86_src[] = {
414 "math" OS_SEP "x86" OS_SEP "acosf.c",
415 "math" OS_SEP "x86" OS_SEP "acosh.c",
416 "math" OS_SEP "x86" OS_SEP "acoshf.c",
417 "math" OS_SEP "x86" OS_SEP "acoshl.c",
418 "math" OS_SEP "x86" OS_SEP "acosl.c",
419 "math" OS_SEP "x86" OS_SEP "asinf.c",
420 "math" OS_SEP "x86" OS_SEP "asinh.c",
421 "math" OS_SEP "x86" OS_SEP "asinhf.c",
422 "math" OS_SEP "x86" OS_SEP "asinhl.c",
423 "math" OS_SEP "x86" OS_SEP "asinl.c",
424 "math" OS_SEP "x86" OS_SEP "atan2.c",
425 "math" OS_SEP "x86" OS_SEP "atan2f.c",
426 "math" OS_SEP "x86" OS_SEP "atan2l.c",
427 "math" OS_SEP "x86" OS_SEP "atanf.c",
428 "math" OS_SEP "x86" OS_SEP "atanh.c",
429 "math" OS_SEP "x86" OS_SEP "atanhf.c",
430 "math" OS_SEP "x86" OS_SEP "atanhl.c",
431 "math" OS_SEP "x86" OS_SEP "atanl.c",
432 "math" OS_SEP "x86" OS_SEP "ceilf.S",
433 "math" OS_SEP "x86" OS_SEP "ceill.S",
434 "math" OS_SEP "x86" OS_SEP "ceil.S",
435 "math" OS_SEP "x86" OS_SEP "_chgsignl.S",
436 "math" OS_SEP "x86" OS_SEP "copysignl.S",
437 "math" OS_SEP "x86" OS_SEP "cos.c",
438 "math" OS_SEP "x86" OS_SEP "cosf.c",
439 "math" OS_SEP "x86" OS_SEP "cosl.c",
440 "math" OS_SEP "x86" OS_SEP "cosl_internal.S",
441 "math" OS_SEP "x86" OS_SEP "cossin.c",
442 "math" OS_SEP "x86" OS_SEP "exp2f.S",
443 "math" OS_SEP "x86" OS_SEP "exp2l.S",
444 "math" OS_SEP "x86" OS_SEP "exp2.S",
445 "math" OS_SEP "x86" OS_SEP "exp.c",
446 "math" OS_SEP "x86" OS_SEP "expl.c",
447 "math" OS_SEP "x86" OS_SEP "expm1.c",
448 "math" OS_SEP "x86" OS_SEP "expm1f.c",
449 "math" OS_SEP "x86" OS_SEP "expm1l.c",
450 "math" OS_SEP "x86" OS_SEP "floorf.S",
451 "math" OS_SEP "x86" OS_SEP "floorl.S",
452 "math" OS_SEP "x86" OS_SEP "floor.S",
453 "math" OS_SEP "x86" OS_SEP "fmod.c",
454 "math" OS_SEP "x86" OS_SEP "fmodf.c",
455 "math" OS_SEP "x86" OS_SEP "fmodl.c",
456 "math" OS_SEP "x86" OS_SEP "fucom.c",
457 "math" OS_SEP "x86" OS_SEP "ilogbf.S",
458 "math" OS_SEP "x86" OS_SEP "ilogbl.S",
459 "math" OS_SEP "x86" OS_SEP "ilogb.S",
460 "math" OS_SEP "x86" OS_SEP "internal_logl.S",
461 "math" OS_SEP "x86" OS_SEP "ldexp.c",
462 "math" OS_SEP "x86" OS_SEP "ldexpl.c",
463 "math" OS_SEP "x86" OS_SEP "log10l.S",
464 "math" OS_SEP "x86" OS_SEP "log1pf.S",
465 "math" OS_SEP "x86" OS_SEP "log1pl.S",
466 "math" OS_SEP "x86" OS_SEP "log1p.S",
467 "math" OS_SEP "x86" OS_SEP "log2f.S",
468 "math" OS_SEP "x86" OS_SEP "log2l.S",
469 "math" OS_SEP "x86" OS_SEP "log2.S",
470 "math" OS_SEP "x86" OS_SEP "logb.c",
471 "math" OS_SEP "x86" OS_SEP "logbf.c",
472 "math" OS_SEP "x86" OS_SEP "logbl.c",
473 "math" OS_SEP "x86" OS_SEP "log.c",
474 "math" OS_SEP "x86" OS_SEP "logl.c",
475 "math" OS_SEP "x86" OS_SEP "nearbyintf.S",
476 "math" OS_SEP "x86" OS_SEP "nearbyintl.S",
477 "math" OS_SEP "x86" OS_SEP "nearbyint.S",
478 "math" OS_SEP "x86" OS_SEP "pow.c",
479 "math" OS_SEP "x86" OS_SEP "powl.c",
480 "math" OS_SEP "x86" OS_SEP "remainderf.S",
481 "math" OS_SEP "x86" OS_SEP "remainderl.S",
482 "math" OS_SEP "x86" OS_SEP "remainder.S",
483 "math" OS_SEP "x86" OS_SEP "remquof.S",
484 "math" OS_SEP "x86" OS_SEP "remquol.S",
485 "math" OS_SEP "x86" OS_SEP "remquo.S",
486 "math" OS_SEP "x86" OS_SEP "scalbnf.S",
487 "math" OS_SEP "x86" OS_SEP "scalbnl.S",
488 "math" OS_SEP "x86" OS_SEP "scalbn.S",
489 "math" OS_SEP "x86" OS_SEP "sin.c",
490 "math" OS_SEP "x86" OS_SEP "sinf.c",
491 "math" OS_SEP "x86" OS_SEP "sinl.c",
492 "math" OS_SEP "x86" OS_SEP "sinl_internal.S",
493 "math" OS_SEP "x86" OS_SEP "tanf.c",
494 "math" OS_SEP "x86" OS_SEP "tanl.S",
495 "math" OS_SEP "x86" OS_SEP "truncf.S",
496 "math" OS_SEP "x86" OS_SEP "trunc.S",
497};
498
499static const char *mingwex_arm32_src[] = {
500 "math" OS_SEP "arm" OS_SEP "_chgsignl.S",
501 "math" OS_SEP "arm" OS_SEP "exp2.c",
502 "math" OS_SEP "arm" OS_SEP "nearbyint.S",
503 "math" OS_SEP "arm" OS_SEP "nearbyintf.S",
504 "math" OS_SEP "arm" OS_SEP "nearbyintl.S",
505 "math" OS_SEP "arm" OS_SEP "trunc.S",
506 "math" OS_SEP "arm" OS_SEP "truncf.S",
507};
508
509static const char *mingwex_arm64_src[] = {
510 "math" OS_SEP "arm64" OS_SEP "_chgsignl.S",
511 "math" OS_SEP "arm64" OS_SEP "exp2f.S",
512 "math" OS_SEP "arm64" OS_SEP "exp2.S",
513 "math" OS_SEP "arm64" OS_SEP "nearbyintf.S",
514 "math" OS_SEP "arm64" OS_SEP "nearbyintl.S",
515 "math" OS_SEP "arm64" OS_SEP "nearbyint.S",
516 "math" OS_SEP "arm64" OS_SEP "truncf.S",
517 "math" OS_SEP "arm64" OS_SEP "trunc.S",
518};
519
520static const char *mingw_uuid_src[] = {
521 "libsrc/ativscp-uuid.c",
522 "libsrc/atsmedia-uuid.c",
523 "libsrc/bth-uuid.c",
524 "libsrc/cguid-uuid.c",
525 "libsrc/comcat-uuid.c",
526 "libsrc/devguid.c",
527 "libsrc/docobj-uuid.c",
528 "libsrc/dxva-uuid.c",
529 "libsrc/exdisp-uuid.c",
530 "libsrc/extras-uuid.c",
531 "libsrc/fwp-uuid.c",
532 "libsrc/guid_nul.c",
533 "libsrc/hlguids-uuid.c",
534 "libsrc/hlink-uuid.c",
535 "libsrc/mlang-uuid.c",
536 "libsrc/msctf-uuid.c",
537 "libsrc/mshtmhst-uuid.c",
538 "libsrc/mshtml-uuid.c",
539 "libsrc/msxml-uuid.c",
540 "libsrc/netcon-uuid.c",
541 "libsrc/ntddkbd-uuid.c",
542 "libsrc/ntddmou-uuid.c",
543 "libsrc/ntddpar-uuid.c",
544 "libsrc/ntddscsi-uuid.c",
545 "libsrc/ntddser-uuid.c",
546 "libsrc/ntddstor-uuid.c",
547 "libsrc/ntddvdeo-uuid.c",
548 "libsrc/oaidl-uuid.c",
549 "libsrc/objidl-uuid.c",
550 "libsrc/objsafe-uuid.c",
551 "libsrc/ocidl-uuid.c",
552 "libsrc/oleacc-uuid.c",
553 "libsrc/olectlid-uuid.c",
554 "libsrc/oleidl-uuid.c",
555 "libsrc/power-uuid.c",
556 "libsrc/powrprof-uuid.c",
557 "libsrc/uianimation-uuid.c",
558 "libsrc/usbcamdi-uuid.c",
559 "libsrc/usbiodef-uuid.c",
560 "libsrc/uuid.c",
561 "libsrc/vds-uuid.c",
562 "libsrc/virtdisk-uuid.c",
563 "libsrc/wia-uuid.c",
564};
565
566struct MinGWDef {
567 const char *name;
568 bool always_link;
569};
570static const MinGWDef mingw_def_list[] = {
571 {"advapi32",true},
572 {"bcrypt", false},
573 {"comctl32",false},
574 {"comdlg32",false},
575 {"crypt32", false},
576 {"cryptnet",false},
577 {"gdi32", false},
578 {"imm32", false},
579 {"kernel32",true},
580 {"lz32", false},
581 {"mpr", false},
582 {"msvcrt", true},
583 {"mswsock", false},
584 {"ncrypt", false},
585 {"netapi32",false},
586 {"ntdll", true},
587 {"ole32", false},
588 {"oleaut32",false},
589 {"opengl32",false},
590 {"psapi", false},
591 {"rpcns4", false},
592 {"rpcrt4", false},
593 {"scarddlg",false},
594 {"setupapi",false},
595 {"shell32", true},
596 {"shlwapi", false},
597 {"urlmon", false},
598 {"user32", true},
599 {"version", false},
600 {"winmm", false},
601 {"winscard",false},
602 {"winspool",false},
603 {"wintrust",false},
604 {"ws2_32", false},
605};
606
607struct LinkJob {
608 CodeGen *codegen;
609 ZigList<const char *> args;
610 bool link_in_crt;
611 HashMap<Buf *, bool, buf_hash, buf_eql_buf> rpath_table;
612 Stage2ProgressNode *build_dep_prog_node;
613};
614
615static const char *build_libc_object(CodeGen *parent_gen, const char *name, CFile *c_file,
616 Stage2ProgressNode *progress_node)
617{
618 CodeGen *child_gen = create_child_codegen(parent_gen, nullptr, OutTypeObj, nullptr, name, progress_node);
619 child_gen->root_out_name = buf_create_from_str(name);
620 ZigList<CFile *> c_source_files = {0};
621 c_source_files.append(c_file);
622 child_gen->c_source_files = c_source_files;
623 codegen_build_and_link(child_gen);
624 return buf_ptr(&child_gen->bin_file_output_path);
625}
626
627static const char *path_from_zig_lib(CodeGen *g, const char *dir, const char *subpath) {
628 Buf *dir1 = buf_alloc();
629 os_path_join(g->zig_lib_dir, buf_create_from_str(dir), dir1);
630 Buf *result = buf_alloc();
631 os_path_join(dir1, buf_create_from_str(subpath), result);
632 return buf_ptr(result);
633}
634
635static const char *path_from_libc(CodeGen *g, const char *subpath) {
636 return path_from_zig_lib(g, "libc", subpath);
637}
638
639static const char *path_from_libunwind(CodeGen *g, const char *subpath) {
640 return path_from_zig_lib(g, "libunwind", subpath);
641}
642
643static const char *build_libunwind(CodeGen *parent, Stage2ProgressNode *progress_node) {
644 CodeGen *child_gen = create_child_codegen(parent, nullptr, OutTypeLib, nullptr, "unwind", progress_node);
645 LinkLib *new_link_lib = codegen_add_link_lib(child_gen, buf_create_from_str("c"));
646 new_link_lib->provided_explicitly = false;
647 enum SrcKind {
648 SrcCpp,
649 SrcC,
650 SrcAsm,
651 };
652 static const struct {
653 const char *path;
654 SrcKind kind;
655 } unwind_src[] = {
656 {"src" OS_SEP "libunwind.cpp", SrcCpp},
657 {"src" OS_SEP "Unwind-EHABI.cpp", SrcCpp},
658 {"src" OS_SEP "Unwind-seh.cpp", SrcCpp},
659
660 {"src" OS_SEP "UnwindLevel1.c", SrcC},
661 {"src" OS_SEP "UnwindLevel1-gcc-ext.c", SrcC},
662 {"src" OS_SEP "Unwind-sjlj.c", SrcC},
663
664 {"src" OS_SEP "UnwindRegistersRestore.S", SrcAsm},
665 {"src" OS_SEP "UnwindRegistersSave.S", SrcAsm},
666 };
667 ZigList<CFile *> c_source_files = {0};
668 for (size_t i = 0; i < array_length(unwind_src); i += 1) {
669 CFile *c_file = heap::c_allocator.create<CFile>();
670 c_file->source_path = path_from_libunwind(parent, unwind_src[i].path);
671 switch (unwind_src[i].kind) {
672 case SrcC:
673 c_file->args.append("-std=c99");
674 break;
675 case SrcCpp:
676 c_file->args.append("-fno-rtti");
677 c_file->args.append("-I");
678 c_file->args.append(path_from_zig_lib(parent, "libcxx", "include"));
679 break;
680 case SrcAsm:
681 break;
682 }
683 c_file->args.append("-I");
684 c_file->args.append(path_from_libunwind(parent, "include"));
685 if (target_supports_fpic(parent->zig_target)) {
686 c_file->args.append("-fPIC");
687 }
688 c_file->args.append("-D_LIBUNWIND_DISABLE_VISIBILITY_ANNOTATIONS");
689 c_file->args.append("-Wa,--noexecstack");
690
691 // This is intentionally always defined because the macro definition means, should it only
692 // build for the target specified by compiler defines. Since we pass -target the compiler
693 // defines will be correct.
694 c_file->args.append("-D_LIBUNWIND_IS_NATIVE_ONLY");
695
696 if (parent->build_mode == BuildModeDebug) {
697 c_file->args.append("-D_DEBUG");
698 }
699 if (parent->is_single_threaded) {
700 c_file->args.append("-D_LIBUNWIND_HAS_NO_THREADS");
701 }
702 c_file->args.append("-Wno-bitwise-conditional-parentheses");
703 c_source_files.append(c_file);
704 }
705 child_gen->c_source_files = c_source_files;
706 codegen_build_and_link(child_gen);
707 return buf_ptr(&child_gen->bin_file_output_path);
708}
709
710static void mingw_add_cc_args(CodeGen *parent, CFile *c_file) {
711 c_file->args.append("-DHAVE_CONFIG_H");
712
713 c_file->args.append("-I");
714 c_file->args.append(buf_ptr(buf_sprintf("%s" OS_SEP "libc" OS_SEP "mingw" OS_SEP "include",
715 buf_ptr(parent->zig_lib_dir))));
716
717 c_file->args.append("-isystem");
718 c_file->args.append(buf_ptr(buf_sprintf("%s" OS_SEP "libc" OS_SEP "include" OS_SEP "any-windows-any",
719 buf_ptr(parent->zig_lib_dir))));
720
721 if (target_is_arm(parent->zig_target) &&
722 target_arch_pointer_bit_width(parent->zig_target->arch) == 32)
723 {
724 c_file->args.append("-mfpu=vfp");
725 }
726
727 c_file->args.append("-std=gnu11");
728 c_file->args.append("-D_CRTBLD");
729 c_file->args.append("-D_WIN32_WINNT=0x0f00");
730 c_file->args.append("-D__MSVCRT_VERSION__=0x700");
731}
732
733static void glibc_add_include_dirs_arch(CFile *c_file, ZigLLVM_ArchType arch, const char *nptl, const char *dir) {
734 bool is_x86 = arch == ZigLLVM_x86 || arch == ZigLLVM_x86_64;
735 bool is_aarch64 = arch == ZigLLVM_aarch64 || arch == ZigLLVM_aarch64_be;
736 bool is_mips = arch == ZigLLVM_mips || arch == ZigLLVM_mipsel ||
737 arch == ZigLLVM_mips64el || arch == ZigLLVM_mips64;
738 bool is_arm = arch == ZigLLVM_arm || arch == ZigLLVM_armeb;
739 bool is_ppc = arch == ZigLLVM_ppc || arch == ZigLLVM_ppc64 || arch == ZigLLVM_ppc64le;
740 bool is_riscv = arch == ZigLLVM_riscv32 || arch == ZigLLVM_riscv64;
741 bool is_sparc = arch == ZigLLVM_sparc || arch == ZigLLVM_sparcel || arch == ZigLLVM_sparcv9;
742 bool is_64 = target_arch_pointer_bit_width(arch) == 64;
743
744 if (is_x86) {
745 if (arch == ZigLLVM_x86_64) {
746 if (nptl != nullptr) {
747 c_file->args.append("-I");
748 c_file->args.append(buf_ptr(buf_sprintf("%s" OS_SEP "x86_64" OS_SEP "%s", dir, nptl)));
749 } else {
750 c_file->args.append("-I");
751 c_file->args.append(buf_ptr(buf_sprintf("%s" OS_SEP "x86_64", dir)));
752 }
753 } else if (arch == ZigLLVM_x86) {
754 if (nptl != nullptr) {
755 c_file->args.append("-I");
756 c_file->args.append(buf_ptr(buf_sprintf("%s" OS_SEP "i386" OS_SEP "%s", dir, nptl)));
757 } else {
758 c_file->args.append("-I");
759 c_file->args.append(buf_ptr(buf_sprintf("%s" OS_SEP "i386", dir)));
760 }
761 }
762 if (nptl != nullptr) {
763 c_file->args.append("-I");
764 c_file->args.append(buf_ptr(buf_sprintf("%s" OS_SEP "x86" OS_SEP "%s", dir, nptl)));
765 } else {
766 c_file->args.append("-I");
767 c_file->args.append(buf_ptr(buf_sprintf("%s" OS_SEP "x86", dir)));
768 }
769 } else if (is_arm) {
770 if (nptl != nullptr) {
771 c_file->args.append("-I");
772 c_file->args.append(buf_ptr(buf_sprintf("%s" OS_SEP "arm" OS_SEP "%s", dir, nptl)));
773 } else {
774 c_file->args.append("-I");
775 c_file->args.append(buf_ptr(buf_sprintf("%s" OS_SEP "arm", dir)));
776 }
777 } else if (is_mips) {
778 if (nptl != nullptr) {
779 c_file->args.append("-I");
780 c_file->args.append(buf_ptr(buf_sprintf("%s" OS_SEP "mips" OS_SEP "%s", dir, nptl)));
781 } else {
782 if (is_64) {
783 c_file->args.append("-I");
784 c_file->args.append(buf_ptr(buf_sprintf("%s" OS_SEP "mips" OS_SEP "mips64", dir)));
785 } else {
786 c_file->args.append("-I");
787 c_file->args.append(buf_ptr(buf_sprintf("%s" OS_SEP "mips" OS_SEP "mips32", dir)));
788 }
789 c_file->args.append("-I");
790 c_file->args.append(buf_ptr(buf_sprintf("%s" OS_SEP "mips", dir)));
791 }
792 } else if (is_sparc) {
793 if (nptl != nullptr) {
794 c_file->args.append("-I");
795 c_file->args.append(buf_ptr(buf_sprintf("%s" OS_SEP "sparc" OS_SEP "%s", dir, nptl)));
796 } else {
797 if (is_64) {
798 c_file->args.append("-I");
799 c_file->args.append(buf_ptr(buf_sprintf("%s" OS_SEP "sparc" OS_SEP "sparc64", dir)));
800 } else {
801 c_file->args.append("-I");
802 c_file->args.append(buf_ptr(buf_sprintf("%s" OS_SEP "sparc" OS_SEP "sparc32", dir)));
803 }
804 c_file->args.append("-I");
805 c_file->args.append(buf_ptr(buf_sprintf("%s" OS_SEP "sparc", dir)));
806 }
807 } else if (is_aarch64) {
808 if (nptl != nullptr) {
809 c_file->args.append("-I");
810 c_file->args.append(buf_ptr(buf_sprintf("%s" OS_SEP "aarch64" OS_SEP "%s", dir, nptl)));
811 } else {
812 c_file->args.append("-I");
813 c_file->args.append(buf_ptr(buf_sprintf("%s" OS_SEP "aarch64", dir)));
814 }
815 } else if (is_ppc) {
816 if (nptl != nullptr) {
817 c_file->args.append("-I");
818 c_file->args.append(buf_ptr(buf_sprintf("%s" OS_SEP "powerpc" OS_SEP "%s", dir, nptl)));
819 } else {
820 if (is_64) {
821 c_file->args.append("-I");
822 c_file->args.append(buf_ptr(buf_sprintf("%s" OS_SEP "powerpc" OS_SEP "powerpc64", dir)));
823 } else {
824 c_file->args.append("-I");
825 c_file->args.append(buf_ptr(buf_sprintf("%s" OS_SEP "powerpc" OS_SEP "powerpc32", dir)));
826 }
827 c_file->args.append("-I");
828 c_file->args.append(buf_ptr(buf_sprintf("%s" OS_SEP "powerpc", dir)));
829 }
830 } else if (is_riscv) {
831 if (nptl != nullptr) {
832 c_file->args.append("-I");
833 c_file->args.append(buf_ptr(buf_sprintf("%s" OS_SEP "riscv" OS_SEP "%s", dir, nptl)));
834 } else {
835 c_file->args.append("-I");
836 c_file->args.append(buf_ptr(buf_sprintf("%s" OS_SEP "riscv", dir)));
837 }
838 }
839}
840
841static void glibc_add_include_dirs(CodeGen *parent, CFile *c_file) {
842 ZigLLVM_ArchType arch = parent->zig_target->arch;
843 const char *nptl = (parent->zig_target->os == OsLinux) ? "nptl" : "htl";
844 const char *glibc = path_from_libc(parent, "glibc");
845
846 c_file->args.append("-I");
847 c_file->args.append(buf_ptr(buf_sprintf("%s" OS_SEP "include", glibc)));
848
849 if (parent->zig_target->os == OsLinux) {
850 glibc_add_include_dirs_arch(c_file, arch, nullptr,
851 path_from_libc(parent, "glibc" OS_SEP "sysdeps" OS_SEP "unix" OS_SEP "sysv" OS_SEP "linux"));
852 }
853
854 if (nptl != nullptr) {
855 glibc_add_include_dirs_arch(c_file, arch, nptl, path_from_libc(parent, "glibc" OS_SEP "sysdeps"));
856 }
857
858 if (parent->zig_target->os == OsLinux) {
859 c_file->args.append("-I");
860 c_file->args.append(path_from_libc(parent, "glibc" OS_SEP "sysdeps" OS_SEP
861 "unix" OS_SEP "sysv" OS_SEP "linux" OS_SEP "generic"));
862
863 c_file->args.append("-I");
864 c_file->args.append(path_from_libc(parent, "glibc" OS_SEP "sysdeps" OS_SEP
865 "unix" OS_SEP "sysv" OS_SEP "linux" OS_SEP "include"));
866 c_file->args.append("-I");
867 c_file->args.append(path_from_libc(parent, "glibc" OS_SEP "sysdeps" OS_SEP
868 "unix" OS_SEP "sysv" OS_SEP "linux"));
869 }
870 if (nptl != nullptr) {
871 c_file->args.append("-I");
872 c_file->args.append(buf_ptr(buf_sprintf("%s" OS_SEP "sysdeps" OS_SEP "%s", glibc, nptl)));
873 }
874
875 c_file->args.append("-I");
876 c_file->args.append(path_from_libc(parent, "glibc" OS_SEP "sysdeps" OS_SEP "pthread"));
877
878 c_file->args.append("-I");
879 c_file->args.append(path_from_libc(parent, "glibc" OS_SEP "sysdeps" OS_SEP "unix" OS_SEP "sysv"));
880
881 glibc_add_include_dirs_arch(c_file, arch, nullptr,
882 path_from_libc(parent, "glibc" OS_SEP "sysdeps" OS_SEP "unix"));
883
884 c_file->args.append("-I");
885 c_file->args.append(path_from_libc(parent, "glibc" OS_SEP "sysdeps" OS_SEP "unix"));
886
887 glibc_add_include_dirs_arch(c_file, arch, nullptr, path_from_libc(parent, "glibc" OS_SEP "sysdeps"));
888
889 c_file->args.append("-I");
890 c_file->args.append(path_from_libc(parent, "glibc" OS_SEP "sysdeps" OS_SEP "generic"));
891
892 c_file->args.append("-I");
893 c_file->args.append(path_from_libc(parent, "glibc"));
894
895 c_file->args.append("-I");
896 c_file->args.append(buf_ptr(buf_sprintf("%s" OS_SEP "libc" OS_SEP "include" OS_SEP "%s-%s-%s",
897 buf_ptr(parent->zig_lib_dir), target_arch_name(parent->zig_target->arch),
898 target_os_name(parent->zig_target->os), target_abi_name(parent->zig_target->abi))));
899
900 c_file->args.append("-I");
901 c_file->args.append(path_from_libc(parent, "include" OS_SEP "generic-glibc"));
902
903 c_file->args.append("-I");
904 c_file->args.append(buf_ptr(buf_sprintf("%s" OS_SEP "libc" OS_SEP "include" OS_SEP "%s-linux-any",
905 buf_ptr(parent->zig_lib_dir), target_arch_name(parent->zig_target->arch))));
906
907 c_file->args.append("-I");
908 c_file->args.append(path_from_libc(parent, "include" OS_SEP "any-linux-any"));
909}
910
911static const char *glibc_start_asm_path(CodeGen *parent, const char *file) {
912 ZigLLVM_ArchType arch = parent->zig_target->arch;
913 bool is_aarch64 = arch == ZigLLVM_aarch64 || arch == ZigLLVM_aarch64_be;
914 bool is_mips = arch == ZigLLVM_mips || arch == ZigLLVM_mipsel ||
915 arch == ZigLLVM_mips64el || arch == ZigLLVM_mips64;
916 bool is_arm = arch == ZigLLVM_arm || arch == ZigLLVM_armeb;
917 bool is_ppc = arch == ZigLLVM_ppc || arch == ZigLLVM_ppc64 || arch == ZigLLVM_ppc64le;
918 bool is_riscv = arch == ZigLLVM_riscv32 || arch == ZigLLVM_riscv64;
919 bool is_sparc = arch == ZigLLVM_sparc || arch == ZigLLVM_sparcel || arch == ZigLLVM_sparcv9;
920 bool is_64 = target_arch_pointer_bit_width(arch) == 64;
921
922 Buf result = BUF_INIT;
923 buf_resize(&result, 0);
924 buf_append_buf(&result, parent->zig_lib_dir);
925 buf_append_str(&result, OS_SEP "libc" OS_SEP "glibc" OS_SEP "sysdeps" OS_SEP);
926 if (is_sparc) {
927 if (is_64) {
928 buf_append_str(&result, "sparc" OS_SEP "sparc64");
929 } else {
930 buf_append_str(&result, "sparc" OS_SEP "sparc32");
931 }
932 } else if (is_arm) {
933 buf_append_str(&result, "arm");
934 } else if (is_mips) {
935 buf_append_str(&result, "mips");
936 } else if (arch == ZigLLVM_x86_64) {
937 buf_append_str(&result, "x86_64");
938 } else if (arch == ZigLLVM_x86) {
939 buf_append_str(&result, "i386");
940 } else if (is_aarch64) {
941 buf_append_str(&result, "aarch64");
942 } else if (is_riscv) {
943 buf_append_str(&result, "riscv");
944 } else if (is_ppc) {
945 if (is_64) {
946 buf_append_str(&result, "powerpc" OS_SEP "powerpc64");
947 } else {
948 buf_append_str(&result, "powerpc" OS_SEP "powerpc32");
949 }
950 }
951
952 buf_append_str(&result, OS_SEP);
953 buf_append_str(&result, file);
954 return buf_ptr(&result);
955}
956
957static const char *musl_start_asm_path(CodeGen *parent, const char *file) {
958 Buf *result = buf_sprintf("%s" OS_SEP "libc" OS_SEP "musl" OS_SEP "crt" OS_SEP "%s" OS_SEP "%s",
959 buf_ptr(parent->zig_lib_dir), target_arch_musl_name(parent->zig_target->arch), file);
960 return buf_ptr(result);
961}
962
963static void musl_add_cc_args(CodeGen *parent, CFile *c_file, bool want_O3) {
964 c_file->args.append("-std=c99");
965 c_file->args.append("-ffreestanding");
966 // Musl adds these args to builds with gcc but clang does not support them.
967 //c_file->args.append("-fexcess-precision=standard");
968 //c_file->args.append("-frounding-math");
969 c_file->args.append("-Wa,--noexecstack");
970 c_file->args.append("-D_XOPEN_SOURCE=700");
971
972 c_file->args.append("-I");
973 c_file->args.append(buf_ptr(buf_sprintf("%s" OS_SEP "libc" OS_SEP "musl" OS_SEP "arch" OS_SEP "%s",
974 buf_ptr(parent->zig_lib_dir), target_arch_musl_name(parent->zig_target->arch))));
975
976 c_file->args.append("-I");
977 c_file->args.append(buf_ptr(buf_sprintf("%s" OS_SEP "libc" OS_SEP "musl" OS_SEP "arch" OS_SEP "generic",
978 buf_ptr(parent->zig_lib_dir))));
979
980 c_file->args.append("-I");
981 c_file->args.append(buf_ptr(buf_sprintf("%s" OS_SEP "libc" OS_SEP "musl" OS_SEP "src" OS_SEP "include",
982 buf_ptr(parent->zig_lib_dir))));
983
984 c_file->args.append("-I");
985 c_file->args.append(buf_ptr(buf_sprintf("%s" OS_SEP "libc" OS_SEP "musl" OS_SEP "src" OS_SEP "internal",
986 buf_ptr(parent->zig_lib_dir))));
987
988 c_file->args.append("-I");
989 c_file->args.append(buf_ptr(buf_sprintf("%s" OS_SEP "libc" OS_SEP "musl" OS_SEP "include",
990 buf_ptr(parent->zig_lib_dir))));
991
992 c_file->args.append("-I");
993 c_file->args.append(buf_ptr(buf_sprintf(
994 "%s" OS_SEP "libc" OS_SEP "include" OS_SEP "%s-%s-musl",
995 buf_ptr(parent->zig_lib_dir),
996 target_arch_musl_name(parent->zig_target->arch),
997 target_os_name(parent->zig_target->os))));
998
999 c_file->args.append("-I");
1000 c_file->args.append(buf_ptr(buf_sprintf("%s" OS_SEP "libc" OS_SEP "include" OS_SEP "generic-musl",
1001 buf_ptr(parent->zig_lib_dir))));
1002
1003 if (want_O3)
1004 c_file->args.append("-O3");
1005 else
1006 c_file->args.append("-Os");
1007
1008 c_file->args.append("-fomit-frame-pointer");
1009 c_file->args.append("-fno-unwind-tables");
1010 c_file->args.append("-fno-asynchronous-unwind-tables");
1011 c_file->args.append("-ffunction-sections");
1012 c_file->args.append("-fdata-sections");
1013}
1014
1015static const char *musl_arch_names[] = {
1016 "aarch64",
1017 "arm",
1018 "generic",
1019 "i386",
1020 "m68k",
1021 "microblaze",
1022 "mips",
1023 "mips64",
1024 "mipsn32",
1025 "or1k",
1026 "powerpc",
1027 "powerpc64",
1028 "riscv64",
1029 "s390x",
1030 "sh",
1031 "x32",
1032 "x86_64",
1033};
1034
1035static bool is_musl_arch_name(const char *name) {
1036 for (size_t i = 0; i < array_length(musl_arch_names); i += 1) {
1037 if (strcmp(name, musl_arch_names[i]) == 0)
1038 return true;
1039 }
1040 return false;
1041}
1042
1043enum MuslSrc {
1044 MuslSrcAsm,
1045 MuslSrcNormal,
1046 MuslSrcO3,
1047};
1048
1049static void add_musl_src_file(HashMap<Buf *, MuslSrc, buf_hash, buf_eql_buf> &source_table,
1050 const char *file_path)
1051{
1052 Buf *src_file = buf_create_from_str(file_path);
1053
1054 MuslSrc src_kind;
1055 if (buf_ends_with_str(src_file, ".c")) {
1056 bool want_O3 = buf_starts_with_str(src_file, "musl/src/malloc/") ||
1057 buf_starts_with_str(src_file, "musl/src/string/") ||
1058 buf_starts_with_str(src_file, "musl/src/internal/");
1059 src_kind = want_O3 ? MuslSrcO3 : MuslSrcNormal;
1060 } else if (buf_ends_with_str(src_file, ".s") || buf_ends_with_str(src_file, ".S")) {
1061 src_kind = MuslSrcAsm;
1062 } else {
1063 zig_unreachable();
1064 }
1065 if (ZIG_OS_SEP_CHAR != '/') {
1066 buf_replace(src_file, '/', ZIG_OS_SEP_CHAR);
1067 }
1068 source_table.put_unique(src_file, src_kind);
1069}
1070
1071static const char *build_musl(CodeGen *parent, Stage2ProgressNode *progress_node) {
1072 CodeGen *child_gen = create_child_codegen(parent, nullptr, OutTypeLib, nullptr, "c", progress_node);
1073
1074 // When there is a src/<arch>/foo.* then it should substitute for src/foo.*
1075 // Even a .s file can substitute for a .c file.
1076
1077 const char *target_musl_arch_name = target_arch_musl_name(parent->zig_target->arch);
1078
1079 HashMap<Buf *, MuslSrc, buf_hash, buf_eql_buf> source_table = {};
1080 source_table.init(2000);
1081
1082 for (size_t i = 0; i < array_length(ZIG_MUSL_SRC_FILES); i += 1) {
1083 add_musl_src_file(source_table, ZIG_MUSL_SRC_FILES[i]);
1084 }
1085
1086 static const char *time32_compat_arch_list[] = {"arm", "i386", "mips", "powerpc"};
1087 for (size_t arch_i = 0; arch_i < array_length(time32_compat_arch_list); arch_i += 1) {
1088 if (strcmp(target_musl_arch_name, time32_compat_arch_list[arch_i]) == 0) {
1089 for (size_t i = 0; i < array_length(ZIG_MUSL_COMPAT_TIME32_FILES); i += 1) {
1090 add_musl_src_file(source_table, ZIG_MUSL_COMPAT_TIME32_FILES[i]);
1091 }
1092 }
1093 }
1094
1095
1096 ZigList<CFile *> c_source_files = {0};
1097
1098 Buf dirname = BUF_INIT;
1099 Buf basename = BUF_INIT;
1100 Buf noextbasename = BUF_INIT;
1101 Buf dirbasename = BUF_INIT;
1102 Buf before_arch_dir = BUF_INIT;
1103
1104 auto source_it = source_table.entry_iterator();
1105 for (;;) {
1106 auto *entry = source_it.next();
1107 if (!entry) break;
1108
1109 Buf *src_file = entry->key;
1110 MuslSrc src_kind = entry->value;
1111
1112 os_path_split(src_file, &dirname, &basename);
1113 os_path_extname(&basename, &noextbasename, nullptr);
1114 os_path_split(&dirname, &before_arch_dir, &dirbasename);
1115
1116 bool is_arch_specific = false;
1117 // Architecture-specific implementations are under a <arch>/ folder.
1118 if (is_musl_arch_name(buf_ptr(&dirbasename))) {
1119 // Not the architecture we're compiling for.
1120 if (strcmp(buf_ptr(&dirbasename), target_musl_arch_name) != 0)
1121 continue;
1122 is_arch_specific = true;
1123 }
1124
1125 if (!is_arch_specific) {
1126 Buf override_path = BUF_INIT;
1127
1128 // Look for an arch specific override.
1129 buf_resize(&override_path, 0);
1130 buf_appendf(&override_path, "%s" OS_SEP "%s" OS_SEP "%s.s",
1131 buf_ptr(&dirname), target_musl_arch_name, buf_ptr(&noextbasename));
1132 if (source_table.maybe_get(&override_path) != nullptr)
1133 continue;
1134
1135 buf_resize(&override_path, 0);
1136 buf_appendf(&override_path, "%s" OS_SEP "%s" OS_SEP "%s.S",
1137 buf_ptr(&dirname), target_musl_arch_name, buf_ptr(&noextbasename));
1138 if (source_table.maybe_get(&override_path) != nullptr)
1139 continue;
1140
1141 buf_resize(&override_path, 0);
1142 buf_appendf(&override_path, "%s" OS_SEP "%s" OS_SEP "%s.c",
1143 buf_ptr(&dirname), target_musl_arch_name, buf_ptr(&noextbasename));
1144 if (source_table.maybe_get(&override_path) != nullptr)
1145 continue;
1146 }
1147
1148 Buf *full_path = buf_sprintf("%s" OS_SEP "libc" OS_SEP "%s",
1149 buf_ptr(parent->zig_lib_dir), buf_ptr(src_file));
1150
1151 CFile *c_file = heap::c_allocator.create<CFile>();
1152 c_file->source_path = buf_ptr(full_path);
1153
1154 musl_add_cc_args(parent, c_file, src_kind == MuslSrcO3);
1155 c_file->args.append("-Qunused-arguments");
1156 c_file->args.append("-w"); // disable all warnings
1157
1158 c_source_files.append(c_file);
1159 }
1160
1161 child_gen->c_source_files = c_source_files;
1162 codegen_build_and_link(child_gen);
1163 return buf_ptr(&child_gen->bin_file_output_path);
1164}
1165
1166static const char *build_libcxxabi(CodeGen *parent, Stage2ProgressNode *progress_node) {
1167 CodeGen *child_gen = create_child_codegen(parent, nullptr, OutTypeLib, nullptr, "c++abi", progress_node);
1168 codegen_add_link_lib(child_gen, buf_create_from_str("c"));
1169
1170 ZigList<CFile *> c_source_files = {0};
1171
1172 const char *cxxabi_include_path = buf_ptr(buf_sprintf("%s" OS_SEP "libcxxabi" OS_SEP "include",
1173 buf_ptr(parent->zig_lib_dir)));
1174 const char *cxx_include_path = buf_ptr(buf_sprintf("%s" OS_SEP "libcxx" OS_SEP "include",
1175 buf_ptr(parent->zig_lib_dir)));
1176
1177 for (size_t i = 0; i < array_length(ZIG_LIBCXXABI_FILES); i += 1) {
1178 const char *rel_src_path = ZIG_LIBCXXABI_FILES[i];
1179
1180 CFile *c_file = heap::c_allocator.create<CFile>();
1181 c_file->source_path = buf_ptr(buf_sprintf("%s" OS_SEP "libcxxabi" OS_SEP "%s",
1182 buf_ptr(parent->zig_lib_dir), rel_src_path));
1183
1184 c_file->args.append("-DHAVE___CXA_THREAD_ATEXIT_IMPL");
1185 c_file->args.append("-D_LIBCPP_DISABLE_EXTERN_TEMPLATE");
1186 c_file->args.append("-D_LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS");
1187 c_file->args.append("-D_LIBCXXABI_BUILDING_LIBRARY");
1188 c_file->args.append("-D_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS");
1189 c_file->args.append("-D_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS");
1190
1191 if (target_abi_is_musl(parent->zig_target->abi)) {
1192 c_file->args.append("-D_LIBCPP_HAS_MUSL_LIBC");
1193 }
1194
1195 c_file->args.append("-I");
1196 c_file->args.append(cxxabi_include_path);
1197
1198 c_file->args.append("-I");
1199 c_file->args.append(cxx_include_path);
1200
1201 c_file->args.append("-O3");
1202 c_file->args.append("-DNDEBUG");
1203 if (target_supports_fpic(parent->zig_target)) {
1204 c_file->args.append("-fPIC");
1205 }
1206 c_file->args.append("-nostdinc++");
1207 c_file->args.append("-fstrict-aliasing");
1208 c_file->args.append("-funwind-tables");
1209 c_file->args.append("-D_DEBUG");
1210 c_file->args.append("-UNDEBUG");
1211 c_file->args.append("-std=c++11");
1212
1213 c_source_files.append(c_file);
1214 }
1215
1216
1217 child_gen->c_source_files = c_source_files;
1218 codegen_build_and_link(child_gen);
1219 return buf_ptr(&child_gen->bin_file_output_path);
1220}
1221
1222static const char *build_libcxx(CodeGen *parent, Stage2ProgressNode *progress_node) {
1223 CodeGen *child_gen = create_child_codegen(parent, nullptr, OutTypeLib, nullptr, "c++", progress_node);
1224 codegen_add_link_lib(child_gen, buf_create_from_str("c"));
1225
1226 ZigList<CFile *> c_source_files = {0};
1227
1228 const char *cxxabi_include_path = buf_ptr(buf_sprintf("%s" OS_SEP "libcxxabi" OS_SEP "include",
1229 buf_ptr(parent->zig_lib_dir)));
1230 const char *cxx_include_path = buf_ptr(buf_sprintf("%s" OS_SEP "libcxx" OS_SEP "include",
1231 buf_ptr(parent->zig_lib_dir)));
1232
1233 for (size_t i = 0; i < array_length(ZIG_LIBCXX_FILES); i += 1) {
1234 const char *rel_src_path = ZIG_LIBCXX_FILES[i];
1235
1236 Buf *src_path_buf = buf_create_from_str(rel_src_path);
1237 if (parent->zig_target->os == OsWindows) {
1238 // filesystem stuff isn't supported on Windows
1239 if (buf_starts_with_str(src_path_buf, "src/filesystem/")) {
1240 continue;
1241 }
1242 } else {
1243 if (buf_starts_with_str(src_path_buf, "src/support/win32/")) {
1244 continue;
1245 }
1246 }
1247
1248 CFile *c_file = heap::c_allocator.create<CFile>();
1249 c_file->source_path = buf_ptr(buf_sprintf("%s" OS_SEP "libcxx" OS_SEP "%s",
1250 buf_ptr(parent->zig_lib_dir), rel_src_path));
1251
1252 c_file->args.append("-DNDEBUG");
1253 c_file->args.append("-D_LIBCPP_BUILDING_LIBRARY");
1254 c_file->args.append("-D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER");
1255 c_file->args.append("-DLIBCXX_BUILDING_LIBCXXABI");
1256 c_file->args.append("-D_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS");
1257 c_file->args.append("-D_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS");
1258
1259 if (target_abi_is_musl(parent->zig_target->abi)) {
1260 c_file->args.append("-D_LIBCPP_HAS_MUSL_LIBC");
1261 }
1262
1263 c_file->args.append("-I");
1264 c_file->args.append(cxx_include_path);
1265
1266 c_file->args.append("-I");
1267 c_file->args.append(cxxabi_include_path);
1268
1269 c_file->args.append("-O3");
1270 c_file->args.append("-DNDEBUG");
1271 if (target_supports_fpic(parent->zig_target)) {
1272 c_file->args.append("-fPIC");
1273 }
1274 c_file->args.append("-nostdinc++");
1275 c_file->args.append("-fvisibility-inlines-hidden");
1276 c_file->args.append("-std=c++14");
1277 c_file->args.append("-Wno-user-defined-literals");
1278
1279 c_source_files.append(c_file);
1280 }
1281
1282
1283 child_gen->c_source_files = c_source_files;
1284 codegen_build_and_link(child_gen);
1285 return buf_ptr(&child_gen->bin_file_output_path);
1286}
1287
1288static void add_msvcrt_os_dep(CodeGen *parent, CodeGen *child_gen, const char *src_path) {
1289 CFile *c_file = heap::c_allocator.create<CFile>();
1290 c_file->source_path = buf_ptr(buf_sprintf("%s" OS_SEP "libc" OS_SEP "mingw" OS_SEP "%s",
1291 buf_ptr(parent->zig_lib_dir), src_path));
1292 c_file->args.append("-DHAVE_CONFIG_H");
1293 c_file->args.append("-D__LIBMSVCRT__");
1294
1295 c_file->args.append("-I");
1296 c_file->args.append(path_from_libc(parent, "mingw" OS_SEP "include"));
1297
1298 c_file->args.append("-std=gnu99");
1299 c_file->args.append("-D_CRTBLD");
1300 c_file->args.append("-D_WIN32_WINNT=0x0f00");
1301 c_file->args.append("-D__MSVCRT_VERSION__=0x700");
1302
1303 c_file->args.append("-isystem");
1304 c_file->args.append(path_from_libc(parent, "include" OS_SEP "any-windows-any"));
1305
1306 c_file->args.append("-g");
1307 c_file->args.append("-O2");
1308
1309 child_gen->c_source_files.append(c_file);
1310}
1311
1312static void add_mingwex_dep(CodeGen *parent, CodeGen *child_gen, const char *src_path) {
1313 CFile *c_file = heap::c_allocator.create<CFile>();
1314 c_file->source_path = buf_ptr(buf_sprintf("%s" OS_SEP "libc" OS_SEP "mingw" OS_SEP "%s",
1315 buf_ptr(parent->zig_lib_dir), src_path));
1316 c_file->args.append("-DHAVE_CONFIG_H");
1317
1318 c_file->args.append("-I");
1319 c_file->args.append(path_from_libc(parent, "mingw"));
1320
1321 c_file->args.append("-I");
1322 c_file->args.append(path_from_libc(parent, "mingw" OS_SEP "include"));
1323
1324 c_file->args.append("-std=gnu99");
1325 c_file->args.append("-D_CRTBLD");
1326 c_file->args.append("-D_WIN32_WINNT=0x0f00");
1327 c_file->args.append("-D__MSVCRT_VERSION__=0x700");
1328 c_file->args.append("-g");
1329 c_file->args.append("-O2");
1330
1331 c_file->args.append("-isystem");
1332 c_file->args.append(path_from_libc(parent, "include" OS_SEP "any-windows-any"));
1333
1334 child_gen->c_source_files.append(c_file);
1335}
1336
1337static void add_mingw_uuid_dep(CodeGen *parent, CodeGen *child_gen, const char *src_path) {
1338 CFile *c_file = heap::c_allocator.create<CFile>();
1339 c_file->source_path = buf_ptr(buf_sprintf("%s" OS_SEP "libc" OS_SEP "mingw" OS_SEP "%s",
1340 buf_ptr(parent->zig_lib_dir), src_path));
1341 c_file->args.append("-DHAVE_CONFIG_H");
1342
1343 c_file->args.append("-I");
1344 c_file->args.append(path_from_libc(parent, "mingw"));
1345
1346 c_file->args.append("-I");
1347 c_file->args.append(path_from_libc(parent, "mingw" OS_SEP "include"));
1348
1349 c_file->args.append("-std=gnu99");
1350 c_file->args.append("-D_CRTBLD");
1351 c_file->args.append("-D_WIN32_WINNT=0x0f00");
1352 c_file->args.append("-D__MSVCRT_VERSION__=0x700");
1353 c_file->args.append("-g");
1354 c_file->args.append("-O2");
1355
1356 c_file->args.append("-isystem");
1357 c_file->args.append(path_from_libc(parent, "include" OS_SEP "any-windows-any"));
1358
1359 child_gen->c_source_files.append(c_file);
1360}
1361
1362static const char *get_libc_crt_file(CodeGen *parent, const char *file, Stage2ProgressNode *progress_node) {
1363 if (parent->libc == nullptr && parent->zig_target->os == OsWindows) {
1364 if (strcmp(file, "crt2.o") == 0) {
1365 CFile *c_file = heap::c_allocator.create<CFile>();
1366 c_file->source_path = buf_ptr(buf_sprintf(
1367 "%s" OS_SEP "libc" OS_SEP "mingw" OS_SEP "crt" OS_SEP "crtexe.c", buf_ptr(parent->zig_lib_dir)));
1368 mingw_add_cc_args(parent, c_file);
1369 c_file->args.append("-U__CRTDLL__");
1370 c_file->args.append("-D__MSVCRT__");
1371 // Uncomment these 3 things for crtu
1372 //c_file->args.append("-DUNICODE");
1373 //c_file->args.append("-D_UNICODE");
1374 //c_file->args.append("-DWPRFLAG=1");
1375 return build_libc_object(parent, "crt2", c_file, progress_node);
1376 } else if (strcmp(file, "dllcrt2.o") == 0) {
1377 CFile *c_file = heap::c_allocator.create<CFile>();
1378 c_file->source_path = buf_ptr(buf_sprintf(
1379 "%s" OS_SEP "libc" OS_SEP "mingw" OS_SEP "crt" OS_SEP "crtdll.c", buf_ptr(parent->zig_lib_dir)));
1380 mingw_add_cc_args(parent, c_file);
1381 c_file->args.append("-U__CRTDLL__");
1382 c_file->args.append("-D__MSVCRT__");
1383 return build_libc_object(parent, "dllcrt2", c_file, progress_node);
1384 } else if (strcmp(file, "mingw32.lib") == 0) {
1385 CodeGen *child_gen = create_child_codegen(parent, nullptr, OutTypeLib, nullptr, "mingw32", progress_node);
1386
1387 static const char *deps[] = {
1388 "mingw" OS_SEP "crt" OS_SEP "crt0_c.c",
1389 "mingw" OS_SEP "crt" OS_SEP "dll_argv.c",
1390 "mingw" OS_SEP "crt" OS_SEP "gccmain.c",
1391 "mingw" OS_SEP "crt" OS_SEP "natstart.c",
1392 "mingw" OS_SEP "crt" OS_SEP "pseudo-reloc-list.c",
1393 "mingw" OS_SEP "crt" OS_SEP "wildcard.c",
1394 "mingw" OS_SEP "crt" OS_SEP "charmax.c",
1395 "mingw" OS_SEP "crt" OS_SEP "crt0_w.c",
1396 "mingw" OS_SEP "crt" OS_SEP "dllargv.c",
1397 "mingw" OS_SEP "crt" OS_SEP "gs_support.c",
1398 "mingw" OS_SEP "crt" OS_SEP "_newmode.c",
1399 "mingw" OS_SEP "crt" OS_SEP "tlssup.c",
1400 "mingw" OS_SEP "crt" OS_SEP "xncommod.c",
1401 "mingw" OS_SEP "crt" OS_SEP "cinitexe.c",
1402 "mingw" OS_SEP "crt" OS_SEP "merr.c",
1403 "mingw" OS_SEP "crt" OS_SEP "usermatherr.c",
1404 "mingw" OS_SEP "crt" OS_SEP "pesect.c",
1405 "mingw" OS_SEP "crt" OS_SEP "udllargc.c",
1406 "mingw" OS_SEP "crt" OS_SEP "xthdloc.c",
1407 "mingw" OS_SEP "crt" OS_SEP "CRT_fp10.c",
1408 "mingw" OS_SEP "crt" OS_SEP "mingw_helpers.c",
1409 "mingw" OS_SEP "crt" OS_SEP "pseudo-reloc.c",
1410 "mingw" OS_SEP "crt" OS_SEP "udll_argv.c",
1411 "mingw" OS_SEP "crt" OS_SEP "xtxtmode.c",
1412 "mingw" OS_SEP "crt" OS_SEP "crt_handler.c",
1413 "mingw" OS_SEP "crt" OS_SEP "tlsthrd.c",
1414 "mingw" OS_SEP "crt" OS_SEP "tlsmthread.c",
1415 "mingw" OS_SEP "crt" OS_SEP "tlsmcrt.c",
1416 "mingw" OS_SEP "crt" OS_SEP "cxa_atexit.c",
1417 };
1418 for (size_t i = 0; i < array_length(deps); i += 1) {
1419 CFile *c_file = heap::c_allocator.create<CFile>();
1420 c_file->source_path = path_from_libc(parent, deps[i]);
1421 c_file->args.append("-DHAVE_CONFIG_H");
1422 c_file->args.append("-D_SYSCRT=1");
1423 c_file->args.append("-DCRTDLL=1");
1424
1425 c_file->args.append("-isystem");
1426 c_file->args.append(path_from_libc(parent, "include" OS_SEP "any-windows-any"));
1427
1428 c_file->args.append("-isystem");
1429 c_file->args.append(path_from_libc(parent, "mingw" OS_SEP "include"));
1430
1431 c_file->args.append("-std=gnu99");
1432 c_file->args.append("-D_CRTBLD");
1433 c_file->args.append("-D_WIN32_WINNT=0x0f00");
1434 c_file->args.append("-D__MSVCRT_VERSION__=0x700");
1435 c_file->args.append("-g");
1436 c_file->args.append("-O2");
1437
1438 child_gen->c_source_files.append(c_file);
1439 }
1440 codegen_build_and_link(child_gen);
1441 return buf_ptr(&child_gen->bin_file_output_path);
1442 } else if (strcmp(file, "msvcrt-os.lib") == 0) {
1443 CodeGen *child_gen = create_child_codegen(parent, nullptr, OutTypeLib, nullptr, "msvcrt-os", progress_node);
1444
1445 for (size_t i = 0; i < array_length(msvcrt_common_src); i += 1) {
1446 add_msvcrt_os_dep(parent, child_gen, msvcrt_common_src[i]);
1447 }
1448 if (parent->zig_target->arch == ZigLLVM_x86) {
1449 for (size_t i = 0; i < array_length(msvcrt_i386_src); i += 1) {
1450 add_msvcrt_os_dep(parent, child_gen, msvcrt_i386_src[i]);
1451 }
1452 } else {
1453 for (size_t i = 0; i < array_length(msvcrt_other_src); i += 1) {
1454 add_msvcrt_os_dep(parent, child_gen, msvcrt_other_src[i]);
1455 }
1456 }
1457 codegen_build_and_link(child_gen);
1458 return buf_ptr(&child_gen->bin_file_output_path);
1459 } else if (strcmp(file, "mingwex.lib") == 0) {
1460 CodeGen *child_gen = create_child_codegen(parent, nullptr, OutTypeLib, nullptr, "mingwex", progress_node);
1461
1462 for (size_t i = 0; i < array_length(mingwex_generic_src); i += 1) {
1463 add_mingwex_dep(parent, child_gen, mingwex_generic_src[i]);
1464 }
1465 if (parent->zig_target->arch == ZigLLVM_x86 || parent->zig_target->arch == ZigLLVM_x86_64) {
1466 for (size_t i = 0; i < array_length(mingwex_x86_src); i += 1) {
1467 add_mingwex_dep(parent, child_gen, mingwex_x86_src[i]);
1468 }
1469 } else if (target_is_arm(parent->zig_target)) {
1470 if (target_arch_pointer_bit_width(parent->zig_target->arch) == 32) {
1471 for (size_t i = 0; i < array_length(mingwex_arm32_src); i += 1) {
1472 add_mingwex_dep(parent, child_gen, mingwex_arm32_src[i]);
1473 }
1474 } else {
1475 for (size_t i = 0; i < array_length(mingwex_arm64_src); i += 1) {
1476 add_mingwex_dep(parent, child_gen, mingwex_arm64_src[i]);
1477 }
1478 }
1479 } else {
1480 zig_unreachable();
1481 }
1482 codegen_build_and_link(child_gen);
1483 return buf_ptr(&child_gen->bin_file_output_path);
1484 } else if (strcmp(file, "uuid.lib") == 0) {
1485 CodeGen *child_gen = create_child_codegen(parent, nullptr, OutTypeLib, nullptr, "uuid", progress_node);
1486 for (size_t i = 0; i < array_length(mingw_uuid_src); i += 1) {
1487 add_mingw_uuid_dep(parent, child_gen, mingw_uuid_src[i]);
1488 }
1489 codegen_build_and_link(child_gen);
1490 return buf_ptr(&child_gen->bin_file_output_path);
1491 } else {
1492 zig_unreachable();
1493 }
1494 } else if (parent->libc == nullptr && target_is_glibc(parent->zig_target)) {
1495 if (strcmp(file, "crti.o") == 0) {
1496 CFile *c_file = heap::c_allocator.create<CFile>();
1497 c_file->source_path = glibc_start_asm_path(parent, "crti.S");
1498 glibc_add_include_dirs(parent, c_file);
1499 c_file->args.append("-D_LIBC_REENTRANT");
1500 c_file->args.append("-include");
1501 c_file->args.append(path_from_libc(parent, "glibc" OS_SEP "include" OS_SEP "libc-modules.h"));
1502 c_file->args.append("-DMODULE_NAME=libc");
1503 c_file->args.append("-Wno-nonportable-include-path");
1504 c_file->args.append("-include");
1505 c_file->args.append(path_from_libc(parent, "glibc" OS_SEP "include" OS_SEP "libc-symbols.h"));
1506 c_file->args.append("-DTOP_NAMESPACE=glibc");
1507 c_file->args.append("-DASSEMBLER");
1508 c_file->args.append("-g");
1509 c_file->args.append("-Wa,--noexecstack");
1510 return build_libc_object(parent, "crti", c_file, progress_node);
1511 } else if (strcmp(file, "crtn.o") == 0) {
1512 CFile *c_file = heap::c_allocator.create<CFile>();
1513 c_file->source_path = glibc_start_asm_path(parent, "crtn.S");
1514 glibc_add_include_dirs(parent, c_file);
1515 c_file->args.append("-D_LIBC_REENTRANT");
1516 c_file->args.append("-DMODULE_NAME=libc");
1517 c_file->args.append("-DTOP_NAMESPACE=glibc");
1518 c_file->args.append("-DASSEMBLER");
1519 c_file->args.append("-g");
1520 c_file->args.append("-Wa,--noexecstack");
1521 return build_libc_object(parent, "crtn", c_file, progress_node);
1522 } else if (strcmp(file, "start.os") == 0) {
1523 CFile *c_file = heap::c_allocator.create<CFile>();
1524 c_file->source_path = glibc_start_asm_path(parent, "start.S");
1525 glibc_add_include_dirs(parent, c_file);
1526 c_file->args.append("-D_LIBC_REENTRANT");
1527 c_file->args.append("-include");
1528 c_file->args.append(path_from_libc(parent, "glibc" OS_SEP "include" OS_SEP "libc-modules.h"));
1529 c_file->args.append("-DMODULE_NAME=libc");
1530 c_file->args.append("-Wno-nonportable-include-path");
1531 c_file->args.append("-include");
1532 c_file->args.append(path_from_libc(parent, "glibc" OS_SEP "include" OS_SEP "libc-symbols.h"));
1533 c_file->args.append("-DPIC");
1534 c_file->args.append("-DSHARED");
1535 c_file->args.append("-DTOP_NAMESPACE=glibc");
1536 c_file->args.append("-DASSEMBLER");
1537 c_file->args.append("-g");
1538 c_file->args.append("-Wa,--noexecstack");
1539 return build_libc_object(parent, "start", c_file, progress_node);
1540 } else if (strcmp(file, "abi-note.o") == 0) {
1541 CFile *c_file = heap::c_allocator.create<CFile>();
1542 c_file->source_path = path_from_libc(parent, "glibc" OS_SEP "csu" OS_SEP "abi-note.S");
1543 c_file->args.append("-I");
1544 c_file->args.append(path_from_libc(parent, "glibc" OS_SEP "csu"));
1545 glibc_add_include_dirs(parent, c_file);
1546 c_file->args.append("-D_LIBC_REENTRANT");
1547 c_file->args.append("-DMODULE_NAME=libc");
1548 c_file->args.append("-DTOP_NAMESPACE=glibc");
1549 c_file->args.append("-DASSEMBLER");
1550 c_file->args.append("-g");
1551 c_file->args.append("-Wa,--noexecstack");
1552 return build_libc_object(parent, "abi-note", c_file, progress_node);
1553 } else if (strcmp(file, "Scrt1.o") == 0) {
1554 const char *start_os = get_libc_crt_file(parent, "start.os", progress_node);
1555 const char *abi_note_o = get_libc_crt_file(parent, "abi-note.o", progress_node);
1556 CodeGen *child_gen = create_child_codegen(parent, nullptr, OutTypeObj, nullptr, "Scrt1", progress_node);
1557 codegen_add_object(child_gen, buf_create_from_str(start_os));
1558 codegen_add_object(child_gen, buf_create_from_str(abi_note_o));
1559 codegen_build_and_link(child_gen);
1560 return buf_ptr(&child_gen->bin_file_output_path);
1561 } else if (strcmp(file, "libc_nonshared.a") == 0) {
1562 CodeGen *child_gen = create_child_codegen(parent, nullptr, OutTypeLib, nullptr, "c_nonshared", progress_node);
1563 {
1564 CFile *c_file = heap::c_allocator.create<CFile>();
1565 c_file->source_path = path_from_libc(parent, "glibc" OS_SEP "csu" OS_SEP "elf-init.c");
1566 c_file->args.append("-std=gnu11");
1567 c_file->args.append("-fgnu89-inline");
1568 c_file->args.append("-g");
1569 c_file->args.append("-O2");
1570 c_file->args.append("-fmerge-all-constants");
1571 c_file->args.append("-fno-stack-protector");
1572 c_file->args.append("-fmath-errno");
1573 c_file->args.append("-fno-stack-protector");
1574 c_file->args.append("-I");
1575 c_file->args.append(path_from_libc(parent, "glibc" OS_SEP "csu"));
1576 glibc_add_include_dirs(parent, c_file);
1577 c_file->args.append("-DSTACK_PROTECTOR_LEVEL=0");
1578 c_file->args.append("-fPIC");
1579 c_file->args.append("-fno-stack-protector");
1580 c_file->args.append("-ftls-model=initial-exec");
1581 c_file->args.append("-D_LIBC_REENTRANT");
1582 c_file->args.append("-include");
1583 c_file->args.append(path_from_libc(parent, "glibc" OS_SEP "include" OS_SEP "libc-modules.h"));
1584 c_file->args.append("-DMODULE_NAME=libc");
1585 c_file->args.append("-Wno-nonportable-include-path");
1586 c_file->args.append("-include");
1587 c_file->args.append(path_from_libc(parent, "glibc" OS_SEP "include" OS_SEP "libc-symbols.h"));
1588 c_file->args.append("-DPIC");
1589 c_file->args.append("-DLIBC_NONSHARED=1");
1590 c_file->args.append("-DTOP_NAMESPACE=glibc");
1591 codegen_add_object(child_gen, buf_create_from_str(
1592 build_libc_object(parent, "elf-init", c_file, progress_node)));
1593 }
1594 static const struct {
1595 const char *name;
1596 const char *path;
1597 } deps[] = {
1598 {"atexit", "glibc" OS_SEP "stdlib" OS_SEP "atexit.c"},
1599 {"at_quick_exit", "glibc" OS_SEP "stdlib" OS_SEP "at_quick_exit.c"},
1600 {"stat", "glibc" OS_SEP "io" OS_SEP "stat.c"},
1601 {"fstat", "glibc" OS_SEP "io" OS_SEP "fstat.c"},
1602 {"lstat", "glibc" OS_SEP "io" OS_SEP "lstat.c"},
1603 {"stat64", "glibc" OS_SEP "io" OS_SEP "stat64.c"},
1604 {"fstat64", "glibc" OS_SEP "io" OS_SEP "fstat64.c"},
1605 {"lstat64", "glibc" OS_SEP "io" OS_SEP "lstat64.c"},
1606 {"fstatat", "glibc" OS_SEP "io" OS_SEP "fstatat.c"},
1607 {"fstatat64", "glibc" OS_SEP "io" OS_SEP "fstatat64.c"},
1608 {"mknod", "glibc" OS_SEP "io" OS_SEP "mknod.c"},
1609 {"mknodat", "glibc" OS_SEP "io" OS_SEP "mknodat.c"},
1610 {"pthread_atfork", "glibc" OS_SEP "nptl" OS_SEP "pthread_atfork.c"},
1611 {"stack_chk_fail_local", "glibc" OS_SEP "debug" OS_SEP "stack_chk_fail_local.c"},
1612 };
1613 for (size_t i = 0; i < array_length(deps); i += 1) {
1614 CFile *c_file = heap::c_allocator.create<CFile>();
1615 c_file->source_path = path_from_libc(parent, deps[i].path);
1616 c_file->args.append("-std=gnu11");
1617 c_file->args.append("-fgnu89-inline");
1618 c_file->args.append("-g");
1619 c_file->args.append("-O2");
1620 c_file->args.append("-fmerge-all-constants");
1621 c_file->args.append("-fno-stack-protector");
1622 c_file->args.append("-fmath-errno");
1623 c_file->args.append("-ftls-model=initial-exec");
1624 c_file->args.append("-Wno-ignored-attributes");
1625 glibc_add_include_dirs(parent, c_file);
1626 c_file->args.append("-D_LIBC_REENTRANT");
1627 c_file->args.append("-include");
1628 c_file->args.append(path_from_libc(parent, "glibc" OS_SEP "include" OS_SEP "libc-modules.h"));
1629 c_file->args.append("-DMODULE_NAME=libc");
1630 c_file->args.append("-Wno-nonportable-include-path");
1631 c_file->args.append("-include");
1632 c_file->args.append(path_from_libc(parent, "glibc" OS_SEP "include" OS_SEP "libc-symbols.h"));
1633 c_file->args.append("-DPIC");
1634 c_file->args.append("-DLIBC_NONSHARED=1");
1635 c_file->args.append("-DTOP_NAMESPACE=glibc");
1636 codegen_add_object(child_gen, buf_create_from_str(
1637 build_libc_object(parent, deps[i].name, c_file, progress_node)));
1638 }
1639 codegen_build_and_link(child_gen);
1640 return buf_ptr(&child_gen->bin_file_output_path);
1641 } else {
1642 zig_unreachable();
1643 }
1644 } else if (parent->libc == nullptr && target_is_musl(parent->zig_target)) {
1645 if (strcmp(file, "crti.o") == 0) {
1646 CFile *c_file = heap::c_allocator.create<CFile>();
1647 c_file->source_path = musl_start_asm_path(parent, "crti.s");
1648 musl_add_cc_args(parent, c_file, false);
1649 c_file->args.append("-Qunused-arguments");
1650 return build_libc_object(parent, "crti", c_file, progress_node);
1651 } else if (strcmp(file, "crtn.o") == 0) {
1652 CFile *c_file = heap::c_allocator.create<CFile>();
1653 c_file->source_path = musl_start_asm_path(parent, "crtn.s");
1654 c_file->args.append("-Qunused-arguments");
1655 musl_add_cc_args(parent, c_file, false);
1656 return build_libc_object(parent, "crtn", c_file, progress_node);
1657 } else if (strcmp(file, "crt1.o") == 0) {
1658 CFile *c_file = heap::c_allocator.create<CFile>();
1659 c_file->source_path = path_from_libc(parent, "musl" OS_SEP "crt" OS_SEP "crt1.c");
1660 musl_add_cc_args(parent, c_file, false);
1661 c_file->args.append("-fno-stack-protector");
1662 c_file->args.append("-DCRT");
1663 return build_libc_object(parent, "crt1", c_file, progress_node);
1664 } else if (strcmp(file, "Scrt1.o") == 0) {
1665 CFile *c_file = heap::c_allocator.create<CFile>();
1666 c_file->source_path = path_from_libc(parent, "musl" OS_SEP "crt" OS_SEP "Scrt1.c");
1667 musl_add_cc_args(parent, c_file, false);
1668 c_file->args.append("-fPIC");
1669 c_file->args.append("-fno-stack-protector");
1670 c_file->args.append("-DCRT");
1671 return build_libc_object(parent, "Scrt1", c_file, progress_node);
1672 } else {
1673 zig_unreachable();
1674 }
1675 } else {
1676 assert(parent->libc != nullptr);
1677 Buf *out_buf = buf_alloc();
1678 os_path_join(buf_create_from_mem(parent->libc->crt_dir, parent->libc->crt_dir_len),
1679 buf_create_from_str(file), out_buf);
1680 return buf_ptr(out_buf);
1681 }
1682}
1683
1684static Buf *build_a_raw(CodeGen *parent_gen, const char *aname, Buf *full_path, OutType child_out_type,
1685 Stage2ProgressNode *progress_node)
1686{
1687 CodeGen *child_gen = create_child_codegen(parent_gen, full_path, child_out_type, parent_gen->libc, aname,
1688 progress_node);
1689
1690 // This is so that compiler_rt and libc.zig libraries know whether they
1691 // will eventually be linked with libc. They make different decisions
1692 // about what to export depending on whether libc is linked.
1693 if (parent_gen->libc_link_lib != nullptr) {
1694 LinkLib *new_link_lib = codegen_add_link_lib(child_gen, parent_gen->libc_link_lib->name);
1695 new_link_lib->provided_explicitly = parent_gen->libc_link_lib->provided_explicitly;
1696 }
1697
1698 // Override the inherited build mode parameter
1699 if (!parent_gen->is_test_build) {
1700 switch (parent_gen->build_mode) {
1701 case BuildModeDebug:
1702 case BuildModeFastRelease:
1703 case BuildModeSafeRelease:
1704 child_gen->build_mode = BuildModeFastRelease;
1705 break;
1706 case BuildModeSmallRelease:
1707 break;
1708 }
1709 }
1710
1711 child_gen->function_sections = true;
1712 child_gen->want_stack_check = WantStackCheckDisabled;
1713
1714 codegen_build_and_link(child_gen);
1715 return &child_gen->bin_file_output_path;
1716}
1717
1718static Buf *build_compiler_rt(CodeGen *parent_gen, OutType child_out_type, Stage2ProgressNode *progress_node) {
1719 Buf *full_path = buf_alloc();
1720 os_path_join(parent_gen->zig_std_special_dir, buf_create_from_str("compiler_rt.zig"), full_path);
1721
1722 return build_a_raw(parent_gen, "compiler_rt", full_path, child_out_type, progress_node);
1723}
1724
1725static Buf *build_c(CodeGen *parent_gen, OutType child_out_type, Stage2ProgressNode *progress_node) {
1726 Buf *full_path = buf_alloc();
1727 os_path_join(parent_gen->zig_std_special_dir, buf_create_from_str("c.zig"), full_path);
1728
1729 return build_a_raw(parent_gen, "c", full_path, child_out_type, progress_node);
1730}
1731
1732static const char *get_darwin_arch_string(const ZigTarget *t) {
1733 switch (t->arch) {
1734 case ZigLLVM_aarch64:
1735 return "arm64";
1736 case ZigLLVM_thumb:
1737 case ZigLLVM_arm:
1738 return "arm";
1739 case ZigLLVM_ppc:
1740 return "ppc";
1741 case ZigLLVM_ppc64:
1742 return "ppc64";
1743 case ZigLLVM_ppc64le:
1744 return "ppc64le";
1745 default:
1746 return ZigLLVMGetArchTypeName(t->arch);
1747 }
1748}
1749
1750
1751static const char *getLDMOption(const ZigTarget *t) {
1752 switch (t->arch) {
1753 case ZigLLVM_x86:
1754 return "elf_i386";
1755 case ZigLLVM_aarch64:
1756 return "aarch64linux";
1757 case ZigLLVM_aarch64_be:
1758 return "aarch64_be_linux";
1759 case ZigLLVM_arm:
1760 case ZigLLVM_thumb:
1761 return "armelf_linux_eabi";
1762 case ZigLLVM_armeb:
1763 case ZigLLVM_thumbeb:
1764 return "armebelf_linux_eabi";
1765 case ZigLLVM_ppc:
1766 return "elf32ppclinux";
1767 case ZigLLVM_ppc64:
1768 return "elf64ppc";
1769 case ZigLLVM_ppc64le:
1770 return "elf64lppc";
1771 case ZigLLVM_sparc:
1772 case ZigLLVM_sparcel:
1773 return "elf32_sparc";
1774 case ZigLLVM_sparcv9:
1775 return "elf64_sparc";
1776 case ZigLLVM_mips:
1777 return "elf32btsmip";
1778 case ZigLLVM_mipsel:
1779 return "elf32ltsmip";
1780 case ZigLLVM_mips64:
1781 return "elf64btsmip";
1782 case ZigLLVM_mips64el:
1783 return "elf64ltsmip";
1784 case ZigLLVM_systemz:
1785 return "elf64_s390";
1786 case ZigLLVM_x86_64:
1787 if (t->abi == ZigLLVM_GNUX32) {
1788 return "elf32_x86_64";
1789 }
1790 // Any target elf will use the freebsd osabi if suffixed with "_fbsd".
1791 if (t->os == OsFreeBSD) {
1792 return "elf_x86_64_fbsd";
1793 }
1794 return "elf_x86_64";
1795 case ZigLLVM_riscv32:
1796 return "elf32lriscv";
1797 case ZigLLVM_riscv64:
1798 return "elf64lriscv";
1799 default:
1800 zig_unreachable();
1801 }
1802}
1803
1804static void add_rpath(LinkJob *lj, Buf *rpath) {
1805 if (lj->rpath_table.maybe_get(rpath) != nullptr)
1806 return;
1807
1808 lj->args.append("-rpath");
1809 lj->args.append(buf_ptr(rpath));
1810
1811 lj->rpath_table.put(rpath, true);
1812}
1813
1814static void add_glibc_libs(LinkJob *lj) {
1815 Error err;
1816 ZigGLibCAbi *glibc_abi;
1817 if ((err = glibc_load_metadata(&glibc_abi, lj->codegen->zig_lib_dir, true))) {
1818 fprintf(stderr, "%s\n", err_str(err));
1819 exit(1);
1820 }
1821
1822 Buf *artifact_dir;
1823 if ((err = glibc_build_dummies_and_maps(lj->codegen, glibc_abi, lj->codegen->zig_target,
1824 &artifact_dir, true, lj->build_dep_prog_node)))
1825 {
1826 fprintf(stderr, "%s\n", err_str(err));
1827 exit(1);
1828 }
1829
1830 size_t lib_count = glibc_lib_count();
1831 for (size_t i = 0; i < lib_count; i += 1) {
1832 const ZigGLibCLib *lib = glibc_lib_enum(i);
1833 Buf *so_path = buf_sprintf("%s" OS_SEP "lib%s.so.%d.0.0", buf_ptr(artifact_dir), lib->name, lib->sover);
1834 lj->args.append(buf_ptr(so_path));
1835 }
1836}
1837
1838static void construct_linker_job_elf(LinkJob *lj) {
1839 CodeGen *g = lj->codegen;
1840
1841 lj->args.append("-error-limit=0");
1842
1843 if (g->out_type == OutTypeExe) {
1844 lj->args.append("-z");
1845 size_t stack_size = (g->stack_size_override == 0) ? 16777216 : g->stack_size_override;
1846 lj->args.append(buf_ptr(buf_sprintf("stack-size=%" ZIG_PRI_usize, stack_size)));
1847 }
1848
1849 if (g->linker_script) {
1850 lj->args.append("-T");
1851 lj->args.append(g->linker_script);
1852 }
1853
1854 switch (g->linker_gc_sections) {
1855 case OptionalBoolNull:
1856 if (g->out_type != OutTypeObj) {
1857 lj->args.append("--gc-sections");
1858 }
1859 break;
1860 case OptionalBoolTrue:
1861 lj->args.append("--gc-sections");
1862 break;
1863 case OptionalBoolFalse:
1864 break;
1865 }
1866
1867 if (g->link_eh_frame_hdr) {
1868 lj->args.append("--eh-frame-hdr");
1869 }
1870
1871 if (g->linker_rdynamic) {
1872 lj->args.append("--export-dynamic");
1873 }
1874
1875 if (g->linker_optimization != nullptr) {
1876 lj->args.append(buf_ptr(g->linker_optimization));
1877 }
1878
1879 if (g->linker_z_nodelete) {
1880 lj->args.append("-z");
1881 lj->args.append("nodelete");
1882 }
1883 if (g->linker_z_defs) {
1884 lj->args.append("-z");
1885 lj->args.append("defs");
1886 }
1887
1888 lj->args.append("-m");
1889 lj->args.append(getLDMOption(g->zig_target));
1890
1891 bool is_lib = g->out_type == OutTypeLib;
1892 bool is_dyn_lib = g->is_dynamic && is_lib;
1893 if (!g->have_dynamic_link) {
1894 if (g->zig_target->arch == ZigLLVM_arm || g->zig_target->arch == ZigLLVM_armeb ||
1895 g->zig_target->arch == ZigLLVM_thumb || g->zig_target->arch == ZigLLVM_thumbeb)
1896 {
1897 lj->args.append("-Bstatic");
1898 } else {
1899 lj->args.append("-static");
1900 }
1901 } else if (is_dyn_lib) {
1902 lj->args.append("-shared");
1903 }
1904
1905 if (target_requires_pie(g->zig_target) && g->out_type == OutTypeExe) {
1906 lj->args.append("-pie");
1907 }
1908
1909 assert(buf_len(&g->bin_file_output_path) != 0);
1910 lj->args.append("-o");
1911 lj->args.append(buf_ptr(&g->bin_file_output_path));
1912
1913 if (lj->link_in_crt) {
1914 const char *crt1o;
1915 if (g->zig_target->os == OsNetBSD) {
1916 crt1o = "crt0.o";
1917 } else if (target_is_android(g->zig_target)) {
1918 if (g->have_dynamic_link) {
1919 crt1o = "crtbegin_dynamic.o";
1920 } else {
1921 crt1o = "crtbegin_static.o";
1922 }
1923 } else if (!g->have_dynamic_link) {
1924 crt1o = "crt1.o";
1925 } else {
1926 crt1o = "Scrt1.o";
1927 }
1928 lj->args.append(get_libc_crt_file(g, crt1o, lj->build_dep_prog_node));
1929 if (target_libc_needs_crti_crtn(g->zig_target)) {
1930 lj->args.append(get_libc_crt_file(g, "crti.o", lj->build_dep_prog_node));
1931 }
1932 }
1933
1934 for (size_t i = 0; i < g->rpath_list.length; i += 1) {
1935 Buf *rpath = g->rpath_list.at(i);
1936 add_rpath(lj, rpath);
1937 }
1938 if (g->each_lib_rpath) {
1939 for (size_t i = 0; i < g->lib_dirs.length; i += 1) {
1940 const char *lib_dir = g->lib_dirs.at(i);
1941 for (size_t i = 0; i < g->link_libs_list.length; i += 1) {
1942 LinkLib *link_lib = g->link_libs_list.at(i);
1943 if (buf_eql_str(link_lib->name, "c")) {
1944 continue;
1945 }
1946 bool does_exist;
1947 Buf *test_path = buf_sprintf("%s/lib%s.so", lib_dir, buf_ptr(link_lib->name));
1948 if (os_file_exists(test_path, &does_exist) != ErrorNone) {
1949 zig_panic("link: unable to check if file exists: %s", buf_ptr(test_path));
1950 }
1951 if (does_exist) {
1952 add_rpath(lj, buf_create_from_str(lib_dir));
1953 break;
1954 }
1955 }
1956 }
1957 }
1958
1959 for (size_t i = 0; i < g->lib_dirs.length; i += 1) {
1960 const char *lib_dir = g->lib_dirs.at(i);
1961 lj->args.append("-L");
1962 lj->args.append(lib_dir);
1963 }
1964
1965 if (g->libc_link_lib != nullptr) {
1966 if (g->libc != nullptr) {
1967 lj->args.append("-L");
1968 lj->args.append(buf_ptr(buf_create_from_mem(g->libc->crt_dir, g->libc->crt_dir_len)));
1969 }
1970
1971 if (g->have_dynamic_link && (is_dyn_lib || g->out_type == OutTypeExe)) {
1972 assert(g->zig_target->dynamic_linker != nullptr);
1973 lj->args.append("-dynamic-linker");
1974 lj->args.append(g->zig_target->dynamic_linker);
1975 }
1976 }
1977
1978 if (is_dyn_lib) {
1979 Buf *soname = (g->override_soname == nullptr) ?
1980 buf_sprintf("lib%s.so.%" ZIG_PRI_usize, buf_ptr(g->root_out_name), g->version_major) :
1981 g->override_soname;
1982 lj->args.append("-soname");
1983 lj->args.append(buf_ptr(soname));
1984
1985 if (g->version_script_path != nullptr) {
1986 lj->args.append("-version-script");
1987 lj->args.append(buf_ptr(g->version_script_path));
1988 }
1989 }
1990
1991 // .o files
1992 for (size_t i = 0; i < g->link_objects.length; i += 1) {
1993 lj->args.append((const char *)buf_ptr(g->link_objects.at(i)));
1994 }
1995
1996 if (!g->is_dummy_so && (g->out_type == OutTypeExe || is_dyn_lib)) {
1997 if (g->libc_link_lib == nullptr) {
1998 Buf *libc_a_path = build_c(g, OutTypeLib, lj->build_dep_prog_node);
1999 lj->args.append(buf_ptr(libc_a_path));
2000 }
2001
2002 Buf *compiler_rt_o_path = build_compiler_rt(g, OutTypeLib, lj->build_dep_prog_node);
2003 lj->args.append(buf_ptr(compiler_rt_o_path));
2004 }
2005
2006 // libraries
2007 for (size_t i = 0; i < g->link_libs_list.length; i += 1) {
2008 LinkLib *link_lib = g->link_libs_list.at(i);
2009 if (buf_eql_str(link_lib->name, "c")) {
2010 // libc is linked specially
2011 continue;
2012 }
2013 if (target_is_libcpp_lib_name(g->zig_target, buf_ptr(link_lib->name))) {
2014 // libc++ is linked specially
2015 continue;
2016 }
2017 if (g->libc == nullptr && target_is_libc_lib_name(g->zig_target, buf_ptr(link_lib->name))) {
2018 // these libraries are always linked below when targeting glibc
2019 continue;
2020 }
2021 Buf *arg;
2022 if (buf_starts_with_str(link_lib->name, "/") || buf_ends_with_str(link_lib->name, ".a") ||
2023 buf_ends_with_str(link_lib->name, ".so"))
2024 {
2025 arg = link_lib->name;
2026 } else {
2027 arg = buf_sprintf("-l%s", buf_ptr(link_lib->name));
2028 }
2029 lj->args.append(buf_ptr(arg));
2030 }
2031
2032 // libc++ dep
2033 if (g->libcpp_link_lib != nullptr && g->out_type != OutTypeObj) {
2034 lj->args.append(build_libcxxabi(g, lj->build_dep_prog_node));
2035 lj->args.append(build_libcxx(g, lj->build_dep_prog_node));
2036 }
2037
2038 // libc dep
2039 if (g->libc_link_lib != nullptr && g->out_type != OutTypeObj) {
2040 if (g->libc != nullptr) {
2041 if (!g->have_dynamic_link) {
2042 lj->args.append("--start-group");
2043 lj->args.append("-lc");
2044 lj->args.append("-lm");
2045 lj->args.append("--end-group");
2046 } else {
2047 lj->args.append("-lc");
2048 lj->args.append("-lm");
2049 }
2050
2051 if (g->zig_target->os == OsFreeBSD ||
2052 g->zig_target->os == OsNetBSD)
2053 {
2054 lj->args.append("-lpthread");
2055 }
2056 } else if (target_is_glibc(g->zig_target)) {
2057 lj->args.append(build_libunwind(g, lj->build_dep_prog_node));
2058 add_glibc_libs(lj);
2059 lj->args.append(get_libc_crt_file(g, "libc_nonshared.a", lj->build_dep_prog_node));
2060 } else if (target_is_musl(g->zig_target)) {
2061 lj->args.append(build_libunwind(g, lj->build_dep_prog_node));
2062 lj->args.append(build_musl(g, lj->build_dep_prog_node));
2063 } else if (g->libcpp_link_lib != nullptr) {
2064 lj->args.append(build_libunwind(g, lj->build_dep_prog_node));
2065 } else {
2066 zig_unreachable();
2067 }
2068 }
2069
2070 // crt end
2071 if (lj->link_in_crt) {
2072 if (target_is_android(g->zig_target)) {
2073 lj->args.append(get_libc_crt_file(g, "crtend_android.o", lj->build_dep_prog_node));
2074 } else if (target_libc_needs_crti_crtn(g->zig_target)) {
2075 lj->args.append(get_libc_crt_file(g, "crtn.o", lj->build_dep_prog_node));
2076 }
2077 }
2078
2079 switch (g->linker_allow_shlib_undefined) {
2080 case OptionalBoolNull:
2081 if (!g->zig_target->is_native_os) {
2082 lj->args.append("--allow-shlib-undefined");
2083 }
2084 break;
2085 case OptionalBoolFalse:
2086 break;
2087 case OptionalBoolTrue:
2088 lj->args.append("--allow-shlib-undefined");
2089 break;
2090 }
2091 switch (g->linker_bind_global_refs_locally) {
2092 case OptionalBoolNull:
2093 case OptionalBoolFalse:
2094 break;
2095 case OptionalBoolTrue:
2096 lj->args.append("-Bsymbolic");
2097 break;
2098 }
2099}
2100
2101static void construct_linker_job_wasm(LinkJob *lj) {
2102 CodeGen *g = lj->codegen;
2103
2104 lj->args.append("-error-limit=0");
2105 // Increase the default stack size to a more reasonable value of 1MB instead of
2106 // the default of 1 Wasm page being 64KB, unless overriden by the user.
2107 size_t stack_size = (g->stack_size_override == 0) ? 1048576 : g->stack_size_override;
2108 lj->args.append("-z");
2109 lj->args.append(buf_ptr(buf_sprintf("stack-size=%" ZIG_PRI_usize, stack_size)));
2110
2111 // put stack before globals so that stack overflow results in segfault immediately before corrupting globals
2112 // see https://github.com/ziglang/zig/issues/4496
2113 lj->args.append("--stack-first");
2114
2115 if (g->out_type != OutTypeExe) {
2116 lj->args.append("--no-entry"); // So lld doesn't look for _start.
2117
2118 // If there are any C source files we cannot rely on individual exports.
2119 if (g->c_source_files.length != 0) {
2120 lj->args.append("--export-all");
2121 } else {
2122 auto export_it = g->exported_symbol_names.entry_iterator();
2123 decltype(g->exported_symbol_names)::Entry *curr_entry = nullptr;
2124 while ((curr_entry = export_it.next()) != nullptr) {
2125 Buf *arg = buf_sprintf("--export=%s", buf_ptr(curr_entry->key));
2126 lj->args.append(buf_ptr(arg));
2127 }
2128 }
2129 }
2130 lj->args.append("--allow-undefined");
2131 lj->args.append("-o");
2132 lj->args.append(buf_ptr(&g->bin_file_output_path));
2133
2134 // .o files
2135 for (size_t i = 0; i < g->link_objects.length; i += 1) {
2136 lj->args.append((const char *)buf_ptr(g->link_objects.at(i)));
2137 }
2138
2139 if (g->out_type != OutTypeObj) {
2140 Buf *libc_o_path = build_c(g, OutTypeObj, lj->build_dep_prog_node);
2141 lj->args.append(buf_ptr(libc_o_path));
2142
2143 Buf *compiler_rt_o_path = build_compiler_rt(g, OutTypeObj, lj->build_dep_prog_node);
2144 lj->args.append(buf_ptr(compiler_rt_o_path));
2145 }
2146}
2147
2148static void coff_append_machine_arg(CodeGen *g, ZigList<const char *> *list) {
2149 if (g->zig_target->arch == ZigLLVM_x86) {
2150 list->append("-MACHINE:X86");
2151 } else if (g->zig_target->arch == ZigLLVM_x86_64) {
2152 list->append("-MACHINE:X64");
2153 } else if (target_is_arm(g->zig_target)) {
2154 if (target_arch_pointer_bit_width(g->zig_target->arch) == 32) {
2155 list->append("-MACHINE:ARM");
2156 } else {
2157 list->append("-MACHINE:ARM64");
2158 }
2159 }
2160}
2161
2162static void link_diag_callback(void *context, const char *ptr, size_t len) {
2163 Buf *diag = reinterpret_cast<Buf *>(context);
2164 buf_append_mem(diag, ptr, len);
2165}
2166
2167static bool zig_lld_link(ZigLLVM_ObjectFormatType oformat, const char **args, size_t arg_count,
2168 Buf *diag)
2169{
2170 Buf *stdout_diag = buf_alloc();
2171 buf_resize(diag, 0);
2172 bool result = ZigLLDLink(oformat, args, arg_count, link_diag_callback, stdout_diag, diag);
2173 buf_destroy(stdout_diag);
2174 return result;
2175}
2176
2177static void add_uefi_link_args(LinkJob *lj) {
2178 lj->args.append("-BASE:0");
2179 lj->args.append("-ENTRY:EfiMain");
2180 lj->args.append("-OPT:REF");
2181 lj->args.append("-SAFESEH:NO");
2182 lj->args.append("-MERGE:.rdata=.data");
2183 lj->args.append("-ALIGN:32");
2184 lj->args.append("-NODEFAULTLIB");
2185 lj->args.append("-SECTION:.xdata,D");
2186}
2187
2188static void add_msvc_link_args(LinkJob *lj, bool is_library) {
2189 CodeGen *g = lj->codegen;
2190
2191 bool is_dynamic = g->is_dynamic;
2192 const char *lib_str = is_dynamic ? "" : "lib";
2193 const char *d_str = (g->build_mode == BuildModeDebug) ? "d" : "";
2194
2195 if (!is_dynamic) {
2196 Buf *cmt_lib_name = buf_sprintf("libcmt%s.lib", d_str);
2197 lj->args.append(buf_ptr(cmt_lib_name));
2198 } else {
2199 Buf *msvcrt_lib_name = buf_sprintf("msvcrt%s.lib", d_str);
2200 lj->args.append(buf_ptr(msvcrt_lib_name));
2201 }
2202
2203 Buf *vcruntime_lib_name = buf_sprintf("%svcruntime%s.lib", lib_str, d_str);
2204 lj->args.append(buf_ptr(vcruntime_lib_name));
2205
2206 Buf *crt_lib_name = buf_sprintf("%sucrt%s.lib", lib_str, d_str);
2207 lj->args.append(buf_ptr(crt_lib_name));
2208
2209 //Visual C++ 2015 Conformance Changes
2210 //https://msdn.microsoft.com/en-us/library/bb531344.aspx
2211 lj->args.append("legacy_stdio_definitions.lib");
2212
2213 // msvcrt depends on kernel32 and ntdll
2214 lj->args.append("kernel32.lib");
2215 lj->args.append("ntdll.lib");
2216}
2217
2218static void print_zig_cc_cmd(ZigList<const char *> *args) {
2219 for (size_t arg_i = 0; arg_i < args->length; arg_i += 1) {
2220 const char *space_str = (arg_i == 0) ? "" : " ";
2221 fprintf(stderr, "%s%s", space_str, args->at(arg_i));
2222 }
2223 fprintf(stderr, "\n");
2224}
2225
2226static const char *get_def_lib(CodeGen *parent, const char *name, Buf *def_in_file) {
2227 Error err;
2228
2229 Buf *self_exe_path = buf_alloc();
2230 if ((err = os_self_exe_path(self_exe_path))) {
2231 fprintf(stderr, "Unable to get self exe path: %s\n", err_str(err));
2232 exit(1);
2233 }
2234 Buf *compiler_id;
2235 if ((err = get_compiler_id(&compiler_id))) {
2236 fprintf(stderr, "Unable to get compiler id: %s\n", err_str(err));
2237 exit(1);
2238 }
2239
2240 Buf *cache_dir = get_global_cache_dir();
2241 Buf *o_dir = buf_sprintf("%s" OS_SEP CACHE_OUT_SUBDIR, buf_ptr(cache_dir));
2242 Buf *manifest_dir = buf_sprintf("%s" OS_SEP CACHE_HASH_SUBDIR, buf_ptr(cache_dir));
2243
2244 Buf *def_include_dir = buf_sprintf("%s" OS_SEP "libc" OS_SEP "mingw" OS_SEP "def-include",
2245 buf_ptr(parent->zig_lib_dir));
2246
2247 CacheHash *cache_hash = heap::c_allocator.create<CacheHash>();
2248 cache_init(cache_hash, manifest_dir);
2249
2250 cache_buf(cache_hash, compiler_id);
2251 cache_file(cache_hash, def_in_file);
2252 cache_buf(cache_hash, def_include_dir);
2253 cache_int(cache_hash, parent->zig_target->arch);
2254
2255 Buf digest = BUF_INIT;
2256 buf_resize(&digest, 0);
2257 if ((err = cache_hit(cache_hash, &digest))) {
2258 if (err != ErrorInvalidFormat) {
2259 if (err == ErrorCacheUnavailable) {
2260 // already printed error
2261 } else {
2262 fprintf(stderr, "unable to check cache when processing .def.in file: %s\n", err_str(err));
2263 }
2264 exit(1);
2265 }
2266 }
2267
2268 Buf *artifact_dir;
2269 Buf *lib_final_path;
2270 Buf *final_lib_basename = buf_sprintf("%s.lib", name);
2271
2272 bool is_cache_miss = (buf_len(&digest) == 0);
2273 if (is_cache_miss) {
2274 if ((err = cache_final(cache_hash, &digest))) {
2275 fprintf(stderr, "Unable to finalize cache hash: %s\n", err_str(err));
2276 exit(1);
2277 }
2278 artifact_dir = buf_alloc();
2279 os_path_join(o_dir, &digest, artifact_dir);
2280 if ((err = os_make_path(artifact_dir))) {
2281 fprintf(stderr, "Unable to create output directory '%s': %s",
2282 buf_ptr(artifact_dir), err_str(err));
2283 exit(1);
2284 }
2285 Buf *final_def_basename = buf_sprintf("%s.def", name);
2286 Buf *def_final_path = buf_alloc();
2287 os_path_join(artifact_dir, final_def_basename, def_final_path);
2288
2289 ZigList<const char *> args = {};
2290 args.append(buf_ptr(self_exe_path));
2291 args.append("clang");
2292 args.append("-x");
2293 args.append("c");
2294 args.append(buf_ptr(def_in_file));
2295 args.append("-Wp,-w");
2296 args.append("-undef");
2297 args.append("-P");
2298 args.append("-I");
2299 args.append(buf_ptr(def_include_dir));
2300 if (target_is_arm(parent->zig_target)) {
2301 if (target_arch_pointer_bit_width(parent->zig_target->arch) == 32) {
2302 args.append("-DDEF_ARM32");
2303 } else {
2304 args.append("-DDEF_ARM64");
2305 }
2306 } else if (parent->zig_target->arch == ZigLLVM_x86) {
2307 args.append("-DDEF_I386");
2308 } else if (parent->zig_target->arch == ZigLLVM_x86_64) {
2309 args.append("-DDEF_X64");
2310 } else {
2311 zig_unreachable();
2312 }
2313 args.append("-E");
2314 args.append("-o");
2315 args.append(buf_ptr(def_final_path));
2316
2317 if (parent->verbose_cc) {
2318 print_zig_cc_cmd(&args);
2319 }
2320 Termination term;
2321 os_spawn_process(args, &term);
2322 if (term.how != TerminationIdClean || term.code != 0) {
2323 fprintf(stderr, "\nThe following command failed:\n");
2324 print_zig_cc_cmd(&args);
2325 exit(1);
2326 }
2327
2328 lib_final_path = buf_alloc();
2329 os_path_join(artifact_dir, final_lib_basename, lib_final_path);
2330
2331 if (ZigLLVMWriteImportLibrary(buf_ptr(def_final_path),
2332 parent->zig_target->arch,
2333 buf_ptr(lib_final_path),
2334 /* kill_at */ true))
2335 {
2336 zig_panic("link: could not emit %s", buf_ptr(lib_final_path));
2337 }
2338 } else {
2339 // cache hit
2340 artifact_dir = buf_alloc();
2341 os_path_join(o_dir, &digest, artifact_dir);
2342 lib_final_path = buf_alloc();
2343 os_path_join(artifact_dir, final_lib_basename, lib_final_path);
2344 }
2345 parent->caches_to_release.append(cache_hash);
2346
2347 return buf_ptr(lib_final_path);
2348}
2349
2350static bool is_linking_system_lib(CodeGen *g, const char *name) {
2351 for (size_t lib_i = 0; lib_i < g->link_libs_list.length; lib_i += 1) {
2352 LinkLib *link_lib = g->link_libs_list.at(lib_i);
2353 if (buf_eql_str(link_lib->name, name)) {
2354 return true;
2355 }
2356 }
2357 return false;
2358}
2359
2360static Error find_mingw_lib_def(LinkJob *lj, const char *name, Buf *out_path) {
2361 CodeGen *g = lj->codegen;
2362 Buf override_path = BUF_INIT;
2363 Error err;
2364
2365 char const *lib_path = nullptr;
2366 if (g->zig_target->arch == ZigLLVM_x86) {
2367 lib_path = "lib32";
2368 } else if (g->zig_target->arch == ZigLLVM_x86_64) {
2369 lib_path = "lib64";
2370 } else if (target_is_arm(g->zig_target)) {
2371 const bool is_32 = target_arch_pointer_bit_width(g->zig_target->arch) == 32;
2372 lib_path = is_32 ? "libarm32" : "libarm64";
2373 } else {
2374 zig_unreachable();
2375 }
2376
2377 // Try the archtecture-specific path first
2378 buf_resize(&override_path, 0);
2379 buf_appendf(&override_path, "%s" OS_SEP "libc" OS_SEP "mingw" OS_SEP "%s" OS_SEP "%s.def", buf_ptr(g->zig_lib_dir), lib_path, name);
2380
2381 bool does_exist;
2382 if ((err = os_file_exists(&override_path, &does_exist)) != ErrorNone) {
2383 return err;
2384 }
2385
2386 if (!does_exist) {
2387 // Try the generic version
2388 buf_resize(&override_path, 0);
2389 buf_appendf(&override_path, "%s" OS_SEP "libc" OS_SEP "mingw" OS_SEP "lib-common" OS_SEP "%s.def", buf_ptr(g->zig_lib_dir), name);
2390
2391 if ((err = os_file_exists(&override_path, &does_exist)) != ErrorNone) {
2392 return err;
2393 }
2394 }
2395
2396 if (!does_exist) {
2397 // Try the generic version and preprocess it
2398 buf_resize(&override_path, 0);
2399 buf_appendf(&override_path, "%s" OS_SEP "libc" OS_SEP "mingw" OS_SEP "lib-common" OS_SEP "%s.def.in", buf_ptr(g->zig_lib_dir), name);
2400
2401 if ((err = os_file_exists(&override_path, &does_exist)) != ErrorNone) {
2402 return err;
2403 }
2404 }
2405
2406 if (!does_exist) {
2407 return ErrorFileNotFound;
2408 }
2409
2410 buf_init_from_buf(out_path, &override_path);
2411 return ErrorNone;
2412}
2413
2414static void add_mingw_link_args(LinkJob *lj, bool is_library) {
2415 CodeGen *g = lj->codegen;
2416
2417 lj->args.append("-lldmingw");
2418
2419 bool is_dll = g->out_type == OutTypeLib && g->is_dynamic;
2420
2421 if (g->zig_target->arch == ZigLLVM_x86) {
2422 lj->args.append("-ALTERNATENAME:__image_base__=___ImageBase");
2423 } else {
2424 lj->args.append("-ALTERNATENAME:__image_base__=__ImageBase");
2425 }
2426
2427 if (is_dll) {
2428 lj->args.append(get_libc_crt_file(g, "dllcrt2.o", lj->build_dep_prog_node));
2429 } else {
2430 lj->args.append(get_libc_crt_file(g, "crt2.o", lj->build_dep_prog_node));
2431 }
2432
2433 lj->args.append(get_libc_crt_file(g, "mingw32.lib", lj->build_dep_prog_node));
2434 lj->args.append(get_libc_crt_file(g, "mingwex.lib", lj->build_dep_prog_node));
2435 lj->args.append(get_libc_crt_file(g, "msvcrt-os.lib", lj->build_dep_prog_node));
2436
2437 for (size_t def_i = 0; def_i < array_length(mingw_def_list); def_i += 1) {
2438 const char *name = mingw_def_list[def_i].name;
2439 const bool always_link = mingw_def_list[def_i].always_link;
2440
2441 if (always_link || is_linking_system_lib(g, name)) {
2442 Buf lib_path = BUF_INIT;
2443 Error err = find_mingw_lib_def(lj, name, &lib_path);
2444
2445 if (err == ErrorFileNotFound) {
2446 zig_panic("link: could not find .def file to build %s\n", name);
2447 } else if (err != ErrorNone) {
2448 zig_panic("link: unable to check if .def file for %s exists: %s",
2449 name, err_str(err));
2450 }
2451
2452 lj->args.append(get_def_lib(g, name, &lib_path));
2453 }
2454 }
2455}
2456
2457static void add_win_link_args(LinkJob *lj, bool is_library, bool *have_windows_dll_import_libs) {
2458 if (lj->link_in_crt) {
2459 if (target_abi_is_gnu(lj->codegen->zig_target->abi)) {
2460 *have_windows_dll_import_libs = true;
2461 add_mingw_link_args(lj, is_library);
2462 } else {
2463 add_msvc_link_args(lj, is_library);
2464 }
2465 } else {
2466 lj->args.append("-NODEFAULTLIB");
2467 if (!is_library) {
2468 if (lj->codegen->have_winmain) {
2469 lj->args.append("-ENTRY:WinMain");
2470 } else if (lj->codegen->have_wwinmain) {
2471 lj->args.append("-ENTRY:wWinMain");
2472 } else if (lj->codegen->have_wwinmain_crt_startup) {
2473 lj->args.append("-ENTRY:wWinMainCRTStartup");
2474 } else {
2475 lj->args.append("-ENTRY:WinMainCRTStartup");
2476 }
2477 }
2478 }
2479}
2480
2481static bool is_mingw_link_lib(Buf *name) {
2482 for (size_t def_i = 0; def_i < array_length(mingw_def_list); def_i += 1) {
2483 if (buf_eql_str_ignore_case(name, mingw_def_list[def_i].name)) {
2484 return true;
2485 }
2486 }
2487 return false;
2488}
2489static void construct_linker_job_coff(LinkJob *lj) {
2490 Error err;
2491 CodeGen *g = lj->codegen;
2492
2493 lj->args.append("-ERRORLIMIT:0");
2494
2495 lj->args.append("-NOLOGO");
2496
2497 if (!g->strip_debug_symbols) {
2498 lj->args.append("-DEBUG");
2499 }
2500
2501 if (g->out_type == OutTypeExe) {
2502 // TODO compile time stack upper bound detection
2503 size_t stack_size = (g->stack_size_override == 0) ? 16777216 : g->stack_size_override;
2504 lj->args.append(buf_ptr(buf_sprintf("-STACK:%" ZIG_PRI_usize, stack_size)));
2505 }
2506
2507 coff_append_machine_arg(g, &lj->args);
2508
2509 bool is_library = g->out_type == OutTypeLib;
2510 if (is_library && g->is_dynamic) {
2511 lj->args.append("-DLL");
2512 }
2513
2514 lj->args.append(buf_ptr(buf_sprintf("-OUT:%s", buf_ptr(&g->bin_file_output_path))));
2515
2516 if (g->libc_link_lib != nullptr && g->libc != nullptr) {
2517 Buf *buff0 = buf_create_from_str("-LIBPATH:");
2518 buf_append_mem(buff0, g->libc->crt_dir, g->libc->crt_dir_len);
2519 lj->args.append(buf_ptr(buff0));
2520
2521 if (target_abi_is_gnu(g->zig_target->abi)) {
2522 Buf *buff1 = buf_create_from_str("-LIBPATH:");
2523 buf_append_mem(buff1, g->libc->sys_include_dir, g->libc->sys_include_dir_len);
2524 lj->args.append(buf_ptr(buff1));
2525
2526 Buf *buff2 = buf_create_from_str("-LIBPATH:");
2527 buf_append_mem(buff2, g->libc->include_dir, g->libc->include_dir_len);
2528 lj->args.append(buf_ptr(buff2));
2529 } else {
2530 Buf *buff1 = buf_create_from_str("-LIBPATH:");
2531 buf_append_mem(buff1, g->libc->msvc_lib_dir, g->libc->msvc_lib_dir_len);
2532 lj->args.append(buf_ptr(buff1));
2533
2534 Buf *buff2 = buf_create_from_str("-LIBPATH:");
2535 buf_append_mem(buff2, g->libc->kernel32_lib_dir, g->libc->kernel32_lib_dir_len);
2536 lj->args.append(buf_ptr(buff2));
2537 }
2538 }
2539
2540 for (size_t i = 0; i < g->lib_dirs.length; i += 1) {
2541 const char *lib_dir = g->lib_dirs.at(i);
2542 lj->args.append(buf_ptr(buf_sprintf("-LIBPATH:%s", lib_dir)));
2543 }
2544
2545 for (size_t i = 0; i < g->link_objects.length; i += 1) {
2546 lj->args.append((const char *)buf_ptr(g->link_objects.at(i)));
2547 }
2548
2549 bool have_windows_dll_import_libs = false;
2550 switch (detect_subsystem(g)) {
2551 case TargetSubsystemAuto:
2552 if (g->zig_target->os == OsUefi) {
2553 add_uefi_link_args(lj);
2554 } else {
2555 add_win_link_args(lj, is_library, &have_windows_dll_import_libs);
2556 }
2557 break;
2558 case TargetSubsystemConsole:
2559 lj->args.append("-SUBSYSTEM:console");
2560 add_win_link_args(lj, is_library, &have_windows_dll_import_libs);
2561 break;
2562 case TargetSubsystemEfiApplication:
2563 lj->args.append("-SUBSYSTEM:efi_application");
2564 add_uefi_link_args(lj);
2565 break;
2566 case TargetSubsystemEfiBootServiceDriver:
2567 lj->args.append("-SUBSYSTEM:efi_boot_service_driver");
2568 add_uefi_link_args(lj);
2569 break;
2570 case TargetSubsystemEfiRom:
2571 lj->args.append("-SUBSYSTEM:efi_rom");
2572 add_uefi_link_args(lj);
2573 break;
2574 case TargetSubsystemEfiRuntimeDriver:
2575 lj->args.append("-SUBSYSTEM:efi_runtime_driver");
2576 add_uefi_link_args(lj);
2577 break;
2578 case TargetSubsystemNative:
2579 lj->args.append("-SUBSYSTEM:native");
2580 add_win_link_args(lj, is_library, &have_windows_dll_import_libs);
2581 break;
2582 case TargetSubsystemPosix:
2583 lj->args.append("-SUBSYSTEM:posix");
2584 add_win_link_args(lj, is_library, &have_windows_dll_import_libs);
2585 break;
2586 case TargetSubsystemWindows:
2587 lj->args.append("-SUBSYSTEM:windows");
2588 add_win_link_args(lj, is_library, &have_windows_dll_import_libs);
2589 break;
2590 }
2591
2592 // libc++ dep
2593 if (g->libcpp_link_lib != nullptr && g->out_type != OutTypeObj) {
2594 lj->args.append(build_libcxxabi(g, lj->build_dep_prog_node));
2595 lj->args.append(build_libcxx(g, lj->build_dep_prog_node));
2596 lj->args.append(build_libunwind(g, lj->build_dep_prog_node));
2597 }
2598
2599 if (g->out_type == OutTypeExe || (g->out_type == OutTypeLib && g->is_dynamic)) {
2600 if (g->libc_link_lib == nullptr && !g->is_dummy_so) {
2601 Buf *libc_a_path = build_c(g, OutTypeLib, lj->build_dep_prog_node);
2602 lj->args.append(buf_ptr(libc_a_path));
2603 }
2604
2605 // msvc compiler_rt is missing some stuff, so we still build it and rely on weak linkage
2606 Buf *compiler_rt_o_path = build_compiler_rt(g, OutTypeLib, lj->build_dep_prog_node);
2607 lj->args.append(buf_ptr(compiler_rt_o_path));
2608 }
2609
2610 for (size_t lib_i = 0; lib_i < g->link_libs_list.length; lib_i += 1) {
2611 LinkLib *link_lib = g->link_libs_list.at(lib_i);
2612 if (buf_eql_str(link_lib->name, "c")) {
2613 continue;
2614 }
2615 if (target_is_libcpp_lib_name(g->zig_target, buf_ptr(link_lib->name))) {
2616 // libc++ is linked specially
2617 continue;
2618 }
2619 if (g->libc == nullptr && target_is_libc_lib_name(g->zig_target, buf_ptr(link_lib->name))) {
2620 // these libraries are always linked below when targeting glibc
2621 continue;
2622 }
2623 bool is_sys_lib = is_mingw_link_lib(link_lib->name);
2624 if (have_windows_dll_import_libs && is_sys_lib) {
2625 continue;
2626 }
2627 // If we're linking in the CRT or the libs are provided explictly we don't want to generate def/libs
2628 if ((lj->link_in_crt && is_sys_lib) || link_lib->provided_explicitly) {
2629 if (target_abi_is_gnu(lj->codegen->zig_target->abi)) {
2630 if (buf_eql_str(link_lib->name, "uuid")) {
2631 // mingw-w64 provides this lib
2632 lj->args.append(get_libc_crt_file(g, "uuid.lib", lj->build_dep_prog_node));
2633 } else {
2634 Buf* lib_name = buf_sprintf("lib%s.a", buf_ptr(link_lib->name));
2635 lj->args.append(buf_ptr(lib_name));
2636 }
2637 } else {
2638 Buf* lib_name = buf_sprintf("%s.lib", buf_ptr(link_lib->name));
2639 lj->args.append(buf_ptr(lib_name));
2640 }
2641 continue;
2642 }
2643
2644 // This library may be a system one and we may have a suitable .lib file
2645
2646 // Normalize the library name to lower case, the FS may be
2647 // case-sensitive
2648 char *name = strdup(buf_ptr(link_lib->name));
2649 assert(name != nullptr);
2650 for (char *ch = name; *ch; ++ch) *ch = tolower(*ch);
2651
2652 Buf lib_path = BUF_INIT;
2653 err = find_mingw_lib_def(lj, name, &lib_path);
2654
2655 if (err == ErrorFileNotFound) {
2656 zig_panic("link: could not find .def file to build %s\n", name);
2657 } else if (err != ErrorNone) {
2658 zig_panic("link: unable to check if .def file for %s exists: %s",
2659 name, err_str(err));
2660 }
2661
2662 lj->args.append(get_def_lib(g, name, &lib_path));
2663
2664 mem::os::free(name);
2665 }
2666}
2667
2668static void construct_linker_job_macho(LinkJob *lj) {
2669 CodeGen *g = lj->codegen;
2670
2671 lj->args.append("-error-limit");
2672 lj->args.append("0");
2673 lj->args.append("-demangle");
2674
2675 switch (g->linker_gc_sections) {
2676 case OptionalBoolNull:
2677 // TODO why do we not follow the same logic of elf here?
2678 break;
2679 case OptionalBoolTrue:
2680 lj->args.append("--gc-sections");
2681 break;
2682 case OptionalBoolFalse:
2683 break;
2684 }
2685
2686 if (g->linker_rdynamic) {
2687 lj->args.append("-export_dynamic");
2688 }
2689
2690 if (g->linker_optimization != nullptr) {
2691 lj->args.append(buf_ptr(g->linker_optimization));
2692 }
2693
2694 if (g->linker_z_nodelete) {
2695 lj->args.append("-z");
2696 lj->args.append("nodelete");
2697 }
2698 if (g->linker_z_defs) {
2699 lj->args.append("-z");
2700 lj->args.append("defs");
2701 }
2702
2703 bool is_lib = g->out_type == OutTypeLib;
2704 bool is_dyn_lib = g->is_dynamic && is_lib;
2705 if (is_lib && !g->is_dynamic) {
2706 lj->args.append("-static");
2707 } else {
2708 lj->args.append("-dynamic");
2709 }
2710
2711 if (is_dyn_lib) {
2712 lj->args.append("-dylib");
2713
2714 Buf *compat_vers = buf_sprintf("%" ZIG_PRI_usize ".0.0", g->version_major);
2715 lj->args.append("-compatibility_version");
2716 lj->args.append(buf_ptr(compat_vers));
2717
2718 Buf *cur_vers = buf_sprintf("%" ZIG_PRI_usize ".%" ZIG_PRI_usize ".%" ZIG_PRI_usize,
2719 g->version_major, g->version_minor, g->version_patch);
2720 lj->args.append("-current_version");
2721 lj->args.append(buf_ptr(cur_vers));
2722
2723 // TODO getting an error when running an executable when doing this rpath thing
2724 //Buf *dylib_install_name = buf_sprintf("@rpath/lib%s.%" ZIG_PRI_usize ".dylib",
2725 // buf_ptr(g->root_out_name), g->version_major);
2726 //lj->args.append("-install_name");
2727 //lj->args.append(buf_ptr(dylib_install_name));
2728
2729 assert(buf_len(&g->bin_file_output_path) != 0);
2730 }
2731
2732 lj->args.append("-arch");
2733 lj->args.append(get_darwin_arch_string(g->zig_target));
2734
2735 if (g->zig_target->glibc_or_darwin_version != nullptr) {
2736 if (g->zig_target->os == OsMacOSX) {
2737 lj->args.append("-macosx_version_min");
2738 } else if (g->zig_target->os == OsIOS) {
2739 if (g->zig_target->arch == ZigLLVM_x86 || g->zig_target->arch == ZigLLVM_x86_64) {
2740 lj->args.append("-ios_simulator_version_min");
2741 } else {
2742 lj->args.append("-iphoneos_version_min");
2743 }
2744 }
2745
2746 Buf *version_string = buf_sprintf("%d.%d.%d",
2747 g->zig_target->glibc_or_darwin_version->major,
2748 g->zig_target->glibc_or_darwin_version->minor,
2749 g->zig_target->glibc_or_darwin_version->patch);
2750 lj->args.append(buf_ptr(version_string));
2751
2752 lj->args.append("-sdk_version");
2753 lj->args.append(buf_ptr(version_string));
2754 } else if (stage2_is_zig0 && g->zig_target->os == OsMacOSX) {
2755 // running `zig0`; `-pie` requires versions >= 10.5; select 10.13
2756 lj->args.append("-macosx_version_min");
2757 lj->args.append("10.13");
2758 lj->args.append("-sdk_version");
2759 lj->args.append("10.13");
2760 }
2761
2762 if (g->out_type == OutTypeExe) {
2763 lj->args.append("-pie");
2764 }
2765
2766 lj->args.append("-o");
2767 lj->args.append(buf_ptr(&g->bin_file_output_path));
2768
2769 for (size_t i = 0; i < g->rpath_list.length; i += 1) {
2770 Buf *rpath = g->rpath_list.at(i);
2771 add_rpath(lj, rpath);
2772 }
2773 if (is_dyn_lib) {
2774 add_rpath(lj, &g->bin_file_output_path);
2775 }
2776
2777 if (is_dyn_lib) {
2778 if (g->system_linker_hack) {
2779 lj->args.append("-headerpad_max_install_names");
2780 }
2781 }
2782
2783 for (size_t i = 0; i < g->lib_dirs.length; i += 1) {
2784 const char *lib_dir = g->lib_dirs.at(i);
2785 lj->args.append("-L");
2786 lj->args.append(lib_dir);
2787 }
2788
2789 // .o files
2790 for (size_t i = 0; i < g->link_objects.length; i += 1) {
2791 lj->args.append((const char *)buf_ptr(g->link_objects.at(i)));
2792 }
2793
2794 // compiler_rt on darwin is missing some stuff, so we still build it and rely on LinkOnce
2795 if (g->out_type == OutTypeExe || is_dyn_lib) {
2796 Buf *compiler_rt_o_path = build_compiler_rt(g, OutTypeLib, lj->build_dep_prog_node);
2797 lj->args.append(buf_ptr(compiler_rt_o_path));
2798 }
2799
2800 // libraries
2801 for (size_t lib_i = 0; lib_i < g->link_libs_list.length; lib_i += 1) {
2802 LinkLib *link_lib = g->link_libs_list.at(lib_i);
2803 if (buf_eql_str(link_lib->name, "c")) {
2804 // libc is linked specially
2805 continue;
2806 }
2807 if (target_is_libcpp_lib_name(g->zig_target, buf_ptr(link_lib->name))) {
2808 // libc++ is linked specially
2809 continue;
2810 }
2811 if (g->zig_target->is_native_os && target_is_libc_lib_name(g->zig_target, buf_ptr(link_lib->name))) {
2812 // libSystem is linked specially
2813 continue;
2814 }
2815
2816 Buf *arg;
2817 if (buf_starts_with_str(link_lib->name, "/") || buf_ends_with_str(link_lib->name, ".a") ||
2818 buf_ends_with_str(link_lib->name, ".dylib"))
2819 {
2820 arg = link_lib->name;
2821 } else {
2822 arg = buf_sprintf("-l%s", buf_ptr(link_lib->name));
2823 }
2824 lj->args.append(buf_ptr(arg));
2825 }
2826
2827 // libc++ dep
2828 if (g->libcpp_link_lib != nullptr && g->out_type != OutTypeObj) {
2829 lj->args.append(build_libcxxabi(g, lj->build_dep_prog_node));
2830 lj->args.append(build_libcxx(g, lj->build_dep_prog_node));
2831 }
2832
2833 // libc dep
2834 if (g->zig_target->is_native_os || stage2_is_zig0) {
2835 // on Darwin, libSystem has libc in it, but also you have to use it
2836 // to make syscalls because the syscall numbers are not documented
2837 // and change between versions.
2838 // so we always link against libSystem
2839 lj->args.append("-lSystem");
2840 }
2841
2842 for (size_t i = 0; i < g->framework_dirs.length; i += 1) {
2843 const char *framework_dir = g->framework_dirs.at(i);
2844 lj->args.append("-F");
2845 lj->args.append(framework_dir);
2846 }
2847
2848 for (size_t i = 0; i < g->darwin_frameworks.length; i += 1) {
2849 lj->args.append("-framework");
2850 lj->args.append(buf_ptr(g->darwin_frameworks.at(i)));
2851 }
2852
2853 switch (g->linker_allow_shlib_undefined) {
2854 case OptionalBoolNull:
2855 if (!g->zig_target->is_native_os && !stage2_is_zig0) {
2856 // TODO https://github.com/ziglang/zig/issues/5059
2857 lj->args.append("-undefined");
2858 lj->args.append("dynamic_lookup");
2859 }
2860 break;
2861 case OptionalBoolFalse:
2862 break;
2863 case OptionalBoolTrue:
2864 lj->args.append("-undefined");
2865 lj->args.append("dynamic_lookup");
2866 break;
2867 }
2868 switch (g->linker_bind_global_refs_locally) {
2869 case OptionalBoolNull:
2870 case OptionalBoolFalse:
2871 break;
2872 case OptionalBoolTrue:
2873 lj->args.append("-Bsymbolic");
2874 break;
2875 }
2876}
2877
2878static void construct_linker_job(LinkJob *lj) {
2879 switch (target_object_format(lj->codegen->zig_target)) {
2880 case ZigLLVM_UnknownObjectFormat:
2881 case ZigLLVM_XCOFF:
2882 zig_unreachable();
2883
2884 case ZigLLVM_COFF:
2885 return construct_linker_job_coff(lj);
2886 case ZigLLVM_ELF:
2887 return construct_linker_job_elf(lj);
2888 case ZigLLVM_MachO:
2889 return construct_linker_job_macho(lj);
2890 case ZigLLVM_Wasm:
2891 return construct_linker_job_wasm(lj);
2892 }
2893}
2894
2895void zig_link_add_compiler_rt(CodeGen *g, Stage2ProgressNode *progress_node) {
2896 Buf *compiler_rt_o_path = build_compiler_rt(g, OutTypeObj, progress_node);
2897 g->link_objects.append(compiler_rt_o_path);
2898}
2899
2900void codegen_link(CodeGen *g) {
2901 codegen_add_time_event(g, "Build Dependencies");
2902 LinkJob lj = {0};
2903
2904 {
2905 const char *progress_name = "Build Dependencies";
2906 codegen_switch_sub_prog_node(g, stage2_progress_start(g->main_progress_node,
2907 progress_name, strlen(progress_name), 0));
2908 lj.build_dep_prog_node = g->sub_progress_node;
2909 }
2910
2911
2912 // even though we're calling LLD as a library it thinks the first
2913 // argument is its own exe name
2914 lj.args.append("lld");
2915
2916 lj.rpath_table.init(4);
2917 lj.codegen = g;
2918
2919 if (g->out_type == OutTypeObj) {
2920 lj.args.append("-r");
2921 }
2922
2923 if (g->out_type == OutTypeLib && !g->is_dynamic && !target_is_wasm(g->zig_target)) {
2924 ZigList<const char *> file_names = {};
2925 for (size_t i = 0; i < g->link_objects.length; i += 1) {
2926 file_names.append(buf_ptr(g->link_objects.at(i)));
2927 }
2928 ZigLLVM_OSType os_type = get_llvm_os_type(g->zig_target->os);
2929 codegen_add_time_event(g, "LLVM Link");
2930 {
2931 const char *progress_name = "Link";
2932 codegen_switch_sub_prog_node(g, stage2_progress_start(g->main_progress_node,
2933 progress_name, strlen(progress_name), 0));
2934 }
2935 if (g->verbose_link) {
2936 fprintf(stderr, "ar rcs %s", buf_ptr(&g->bin_file_output_path));
2937 for (size_t i = 0; i < file_names.length; i += 1) {
2938 fprintf(stderr, " %s", file_names.at(i));
2939 }
2940 fprintf(stderr, "\n");
2941 }
2942 if (ZigLLVMWriteArchive(buf_ptr(&g->bin_file_output_path), file_names.items, file_names.length, os_type)) {
2943 fprintf(stderr, "Unable to write archive '%s'\n", buf_ptr(&g->bin_file_output_path));
2944 exit(1);
2945 }
2946 return;
2947 }
2948
2949 lj.link_in_crt = (g->libc_link_lib != nullptr && g->out_type == OutTypeExe);
2950
2951 construct_linker_job(&lj);
2952
2953 if (g->verbose_link) {
2954 for (size_t i = 0; i < lj.args.length; i += 1) {
2955 const char *space = (i != 0) ? " " : "";
2956 fprintf(stderr, "%s%s", space, lj.args.at(i));
2957 }
2958 fprintf(stderr, "\n");
2959 }
2960
2961 Buf diag = BUF_INIT;
2962
2963 codegen_add_time_event(g, "LLVM Link");
2964 {
2965 const char *progress_name = "Link";
2966 codegen_switch_sub_prog_node(g, stage2_progress_start(g->main_progress_node,
2967 progress_name, strlen(progress_name), 0));
2968 }
2969 if (g->system_linker_hack && g->zig_target->os == OsMacOSX) {
2970 Termination term;
2971 ZigList<const char *> args = {};
2972 args.append("ld");
2973 for (size_t i = 1; i < lj.args.length; i += 1) {
2974 args.append(lj.args.at(i));
2975 }
2976 os_spawn_process(args, &term);
2977 if (term.how != TerminationIdClean || term.code != 0) {
2978 exit(1);
2979 }
2980 } else if (!zig_lld_link(target_object_format(g->zig_target), lj.args.items, lj.args.length, &diag)) {
2981 fprintf(stderr, "%s\n", buf_ptr(&diag));
2982 exit(1);
2983 }
2984}
2985
src/main.cpp deleted-1474
...@@ -1,1474 +0,0 @@
1/*
2 * Copyright (c) 2015 Andrew Kelley
3 *
4 * This file is part of zig, which is MIT licensed.
5 * See http://opensource.org/licenses/MIT
6 */
7
8#include "ast_render.hpp"
9#include "buffer.hpp"
10#include "codegen.hpp"
11#include "compiler.hpp"
12#include "config.h"
13#include "error.hpp"
14#include "heap.hpp"
15#include "os.hpp"
16#include "target.hpp"
17#include "stage2.h"
18#include "glibc.hpp"
19#include "dump_analysis.hpp"
20#include "mem_profile.hpp"
21
22#include <stdio.h>
23
24static int print_error_usage(const char *arg0) {
25 fprintf(stderr, "See `%s --help` for detailed usage information\n", arg0);
26 return EXIT_FAILURE;
27}
28
29static int print_full_usage(const char *arg0, FILE *file, int return_code) {
30 fprintf(file,
31 "Usage: %s [command] [options]\n"
32 "\n"
33 "Commands:\n"
34 " build build project from build.zig\n"
35 " build-exe [source] create executable from source or object files\n"
36 " build-lib [source] create library from source or object files\n"
37 " build-obj [source] create object from source or assembly\n"
38 " builtin show the source code of @import(\"builtin\")\n"
39 " cc use Zig as a drop-in C compiler\n"
40 " c++ use Zig as a drop-in C++ compiler\n"
41 " env print lib path, std path, compiler id and version\n"
42 " fmt parse files and render in canonical zig format\n"
43 " id print the base64-encoded compiler id\n"
44 " init-exe initialize a `zig build` application in the cwd\n"
45 " init-lib initialize a `zig build` library in the cwd\n"
46 " libc [paths_file] Display native libc paths file or validate one\n"
47 " run [source] [-- [args]] create executable and run immediately\n"
48 " translate-c [source] convert c code to zig code\n"
49 " targets list available compilation targets\n"
50 " test [source] create and run a test build\n"
51 " version print version number and exit\n"
52 " zen print zen of zig and exit\n"
53 "\n"
54 "Compile Options:\n"
55 " --c-source [options] [file] compile C source code\n"
56 " --cache-dir [path] override the local cache directory\n"
57 " --cache [auto|off|on] build in cache, print output path to stdout\n"
58 " --color [auto|off|on] enable or disable colored error messages\n"
59 " --disable-valgrind omit valgrind client requests in debug builds\n"
60 " --eh-frame-hdr enable C++ exception handling by passing --eh-frame-hdr to linker\n"
61 " --enable-valgrind include valgrind client requests release builds\n"
62 " -fstack-check enable stack probing in unsafe builds\n"
63 " -fno-stack-check disable stack probing in safe builds\n"
64 " -fsanitize-c enable C undefined behavior detection in unsafe builds\n"
65 " -fno-sanitize-c disable C undefined behavior detection in safe builds\n"
66 " --emit [asm|bin|llvm-ir] (deprecated) emit a specific file format as compilation output\n"
67 " -fPIC enable Position Independent Code\n"
68 " -fno-PIC disable Position Independent Code\n"
69 " -ftime-report print timing diagnostics\n"
70 " -fstack-report print stack size diagnostics\n"
71 " -fmem-report print memory usage diagnostics\n"
72 " -fdump-analysis write analysis.json file with type information\n"
73 " -femit-docs create a docs/ dir with html documentation\n"
74 " -fno-emit-docs do not produce docs/ dir with html documentation\n"
75 " -femit-bin (default) output machine code\n"
76 " -fno-emit-bin do not output machine code\n"
77 " -femit-asm output .s (assembly code)\n"
78 " -fno-emit-asm (default) do not output .s (assembly code)\n"
79 " -femit-llvm-ir produce a .ll file with LLVM IR\n"
80 " -fno-emit-llvm-ir (default) do not produce a .ll file with LLVM IR\n"
81 " -femit-h generate a C header file (.h)\n"
82 " -fno-emit-h (default) do not generate a C header file (.h)\n"
83 " --libc [file] Provide a file which specifies libc paths\n"
84 " --name [name] override output name\n"
85 " --output-dir [dir] override output directory (defaults to cwd)\n"
86 " --pkg-begin [name] [path] make pkg available to import and push current pkg\n"
87 " --pkg-end pop current pkg\n"
88 " --main-pkg-path set the directory of the root package\n"
89 " --release-fast build with optimizations on and safety off\n"
90 " --release-safe build with optimizations on and safety on\n"
91 " --release-small build with size optimizations on and safety off\n"
92 " --single-threaded source may assume it is only used single-threaded\n"
93 " -dynamic create a shared library (.so; .dll; .dylib)\n"
94 " --strip exclude debug symbols\n"
95 " -target [name] <arch>-<os>-<abi> see the targets command\n"
96 " --verbose-tokenize enable compiler debug output for tokenization\n"
97 " --verbose-ast enable compiler debug output for AST parsing\n"
98 " --verbose-link enable compiler debug output for linking\n"
99 " --verbose-ir enable compiler debug output for Zig IR\n"
100 " --verbose-llvm-ir enable compiler debug output for LLVM IR\n"
101 " --verbose-cimport enable compiler debug output for C imports\n"
102 " --verbose-cc enable compiler debug output for C compilation\n"
103 " --verbose-llvm-cpu-features enable compiler debug output for LLVM CPU features\n"
104 " -dirafter [dir] add directory to AFTER include search path\n"
105 " -isystem [dir] add directory to SYSTEM include search path\n"
106 " -I[dir] add directory to include search path\n"
107 " -mllvm [arg] (unsupported) forward an arg to LLVM's option processing\n"
108 " --override-lib-dir [arg] override path to Zig lib directory\n"
109 " -ffunction-sections places each function in a separate section\n"
110 " -D[macro]=[value] define C [macro] to [value] (1 if [value] omitted)\n"
111 " -mcpu [cpu] specify target CPU and feature set\n"
112 " -code-model [default|tiny| set target code model\n"
113 " small|kernel|\n"
114 " medium|large]\n"
115 "\n"
116 "Link Options:\n"
117 " --bundle-compiler-rt for static libraries, include compiler-rt symbols\n"
118 " --dynamic-linker [path] set the path to ld.so\n"
119 " --each-lib-rpath add rpath for each used dynamic library\n"
120 " --library [lib] link against lib\n"
121 " --forbid-library [lib] make it an error to link against lib\n"
122 " --library-path [dir] add a directory to the library search path\n"
123 " --linker-script [path] use a custom linker script\n"
124 " --version-script [path] provide a version .map file\n"
125 " --object [obj] add object file to build\n"
126 " -L[dir] alias for --library-path\n"
127 " -l[lib] alias for --library\n"
128 " -rdynamic add all symbols to the dynamic symbol table\n"
129 " -rpath [path] add directory to the runtime library search path\n"
130 " --stack [size] (linux, windows, Wasm) override default stack size\n"
131 " --subsystem [subsystem] (windows) /SUBSYSTEM:<subsystem> to the linker\n"
132 " -F[dir] (darwin) add search path for frameworks\n"
133 " -framework [name] (darwin) link against framework\n"
134 " --ver-major [ver] dynamic library semver major version\n"
135 " --ver-minor [ver] dynamic library semver minor version\n"
136 " --ver-patch [ver] dynamic library semver patch version\n"
137 " -Bsymbolic bind global references locally\n"
138 "\n"
139 "Test Options:\n"
140 " --test-filter [text] skip tests that do not match filter\n"
141 " --test-name-prefix [text] add prefix to all tests\n"
142 " --test-cmd [arg] specify test execution command one arg at a time\n"
143 " --test-cmd-bin appends test binary path to test cmd args\n"
144 " --test-evented-io runs the test in evented I/O mode\n"
145 , arg0);
146 return return_code;
147}
148
149static int print_libc_usage(const char *arg0, FILE *file, int return_code) {
150 fprintf(file,
151 "Usage: %s libc\n"
152 "\n"
153 "Detect the native libc installation and print the resulting paths to stdout.\n"
154 "You can save this into a file and then edit the paths to create a cross\n"
155 "compilation libc kit. Then you can pass `--libc [file]` for Zig to use it.\n"
156 "\n"
157 "When compiling natively and no `--libc` argument provided, Zig will create\n"
158 "`%s/native_libc.txt`\n"
159 "so that it does not have to detect libc on every invocation. You can remove\n"
160 "this file to have Zig re-detect the native libc.\n"
161 "\n\n"
162 "Usage: %s libc [file]\n"
163 "\n"
164 "Parse a libc installation text file and validate it.\n"
165 , arg0, buf_ptr(get_global_cache_dir()), arg0);
166 return return_code;
167}
168
169enum Cmd {
170 CmdNone,
171 CmdBuild,
172 CmdBuiltin,
173 CmdRun,
174 CmdTargets,
175 CmdTest,
176 CmdTranslateC,
177 CmdVersion,
178 CmdZen,
179 CmdLibC,
180};
181
182static const char *default_zig_cache_name = "zig-cache";
183
184struct CliPkg {
185 const char *name;
186 const char *path;
187 ZigList<CliPkg *> children;
188 CliPkg *parent;
189};
190
191static void add_package(CodeGen *g, CliPkg *cli_pkg, ZigPackage *pkg) {
192 for (size_t i = 0; i < cli_pkg->children.length; i += 1) {
193 CliPkg *child_cli_pkg = cli_pkg->children.at(i);
194
195 Buf *dirname = buf_alloc();
196 Buf *basename = buf_alloc();
197 os_path_split(buf_create_from_str(child_cli_pkg->path), dirname, basename);
198
199 ZigPackage *child_pkg = codegen_create_package(g, buf_ptr(dirname), buf_ptr(basename),
200 buf_ptr(buf_sprintf("%s.%s", buf_ptr(&pkg->pkg_path), child_cli_pkg->name)));
201 auto entry = pkg->package_table.put_unique(buf_create_from_str(child_cli_pkg->name), child_pkg);
202 if (entry) {
203 ZigPackage *existing_pkg = entry->value;
204 Buf *full_path = buf_alloc();
205 os_path_join(&existing_pkg->root_src_dir, &existing_pkg->root_src_path, full_path);
206 fprintf(stderr, "Unable to add package '%s'->'%s': already exists as '%s'\n",
207 child_cli_pkg->name, child_cli_pkg->path, buf_ptr(full_path));
208 exit(EXIT_FAILURE);
209 }
210
211 add_package(g, child_cli_pkg, child_pkg);
212 }
213}
214
215enum CacheOpt {
216 CacheOptAuto,
217 CacheOptOn,
218 CacheOptOff,
219};
220
221static bool get_cache_opt(CacheOpt opt, bool default_value) {
222 switch (opt) {
223 case CacheOptAuto:
224 return default_value;
225 case CacheOptOn:
226 return true;
227 case CacheOptOff:
228 return false;
229 }
230 zig_unreachable();
231}
232
233static int zig_error_no_build_file(void) {
234 fprintf(stderr,
235 "No 'build.zig' file found, in the current directory or any parent directories.\n"
236 "Initialize a 'build.zig' template file with `zig init-lib` or `zig init-exe`,\n"
237 "or see `zig --help` for more options.\n"
238 );
239 return EXIT_FAILURE;
240}
241
242static bool str_starts_with(const char *s1, const char *s2) {
243 size_t s2_len = strlen(s2);
244 if (strlen(s1) < s2_len) {
245 return false;
246 }
247 return memcmp(s1, s2, s2_len) == 0;
248}
249
250extern "C" int ZigClang_main(int argc, char **argv);
251
252#ifdef ZIG_ENABLE_MEM_PROFILE
253bool mem_report = false;
254#endif
255
256int main_exit(Stage2ProgressNode *root_progress_node, int exit_code) {
257 if (root_progress_node != nullptr) {
258 stage2_progress_end(root_progress_node);
259 }
260 return exit_code;
261}
262
263static int main0(int argc, char **argv) {
264 char *arg0 = argv[0];
265 Error err;
266
267 if (argc >= 2 && (strcmp(argv[1], "clang") == 0 ||
268 strcmp(argv[1], "-cc1") == 0 || strcmp(argv[1], "-cc1as") == 0))
269 {
270 return ZigClang_main(argc, argv);
271 }
272
273 if (argc == 2 && strcmp(argv[1], "id") == 0) {
274 Buf *compiler_id;
275 if ((err = get_compiler_id(&compiler_id))) {
276 fprintf(stderr, "Unable to determine compiler id: %s\n", err_str(err));
277 return EXIT_FAILURE;
278 }
279 printf("%s\n", buf_ptr(compiler_id));
280 return EXIT_SUCCESS;
281 }
282
283 enum InitKind {
284 InitKindNone,
285 InitKindExe,
286 InitKindLib,
287 };
288 InitKind init_kind = InitKindNone;
289 if (argc >= 2) {
290 const char *init_cmd = argv[1];
291 if (strcmp(init_cmd, "init-exe") == 0) {
292 init_kind = InitKindExe;
293 } else if (strcmp(init_cmd, "init-lib") == 0) {
294 init_kind = InitKindLib;
295 }
296 if (init_kind != InitKindNone) {
297 if (argc >= 3) {
298 fprintf(stderr, "Unexpected extra argument: %s\n", argv[2]);
299 return print_error_usage(arg0);
300 }
301 Buf *cmd_template_path = buf_alloc();
302 os_path_join(get_zig_special_dir(get_zig_lib_dir()), buf_create_from_str(init_cmd), cmd_template_path);
303 Buf *build_zig_path = buf_alloc();
304 os_path_join(cmd_template_path, buf_create_from_str("build.zig"), build_zig_path);
305 Buf *src_dir_path = buf_alloc();
306 os_path_join(cmd_template_path, buf_create_from_str("src"), src_dir_path);
307 Buf *main_zig_path = buf_alloc();
308 os_path_join(src_dir_path, buf_create_from_str("main.zig"), main_zig_path);
309
310 Buf *cwd = buf_alloc();
311 if ((err = os_get_cwd(cwd))) {
312 fprintf(stderr, "Unable to get cwd: %s\n", err_str(err));
313 return EXIT_FAILURE;
314 }
315 Buf *cwd_basename = buf_alloc();
316 os_path_split(cwd, nullptr, cwd_basename);
317
318 Buf *build_zig_contents = buf_alloc();
319 if ((err = os_fetch_file_path(build_zig_path, build_zig_contents))) {
320 fprintf(stderr, "Unable to read %s: %s\n", buf_ptr(build_zig_path), err_str(err));
321 return EXIT_FAILURE;
322 }
323 Buf *modified_build_zig_contents = buf_alloc();
324 for (size_t i = 0; i < buf_len(build_zig_contents); i += 1) {
325 char c = buf_ptr(build_zig_contents)[i];
326 if (c == '$') {
327 buf_append_buf(modified_build_zig_contents, cwd_basename);
328 } else {
329 buf_append_char(modified_build_zig_contents, c);
330 }
331 }
332
333 Buf *main_zig_contents = buf_alloc();
334 if ((err = os_fetch_file_path(main_zig_path, main_zig_contents))) {
335 fprintf(stderr, "Unable to read %s: %s\n", buf_ptr(main_zig_path), err_str(err));
336 return EXIT_FAILURE;
337 }
338
339 Buf *out_build_zig_path = buf_create_from_str("build.zig");
340 Buf *out_src_dir_path = buf_create_from_str("src");
341 Buf *out_main_zig_path = buf_alloc();
342 os_path_join(out_src_dir_path, buf_create_from_str("main.zig"), out_main_zig_path);
343
344 bool already_exists;
345 if ((err = os_file_exists(out_build_zig_path, &already_exists))) {
346 fprintf(stderr, "Unable test existence of %s: %s\n", buf_ptr(out_build_zig_path), err_str(err));
347 return EXIT_FAILURE;
348 }
349 if (already_exists) {
350 fprintf(stderr, "This file would be overwritten: %s\n", buf_ptr(out_build_zig_path));
351 return EXIT_FAILURE;
352 }
353
354 if ((err = os_make_dir(out_src_dir_path))) {
355 fprintf(stderr, "Unable to make directory: %s: %s\n", buf_ptr(out_src_dir_path), err_str(err));
356 return EXIT_FAILURE;
357 }
358 if ((err = os_write_file(out_build_zig_path, modified_build_zig_contents))) {
359 fprintf(stderr, "Unable to write file: %s: %s\n", buf_ptr(out_build_zig_path), err_str(err));
360 return EXIT_FAILURE;
361 }
362 if ((err = os_write_file(out_main_zig_path, main_zig_contents))) {
363 fprintf(stderr, "Unable to write file: %s: %s\n", buf_ptr(out_main_zig_path), err_str(err));
364 return EXIT_FAILURE;
365 }
366 fprintf(stderr, "Created %s\n", buf_ptr(out_build_zig_path));
367 fprintf(stderr, "Created %s\n", buf_ptr(out_main_zig_path));
368 if (init_kind == InitKindExe) {
369 fprintf(stderr, "\nNext, try `zig build --help` or `zig build run`\n");
370 } else if (init_kind == InitKindLib) {
371 fprintf(stderr, "\nNext, try `zig build --help` or `zig build test`\n");
372 } else {
373 zig_unreachable();
374 }
375
376 return EXIT_SUCCESS;
377 }
378 }
379
380 Cmd cmd = CmdNone;
381 const char *in_file = nullptr;
382 Buf *output_dir = nullptr;
383 bool strip = false;
384 bool is_dynamic = false;
385 OutType out_type = OutTypeUnknown;
386 const char *out_name = nullptr;
387 bool verbose_tokenize = false;
388 bool verbose_ast = false;
389 bool verbose_link = false;
390 bool verbose_ir = false;
391 bool verbose_llvm_ir = false;
392 bool verbose_cimport = false;
393 bool verbose_cc = false;
394 bool verbose_llvm_cpu_features = false;
395 bool link_eh_frame_hdr = false;
396 ErrColor color = ErrColorAuto;
397 CacheOpt enable_cache = CacheOptAuto;
398 const char *dynamic_linker = nullptr;
399 const char *libc_txt = nullptr;
400 ZigList<const char *> clang_argv = {0};
401 ZigList<const char *> lib_dirs = {0};
402 ZigList<const char *> link_libs = {0};
403 ZigList<const char *> forbidden_link_libs = {0};
404 ZigList<const char *> framework_dirs = {0};
405 ZigList<const char *> frameworks = {0};
406 bool have_libc = false;
407 const char *target_string = nullptr;
408 bool rdynamic = false;
409 const char *linker_script = nullptr;
410 Buf *version_script = nullptr;
411 ZigList<const char *> rpath_list = {0};
412 bool each_lib_rpath = false;
413 ZigList<const char *> objects = {0};
414 ZigList<CFile *> c_source_files = {0};
415 const char *test_filter = nullptr;
416 const char *test_name_prefix = nullptr;
417 bool test_evented_io = false;
418 bool is_versioned = false;
419 size_t ver_major = 0;
420 size_t ver_minor = 0;
421 size_t ver_patch = 0;
422 bool timing_info = false;
423 bool stack_report = false;
424 bool enable_dump_analysis = false;
425 bool enable_doc_generation = false;
426 bool emit_bin = true;
427 const char *emit_bin_override_path = nullptr;
428 bool emit_asm = false;
429 bool emit_llvm_ir = false;
430 bool emit_h = false;
431 const char *cache_dir = nullptr;
432 CliPkg *cur_pkg = heap::c_allocator.create<CliPkg>();
433 BuildMode build_mode = BuildModeDebug;
434 ZigList<const char *> test_exec_args = {0};
435 int runtime_args_start = -1;
436 bool system_linker_hack = false;
437 TargetSubsystem subsystem = TargetSubsystemAuto;
438 bool want_single_threaded = false;
439 bool bundle_compiler_rt = false;
440 Buf *override_lib_dir = nullptr;
441 Buf *main_pkg_path = nullptr;
442 ValgrindSupport valgrind_support = ValgrindSupportAuto;
443 WantPIC want_pic = WantPICAuto;
444 WantStackCheck want_stack_check = WantStackCheckAuto;
445 WantCSanitize want_sanitize_c = WantCSanitizeAuto;
446 bool function_sections = false;
447 const char *mcpu = nullptr;
448 CodeModel code_model = CodeModelDefault;
449 bool want_native_include_dirs = false;
450 OptionalBool linker_bind_global_refs_locally = OptionalBoolNull;
451 size_t stack_size_override = 0;
452
453 ZigList<const char *> llvm_argv = {0};
454 llvm_argv.append("zig (LLVM option parsing)");
455
456 if (argc >= 2 && strcmp(argv[1], "build") == 0) {
457 Buf zig_exe_path_buf = BUF_INIT;
458 if ((err = os_self_exe_path(&zig_exe_path_buf))) {
459 fprintf(stderr, "Unable to determine path to zig's own executable\n");
460 return EXIT_FAILURE;
461 }
462 const char *zig_exe_path = buf_ptr(&zig_exe_path_buf);
463 const char *build_file = nullptr;
464
465 init_all_targets();
466
467 ZigList<const char *> args = {0};
468 args.append(NULL); // placeholder
469 args.append(zig_exe_path);
470 args.append(NULL); // placeholder
471 args.append(NULL); // placeholder
472 for (int i = 2; i < argc; i += 1) {
473 if (strcmp(argv[i], "--help") == 0) {
474 args.append(argv[i]);
475 } else if (i + 1 < argc && strcmp(argv[i], "--build-file") == 0) {
476 build_file = argv[i + 1];
477 i += 1;
478 } else if (i + 1 < argc && strcmp(argv[i], "--cache-dir") == 0) {
479 cache_dir = argv[i + 1];
480 i += 1;
481 } else if (i + 1 < argc && strcmp(argv[i], "--override-lib-dir") == 0) {
482 override_lib_dir = buf_create_from_str(argv[i + 1]);
483 i += 1;
484
485 args.append("--override-lib-dir");
486 args.append(buf_ptr(override_lib_dir));
487 } else {
488 args.append(argv[i]);
489 }
490 }
491
492 Buf *zig_lib_dir = (override_lib_dir == nullptr) ? get_zig_lib_dir() : override_lib_dir;
493
494 Buf *build_runner_path = buf_alloc();
495 os_path_join(get_zig_special_dir(zig_lib_dir), buf_create_from_str("build_runner.zig"), build_runner_path);
496
497 ZigTarget target;
498 if ((err = target_parse_triple(&target, "native", nullptr, nullptr))) {
499 fprintf(stderr, "Unable to get native target: %s\n", err_str(err));
500 return EXIT_FAILURE;
501 }
502
503 Buf *build_file_buf = buf_create_from_str((build_file != nullptr) ? build_file : "build.zig");
504 Buf build_file_abs = os_path_resolve(&build_file_buf, 1);
505 Buf build_file_basename = BUF_INIT;
506 Buf build_file_dirname = BUF_INIT;
507 os_path_split(&build_file_abs, &build_file_dirname, &build_file_basename);
508
509 for (;;) {
510 bool build_file_exists;
511 if ((err = os_file_exists(&build_file_abs, &build_file_exists))) {
512 fprintf(stderr, "unable to check existence of '%s': %s\n", buf_ptr(&build_file_abs), err_str(err));
513 return 1;
514 }
515 if (build_file_exists)
516 break;
517
518 if (build_file != nullptr) {
519 // they asked for a specific build file path. only look for that one
520 return zig_error_no_build_file();
521 }
522
523 Buf *next_dir = buf_alloc();
524 os_path_dirname(&build_file_dirname, next_dir);
525 if (buf_eql_buf(&build_file_dirname, next_dir)) {
526 // no more parent directories to search, give up
527 return zig_error_no_build_file();
528 }
529 os_path_join(next_dir, &build_file_basename, &build_file_abs);
530 buf_init_from_buf(&build_file_dirname, next_dir);
531 }
532
533 Buf full_cache_dir = BUF_INIT;
534 if (cache_dir == nullptr) {
535 os_path_join(&build_file_dirname, buf_create_from_str(default_zig_cache_name), &full_cache_dir);
536 } else {
537 Buf *cache_dir_buf = buf_create_from_str(cache_dir);
538 full_cache_dir = os_path_resolve(&cache_dir_buf, 1);
539 }
540 Stage2ProgressNode *root_progress_node = stage2_progress_start_root(stage2_progress_create(), "", 0, 0);
541
542 CodeGen *g = codegen_create(main_pkg_path, build_runner_path, &target, OutTypeExe,
543 BuildModeDebug, override_lib_dir, nullptr, &full_cache_dir, false, root_progress_node);
544 g->valgrind_support = valgrind_support;
545 g->enable_time_report = timing_info;
546 codegen_set_out_name(g, buf_create_from_str("build"));
547
548 args.items[2] = buf_ptr(&build_file_dirname);
549 args.items[3] = buf_ptr(&full_cache_dir);
550
551 ZigPackage *build_pkg = codegen_create_package(g, buf_ptr(&build_file_dirname),
552 buf_ptr(&build_file_basename), "std.special");
553 g->main_pkg->package_table.put(buf_create_from_str("@build"), build_pkg);
554 g->enable_cache = get_cache_opt(enable_cache, true);
555 codegen_build_and_link(g);
556 if (root_progress_node != nullptr) {
557 stage2_progress_end(root_progress_node);
558 root_progress_node = nullptr;
559 }
560
561 Termination term;
562 args.items[0] = buf_ptr(&g->bin_file_output_path);
563 os_spawn_process(args, &term);
564 if (term.how != TerminationIdClean || term.code != 0) {
565 fprintf(stderr, "\nBuild failed. The following command failed:\n");
566 const char *prefix = "";
567 for (size_t i = 0; i < args.length; i += 1) {
568 fprintf(stderr, "%s%s", prefix, args.at(i));
569 prefix = " ";
570 }
571 fprintf(stderr, "\n");
572 }
573 return (term.how == TerminationIdClean) ? term.code : -1;
574 } else if (argc >= 2 && strcmp(argv[1], "fmt") == 0) {
575 return stage2_fmt(argc, argv);
576 } else if (argc >= 2 && strcmp(argv[1], "env") == 0) {
577 return stage2_env(argc, argv);
578 } else if (argc >= 2 && strcmp(argv[1], "cc") == 0) {
579 return stage2_cc(argc, argv, false);
580 } else if (argc >= 2 && strcmp(argv[1], "c++") == 0) {
581 return stage2_cc(argc, argv, true);
582 } else for (int i = 1; i < argc; i += 1) {
583 char *arg = argv[i];
584
585 if (arg[0] == '-') {
586 if (strcmp(arg, "--") == 0) {
587 if (cmd == CmdRun) {
588 runtime_args_start = i + 1;
589 break; // rest of the args are for the program
590 } else {
591 fprintf(stderr, "Unexpected end-of-parameter mark: %s\n", arg);
592 }
593 } else if (strcmp(arg, "--release-fast") == 0) {
594 build_mode = BuildModeFastRelease;
595 } else if (strcmp(arg, "--release-safe") == 0) {
596 build_mode = BuildModeSafeRelease;
597 } else if (strcmp(arg, "--release-small") == 0) {
598 build_mode = BuildModeSmallRelease;
599 } else if (strcmp(arg, "--help") == 0) {
600 if (cmd == CmdLibC) {
601 return print_libc_usage(arg0, stdout, EXIT_SUCCESS);
602 } else {
603 return print_full_usage(arg0, stdout, EXIT_SUCCESS);
604 }
605 } else if (strcmp(arg, "--strip") == 0) {
606 strip = true;
607 } else if (strcmp(arg, "-dynamic") == 0) {
608 is_dynamic = true;
609 } else if (strcmp(arg, "--verbose-tokenize") == 0) {
610 verbose_tokenize = true;
611 } else if (strcmp(arg, "--verbose-ast") == 0) {
612 verbose_ast = true;
613 } else if (strcmp(arg, "--verbose-link") == 0) {
614 verbose_link = true;
615 } else if (strcmp(arg, "--verbose-ir") == 0) {
616 verbose_ir = true;
617 } else if (strcmp(arg, "--verbose-llvm-ir") == 0) {
618 verbose_llvm_ir = true;
619 } else if (strcmp(arg, "--verbose-cimport") == 0) {
620 verbose_cimport = true;
621 } else if (strcmp(arg, "--verbose-cc") == 0) {
622 verbose_cc = true;
623 } else if (strcmp(arg, "--verbose-llvm-cpu-features") == 0) {
624 verbose_llvm_cpu_features = true;
625 } else if (strcmp(arg, "-rdynamic") == 0) {
626 rdynamic = true;
627 } else if (strcmp(arg, "--each-lib-rpath") == 0) {
628 each_lib_rpath = true;
629 } else if (strcmp(arg, "-ftime-report") == 0) {
630 timing_info = true;
631 } else if (strcmp(arg, "-fstack-report") == 0) {
632 stack_report = true;
633 } else if (strcmp(arg, "-fmem-report") == 0) {
634#ifdef ZIG_ENABLE_MEM_PROFILE
635 mem_report = true;
636 mem::report_print = true;
637#else
638 fprintf(stderr, "-fmem-report requires configuring with -DZIG_ENABLE_MEM_PROFILE=ON\n");
639 return print_error_usage(arg0);
640#endif
641 } else if (strcmp(arg, "-fdump-analysis") == 0) {
642 enable_dump_analysis = true;
643 } else if (strcmp(arg, "-femit-docs") == 0) {
644 enable_doc_generation = true;
645 } else if (strcmp(arg, "--enable-valgrind") == 0) {
646 valgrind_support = ValgrindSupportEnabled;
647 } else if (strcmp(arg, "--disable-valgrind") == 0) {
648 valgrind_support = ValgrindSupportDisabled;
649 } else if (strcmp(arg, "--eh-frame-hdr") == 0) {
650 link_eh_frame_hdr = true;
651 } else if (strcmp(arg, "-fPIC") == 0) {
652 want_pic = WantPICEnabled;
653 } else if (strcmp(arg, "-fno-PIC") == 0) {
654 want_pic = WantPICDisabled;
655 } else if (strcmp(arg, "-fstack-check") == 0) {
656 want_stack_check = WantStackCheckEnabled;
657 } else if (strcmp(arg, "-fno-stack-check") == 0) {
658 want_stack_check = WantStackCheckDisabled;
659 } else if (strcmp(arg, "-fsanitize-c") == 0) {
660 want_sanitize_c = WantCSanitizeEnabled;
661 } else if (strcmp(arg, "-fno-sanitize-c") == 0) {
662 want_sanitize_c = WantCSanitizeDisabled;
663 } else if (strcmp(arg, "--system-linker-hack") == 0) {
664 system_linker_hack = true;
665 } else if (strcmp(arg, "--single-threaded") == 0) {
666 want_single_threaded = true;;
667 } else if (strcmp(arg, "--bundle-compiler-rt") == 0) {
668 bundle_compiler_rt = true;
669 } else if (strcmp(arg, "-Bsymbolic") == 0) {
670 linker_bind_global_refs_locally = OptionalBoolTrue;
671 } else if (strcmp(arg, "--test-cmd-bin") == 0) {
672 test_exec_args.append(nullptr);
673 } else if (arg[1] == 'D' && arg[2] != 0) {
674 clang_argv.append("-D");
675 clang_argv.append(&arg[2]);
676 } else if (arg[1] == 'L' && arg[2] != 0) {
677 // alias for --library-path
678 lib_dirs.append(&arg[2]);
679 } else if (arg[1] == 'l' && arg[2] != 0) {
680 // alias for --library
681 const char *l = &arg[2];
682 if (strcmp(l, "c") == 0) {
683 have_libc = true;
684 link_libs.append("c");
685 } else if (strcmp(l, "c++") == 0 || strcmp(l, "stdc++") == 0) {
686 link_libs.append("c++");
687 } else {
688 link_libs.append(l);
689 }
690 } else if (arg[1] == 'I' && arg[2] != 0) {
691 clang_argv.append("-I");
692 clang_argv.append(&arg[2]);
693 } else if (arg[1] == 'F' && arg[2] != 0) {
694 framework_dirs.append(&arg[2]);
695 } else if (strcmp(arg, "--pkg-begin") == 0) {
696 if (i + 2 >= argc) {
697 fprintf(stderr, "Expected 2 arguments after --pkg-begin\n");
698 return print_error_usage(arg0);
699 }
700 CliPkg *new_cur_pkg = heap::c_allocator.create<CliPkg>();
701 i += 1;
702 new_cur_pkg->name = argv[i];
703 i += 1;
704 new_cur_pkg->path = argv[i];
705 new_cur_pkg->parent = cur_pkg;
706 cur_pkg->children.append(new_cur_pkg);
707 cur_pkg = new_cur_pkg;
708 } else if (strcmp(arg, "--pkg-end") == 0) {
709 if (cur_pkg->parent == nullptr) {
710 fprintf(stderr, "Encountered --pkg-end with no matching --pkg-begin\n");
711 return EXIT_FAILURE;
712 }
713 cur_pkg = cur_pkg->parent;
714 } else if (strcmp(arg, "-ffunction-sections") == 0) {
715 function_sections = true;
716 } else if (strcmp(arg, "--test-evented-io") == 0) {
717 test_evented_io = true;
718 } else if (strcmp(arg, "-femit-bin") == 0) {
719 emit_bin = true;
720 } else if (strcmp(arg, "-fno-emit-bin") == 0) {
721 emit_bin = false;
722 } else if (strcmp(arg, "-femit-asm") == 0) {
723 emit_asm = true;
724 } else if (strcmp(arg, "-fno-emit-asm") == 0) {
725 emit_asm = false;
726 } else if (strcmp(arg, "-femit-llvm-ir") == 0) {
727 emit_llvm_ir = true;
728 } else if (strcmp(arg, "-fno-emit-llvm-ir") == 0) {
729 emit_llvm_ir = false;
730 } else if (strcmp(arg, "-femit-h") == 0) {
731 emit_h = true;
732 } else if (strcmp(arg, "-fno-emit-h") == 0 || strcmp(arg, "--disable-gen-h") == 0) {
733 // the --disable-gen-h is there to support godbolt. once they upgrade to -fno-emit-h then we can remove this
734 emit_h = false;
735 } else if (str_starts_with(arg, "-mcpu=")) {
736 mcpu = arg + strlen("-mcpu=");
737 } else if (i + 1 >= argc) {
738 fprintf(stderr, "Expected another argument after %s\n", arg);
739 return print_error_usage(arg0);
740 } else {
741 i += 1;
742 if (strcmp(arg, "--output-dir") == 0) {
743 output_dir = buf_create_from_str(argv[i]);
744 } else if (strcmp(arg, "--color") == 0) {
745 if (strcmp(argv[i], "auto") == 0) {
746 color = ErrColorAuto;
747 } else if (strcmp(argv[i], "on") == 0) {
748 color = ErrColorOn;
749 } else if (strcmp(argv[i], "off") == 0) {
750 color = ErrColorOff;
751 } else {
752 fprintf(stderr, "--color options are 'auto', 'on', or 'off'\n");
753 return print_error_usage(arg0);
754 }
755 } else if (strcmp(arg, "--cache") == 0) {
756 if (strcmp(argv[i], "auto") == 0) {
757 enable_cache = CacheOptAuto;
758 } else if (strcmp(argv[i], "on") == 0) {
759 enable_cache = CacheOptOn;
760 } else if (strcmp(argv[i], "off") == 0) {
761 enable_cache = CacheOptOff;
762 } else {
763 fprintf(stderr, "--cache options are 'auto', 'on', or 'off'\n");
764 return print_error_usage(arg0);
765 }
766 } else if (strcmp(arg, "--emit") == 0) {
767 if (strcmp(argv[i], "asm") == 0) {
768 emit_asm = true;
769 emit_bin = false;
770 } else if (strcmp(argv[i], "bin") == 0) {
771 emit_bin = true;
772 } else if (strcmp(argv[i], "llvm-ir") == 0) {
773 emit_llvm_ir = true;
774 emit_bin = false;
775 } else {
776 fprintf(stderr, "--emit options are 'asm', 'bin', or 'llvm-ir'\n");
777 return print_error_usage(arg0);
778 }
779 } else if (strcmp(arg, "--name") == 0) {
780 out_name = argv[i];
781 } else if (strcmp(arg, "--dynamic-linker") == 0) {
782 dynamic_linker = argv[i];
783 } else if (strcmp(arg, "--libc") == 0) {
784 libc_txt = argv[i];
785 } else if (strcmp(arg, "-D") == 0) {
786 clang_argv.append("-D");
787 clang_argv.append(argv[i]);
788 } else if (strcmp(arg, "-isystem") == 0) {
789 clang_argv.append("-isystem");
790 clang_argv.append(argv[i]);
791 } else if (strcmp(arg, "-I") == 0) {
792 clang_argv.append("-I");
793 clang_argv.append(argv[i]);
794 } else if (strcmp(arg, "-dirafter") == 0) {
795 clang_argv.append("-dirafter");
796 clang_argv.append(argv[i]);
797 } else if (strcmp(arg, "-mllvm") == 0) {
798 clang_argv.append("-mllvm");
799 clang_argv.append(argv[i]);
800
801 llvm_argv.append(argv[i]);
802 } else if (strcmp(arg, "-code-model") == 0) {
803 if (strcmp(argv[i], "default") == 0) {
804 code_model = CodeModelDefault;
805 } else if (strcmp(argv[i], "tiny") == 0) {
806 code_model = CodeModelTiny;
807 } else if (strcmp(argv[i], "small") == 0) {
808 code_model = CodeModelSmall;
809 } else if (strcmp(argv[i], "kernel") == 0) {
810 code_model = CodeModelKernel;
811 } else if (strcmp(argv[i], "medium") == 0) {
812 code_model = CodeModelMedium;
813 } else if (strcmp(argv[i], "large") == 0) {
814 code_model = CodeModelLarge;
815 } else {
816 fprintf(stderr, "-code-model options are 'default', 'tiny', 'small', 'kernel', 'medium', or 'large'\n");
817 return print_error_usage(arg0);
818 }
819 } else if (strcmp(arg, "--override-lib-dir") == 0) {
820 override_lib_dir = buf_create_from_str(argv[i]);
821 } else if (strcmp(arg, "--main-pkg-path") == 0) {
822 main_pkg_path = buf_create_from_str(argv[i]);
823 } else if (strcmp(arg, "--library-path") == 0 || strcmp(arg, "-L") == 0) {
824 lib_dirs.append(argv[i]);
825 } else if (strcmp(arg, "-F") == 0) {
826 framework_dirs.append(argv[i]);
827 } else if (strcmp(arg, "--library") == 0 || strcmp(arg, "-l") == 0) {
828 if (strcmp(argv[i], "c") == 0) {
829 have_libc = true;
830 link_libs.append("c");
831 } else if (strcmp(argv[i], "c++") == 0 || strcmp(argv[i], "stdc++") == 0) {
832 link_libs.append("c++");
833 } else {
834 link_libs.append(argv[i]);
835 }
836 } else if (strcmp(arg, "--forbid-library") == 0) {
837 forbidden_link_libs.append(argv[i]);
838 } else if (strcmp(arg, "--object") == 0) {
839 objects.append(argv[i]);
840 } else if (strcmp(arg, "--c-source") == 0) {
841 CFile *c_file = heap::c_allocator.create<CFile>();
842 for (;;) {
843 if (argv[i][0] == '-') {
844 c_file->args.append(argv[i]);
845 i += 1;
846 if (i < argc) {
847 continue;
848 }
849
850 break;
851 } else {
852 c_file->source_path = argv[i];
853 c_source_files.append(c_file);
854 break;
855 }
856 }
857 } else if (strcmp(arg, "--cache-dir") == 0) {
858 cache_dir = argv[i];
859 } else if (strcmp(arg, "-target") == 0) {
860 target_string = argv[i];
861 } else if (strcmp(arg, "-framework") == 0) {
862 frameworks.append(argv[i]);
863 } else if (strcmp(arg, "--linker-script") == 0) {
864 linker_script = argv[i];
865 } else if (strcmp(arg, "--version-script") == 0) {
866 version_script = buf_create_from_str(argv[i]);
867 } else if (strcmp(arg, "-rpath") == 0) {
868 rpath_list.append(argv[i]);
869 } else if (strcmp(arg, "--test-filter") == 0) {
870 test_filter = argv[i];
871 } else if (strcmp(arg, "--test-name-prefix") == 0) {
872 test_name_prefix = argv[i];
873 } else if (strcmp(arg, "--ver-major") == 0) {
874 is_versioned = true;
875 ver_major = atoi(argv[i]);
876 } else if (strcmp(arg, "--ver-minor") == 0) {
877 is_versioned = true;
878 ver_minor = atoi(argv[i]);
879 } else if (strcmp(arg, "--ver-patch") == 0) {
880 is_versioned = true;
881 ver_patch = atoi(argv[i]);
882 } else if (strcmp(arg, "--test-cmd") == 0) {
883 test_exec_args.append(argv[i]);
884 } else if (strcmp(arg, "--stack") == 0) {
885 stack_size_override = atoi(argv[i]);
886 } else if (strcmp(arg, "--subsystem") == 0) {
887 if (strcmp(argv[i], "console") == 0) {
888 subsystem = TargetSubsystemConsole;
889 } else if (strcmp(argv[i], "windows") == 0) {
890 subsystem = TargetSubsystemWindows;
891 } else if (strcmp(argv[i], "posix") == 0) {
892 subsystem = TargetSubsystemPosix;
893 } else if (strcmp(argv[i], "native") == 0) {
894 subsystem = TargetSubsystemNative;
895 } else if (strcmp(argv[i], "efi_application") == 0) {
896 subsystem = TargetSubsystemEfiApplication;
897 } else if (strcmp(argv[i], "efi_boot_service_driver") == 0) {
898 subsystem = TargetSubsystemEfiBootServiceDriver;
899 } else if (strcmp(argv[i], "efi_rom") == 0) {
900 subsystem = TargetSubsystemEfiRom;
901 } else if (strcmp(argv[i], "efi_runtime_driver") == 0) {
902 subsystem = TargetSubsystemEfiRuntimeDriver;
903 } else {
904 fprintf(stderr, "invalid: --subsystem %s\n"
905 "Options are:\n"
906 " console\n"
907 " windows\n"
908 " posix\n"
909 " native\n"
910 " efi_application\n"
911 " efi_boot_service_driver\n"
912 " efi_rom\n"
913 " efi_runtime_driver\n"
914 , argv[i]);
915 return EXIT_FAILURE;
916 }
917 } else if (strcmp(arg, "-mcpu") == 0) {
918 mcpu = argv[i];
919 } else {
920 fprintf(stderr, "Invalid argument: %s\n", arg);
921 return print_error_usage(arg0);
922 }
923 }
924 } else if (cmd == CmdNone) {
925 if (strcmp(arg, "build-exe") == 0) {
926 cmd = CmdBuild;
927 out_type = OutTypeExe;
928 } else if (strcmp(arg, "build-obj") == 0) {
929 cmd = CmdBuild;
930 out_type = OutTypeObj;
931 } else if (strcmp(arg, "build-lib") == 0) {
932 cmd = CmdBuild;
933 out_type = OutTypeLib;
934 } else if (strcmp(arg, "run") == 0) {
935 cmd = CmdRun;
936 out_type = OutTypeExe;
937 } else if (strcmp(arg, "version") == 0) {
938 cmd = CmdVersion;
939 } else if (strcmp(arg, "zen") == 0) {
940 cmd = CmdZen;
941 } else if (strcmp(arg, "libc") == 0) {
942 cmd = CmdLibC;
943 } else if (strcmp(arg, "translate-c") == 0) {
944 cmd = CmdTranslateC;
945 } else if (strcmp(arg, "test") == 0) {
946 cmd = CmdTest;
947 out_type = OutTypeExe;
948 } else if (strcmp(arg, "targets") == 0) {
949 cmd = CmdTargets;
950 } else if (strcmp(arg, "builtin") == 0) {
951 cmd = CmdBuiltin;
952 } else {
953 fprintf(stderr, "Unrecognized command: %s\n", arg);
954 return print_error_usage(arg0);
955 }
956 } else {
957 switch (cmd) {
958 case CmdBuild:
959 case CmdRun:
960 case CmdTranslateC:
961 case CmdTest:
962 case CmdLibC:
963 if (!in_file) {
964 in_file = arg;
965 } else {
966 fprintf(stderr, "Unexpected extra parameter: %s\n", arg);
967 return print_error_usage(arg0);
968 }
969 break;
970 case CmdBuiltin:
971 case CmdVersion:
972 case CmdZen:
973 case CmdTargets:
974 fprintf(stderr, "Unexpected extra parameter: %s\n", arg);
975 return print_error_usage(arg0);
976 case CmdNone:
977 zig_unreachable();
978 }
979 }
980 }
981
982 if (cur_pkg->parent != nullptr) {
983 fprintf(stderr, "Unmatched --pkg-begin\n");
984 return EXIT_FAILURE;
985 }
986
987 Stage2Progress *progress = stage2_progress_create();
988 Stage2ProgressNode *root_progress_node = stage2_progress_start_root(progress, "", 0, 0);
989 if (color == ErrColorOff) stage2_progress_disable_tty(progress);
990
991 init_all_targets();
992
993 ZigTarget target;
994 if ((err = target_parse_triple(&target, target_string, mcpu, dynamic_linker))) {
995 fprintf(stderr, "invalid target: %s\n"
996 "See `%s targets` to display valid targets.\n", err_str(err), arg0);
997 return print_error_usage(arg0);
998 }
999
1000 Buf zig_triple_buf = BUF_INIT;
1001 target_triple_zig(&zig_triple_buf, &target);
1002
1003 // If both output_dir and enable_cache are provided, and doing build-lib, we
1004 // will just do a file copy at the end. This helps when bootstrapping zig from zig0
1005 // because we want to pass something like this:
1006 // zig0 build-lib --cache on --output-dir ${CMAKE_BINARY_DIR}
1007 // And we don't have access to `zig0 build` because that would require detecting native libc
1008 // on systems where we are not able to build a libc from source for them.
1009 // But that's the only reason this works, so otherwise we give an error here.
1010 Buf *final_output_dir_step = nullptr;
1011 if (output_dir != nullptr && enable_cache == CacheOptOn) {
1012 if (cmd == CmdBuild && out_type == OutTypeLib) {
1013 final_output_dir_step = output_dir;
1014 output_dir = nullptr;
1015 } else {
1016 fprintf(stderr, "`--output-dir` is incompatible with --cache on.\n");
1017 return print_error_usage(arg0);
1018 }
1019 }
1020
1021 if (target_requires_pic(&target, have_libc) && want_pic == WantPICDisabled) {
1022 fprintf(stderr, "`--disable-pic` is incompatible with target '%s'\n", buf_ptr(&zig_triple_buf));
1023 return print_error_usage(arg0);
1024 }
1025
1026 if ((emit_asm || emit_llvm_ir) && in_file == nullptr) {
1027 fprintf(stderr, "A root source file is required when using `-femit-asm` or `-femit-llvm-ir`\n");
1028 return print_error_usage(arg0);
1029 }
1030
1031 if (llvm_argv.length > 1) {
1032 llvm_argv.append(nullptr);
1033 ZigLLVMParseCommandLineOptions(llvm_argv.length - 1, llvm_argv.items);
1034 }
1035
1036 switch (cmd) {
1037 case CmdLibC: {
1038 if (in_file) {
1039 Stage2LibCInstallation libc;
1040 if ((err = stage2_libc_parse(&libc, in_file))) {
1041 fprintf(stderr, "unable to parse libc file: %s\n", err_str(err));
1042 return main_exit(root_progress_node, EXIT_FAILURE);
1043 }
1044 return main_exit(root_progress_node, EXIT_SUCCESS);
1045 }
1046 Stage2LibCInstallation libc;
1047 if ((err = stage2_libc_find_native(&libc))) {
1048 fprintf(stderr, "unable to find native libc file: %s\n", err_str(err));
1049 return main_exit(root_progress_node, EXIT_FAILURE);
1050 }
1051 if ((err = stage2_libc_render(&libc, stdout))) {
1052 fprintf(stderr, "unable to print libc file: %s\n", err_str(err));
1053 return main_exit(root_progress_node, EXIT_FAILURE);
1054 }
1055 return main_exit(root_progress_node, EXIT_SUCCESS);
1056 }
1057 case CmdBuiltin: {
1058 CodeGen *g = codegen_create(main_pkg_path, nullptr, &target,
1059 out_type, build_mode, override_lib_dir, nullptr, nullptr, false, root_progress_node);
1060 codegen_set_strip(g, strip);
1061 for (size_t i = 0; i < link_libs.length; i += 1) {
1062 LinkLib *link_lib = codegen_add_link_lib(g, buf_create_from_str(link_libs.at(i)));
1063 link_lib->provided_explicitly = true;
1064 }
1065 g->subsystem = subsystem;
1066 g->valgrind_support = valgrind_support;
1067 g->want_pic = want_pic;
1068 g->want_stack_check = want_stack_check;
1069 g->want_sanitize_c = want_sanitize_c;
1070 g->want_single_threaded = want_single_threaded;
1071 g->test_is_evented = test_evented_io;
1072 Buf *builtin_source = codegen_generate_builtin_source(g);
1073 if (fwrite(buf_ptr(builtin_source), 1, buf_len(builtin_source), stdout) != buf_len(builtin_source)) {
1074 fprintf(stderr, "unable to write to stdout: %s\n", strerror(ferror(stdout)));
1075 return main_exit(root_progress_node, EXIT_FAILURE);
1076 }
1077 return main_exit(root_progress_node, EXIT_SUCCESS);
1078 }
1079 case CmdRun:
1080 case CmdBuild:
1081 case CmdTranslateC:
1082 case CmdTest:
1083 {
1084 if (cmd == CmdBuild && !in_file && objects.length == 0 &&
1085 c_source_files.length == 0)
1086 {
1087 fprintf(stderr,
1088 "Expected at least one of these things:\n"
1089 " * Zig root source file argument\n"
1090 " * --object argument\n"
1091 " * --c-source argument\n");
1092 return print_error_usage(arg0);
1093 } else if ((cmd == CmdTranslateC ||
1094 cmd == CmdTest || cmd == CmdRun) && !in_file)
1095 {
1096 fprintf(stderr, "Expected source file argument.\n");
1097 return print_error_usage(arg0);
1098 } else if (cmd == CmdRun && !emit_bin) {
1099 fprintf(stderr, "Cannot run without emitting a binary file.\n");
1100 return print_error_usage(arg0);
1101 }
1102
1103 bool any_system_lib_dependencies = false;
1104 for (size_t i = 0; i < link_libs.length; i += 1) {
1105 if (!target_is_libc_lib_name(&target, link_libs.at(i)) &&
1106 !target_is_libcpp_lib_name(&target, link_libs.at(i)))
1107 {
1108 any_system_lib_dependencies = true;
1109 break;
1110 }
1111 }
1112
1113 if (target.is_native_os && (any_system_lib_dependencies || want_native_include_dirs)) {
1114 Error err;
1115 Stage2NativePaths paths;
1116 if ((err = stage2_detect_native_paths(&paths))) {
1117 fprintf(stderr, "unable to detect native system paths: %s\n", err_str(err));
1118 exit(1);
1119 }
1120 for (size_t i = 0; i < paths.warnings_len; i += 1) {
1121 const char *warning = paths.warnings_ptr[i];
1122 fprintf(stderr, "warning: %s\n", warning);
1123 }
1124 for (size_t i = 0; i < paths.include_dirs_len; i += 1) {
1125 const char *include_dir = paths.include_dirs_ptr[i];
1126 clang_argv.append("-isystem");
1127 clang_argv.append(include_dir);
1128 }
1129 for (size_t i = 0; i < paths.lib_dirs_len; i += 1) {
1130 const char *lib_dir = paths.lib_dirs_ptr[i];
1131 lib_dirs.append(lib_dir);
1132 }
1133 for (size_t i = 0; i < paths.rpaths_len; i += 1) {
1134 const char *rpath = paths.rpaths_ptr[i];
1135 rpath_list.append(rpath);
1136 }
1137 }
1138
1139
1140 assert(cmd != CmdBuild || out_type != OutTypeUnknown);
1141
1142 bool need_name = (cmd == CmdBuild || cmd == CmdTranslateC);
1143
1144 if (cmd == CmdRun) {
1145 out_name = "run";
1146 }
1147
1148 Buf *in_file_buf = nullptr;
1149
1150 Buf *buf_out_name = (cmd == CmdTest) ? buf_create_from_str("test") :
1151 (out_name == nullptr) ? nullptr : buf_create_from_str(out_name);
1152
1153 if (in_file) {
1154 in_file_buf = buf_create_from_str(in_file);
1155
1156 if (need_name && buf_out_name == nullptr) {
1157 Buf basename = BUF_INIT;
1158 os_path_split(in_file_buf, nullptr, &basename);
1159 buf_out_name = buf_alloc();
1160 os_path_extname(&basename, buf_out_name, nullptr);
1161 }
1162 }
1163
1164 if (need_name && buf_out_name == nullptr && c_source_files.length == 1) {
1165 Buf basename = BUF_INIT;
1166 os_path_split(buf_create_from_str(c_source_files.at(0)->source_path), nullptr, &basename);
1167 buf_out_name = buf_alloc();
1168 os_path_extname(&basename, buf_out_name, nullptr);
1169 }
1170 if (need_name && buf_out_name == nullptr && objects.length == 1) {
1171 Buf basename = BUF_INIT;
1172 os_path_split(buf_create_from_str(objects.at(0)), nullptr, &basename);
1173 buf_out_name = buf_alloc();
1174 os_path_extname(&basename, buf_out_name, nullptr);
1175 }
1176 if (need_name && buf_out_name == nullptr && emit_bin_override_path != nullptr) {
1177 Buf basename = BUF_INIT;
1178 os_path_split(buf_create_from_str(emit_bin_override_path), nullptr, &basename);
1179 buf_out_name = buf_alloc();
1180 os_path_extname(&basename, buf_out_name, nullptr);
1181 }
1182
1183 if (need_name && buf_out_name == nullptr) {
1184 fprintf(stderr, "--name [name] not provided and unable to infer\n\n");
1185 return print_error_usage(arg0);
1186 }
1187
1188 Buf *zig_root_source_file = (cmd == CmdTranslateC) ? nullptr : in_file_buf;
1189
1190 if (cmd == CmdRun && buf_out_name == nullptr) {
1191 buf_out_name = buf_create_from_str("run");
1192 }
1193 Stage2LibCInstallation *libc = nullptr;
1194 if (libc_txt != nullptr) {
1195 libc = heap::c_allocator.create<Stage2LibCInstallation>();
1196 if ((err = stage2_libc_parse(libc, libc_txt))) {
1197 fprintf(stderr, "Unable to parse --libc text file: %s\n", err_str(err));
1198 return main_exit(root_progress_node, EXIT_FAILURE);
1199 }
1200 }
1201 Buf *cache_dir_buf;
1202 if (cache_dir == nullptr) {
1203 if (cmd == CmdRun) {
1204 cache_dir_buf = get_global_cache_dir();
1205 } else {
1206 cache_dir_buf = buf_create_from_str(default_zig_cache_name);
1207 }
1208 } else {
1209 cache_dir_buf = buf_create_from_str(cache_dir);
1210 }
1211 CodeGen *g = codegen_create(main_pkg_path, zig_root_source_file, &target, out_type, build_mode,
1212 override_lib_dir, libc, cache_dir_buf, cmd == CmdTest, root_progress_node);
1213 if (llvm_argv.length >= 2) codegen_set_llvm_argv(g, llvm_argv.items + 1, llvm_argv.length - 2);
1214 g->valgrind_support = valgrind_support;
1215 g->link_eh_frame_hdr = link_eh_frame_hdr;
1216 g->want_pic = want_pic;
1217 g->want_stack_check = want_stack_check;
1218 g->want_sanitize_c = want_sanitize_c;
1219 g->subsystem = subsystem;
1220
1221 g->enable_time_report = timing_info;
1222 g->enable_stack_report = stack_report;
1223 g->enable_dump_analysis = enable_dump_analysis;
1224 g->enable_doc_generation = enable_doc_generation;
1225 g->emit_bin = emit_bin;
1226 g->emit_asm = emit_asm;
1227 g->emit_llvm_ir = emit_llvm_ir;
1228
1229 codegen_set_out_name(g, buf_out_name);
1230 codegen_set_lib_version(g, is_versioned, ver_major, ver_minor, ver_patch);
1231 g->want_single_threaded = want_single_threaded;
1232 codegen_set_linker_script(g, linker_script);
1233 g->version_script_path = version_script;
1234 if (each_lib_rpath)
1235 codegen_set_each_lib_rpath(g, each_lib_rpath);
1236
1237 codegen_set_clang_argv(g, clang_argv.items, clang_argv.length);
1238
1239 codegen_set_strip(g, strip);
1240 g->is_dynamic = is_dynamic;
1241 g->verbose_tokenize = verbose_tokenize;
1242 g->verbose_ast = verbose_ast;
1243 g->verbose_link = verbose_link;
1244 g->verbose_ir = verbose_ir;
1245 g->verbose_llvm_ir = verbose_llvm_ir;
1246 g->verbose_cimport = verbose_cimport;
1247 g->verbose_cc = verbose_cc;
1248 g->verbose_llvm_cpu_features = verbose_llvm_cpu_features;
1249 g->output_dir = output_dir;
1250 g->disable_gen_h = !emit_h;
1251 g->bundle_compiler_rt = bundle_compiler_rt;
1252 codegen_set_errmsg_color(g, color);
1253 g->system_linker_hack = system_linker_hack;
1254 g->function_sections = function_sections;
1255 g->code_model = code_model;
1256
1257 g->linker_bind_global_refs_locally = linker_bind_global_refs_locally;
1258 g->stack_size_override = stack_size_override;
1259
1260 for (size_t i = 0; i < lib_dirs.length; i += 1) {
1261 codegen_add_lib_dir(g, lib_dirs.at(i));
1262 }
1263 for (size_t i = 0; i < framework_dirs.length; i += 1) {
1264 g->framework_dirs.append(framework_dirs.at(i));
1265 }
1266 for (size_t i = 0; i < link_libs.length; i += 1) {
1267 LinkLib *link_lib = codegen_add_link_lib(g, buf_create_from_str(link_libs.at(i)));
1268 link_lib->provided_explicitly = true;
1269 }
1270 for (size_t i = 0; i < forbidden_link_libs.length; i += 1) {
1271 Buf *forbidden_link_lib = buf_create_from_str(forbidden_link_libs.at(i));
1272 codegen_add_forbidden_lib(g, forbidden_link_lib);
1273 }
1274 for (size_t i = 0; i < frameworks.length; i += 1) {
1275 codegen_add_framework(g, frameworks.at(i));
1276 }
1277 for (size_t i = 0; i < rpath_list.length; i += 1) {
1278 codegen_add_rpath(g, rpath_list.at(i));
1279 }
1280
1281 codegen_set_rdynamic(g, rdynamic);
1282
1283 if (test_filter) {
1284 codegen_set_test_filter(g, buf_create_from_str(test_filter));
1285 }
1286 g->test_is_evented = test_evented_io;
1287
1288 if (test_name_prefix) {
1289 codegen_set_test_name_prefix(g, buf_create_from_str(test_name_prefix));
1290 }
1291
1292 add_package(g, cur_pkg, g->main_pkg);
1293
1294 if (cmd == CmdBuild || cmd == CmdRun || cmd == CmdTest) {
1295 g->c_source_files = c_source_files;
1296 for (size_t i = 0; i < objects.length; i += 1) {
1297 codegen_add_object(g, buf_create_from_str(objects.at(i)));
1298 }
1299 }
1300
1301
1302 if (cmd == CmdBuild || cmd == CmdRun) {
1303 g->enable_cache = get_cache_opt(enable_cache, cmd == CmdRun);
1304 codegen_build_and_link(g);
1305 if (root_progress_node != nullptr) {
1306 stage2_progress_end(root_progress_node);
1307 root_progress_node = nullptr;
1308 }
1309 if (timing_info)
1310 codegen_print_timing_report(g, stdout);
1311 if (stack_report)
1312 zig_print_stack_report(g, stdout);
1313
1314 if (cmd == CmdRun) {
1315#ifdef ZIG_ENABLE_MEM_PROFILE
1316 if (mem::report_print)
1317 mem::print_report();
1318#endif
1319
1320 const char *exec_path = buf_ptr(&g->bin_file_output_path);
1321 ZigList<const char*> args = {0};
1322
1323 args.append(exec_path);
1324 if (runtime_args_start != -1) {
1325 for (int i = runtime_args_start; i < argc; ++i) {
1326 args.append(argv[i]);
1327 }
1328 }
1329 args.append(nullptr);
1330
1331 os_execv(exec_path, args.items);
1332
1333 args.pop();
1334 Termination term;
1335 os_spawn_process(args, &term);
1336 return term.code;
1337 } else if (cmd == CmdBuild) {
1338 if (emit_bin_override_path != nullptr) {
1339#if defined(ZIG_OS_WINDOWS)
1340 buf_replace(g->output_dir, '/', '\\');
1341#endif
1342 Buf *dest_path = buf_create_from_str(emit_bin_override_path);
1343 Buf *source_path = &g->bin_file_output_path;
1344 if ((err = os_update_file(source_path, dest_path))) {
1345 fprintf(stderr, "unable to copy %s to %s: %s\n", buf_ptr(source_path),
1346 buf_ptr(dest_path), err_str(err));
1347 return main_exit(root_progress_node, EXIT_FAILURE);
1348 }
1349 } else if (g->enable_cache) {
1350#if defined(ZIG_OS_WINDOWS)
1351 buf_replace(&g->bin_file_output_path, '/', '\\');
1352 buf_replace(g->output_dir, '/', '\\');
1353#endif
1354 if (final_output_dir_step != nullptr) {
1355 Buf *dest_basename = buf_alloc();
1356 os_path_split(&g->bin_file_output_path, nullptr, dest_basename);
1357 Buf *dest_path = buf_alloc();
1358 os_path_join(final_output_dir_step, dest_basename, dest_path);
1359
1360 if ((err = os_update_file(&g->bin_file_output_path, dest_path))) {
1361 fprintf(stderr, "unable to copy %s to %s: %s\n", buf_ptr(&g->bin_file_output_path),
1362 buf_ptr(dest_path), err_str(err));
1363 return main_exit(root_progress_node, EXIT_FAILURE);
1364 }
1365 } else {
1366 if (printf("%s\n", buf_ptr(g->output_dir)) < 0)
1367 return main_exit(root_progress_node, EXIT_FAILURE);
1368 }
1369 }
1370 return main_exit(root_progress_node, EXIT_SUCCESS);
1371 } else {
1372 zig_unreachable();
1373 }
1374 } else if (cmd == CmdTranslateC) {
1375 g->enable_cache = get_cache_opt(enable_cache, false);
1376 codegen_translate_c(g, in_file_buf);
1377 if (timing_info)
1378 codegen_print_timing_report(g, stderr);
1379 return main_exit(root_progress_node, EXIT_SUCCESS);
1380 } else if (cmd == CmdTest) {
1381 ZigTarget native;
1382 if ((err = target_parse_triple(&native, "native", nullptr, nullptr))) {
1383 fprintf(stderr, "Unable to get native target: %s\n", err_str(err));
1384 return EXIT_FAILURE;
1385 }
1386
1387 g->enable_cache = get_cache_opt(enable_cache, output_dir == nullptr);
1388 codegen_build_and_link(g);
1389 if (root_progress_node != nullptr) {
1390 stage2_progress_end(root_progress_node);
1391 root_progress_node = nullptr;
1392 }
1393
1394 if (timing_info) {
1395 codegen_print_timing_report(g, stdout);
1396 }
1397
1398 if (stack_report) {
1399 zig_print_stack_report(g, stdout);
1400 }
1401
1402 if (!g->emit_bin) {
1403 fprintf(stderr, "Semantic analysis complete. No binary produced due to -fno-emit-bin.\n");
1404 return main_exit(root_progress_node, EXIT_SUCCESS);
1405 }
1406
1407 Buf *test_exe_path_unresolved = &g->bin_file_output_path;
1408 Buf *test_exe_path = buf_alloc();
1409 *test_exe_path = os_path_resolve(&test_exe_path_unresolved, 1);
1410
1411 if (!g->emit_bin) {
1412 fprintf(stderr, "Created %s but skipping execution because no binary generated.\n",
1413 buf_ptr(test_exe_path));
1414 return main_exit(root_progress_node, EXIT_SUCCESS);
1415 }
1416
1417 for (size_t i = 0; i < test_exec_args.length; i += 1) {
1418 if (test_exec_args.items[i] == nullptr) {
1419 test_exec_args.items[i] = buf_ptr(test_exe_path);
1420 }
1421 }
1422
1423 if (!target_can_exec(&native, &target) && test_exec_args.length == 0) {
1424 fprintf(stderr, "Created %s but skipping execution because it is non-native.\n",
1425 buf_ptr(test_exe_path));
1426 return main_exit(root_progress_node, EXIT_SUCCESS);
1427 }
1428
1429 Termination term;
1430 if (test_exec_args.length == 0) {
1431 test_exec_args.append(buf_ptr(test_exe_path));
1432 }
1433 os_spawn_process(test_exec_args, &term);
1434 if (term.how != TerminationIdClean || term.code != 0) {
1435 fprintf(stderr, "\nTests failed. Use the following command to reproduce the failure:\n");
1436 fprintf(stderr, "%s\n", buf_ptr(test_exe_path));
1437 }
1438 return main_exit(root_progress_node, (term.how == TerminationIdClean) ? term.code : -1);
1439 } else {
1440 zig_unreachable();
1441 }
1442 }
1443 case CmdVersion:
1444 printf("%s\n", ZIG_VERSION_STRING);
1445 return main_exit(root_progress_node, EXIT_SUCCESS);
1446 case CmdZen: {
1447 const char *ptr;
1448 size_t len;
1449 stage2_zen(&ptr, &len);
1450 fwrite(ptr, len, 1, stdout);
1451 return main_exit(root_progress_node, EXIT_SUCCESS);
1452 }
1453 case CmdTargets:
1454 return stage2_cmd_targets(target_string, mcpu, dynamic_linker);
1455 case CmdNone:
1456 return print_full_usage(arg0, stderr, EXIT_FAILURE);
1457 }
1458 zig_unreachable();
1459}
1460
1461int main(int argc, char **argv) {
1462 stage2_attach_segfault_handler();
1463 os_init();
1464 mem::init();
1465
1466 auto result = main0(argc, argv);
1467
1468#ifdef ZIG_ENABLE_MEM_PROFILE
1469 if (mem::report_print)
1470 mem::intern_counters.print_report();
1471#endif
1472 mem::deinit();
1473 return result;
1474}
src/mem.cpp-13
...@@ -7,7 +7,6 @@...@@ -7,7 +7,6 @@
77
8#include "config.h"8#include "config.h"
9#include "mem.hpp"9#include "mem.hpp"
10#include "mem_profile.hpp"
11#include "heap.hpp"10#include "heap.hpp"
1211
13namespace mem {12namespace mem {
...@@ -22,16 +21,4 @@ void deinit() {...@@ -22,16 +21,4 @@ void deinit() {
22 heap::bootstrap_allocator_state.deinit();21 heap::bootstrap_allocator_state.deinit();
23}22}
2423
25#ifdef ZIG_ENABLE_MEM_PROFILE
26void print_report(FILE *file) {
27 heap::c_allocator_state.print_report(file);
28 intern_counters.print_report(file);
29}
30#endif
31
32#ifdef ZIG_ENABLE_MEM_PROFILE
33bool report_print = false;
34FILE *report_file{nullptr};
35#endif
36
37} // namespace mem24} // namespace mem
src/mem.hpp-9
...@@ -135,15 +135,6 @@ protected:...@@ -135,15 +135,6 @@ protected:
135 virtual void internal_deallocate(const TypeInfo &info, void *ptr, size_t count) = 0;135 virtual void internal_deallocate(const TypeInfo &info, void *ptr, size_t count) = 0;
136};136};
137137
138#ifdef ZIG_ENABLE_MEM_PROFILE
139void print_report(FILE *file = nullptr);
140
141// global memory report flag
142extern bool report_print;
143// global memory report default destination
144extern FILE *report_file;
145#endif
146
147} // namespace mem138} // namespace mem
148139
149#endif140#endif
src/mem_profile.cpp deleted-181
...@@ -1,181 +0,0 @@
1/*
2 * Copyright (c) 2020 Andrew Kelley
3 *
4 * This file is part of zig, which is MIT licensed.
5 * See http://opensource.org/licenses/MIT
6 */
7
8#include "config.h"
9
10#ifdef ZIG_ENABLE_MEM_PROFILE
11
12#include "mem.hpp"
13#include "mem_list.hpp"
14#include "mem_profile.hpp"
15#include "heap.hpp"
16
17namespace mem {
18
19void Profile::init(const char *name, const char *kind) {
20 this->name = name;
21 this->kind = kind;
22 this->usage_table.init(heap::bootstrap_allocator, 1024);
23}
24
25void Profile::deinit() {
26 assert(this->name != nullptr);
27 if (mem::report_print)
28 this->print_report();
29 this->usage_table.deinit(heap::bootstrap_allocator);
30 this->name = nullptr;
31}
32
33void Profile::record_alloc(const TypeInfo &info, size_t count) {
34 if (count == 0) return;
35 auto existing_entry = this->usage_table.put_unique(
36 heap::bootstrap_allocator,
37 UsageKey{info.name_ptr, info.name_len},
38 Entry{info, 1, count, 0, 0} );
39 if (existing_entry != nullptr) {
40 assert(existing_entry->value.info.size == info.size); // allocated name does not match type
41 existing_entry->value.alloc.calls += 1;
42 existing_entry->value.alloc.objects += count;
43 }
44}
45
46void Profile::record_dealloc(const TypeInfo &info, size_t count) {
47 if (count == 0) return;
48 auto existing_entry = this->usage_table.maybe_get(UsageKey{info.name_ptr, info.name_len});
49 if (existing_entry == nullptr) {
50 fprintf(stderr, "deallocated name '");
51 for (size_t i = 0; i < info.name_len; ++i)
52 fputc(info.name_ptr[i], stderr);
53 zig_panic("' (size %zu) not found in allocated table; compromised memory usage stats", info.size);
54 }
55 if (existing_entry->value.info.size != info.size) {
56 fprintf(stderr, "deallocated name '");
57 for (size_t i = 0; i < info.name_len; ++i)
58 fputc(info.name_ptr[i], stderr);
59 zig_panic("' does not match expected type size %zu", info.size);
60 }
61 assert(existing_entry->value.alloc.calls - existing_entry->value.dealloc.calls > 0);
62 assert(existing_entry->value.alloc.objects - existing_entry->value.dealloc.objects >= count);
63 existing_entry->value.dealloc.calls += 1;
64 existing_entry->value.dealloc.objects += count;
65}
66
67static size_t entry_remain_total_bytes(const Profile::Entry *entry) {
68 return (entry->alloc.objects - entry->dealloc.objects) * entry->info.size;
69}
70
71static int entry_compare(const void *a, const void *b) {
72 size_t total_a = entry_remain_total_bytes(*reinterpret_cast<Profile::Entry *const *>(a));
73 size_t total_b = entry_remain_total_bytes(*reinterpret_cast<Profile::Entry *const *>(b));
74 if (total_a > total_b)
75 return -1;
76 if (total_a < total_b)
77 return 1;
78 return 0;
79};
80
81void Profile::print_report(FILE *file) {
82 if (!file) {
83 file = report_file;
84 if (!file)
85 file = stderr;
86 }
87 fprintf(file, "\n--- MEMORY PROFILE REPORT [%s]: %s ---\n", this->kind, this->name);
88
89 List<const Entry *> list;
90 auto it = this->usage_table.entry_iterator();
91 for (;;) {
92 auto entry = it.next();
93 if (!entry)
94 break;
95 list.append(&heap::bootstrap_allocator, &entry->value);
96 }
97
98 qsort(list.items, list.length, sizeof(const Entry *), entry_compare);
99
100 size_t total_bytes_alloc = 0;
101 size_t total_bytes_dealloc = 0;
102
103 size_t total_calls_alloc = 0;
104 size_t total_calls_dealloc = 0;
105
106 for (size_t i = 0; i < list.length; i += 1) {
107 const Entry *entry = list.at(i);
108 fprintf(file, " ");
109 for (size_t j = 0; j < entry->info.name_len; ++j)
110 fputc(entry->info.name_ptr[j], file);
111 fprintf(file, ": %zu bytes each", entry->info.size);
112
113 fprintf(file, ", alloc{ %zu calls, %zu objects, total ", entry->alloc.calls, entry->alloc.objects);
114 const auto alloc_num_bytes = entry->alloc.objects * entry->info.size;
115 zig_pretty_print_bytes(file, alloc_num_bytes);
116
117 fprintf(file, " }, dealloc{ %zu calls, %zu objects, total ", entry->dealloc.calls, entry->dealloc.objects);
118 const auto dealloc_num_bytes = entry->dealloc.objects * entry->info.size;
119 zig_pretty_print_bytes(file, dealloc_num_bytes);
120
121 fprintf(file, " }, remain{ %zu calls, %zu objects, total ",
122 entry->alloc.calls - entry->dealloc.calls,
123 entry->alloc.objects - entry->dealloc.objects );
124 const auto remain_num_bytes = alloc_num_bytes - dealloc_num_bytes;
125 zig_pretty_print_bytes(file, remain_num_bytes);
126
127 fprintf(file, " }\n");
128
129 total_bytes_alloc += alloc_num_bytes;
130 total_bytes_dealloc += dealloc_num_bytes;
131
132 total_calls_alloc += entry->alloc.calls;
133 total_calls_dealloc += entry->dealloc.calls;
134 }
135
136 fprintf(file, "\n Total bytes allocated: ");
137 zig_pretty_print_bytes(file, total_bytes_alloc);
138 fprintf(file, ", deallocated: ");
139 zig_pretty_print_bytes(file, total_bytes_dealloc);
140 fprintf(file, ", remaining: ");
141 zig_pretty_print_bytes(file, total_bytes_alloc - total_bytes_dealloc);
142
143 fprintf(file, "\n Total calls alloc: %zu, dealloc: %zu, remain: %zu\n",
144 total_calls_alloc, total_calls_dealloc, (total_calls_alloc - total_calls_dealloc));
145
146 list.deinit(&heap::bootstrap_allocator);
147}
148
149uint32_t Profile::usage_hash(UsageKey key) {
150 // FNV 32-bit hash
151 uint32_t h = 2166136261;
152 for (size_t i = 0; i < key.name_len; ++i) {
153 h = h ^ key.name_ptr[i];
154 h = h * 16777619;
155 }
156 return h;
157}
158
159bool Profile::usage_equal(UsageKey a, UsageKey b) {
160 return memcmp(a.name_ptr, b.name_ptr, a.name_len > b.name_len ? a.name_len : b.name_len) == 0;
161}
162
163void InternCounters::print_report(FILE *file) {
164 if (!file) {
165 file = report_file;
166 if (!file)
167 file = stderr;
168 }
169 fprintf(file, "\n--- IR INTERNING REPORT ---\n");
170 fprintf(file, " undefined: interned %zu times\n", intern_counters.x_undefined);
171 fprintf(file, " void: interned %zu times\n", intern_counters.x_void);
172 fprintf(file, " null: interned %zu times\n", intern_counters.x_null);
173 fprintf(file, " unreachable: interned %zu times\n", intern_counters.x_unreachable);
174 fprintf(file, " zero_byte: interned %zu times\n", intern_counters.zero_byte);
175}
176
177InternCounters intern_counters;
178
179} // namespace mem
180
181#endif
src/mem_profile.hpp deleted-71
...@@ -1,71 +0,0 @@
1/*
2 * Copyright (c) 2020 Andrew Kelley
3 *
4 * This file is part of zig, which is MIT licensed.
5 * See http://opensource.org/licenses/MIT
6 */
7
8#ifndef ZIG_MEM_PROFILE_HPP
9#define ZIG_MEM_PROFILE_HPP
10
11#include "config.h"
12
13#ifdef ZIG_ENABLE_MEM_PROFILE
14
15#include <stdio.h>
16
17#include "mem.hpp"
18#include "mem_hash_map.hpp"
19#include "util.hpp"
20
21namespace mem {
22
23struct Profile {
24 void init(const char *name, const char *kind);
25 void deinit();
26
27 void record_alloc(const TypeInfo &info, size_t count);
28 void record_dealloc(const TypeInfo &info, size_t count);
29
30 void print_report(FILE *file = nullptr);
31
32 struct Entry {
33 TypeInfo info;
34
35 struct Use {
36 size_t calls;
37 size_t objects;
38 } alloc, dealloc;
39 };
40
41private:
42 const char *name;
43 const char *kind;
44
45 struct UsageKey {
46 const char *name_ptr;
47 size_t name_len;
48 };
49
50 static uint32_t usage_hash(UsageKey key);
51 static bool usage_equal(UsageKey a, UsageKey b);
52
53 HashMap<UsageKey, Entry, usage_hash, usage_equal> usage_table;
54};
55
56struct InternCounters {
57 size_t x_undefined;
58 size_t x_void;
59 size_t x_null;
60 size_t x_unreachable;
61 size_t zero_byte;
62
63 void print_report(FILE *file = nullptr);
64};
65
66extern InternCounters intern_counters;
67
68} // namespace mem
69
70#endif
71#endif
src/mem_type_info.hpp-109
...@@ -10,18 +10,8 @@...@@ -10,18 +10,8 @@
1010
11#include "config.h"11#include "config.h"
1212
13#ifndef ZIG_TYPE_INFO_IMPLEMENTATION
14# ifdef ZIG_ENABLE_MEM_PROFILE
15# define ZIG_TYPE_INFO_IMPLEMENTATION 1
16# else
17# define ZIG_TYPE_INFO_IMPLEMENTATION 0
18# endif
19#endif
20
21namespace mem {13namespace mem {
2214
23#if ZIG_TYPE_INFO_IMPLEMENTATION == 0
24
25struct TypeInfo {15struct TypeInfo {
26 size_t size;16 size_t size;
27 size_t alignment;17 size_t alignment;
...@@ -32,105 +22,6 @@ struct TypeInfo {...@@ -32,105 +22,6 @@ struct TypeInfo {
32 }22 }
33};23};
3424
35#elif ZIG_TYPE_INFO_IMPLEMENTATION == 1
36
37//
38// A non-portable way to get a human-readable type-name compatible with
39// non-RTTI C++ compiler mode; eg. `-fno-rtti`.
40//
41// Minimum requirements are c++11 and a compiler that has a constant for the
42// current function's decorated name whereby a template-type name can be
43// computed. eg. `__PRETTY_FUNCTION__` or `__FUNCSIG__`.
44//
45// given the following snippet:
46//
47// | #include <stdio.h>
48// |
49// | struct Top {};
50// | namespace mynamespace {
51// | using custom = unsigned int;
52// | struct Foo {
53// | struct Bar {};
54// | };
55// | };
56// |
57// | template <typename T>
58// | void foobar() {
59// | #ifdef _MSC_VER
60// | fprintf(stderr, "--> %s\n", __FUNCSIG__);
61// | #else
62// | fprintf(stderr, "--> %s\n", __PRETTY_FUNCTION__);
63// | #endif
64// | }
65// |
66// | int main() {
67// | foobar<Top>();
68// | foobar<unsigned int>();
69// | foobar<mynamespace::custom>();
70// | foobar<mynamespace::Foo*>();
71// | foobar<mynamespace::Foo::Bar*>();
72// | }
73//
74// gcc 9.2.0 produces:
75// --> void foobar() [with T = Top]
76// --> void foobar() [with T = unsigned int]
77// --> void foobar() [with T = unsigned int]
78// --> void foobar() [with T = mynamespace::Foo*]
79// --> void foobar() [with T = mynamespace::Foo::Bar*]
80//
81// xcode 11.3.1/clang produces:
82// --> void foobar() [T = Top]
83// --> void foobar() [T = unsigned int]
84// --> void foobar() [T = unsigned int]
85// --> void foobar() [T = mynamespace::Foo *]
86// --> void foobar() [T = mynamespace::Foo::Bar *]
87//
88// VStudio 2019 16.5.0/msvc produces:
89// --> void __cdecl foobar<struct Top>(void)
90// --> void __cdecl foobar<unsigned int>(void)
91// --> void __cdecl foobar<unsigned int>(void)
92// --> void __cdecl foobar<structmynamespace::Foo*>(void)
93// --> void __cdecl foobar<structmynamespace::Foo::Bar*>(void)
94//
95struct TypeInfo {
96 const char *name_ptr;
97 size_t name_len;
98 size_t size;
99 size_t alignment;
100
101 static constexpr TypeInfo to_type_info(const char *str, size_t start, size_t end, size_t size, size_t alignment) {
102 return TypeInfo{str + start, end - start, size, alignment};
103 }
104
105 static constexpr size_t index_of(const char *str, char c) {
106 return *str == c ? 0 : 1 + index_of(str + 1, c);
107 }
108
109 template <typename T>
110 static constexpr const char *decorated_name() {
111#ifdef _MSC_VER
112 return __FUNCSIG__;
113#else
114 return __PRETTY_FUNCTION__;
115#endif
116 }
117
118 static constexpr TypeInfo extract(const char *decorated, size_t size, size_t alignment) {
119#ifdef _MSC_VER
120 return to_type_info(decorated, index_of(decorated, '<') + 1, index_of(decorated, '>'), size, alignment);
121#else
122 return to_type_info(decorated, index_of(decorated, '=') + 2, index_of(decorated, ']'), size, alignment);
123#endif
124 }
125
126 template <typename T>
127 static constexpr TypeInfo make() {
128 return TypeInfo::extract(TypeInfo::decorated_name<T>(), sizeof(T), alignof(T));
129 }
130};
131
132#endif // ZIG_TYPE_INFO_IMPLEMENTATION
133
134} // namespace mem25} // namespace mem
13526
136#endif27#endif
src/stage1.cpp created+127
...@@ -0,0 +1,127 @@
1/*
2 * Copyright (c) 2020 Andrew Kelley
3 *
4 * This file is part of zig, which is MIT licensed.
5 * See http://opensource.org/licenses/MIT
6 */
7
8#include "stage1.h"
9#include "os.hpp"
10#include "all_types.hpp"
11#include "codegen.hpp"
12
13void zig_stage1_os_init(void) {
14 os_init();
15 mem::init();
16 init_all_targets();
17}
18
19struct ZigStage1 *zig_stage1_create(BuildMode optimize_mode,
20 const char *main_pkg_path_ptr, size_t main_pkg_path_len,
21 const char *root_src_path_ptr, size_t root_src_path_len,
22 const char *zig_lib_dir_ptr, size_t zig_lib_dir_len,
23 const ZigTarget *target, bool is_test_build, Stage2ProgressNode *progress_node)
24{
25 Buf *main_pkg_path = buf_create_from_mem(main_pkg_path_ptr, main_pkg_path_len);
26 Buf *root_src_path = buf_create_from_mem(root_src_path_ptr, root_src_path_len);
27 Buf *zig_lib_dir = buf_create_from_mem(zig_lib_dir_ptr, zig_lib_dir_len);
28 CodeGen *g = codegen_create(main_pkg_path, root_src_path, target, optimize_mode,
29 zig_lib_dir, is_test_build, progress_node);
30 return &g->stage1;
31}
32
33void zig_stage1_destroy(struct ZigStage1 *stage1) {
34 CodeGen *codegen = reinterpret_cast<CodeGen *>(stage1);
35 codegen_destroy(codegen);
36}
37
38static void add_package(CodeGen *g, ZigStage1Pkg *stage1_pkg, ZigPackage *pkg) {
39 for (size_t i = 0; i < stage1_pkg->children_len; i += 1) {
40 ZigStage1Pkg *child_cli_pkg = stage1_pkg->children_ptr[i];
41
42 Buf *dirname = buf_alloc();
43 Buf *basename = buf_alloc();
44 os_path_split(buf_create_from_mem(child_cli_pkg->path_ptr, child_cli_pkg->path_len), dirname, basename);
45
46 ZigPackage *child_pkg = codegen_create_package(g, buf_ptr(dirname), buf_ptr(basename),
47 buf_ptr(buf_sprintf("%s.%.*s", buf_ptr(&pkg->pkg_path),
48 (int)child_cli_pkg->name_len, child_cli_pkg->name_ptr)));
49 auto entry = pkg->package_table.put_unique(
50 buf_create_from_mem(child_cli_pkg->name_ptr, child_cli_pkg->name_len),
51 child_pkg);
52 if (entry) {
53 ZigPackage *existing_pkg = entry->value;
54 Buf *full_path = buf_alloc();
55 os_path_join(&existing_pkg->root_src_dir, &existing_pkg->root_src_path, full_path);
56 fprintf(stderr, "Unable to add package '%.*s'->'%.*s': already exists as '%s'\n",
57 (int)child_cli_pkg->name_len, child_cli_pkg->name_ptr,
58 (int)child_cli_pkg->path_len, child_cli_pkg->path_ptr,
59 buf_ptr(full_path));
60 exit(EXIT_FAILURE);
61 }
62
63 add_package(g, child_cli_pkg, child_pkg);
64 }
65}
66
67void zig_stage1_build_object(struct ZigStage1 *stage1) {
68 CodeGen *g = reinterpret_cast<CodeGen *>(stage1);
69
70 g->root_out_name = buf_create_from_mem(stage1->root_name_ptr, stage1->root_name_len);
71 g->zig_lib_dir = buf_create_from_mem(stage1->zig_lib_dir_ptr, stage1->zig_lib_dir_len);
72 g->zig_std_dir = buf_create_from_mem(stage1->zig_std_dir_ptr, stage1->zig_std_dir_len);
73 g->output_dir = buf_create_from_mem(stage1->output_dir_ptr, stage1->output_dir_len);
74 if (stage1->builtin_zig_path_len != 0) {
75 g->builtin_zig_path = buf_create_from_mem(stage1->builtin_zig_path_ptr, stage1->builtin_zig_path_len);
76 }
77 if (stage1->test_filter_len != 0) {
78 g->test_filter = buf_create_from_mem(stage1->test_filter_ptr, stage1->test_filter_len);
79 }
80 if (stage1->test_name_prefix_len != 0) {
81 g->test_name_prefix = buf_create_from_mem(stage1->test_name_prefix_ptr, stage1->test_name_prefix_len);
82 }
83
84 g->link_mode_dynamic = stage1->link_mode_dynamic;
85 g->dll_export_fns = stage1->dll_export_fns;
86 g->have_pic = stage1->pic;
87 g->have_stack_probing = stage1->enable_stack_probing;
88 g->is_single_threaded = stage1->is_single_threaded;
89 g->valgrind_enabled = stage1->valgrind_enabled;
90 g->link_libc = stage1->link_libc;
91 g->link_libcpp = stage1->link_libcpp;
92 g->function_sections = stage1->function_sections;
93
94 g->subsystem = stage1->subsystem;
95
96 g->enable_time_report = stage1->enable_time_report;
97 g->enable_stack_report = stage1->enable_stack_report;
98 g->enable_dump_analysis = stage1->dump_analysis;
99 g->enable_doc_generation = stage1->enable_doc_generation;
100 g->emit_bin = stage1->emit_bin;
101 g->emit_asm = stage1->emit_asm;
102 g->emit_llvm_ir = stage1->emit_llvm_ir;
103 g->test_is_evented = stage1->test_is_evented;
104
105 g->verbose_tokenize = stage1->verbose_tokenize;
106 g->verbose_ast = stage1->verbose_ast;
107 g->verbose_link = stage1->verbose_link;
108 g->verbose_ir = stage1->verbose_ir;
109 g->verbose_llvm_ir = stage1->verbose_llvm_ir;
110 g->verbose_cimport = stage1->verbose_cimport;
111 g->verbose_cc = stage1->verbose_cc;
112 g->verbose_llvm_cpu_features = stage1->verbose_llvm_cpu_features;
113
114 g->err_color = stage1->err_color;
115 g->code_model = stage1->code_model;
116
117 {
118 g->strip_debug_symbols = stage1->strip;
119 if (!target_has_debug_info(g->zig_target)) {
120 g->strip_debug_symbols = true;
121 }
122 }
123
124 add_package(g, stage1->root_pkg, g->main_pkg);
125
126 codegen_build_object(g);
127}
src/stage1.h created+217
...@@ -0,0 +1,217 @@
1/*
2 * Copyright (c) 2020 Andrew Kelley
3 *
4 * This file is part of zig, which is MIT licensed.
5 * See http://opensource.org/licenses/MIT
6 */
7
8// This file deals with exposing stage1 C++ code to stage2 Zig code.
9
10#ifndef ZIG_STAGE1_H
11#define ZIG_STAGE1_H
12
13#include "zig_llvm.h"
14
15#include <stddef.h>
16
17#ifdef __cplusplus
18#define ZIG_EXTERN_C extern "C"
19#else
20#define ZIG_EXTERN_C
21#endif
22
23// ABI warning
24enum ErrColor {
25 ErrColorAuto,
26 ErrColorOff,
27 ErrColorOn,
28};
29
30// ABI warning
31enum CodeModel {
32 CodeModelDefault,
33 CodeModelTiny,
34 CodeModelSmall,
35 CodeModelKernel,
36 CodeModelMedium,
37 CodeModelLarge,
38};
39
40// ABI warning
41enum TargetSubsystem {
42 TargetSubsystemConsole,
43 TargetSubsystemWindows,
44 TargetSubsystemPosix,
45 TargetSubsystemNative,
46 TargetSubsystemEfiApplication,
47 TargetSubsystemEfiBootServiceDriver,
48 TargetSubsystemEfiRom,
49 TargetSubsystemEfiRuntimeDriver,
50
51 // This means Zig should infer the subsystem.
52 // It's last so that the indexes of other items can line up
53 // with the enum in builtin.zig.
54 TargetSubsystemAuto
55};
56
57
58// ABI warning
59// Synchronize with target.cpp::os_list
60enum Os {
61 OsFreestanding,
62 OsAnanas,
63 OsCloudABI,
64 OsDragonFly,
65 OsFreeBSD,
66 OsFuchsia,
67 OsIOS,
68 OsKFreeBSD,
69 OsLinux,
70 OsLv2, // PS3
71 OsMacOSX,
72 OsNetBSD,
73 OsOpenBSD,
74 OsSolaris,
75 OsWindows,
76 OsHaiku,
77 OsMinix,
78 OsRTEMS,
79 OsNaCl, // Native Client
80 OsCNK, // BG/P Compute-Node Kernel
81 OsAIX,
82 OsCUDA, // NVIDIA CUDA
83 OsNVCL, // NVIDIA OpenCL
84 OsAMDHSA, // AMD HSA Runtime
85 OsPS4,
86 OsELFIAMCU,
87 OsTvOS, // Apple tvOS
88 OsWatchOS, // Apple watchOS
89 OsMesa3D,
90 OsContiki,
91 OsAMDPAL,
92 OsHermitCore,
93 OsHurd,
94 OsWASI,
95 OsEmscripten,
96 OsUefi,
97 OsOther,
98};
99
100// ABI warning
101struct ZigTarget {
102 enum ZigLLVM_ArchType arch;
103 enum ZigLLVM_VendorType vendor;
104
105 enum ZigLLVM_EnvironmentType abi;
106 Os os;
107
108 bool is_native_os;
109 bool is_native_cpu;
110
111 const char *llvm_cpu_name;
112 const char *llvm_cpu_features;
113 const char *cpu_builtin_str;
114 const char *os_builtin_str;
115 const char *dynamic_linker;
116
117 const char **llvm_cpu_features_asm_ptr;
118 size_t llvm_cpu_features_asm_len;
119};
120
121// ABI warning
122struct Stage2Progress;
123// ABI warning
124struct Stage2ProgressNode;
125
126enum BuildMode {
127 BuildModeDebug,
128 BuildModeFastRelease,
129 BuildModeSafeRelease,
130 BuildModeSmallRelease,
131};
132
133
134struct ZigStage1Pkg {
135 const char *name_ptr;
136 size_t name_len;
137
138 const char *path_ptr;
139 size_t path_len;
140
141 struct ZigStage1Pkg **children_ptr;
142 size_t children_len;
143
144 struct ZigStage1Pkg *parent;
145};
146
147// This struct is used by both main.cpp and stage1.zig.
148struct ZigStage1 {
149 const char *root_name_ptr;
150 size_t root_name_len;
151
152 const char *output_dir_ptr;
153 size_t output_dir_len;
154
155 const char *builtin_zig_path_ptr;
156 size_t builtin_zig_path_len;
157
158 const char *test_filter_ptr;
159 size_t test_filter_len;
160
161 const char *test_name_prefix_ptr;
162 size_t test_name_prefix_len;
163
164 const char *zig_lib_dir_ptr;
165 size_t zig_lib_dir_len;
166
167 const char *zig_std_dir_ptr;
168 size_t zig_std_dir_len;
169
170 void *userdata;
171 struct ZigStage1Pkg *root_pkg;
172
173 CodeModel code_model;
174 TargetSubsystem subsystem;
175 ErrColor err_color;
176
177 bool pic;
178 bool link_libc;
179 bool link_libcpp;
180 bool strip;
181 bool is_single_threaded;
182 bool dll_export_fns;
183 bool link_mode_dynamic;
184 bool valgrind_enabled;
185 bool function_sections;
186 bool enable_stack_probing;
187 bool enable_time_report;
188 bool enable_stack_report;
189 bool dump_analysis;
190 bool enable_doc_generation;
191 bool emit_bin;
192 bool emit_asm;
193 bool emit_llvm_ir;
194 bool test_is_evented;
195 bool verbose_tokenize;
196 bool verbose_ast;
197 bool verbose_link;
198 bool verbose_ir;
199 bool verbose_llvm_ir;
200 bool verbose_cimport;
201 bool verbose_cc;
202 bool verbose_llvm_cpu_features;
203};
204
205ZIG_EXTERN_C void zig_stage1_os_init(void);
206
207ZIG_EXTERN_C struct ZigStage1 *zig_stage1_create(enum BuildMode optimize_mode,
208 const char *main_pkg_path_ptr, size_t main_pkg_path_len,
209 const char *root_src_path_ptr, size_t root_src_path_len,
210 const char *zig_lib_dir_ptr, size_t zig_lib_dir_len,
211 const ZigTarget *target, bool is_test_build, Stage2ProgressNode *progress_node);
212
213ZIG_EXTERN_C void zig_stage1_build_object(struct ZigStage1 *);
214
215ZIG_EXTERN_C void zig_stage1_destroy(struct ZigStage1 *);
216
217#endif
src/stage2.cpp+21-104
...@@ -5,40 +5,12 @@...@@ -5,40 +5,12 @@
5#include "util.hpp"5#include "util.hpp"
6#include "zig_llvm.h"6#include "zig_llvm.h"
7#include "target.hpp"7#include "target.hpp"
8#include "buffer.hpp"
9#include "os.hpp"
8#include <stdio.h>10#include <stdio.h>
9#include <stdlib.h>11#include <stdlib.h>
10#include <string.h>12#include <string.h>
1113
12Error stage2_translate_c(struct Stage2Ast **out_ast,
13 struct Stage2ErrorMsg **out_errors_ptr, size_t *out_errors_len,
14 const char **args_begin, const char **args_end, const char *resources_path)
15{
16 const char *msg = "stage0 called stage2_translate_c";
17 stage2_panic(msg, strlen(msg));
18}
19
20void stage2_free_clang_errors(struct Stage2ErrorMsg *ptr, size_t len) {
21 const char *msg = "stage0 called stage2_free_clang_errors";
22 stage2_panic(msg, strlen(msg));
23}
24
25void stage2_zen(const char **ptr, size_t *len) {
26 const char *msg = "stage0 called stage2_zen";
27 stage2_panic(msg, strlen(msg));
28}
29
30int stage2_env(int argc, char** argv) {
31 const char *msg = "stage0 called stage2_env";
32 stage2_panic(msg, strlen(msg));
33}
34
35int stage2_cc(int argc, char** argv, bool is_cpp) {
36 const char *msg = "stage0 called stage2_cc";
37 stage2_panic(msg, strlen(msg));
38}
39
40void stage2_attach_segfault_handler(void) { }
41
42void stage2_panic(const char *ptr, size_t len) {14void stage2_panic(const char *ptr, size_t len) {
43 fwrite(ptr, 1, len, stderr);15 fwrite(ptr, 1, len, stderr);
44 fprintf(stderr, "\n");16 fprintf(stderr, "\n");
...@@ -46,32 +18,6 @@ void stage2_panic(const char *ptr, size_t len) {...@@ -46,32 +18,6 @@ void stage2_panic(const char *ptr, size_t len) {
46 abort();18 abort();
47}19}
4820
49void stage2_render_ast(struct Stage2Ast *ast, FILE *output_file) {
50 const char *msg = "stage0 called stage2_render_ast";
51 stage2_panic(msg, strlen(msg));
52}
53
54int stage2_fmt(int argc, char **argv) {
55 const char *msg = "stage0 called stage2_fmt";
56 stage2_panic(msg, strlen(msg));
57}
58
59stage2_DepTokenizer stage2_DepTokenizer_init(const char *input, size_t len) {
60 const char *msg = "stage0 called stage2_DepTokenizer_init";
61 stage2_panic(msg, strlen(msg));
62}
63
64void stage2_DepTokenizer_deinit(stage2_DepTokenizer *self) {
65 const char *msg = "stage0 called stage2_DepTokenizer_deinit";
66 stage2_panic(msg, strlen(msg));
67}
68
69stage2_DepNextResult stage2_DepTokenizer_next(stage2_DepTokenizer *self) {
70 const char *msg = "stage0 called stage2_DepTokenizer_next";
71 stage2_panic(msg, strlen(msg));
72}
73
74
75struct Stage2Progress {21struct Stage2Progress {
76 int trash;22 int trash;
77};23};
...@@ -196,10 +142,6 @@ static void get_native_target(ZigTarget *target) {...@@ -196,10 +142,6 @@ static void get_native_target(ZigTarget *target) {
196 if (target->abi == ZigLLVM_UnknownEnvironment) {142 if (target->abi == ZigLLVM_UnknownEnvironment) {
197 target->abi = target_default_abi(target->arch, target->os);143 target->abi = target_default_abi(target->arch, target->os);
198 }144 }
199 if (target_is_glibc(target)) {
200 target->glibc_or_darwin_version = heap::c_allocator.create<Stage2SemVer>();
201 target_init_default_glibc_version(target);
202 }
203}145}
204146
205Error stage2_target_parse(struct ZigTarget *target, const char *zig_triple, const char *mcpu,147Error stage2_target_parse(struct ZigTarget *target, const char *zig_triple, const char *mcpu,
...@@ -217,13 +159,11 @@ Error stage2_target_parse(struct ZigTarget *target, const char *zig_triple, cons...@@ -217,13 +159,11 @@ Error stage2_target_parse(struct ZigTarget *target, const char *zig_triple, cons
217 if (mcpu == nullptr) {159 if (mcpu == nullptr) {
218 target->llvm_cpu_name = ZigLLVMGetHostCPUName();160 target->llvm_cpu_name = ZigLLVMGetHostCPUName();
219 target->llvm_cpu_features = ZigLLVMGetNativeFeatures();161 target->llvm_cpu_features = ZigLLVMGetNativeFeatures();
220 target->cache_hash = "native\n\n";
221 } else if (strcmp(mcpu, "baseline") == 0) {162 } else if (strcmp(mcpu, "baseline") == 0) {
222 target->is_native_os = false;163 target->is_native_os = false;
223 target->is_native_cpu = false;164 target->is_native_cpu = false;
224 target->llvm_cpu_name = "";165 target->llvm_cpu_name = "";
225 target->llvm_cpu_features = "";166 target->llvm_cpu_features = "";
226 target->cache_hash = "baseline\n\n";
227 } else {167 } else {
228 const char *msg = "stage0 can't handle CPU/features in the target";168 const char *msg = "stage0 can't handle CPU/features in the target";
229 stage2_panic(msg, strlen(msg));169 stage2_panic(msg, strlen(msg));
...@@ -264,11 +204,8 @@ Error stage2_target_parse(struct ZigTarget *target, const char *zig_triple, cons...@@ -264,11 +204,8 @@ Error stage2_target_parse(struct ZigTarget *target, const char *zig_triple, cons
264 const char *msg = "stage0 can't handle CPU/features in the target";204 const char *msg = "stage0 can't handle CPU/features in the target";
265 stage2_panic(msg, strlen(msg));205 stage2_panic(msg, strlen(msg));
266 }206 }
267 target->cache_hash = "\n\n";
268 }207 }
269208
270 target->cache_hash_len = strlen(target->cache_hash);
271
272 if (dynamic_linker != nullptr) {209 if (dynamic_linker != nullptr) {
273 target->dynamic_linker = dynamic_linker;210 target->dynamic_linker = dynamic_linker;
274 }211 }
...@@ -276,49 +213,29 @@ Error stage2_target_parse(struct ZigTarget *target, const char *zig_triple, cons...@@ -276,49 +213,29 @@ Error stage2_target_parse(struct ZigTarget *target, const char *zig_triple, cons
276 return ErrorNone;213 return ErrorNone;
277}214}
278215
279int stage2_cmd_targets(const char *zig_triple, const char *mcpu, const char *dynamic_linker) {216const char *stage2_fetch_file(struct ZigStage1 *stage1, const char *path_ptr, size_t path_len,
280 const char *msg = "stage0 called stage2_cmd_targets";217 size_t *result_len)
281 stage2_panic(msg, strlen(msg));218{
282}219 Error err;
283220 Buf contents_buf = BUF_INIT;
284enum Error stage2_libc_parse(struct Stage2LibCInstallation *libc, const char *libc_file) {221 Buf path_buf = BUF_INIT;
285 libc->include_dir = "/dummy/include";
286 libc->include_dir_len = strlen(libc->include_dir);
287 libc->sys_include_dir = "/dummy/sys/include";
288 libc->sys_include_dir_len = strlen(libc->sys_include_dir);
289 libc->crt_dir = "";
290 libc->crt_dir_len = strlen(libc->crt_dir);
291 libc->msvc_lib_dir = "";
292 libc->msvc_lib_dir_len = strlen(libc->msvc_lib_dir);
293 libc->kernel32_lib_dir = "";
294 libc->kernel32_lib_dir_len = strlen(libc->kernel32_lib_dir);
295 return ErrorNone;
296}
297222
298enum Error stage2_libc_render(struct Stage2LibCInstallation *self, FILE *file) {223 buf_init_from_mem(&path_buf, path_ptr, path_len);
299 const char *msg = "stage0 called stage2_libc_render";224 if ((err = os_fetch_file_path(&path_buf, &contents_buf))) {
300 stage2_panic(msg, strlen(msg));225 return nullptr;
226 }
227 *result_len = buf_len(&contents_buf);
228 return buf_ptr(&contents_buf);
301}229}
302230
303enum Error stage2_libc_find_native(struct Stage2LibCInstallation *libc) {231const char *stage2_cimport(struct ZigStage1 *stage1) {
304 const char *msg = "stage0 called stage2_libc_find_native";232 const char *msg = "stage0 called stage2_cimport";
305 stage2_panic(msg, strlen(msg));233 stage2_panic(msg, strlen(msg));
306}234}
307235
308enum Error stage2_detect_native_paths(struct Stage2NativePaths *native_paths) {236const char *stage2_add_link_lib(struct ZigStage1 *stage1,
309 native_paths->include_dirs_ptr = nullptr;237 const char *lib_name_ptr, size_t lib_name_len,
310 native_paths->include_dirs_len = 0;238 const char *symbol_name_ptr, size_t symbol_name_len)
311239{
312 native_paths->lib_dirs_ptr = nullptr;240 return nullptr;
313 native_paths->lib_dirs_len = 0;
314
315 native_paths->rpaths_ptr = nullptr;
316 native_paths->rpaths_len = 0;
317
318 native_paths->warnings_ptr = nullptr;
319 native_paths->warnings_len = 0;
320
321 return ErrorNone;
322}241}
323
324const bool stage2_is_zig0 = true;
src/stage2.h+10-172
...@@ -5,6 +5,8 @@...@@ -5,6 +5,8 @@
5 * See http://opensource.org/licenses/MIT5 * See http://opensource.org/licenses/MIT
6 */6 */
77
8// This file deals with exposing stage2 Zig code to stage1 C++ code.
9
8#ifndef ZIG_STAGE2_H10#ifndef ZIG_STAGE2_H
9#define ZIG_STAGE2_H11#define ZIG_STAGE2_H
1012
...@@ -12,7 +14,7 @@...@@ -12,7 +14,7 @@
12#include <stdint.h>14#include <stdint.h>
13#include <stdio.h>15#include <stdio.h>
1416
15#include "zig_llvm.h"17#include "stage1.h"
1618
17#ifdef __cplusplus19#ifdef __cplusplus
18#define ZIG_EXTERN_C extern "C"20#define ZIG_EXTERN_C extern "C"
...@@ -27,7 +29,7 @@...@@ -27,7 +29,7 @@
27#endif29#endif
2830
29// ABI warning: the types and declarations in this file must match both those in31// ABI warning: the types and declarations in this file must match both those in
30// stage2.cpp and src-self-hosted/stage2.zig.32// stage2.cpp and src-self-hosted/stage1.zig.
3133
32// ABI warning34// ABI warning
33enum Error {35enum Error {
...@@ -124,74 +126,9 @@ struct Stage2ErrorMsg {...@@ -124,74 +126,9 @@ struct Stage2ErrorMsg {
124 unsigned offset; // byte offset into source126 unsigned offset; // byte offset into source
125};127};
126128
127// ABI warning
128struct Stage2Ast;
129
130// ABI warning
131ZIG_EXTERN_C enum Error stage2_translate_c(struct Stage2Ast **out_ast,
132 struct Stage2ErrorMsg **out_errors_ptr, size_t *out_errors_len,
133 const char **args_begin, const char **args_end, const char *resources_path);
134
135// ABI warning
136ZIG_EXTERN_C void stage2_free_clang_errors(struct Stage2ErrorMsg *ptr, size_t len);
137
138// ABI warning
139ZIG_EXTERN_C void stage2_render_ast(struct Stage2Ast *ast, FILE *output_file);
140
141// ABI warning
142ZIG_EXTERN_C void stage2_zen(const char **ptr, size_t *len);
143
144// ABI warning
145ZIG_EXTERN_C int stage2_env(int argc, char **argv);
146
147// ABI warning
148ZIG_EXTERN_C int stage2_cc(int argc, char **argv, bool is_cpp);
149
150// ABI warning
151ZIG_EXTERN_C void stage2_attach_segfault_handler(void);
152
153// ABI warning129// ABI warning
154ZIG_EXTERN_C ZIG_ATTRIBUTE_NORETURN void stage2_panic(const char *ptr, size_t len);130ZIG_EXTERN_C ZIG_ATTRIBUTE_NORETURN void stage2_panic(const char *ptr, size_t len);
155131
156// ABI warning
157ZIG_EXTERN_C int stage2_fmt(int argc, char **argv);
158
159// ABI warning
160struct stage2_DepTokenizer {
161 void *handle;
162};
163
164// ABI warning
165struct stage2_DepNextResult {
166 enum TypeId {
167 error,
168 null,
169 target,
170 prereq,
171 };
172
173 TypeId type_id;
174
175 // when ent == error --> error text
176 // when ent == null --> undefined
177 // when ent == target --> target pathname
178 // when ent == prereq --> prereq pathname
179 const char *textz;
180};
181
182// ABI warning
183ZIG_EXTERN_C stage2_DepTokenizer stage2_DepTokenizer_init(const char *input, size_t len);
184
185// ABI warning
186ZIG_EXTERN_C void stage2_DepTokenizer_deinit(stage2_DepTokenizer *self);
187
188// ABI warning
189ZIG_EXTERN_C stage2_DepNextResult stage2_DepTokenizer_next(stage2_DepTokenizer *self);
190
191// ABI warning
192struct Stage2Progress;
193// ABI warning
194struct Stage2ProgressNode;
195// ABI warning132// ABI warning
196ZIG_EXTERN_C Stage2Progress *stage2_progress_create(void);133ZIG_EXTERN_C Stage2Progress *stage2_progress_create(void);
197// ABI warning134// ABI warning
...@@ -212,69 +149,6 @@ ZIG_EXTERN_C void stage2_progress_complete_one(Stage2ProgressNode *node);...@@ -212,69 +149,6 @@ ZIG_EXTERN_C void stage2_progress_complete_one(Stage2ProgressNode *node);
212ZIG_EXTERN_C void stage2_progress_update_node(Stage2ProgressNode *node,149ZIG_EXTERN_C void stage2_progress_update_node(Stage2ProgressNode *node,
213 size_t completed_count, size_t estimated_total_items);150 size_t completed_count, size_t estimated_total_items);
214151
215// ABI warning
216struct Stage2LibCInstallation {
217 const char *include_dir;
218 size_t include_dir_len;
219 const char *sys_include_dir;
220 size_t sys_include_dir_len;
221 const char *crt_dir;
222 size_t crt_dir_len;
223 const char *msvc_lib_dir;
224 size_t msvc_lib_dir_len;
225 const char *kernel32_lib_dir;
226 size_t kernel32_lib_dir_len;
227};
228
229// ABI warning
230ZIG_EXTERN_C enum Error stage2_libc_parse(struct Stage2LibCInstallation *libc, const char *libc_file);
231// ABI warning
232ZIG_EXTERN_C enum Error stage2_libc_render(struct Stage2LibCInstallation *self, FILE *file);
233// ABI warning
234ZIG_EXTERN_C enum Error stage2_libc_find_native(struct Stage2LibCInstallation *libc);
235
236// ABI warning
237// Synchronize with target.cpp::os_list
238enum Os {
239 OsFreestanding,
240 OsAnanas,
241 OsCloudABI,
242 OsDragonFly,
243 OsFreeBSD,
244 OsFuchsia,
245 OsIOS,
246 OsKFreeBSD,
247 OsLinux,
248 OsLv2, // PS3
249 OsMacOSX,
250 OsNetBSD,
251 OsOpenBSD,
252 OsSolaris,
253 OsWindows,
254 OsHaiku,
255 OsMinix,
256 OsRTEMS,
257 OsNaCl, // Native Client
258 OsCNK, // BG/P Compute-Node Kernel
259 OsAIX,
260 OsCUDA, // NVIDIA CUDA
261 OsNVCL, // NVIDIA OpenCL
262 OsAMDHSA, // AMD HSA Runtime
263 OsPS4,
264 OsELFIAMCU,
265 OsTvOS, // Apple tvOS
266 OsWatchOS, // Apple watchOS
267 OsMesa3D,
268 OsContiki,
269 OsAMDPAL,
270 OsHermitCore,
271 OsHurd,
272 OsWASI,
273 OsEmscripten,
274 OsUefi,
275 OsOther,
276};
277
278// ABI warning152// ABI warning
279struct Stage2SemVer {153struct Stage2SemVer {
280 uint32_t major;154 uint32_t major;
...@@ -282,56 +156,20 @@ struct Stage2SemVer {...@@ -282,56 +156,20 @@ struct Stage2SemVer {
282 uint32_t patch;156 uint32_t patch;
283};157};
284158
285// ABI warning
286struct ZigTarget {
287 enum ZigLLVM_ArchType arch;
288 enum ZigLLVM_VendorType vendor;
289
290 enum ZigLLVM_EnvironmentType abi;
291 Os os;
292
293 bool is_native_os;
294 bool is_native_cpu;
295
296 // null means default. this is double-purposed to be darwin min version
297 struct Stage2SemVer *glibc_or_darwin_version;
298
299 const char *llvm_cpu_name;
300 const char *llvm_cpu_features;
301 const char *cpu_builtin_str;
302 const char *cache_hash;
303 size_t cache_hash_len;
304 const char *os_builtin_str;
305 const char *dynamic_linker;
306 const char *standard_dynamic_linker_path;
307
308 const char **llvm_cpu_features_asm_ptr;
309 size_t llvm_cpu_features_asm_len;
310};
311
312// ABI warning159// ABI warning
313ZIG_EXTERN_C enum Error stage2_target_parse(struct ZigTarget *target, const char *zig_triple, const char *mcpu,160ZIG_EXTERN_C enum Error stage2_target_parse(struct ZigTarget *target, const char *zig_triple, const char *mcpu,
314 const char *dynamic_linker);161 const char *dynamic_linker);
315162
316// ABI warning163// ABI warning
317ZIG_EXTERN_C int stage2_cmd_targets(const char *zig_triple, const char *mcpu, const char *dynamic_linker);164ZIG_EXTERN_C const char *stage2_fetch_file(struct ZigStage1 *stage1, const char *path_ptr, size_t path_len,
165 size_t *result_len);
318166
319
320// ABI warning
321struct Stage2NativePaths {
322 const char **include_dirs_ptr;
323 size_t include_dirs_len;
324 const char **lib_dirs_ptr;
325 size_t lib_dirs_len;
326 const char **rpaths_ptr;
327 size_t rpaths_len;
328 const char **warnings_ptr;
329 size_t warnings_len;
330};
331// ABI warning167// ABI warning
332ZIG_EXTERN_C enum Error stage2_detect_native_paths(struct Stage2NativePaths *native_paths);168ZIG_EXTERN_C const char *stage2_cimport(struct ZigStage1 *stage1);
333169
334// ABI warning170// ABI warning
335ZIG_EXTERN_C const bool stage2_is_zig0;171ZIG_EXTERN_C const char *stage2_add_link_lib(struct ZigStage1 *stage1,
172 const char *lib_name_ptr, size_t lib_name_len,
173 const char *symbol_name_ptr, size_t symbol_name_len);
336174
337#endif175#endif
src/target.cpp-127
...@@ -10,8 +10,6 @@...@@ -10,8 +10,6 @@
10#include "target.hpp"10#include "target.hpp"
11#include "util.hpp"11#include "util.hpp"
12#include "os.hpp"12#include "os.hpp"
13#include "compiler.hpp"
14#include "glibc.hpp"
1513
16#include <stdio.h>14#include <stdio.h>
1715
...@@ -346,33 +344,6 @@ const char *target_abi_name(ZigLLVM_EnvironmentType abi) {...@@ -346,33 +344,6 @@ const char *target_abi_name(ZigLLVM_EnvironmentType abi) {
346 return ZigLLVMGetEnvironmentTypeName(abi);344 return ZigLLVMGetEnvironmentTypeName(abi);
347}345}
348346
349Error target_parse_glibc_version(Stage2SemVer *glibc_ver, const char *text) {
350 glibc_ver->major = 2;
351 glibc_ver->minor = 0;
352 glibc_ver->patch = 0;
353 SplitIterator it = memSplit(str(text), str("GLIBC_."));
354 {
355 Optional<Slice<uint8_t>> opt_component = SplitIterator_next(&it);
356 if (!opt_component.is_some) return ErrorUnknownABI;
357 glibc_ver->major = strtoul(buf_ptr(buf_create_from_slice(opt_component.value)), nullptr, 10);
358 }
359 {
360 Optional<Slice<uint8_t>> opt_component = SplitIterator_next(&it);
361 if (!opt_component.is_some) return ErrorNone;
362 glibc_ver->minor = strtoul(buf_ptr(buf_create_from_slice(opt_component.value)), nullptr, 10);
363 }
364 {
365 Optional<Slice<uint8_t>> opt_component = SplitIterator_next(&it);
366 if (!opt_component.is_some) return ErrorNone;
367 glibc_ver->patch = strtoul(buf_ptr(buf_create_from_slice(opt_component.value)), nullptr, 10);
368 }
369 return ErrorNone;
370}
371
372void target_init_default_glibc_version(ZigTarget *target) {
373 *target->glibc_or_darwin_version = {2, 17, 0};
374}
375
376Error target_parse_arch(ZigLLVM_ArchType *out_arch, const char *arch_ptr, size_t arch_len) {347Error target_parse_arch(ZigLLVM_ArchType *out_arch, const char *arch_ptr, size_t arch_len) {
377 *out_arch = ZigLLVM_UnknownArch;348 *out_arch = ZigLLVM_UnknownArch;
378 for (size_t arch_i = 0; arch_i < array_length(arch_list); arch_i += 1) {349 for (size_t arch_i = 0; arch_i < array_length(arch_list); arch_i += 1) {
...@@ -756,66 +727,6 @@ const char *target_llvm_ir_file_ext(const ZigTarget *target) {...@@ -756,66 +727,6 @@ const char *target_llvm_ir_file_ext(const ZigTarget *target) {
756 return ".ll";727 return ".ll";
757}728}
758729
759const char *target_exe_file_ext(const ZigTarget *target) {
760 if (target->os == OsWindows) {
761 return ".exe";
762 } else if (target->os == OsUefi) {
763 return ".efi";
764 } else if (target_is_wasm(target)) {
765 return ".wasm";
766 } else {
767 return "";
768 }
769}
770
771const char *target_lib_file_prefix(const ZigTarget *target) {
772 if ((target->os == OsWindows && !target_abi_is_gnu(target->abi)) ||
773 target->os == OsUefi ||
774 target_is_wasm(target))
775 {
776 return "";
777 } else {
778 return "lib";
779 }
780}
781
782const char *target_lib_file_ext(const ZigTarget *target, bool is_static, bool is_versioned,
783 size_t version_major, size_t version_minor, size_t version_patch)
784{
785 if (target_is_wasm(target)) {
786 return ".wasm";
787 }
788 if (target->os == OsWindows || target->os == OsUefi) {
789 if (is_static) {
790 if (target->os == OsWindows && target_abi_is_gnu(target->abi)) {
791 return ".a";
792 } else {
793 return ".lib";
794 }
795 } else {
796 return ".dll";
797 }
798 } else {
799 if (is_static) {
800 return ".a";
801 } else if (target_os_is_darwin(target->os)) {
802 if (is_versioned) {
803 return buf_ptr(buf_sprintf(".%" ZIG_PRI_usize ".%" ZIG_PRI_usize ".%" ZIG_PRI_usize ".dylib",
804 version_major, version_minor, version_patch));
805 } else {
806 return ".dylib";
807 }
808 } else {
809 if (is_versioned) {
810 return buf_ptr(buf_sprintf(".so.%" ZIG_PRI_usize ".%" ZIG_PRI_usize ".%" ZIG_PRI_usize,
811 version_major, version_minor, version_patch));
812 } else {
813 return ".so";
814 }
815 }
816 }
817}
818
819bool target_is_android(const ZigTarget *target) {730bool target_is_android(const ZigTarget *target) {
820 return target->abi == ZigLLVM_Android;731 return target->abi == ZigLLVM_Android;
821}732}
...@@ -992,40 +903,6 @@ bool target_os_requires_libc(Os os) {...@@ -992,40 +903,6 @@ bool target_os_requires_libc(Os os) {
992 return (target_os_is_darwin(os) || os == OsFreeBSD || os == OsNetBSD || os == OsDragonFly);903 return (target_os_is_darwin(os) || os == OsFreeBSD || os == OsNetBSD || os == OsDragonFly);
993}904}
994905
995bool target_supports_fpic(const ZigTarget *target) {
996 // This is not whether the target supports Position Independent Code, but whether the -fPIC
997 // C compiler argument is valid.
998 return target->os != OsWindows;
999}
1000
1001bool target_supports_clang_march_native(const ZigTarget *target) {
1002 // Whether clang supports -march=native on this target.
1003 // Arguably it should always work, but in reality it gives:
1004 // error: the clang compiler does not support '-march=native'
1005 // If we move CPU detection logic into Zig itelf, we will not need this,
1006 // instead we will always pass target features and CPU configuration explicitly.
1007 return target->arch != ZigLLVM_aarch64 &&
1008 target->arch != ZigLLVM_aarch64_be;
1009}
1010
1011bool target_supports_stack_probing(const ZigTarget *target) {
1012 return target->os != OsWindows && target->os != OsUefi && (target->arch == ZigLLVM_x86 || target->arch == ZigLLVM_x86_64);
1013}
1014
1015bool target_supports_sanitize_c(const ZigTarget *target) {
1016 return true;
1017}
1018
1019bool target_requires_pic(const ZigTarget *target, bool linking_libc) {
1020 // This function returns whether non-pic code is completely invalid on the given target.
1021 return target_is_android(target) || target->os == OsWindows || target->os == OsUefi || target_os_requires_libc(target->os) ||
1022 (linking_libc && target_is_glibc(target));
1023}
1024
1025bool target_requires_pie(const ZigTarget *target) {
1026 return target_is_android(target);
1027}
1028
1029bool target_is_glibc(const ZigTarget *target) {906bool target_is_glibc(const ZigTarget *target) {
1030 return target->os == OsLinux && target_abi_is_gnu(target->abi);907 return target->os == OsLinux && target_abi_is_gnu(target->abi);
1031}908}
...@@ -1038,10 +915,6 @@ bool target_is_wasm(const ZigTarget *target) {...@@ -1038,10 +915,6 @@ bool target_is_wasm(const ZigTarget *target) {
1038 return target->arch == ZigLLVM_wasm32 || target->arch == ZigLLVM_wasm64;915 return target->arch == ZigLLVM_wasm32 || target->arch == ZigLLVM_wasm64;
1039}916}
1040917
1041bool target_is_single_threaded(const ZigTarget *target) {
1042 return target_is_wasm(target);
1043}
1044
1045ZigLLVM_EnvironmentType target_default_abi(ZigLLVM_ArchType arch, Os os) {918ZigLLVM_EnvironmentType target_default_abi(ZigLLVM_ArchType arch, Os os) {
1046 if (arch == ZigLLVM_wasm32 || arch == ZigLLVM_wasm64) {919 if (arch == ZigLLVM_wasm32 || arch == ZigLLVM_wasm64) {
1047 return ZigLLVM_Musl;920 return ZigLLVM_Musl;
src/target.hpp-30
...@@ -12,22 +12,6 @@...@@ -12,22 +12,6 @@
1212
13struct Buf;13struct Buf;
1414
15enum TargetSubsystem {
16 TargetSubsystemConsole,
17 TargetSubsystemWindows,
18 TargetSubsystemPosix,
19 TargetSubsystemNative,
20 TargetSubsystemEfiApplication,
21 TargetSubsystemEfiBootServiceDriver,
22 TargetSubsystemEfiRom,
23 TargetSubsystemEfiRuntimeDriver,
24
25 // This means Zig should infer the subsystem.
26 // It's last so that the indexes of other items can line up
27 // with the enum in builtin.zig.
28 TargetSubsystemAuto
29};
30
31enum CIntType {15enum CIntType {
32 CIntTypeShort,16 CIntTypeShort,
33 CIntTypeUShort,17 CIntTypeUShort,
...@@ -46,9 +30,6 @@ Error target_parse_arch(ZigLLVM_ArchType *arch, const char *arch_ptr, size_t arc...@@ -46,9 +30,6 @@ Error target_parse_arch(ZigLLVM_ArchType *arch, const char *arch_ptr, size_t arc
46Error target_parse_os(Os *os, const char *os_ptr, size_t os_len);30Error target_parse_os(Os *os, const char *os_ptr, size_t os_len);
47Error target_parse_abi(ZigLLVM_EnvironmentType *abi, const char *abi_ptr, size_t abi_len);31Error target_parse_abi(ZigLLVM_EnvironmentType *abi, const char *abi_ptr, size_t abi_len);
4832
49Error target_parse_glibc_version(Stage2SemVer *out, const char *text);
50void target_init_default_glibc_version(ZigTarget *target);
51
52size_t target_arch_count(void);33size_t target_arch_count(void);
53ZigLLVM_ArchType target_arch_enum(size_t index);34ZigLLVM_ArchType target_arch_enum(size_t index);
54const char *target_arch_name(ZigLLVM_ArchType arch);35const char *target_arch_name(ZigLLVM_ArchType arch);
...@@ -85,10 +66,6 @@ uint32_t target_c_type_size_in_bits(const ZigTarget *target, CIntType id);...@@ -85,10 +66,6 @@ uint32_t target_c_type_size_in_bits(const ZigTarget *target, CIntType id);
85const char *target_o_file_ext(const ZigTarget *target);66const char *target_o_file_ext(const ZigTarget *target);
86const char *target_asm_file_ext(const ZigTarget *target);67const char *target_asm_file_ext(const ZigTarget *target);
87const char *target_llvm_ir_file_ext(const ZigTarget *target);68const char *target_llvm_ir_file_ext(const ZigTarget *target);
88const char *target_exe_file_ext(const ZigTarget *target);
89const char *target_lib_file_prefix(const ZigTarget *target);
90const char *target_lib_file_ext(const ZigTarget *target, bool is_static, bool is_versioned,
91 size_t version_major, size_t version_minor, size_t version_patch);
9269
93bool target_can_exec(const ZigTarget *host_target, const ZigTarget *guest_target);70bool target_can_exec(const ZigTarget *host_target, const ZigTarget *guest_target);
94ZigLLVM_OSType get_llvm_os_type(Os os_type);71ZigLLVM_OSType get_llvm_os_type(Os os_type);
...@@ -104,10 +81,6 @@ bool target_can_build_libc(const ZigTarget *target);...@@ -104,10 +81,6 @@ bool target_can_build_libc(const ZigTarget *target);
104const char *target_libc_generic_name(const ZigTarget *target);81const char *target_libc_generic_name(const ZigTarget *target);
105bool target_is_libc_lib_name(const ZigTarget *target, const char *name);82bool target_is_libc_lib_name(const ZigTarget *target, const char *name);
106bool target_is_libcpp_lib_name(const ZigTarget *target, const char *name);83bool target_is_libcpp_lib_name(const ZigTarget *target, const char *name);
107bool target_supports_fpic(const ZigTarget *target);
108bool target_supports_clang_march_native(const ZigTarget *target);
109bool target_requires_pic(const ZigTarget *target, bool linking_libc);
110bool target_requires_pie(const ZigTarget *target);
111bool target_abi_is_gnu(ZigLLVM_EnvironmentType abi);84bool target_abi_is_gnu(ZigLLVM_EnvironmentType abi);
112bool target_abi_is_musl(ZigLLVM_EnvironmentType abi);85bool target_abi_is_musl(ZigLLVM_EnvironmentType abi);
113bool target_is_glibc(const ZigTarget *target);86bool target_is_glibc(const ZigTarget *target);
...@@ -115,9 +88,6 @@ bool target_is_musl(const ZigTarget *target);...@@ -115,9 +88,6 @@ bool target_is_musl(const ZigTarget *target);
115bool target_is_wasm(const ZigTarget *target);88bool target_is_wasm(const ZigTarget *target);
116bool target_is_riscv(const ZigTarget *target);89bool target_is_riscv(const ZigTarget *target);
117bool target_is_android(const ZigTarget *target);90bool target_is_android(const ZigTarget *target);
118bool target_is_single_threaded(const ZigTarget *target);
119bool target_supports_stack_probing(const ZigTarget *target);
120bool target_supports_sanitize_c(const ZigTarget *target);
121bool target_has_debug_info(const ZigTarget *target);91bool target_has_debug_info(const ZigTarget *target);
122const char *target_arch_musl_name(ZigLLVM_ArchType arch);92const char *target_arch_musl_name(ZigLLVM_ArchType arch);
12393
src/zig0.cpp created+307
...@@ -0,0 +1,307 @@
1/*
2 * Copyright (c) 2015 Andrew Kelley
3 *
4 * This file is part of zig, which is MIT licensed.
5 * See http://opensource.org/licenses/MIT
6 */
7
8// This file is the entry point for zig0, which is *only* used to build
9// stage2, the self-hosted compiler, into an object file, which is then
10// linked by the same build system (cmake) that linked this binary.
11
12#include "stage1.h"
13#include "heap.hpp"
14#include "stage2.h"
15#include "target.hpp"
16#include "error.hpp"
17
18#include <stdio.h>
19#include <string.h>
20
21static int print_error_usage(const char *arg0) {
22 fprintf(stderr, "See `%s --help` for detailed usage information\n", arg0);
23 return EXIT_FAILURE;
24}
25
26static int print_full_usage(const char *arg0, FILE *file, int return_code) {
27 fprintf(file,
28 "Usage: %s [options] builds an object file\n"
29 "\n"
30 "Options:\n"
31 " --color [auto|off|on] enable or disable colored error messages\n"
32 " --name [name] override output name\n"
33 " --output-dir [dir] override output directory (defaults to cwd)\n"
34 " --pkg-begin [name] [path] make pkg available to import and push current pkg\n"
35 " --pkg-end pop current pkg\n"
36 " --main-pkg-path set the directory of the root package\n"
37 " --release-fast build with optimizations on and safety off\n"
38 " --release-safe build with optimizations on and safety on\n"
39 " --release-small build with size optimizations on and safety off\n"
40 " --single-threaded source may assume it is only used single-threaded\n"
41 " -dynamic create a shared library (.so; .dll; .dylib)\n"
42 " --strip exclude debug symbols\n"
43 " -target [name] <arch>-<os>-<abi> see the targets command\n"
44 " -mcpu [cpu] specify target CPU and feature set\n"
45 " --verbose-tokenize enable compiler debug output for tokenization\n"
46 " --verbose-ast enable compiler debug output for AST parsing\n"
47 " --verbose-link enable compiler debug output for linking\n"
48 " --verbose-ir enable compiler debug output for Zig IR\n"
49 " --verbose-llvm-ir enable compiler debug output for LLVM IR\n"
50 " --verbose-cimport enable compiler debug output for C imports\n"
51 " --verbose-cc enable compiler debug output for C compilation\n"
52 " --verbose-llvm-cpu-features enable compiler debug output for LLVM CPU features\n"
53 "\n"
54 , arg0);
55 return return_code;
56}
57
58static bool str_starts_with(const char *s1, const char *s2) {
59 size_t s2_len = strlen(s2);
60 if (strlen(s1) < s2_len) {
61 return false;
62 }
63 return memcmp(s1, s2, s2_len) == 0;
64}
65
66int main_exit(Stage2ProgressNode *root_progress_node, int exit_code) {
67 if (root_progress_node != nullptr) {
68 stage2_progress_end(root_progress_node);
69 }
70 return exit_code;
71}
72
73int main(int argc, char **argv) {
74 zig_stage1_os_init();
75
76 char *arg0 = argv[0];
77 Error err;
78
79 const char *in_file = nullptr;
80 const char *output_dir = nullptr;
81 bool strip = false;
82 const char *out_name = nullptr;
83 bool verbose_tokenize = false;
84 bool verbose_ast = false;
85 bool verbose_link = false;
86 bool verbose_ir = false;
87 bool verbose_llvm_ir = false;
88 bool verbose_cimport = false;
89 bool verbose_cc = false;
90 bool verbose_llvm_cpu_features = false;
91 ErrColor color = ErrColorAuto;
92 const char *dynamic_linker = nullptr;
93 bool link_libc = false;
94 bool link_libcpp = false;
95 const char *target_string = nullptr;
96 ZigStage1Pkg *cur_pkg = heap::c_allocator.create<ZigStage1Pkg>();
97 BuildMode build_mode = BuildModeDebug;
98 TargetSubsystem subsystem = TargetSubsystemAuto;
99 const char *override_lib_dir = nullptr;
100 const char *main_pkg_path = nullptr;
101 const char *mcpu = nullptr;
102
103 for (int i = 1; i < argc; i += 1) {
104 char *arg = argv[i];
105
106 if (arg[0] == '-') {
107 if (strcmp(arg, "--") == 0) {
108 fprintf(stderr, "Unexpected end-of-parameter mark: %s\n", arg);
109 } else if (strcmp(arg, "--release-fast") == 0) {
110 build_mode = BuildModeFastRelease;
111 } else if (strcmp(arg, "--release-safe") == 0) {
112 build_mode = BuildModeSafeRelease;
113 } else if (strcmp(arg, "--release-small") == 0) {
114 build_mode = BuildModeSmallRelease;
115 } else if (strcmp(arg, "--help") == 0) {
116 return print_full_usage(arg0, stdout, EXIT_SUCCESS);
117 } else if (strcmp(arg, "--strip") == 0) {
118 strip = true;
119 } else if (strcmp(arg, "--verbose-tokenize") == 0) {
120 verbose_tokenize = true;
121 } else if (strcmp(arg, "--verbose-ast") == 0) {
122 verbose_ast = true;
123 } else if (strcmp(arg, "--verbose-link") == 0) {
124 verbose_link = true;
125 } else if (strcmp(arg, "--verbose-ir") == 0) {
126 verbose_ir = true;
127 } else if (strcmp(arg, "--verbose-llvm-ir") == 0) {
128 verbose_llvm_ir = true;
129 } else if (strcmp(arg, "--verbose-cimport") == 0) {
130 verbose_cimport = true;
131 } else if (strcmp(arg, "--verbose-cc") == 0) {
132 verbose_cc = true;
133 } else if (strcmp(arg, "--verbose-llvm-cpu-features") == 0) {
134 verbose_llvm_cpu_features = true;
135 } else if (arg[1] == 'l' && arg[2] != 0) {
136 // alias for --library
137 const char *l = &arg[2];
138 if (strcmp(l, "c") == 0) {
139 link_libc = true;
140 } else if (strcmp(l, "c++") == 0 || strcmp(l, "stdc++") == 0) {
141 link_libcpp = true;
142 }
143 } else if (strcmp(arg, "--pkg-begin") == 0) {
144 if (i + 2 >= argc) {
145 fprintf(stderr, "Expected 2 arguments after --pkg-begin\n");
146 return print_error_usage(arg0);
147 }
148 ZigStage1Pkg *new_cur_pkg = heap::c_allocator.create<ZigStage1Pkg>();
149 i += 1;
150 new_cur_pkg->name_ptr = argv[i];
151 new_cur_pkg->name_len = strlen(argv[i]);
152 i += 1;
153 new_cur_pkg->path_ptr = argv[i];
154 new_cur_pkg->path_len = strlen(argv[i]);
155 new_cur_pkg->parent = cur_pkg;
156 cur_pkg->children_ptr = heap::c_allocator.reallocate<ZigStage1Pkg *>(cur_pkg->children_ptr,
157 cur_pkg->children_len, cur_pkg->children_len + 1);
158 cur_pkg->children_ptr[cur_pkg->children_len] = new_cur_pkg;
159 cur_pkg->children_len += 1;
160
161 cur_pkg = new_cur_pkg;
162 } else if (strcmp(arg, "--pkg-end") == 0) {
163 if (cur_pkg->parent == nullptr) {
164 fprintf(stderr, "Encountered --pkg-end with no matching --pkg-begin\n");
165 return EXIT_FAILURE;
166 }
167 cur_pkg = cur_pkg->parent;
168 } else if (str_starts_with(arg, "-mcpu=")) {
169 mcpu = arg + strlen("-mcpu=");
170 } else if (i + 1 >= argc) {
171 fprintf(stderr, "Expected another argument after %s\n", arg);
172 return print_error_usage(arg0);
173 } else {
174 i += 1;
175 if (strcmp(arg, "--output-dir") == 0) {
176 output_dir = argv[i];
177 } else if (strcmp(arg, "--color") == 0) {
178 if (strcmp(argv[i], "auto") == 0) {
179 color = ErrColorAuto;
180 } else if (strcmp(argv[i], "on") == 0) {
181 color = ErrColorOn;
182 } else if (strcmp(argv[i], "off") == 0) {
183 color = ErrColorOff;
184 } else {
185 fprintf(stderr, "--color options are 'auto', 'on', or 'off'\n");
186 return print_error_usage(arg0);
187 }
188 } else if (strcmp(arg, "--name") == 0) {
189 out_name = argv[i];
190 } else if (strcmp(arg, "--dynamic-linker") == 0) {
191 dynamic_linker = argv[i];
192 } else if (strcmp(arg, "--override-lib-dir") == 0) {
193 override_lib_dir = argv[i];
194 } else if (strcmp(arg, "--main-pkg-path") == 0) {
195 main_pkg_path = argv[i];
196 } else if (strcmp(arg, "--library") == 0 || strcmp(arg, "-l") == 0) {
197 if (strcmp(argv[i], "c") == 0) {
198 link_libc = true;
199 } else if (strcmp(argv[i], "c++") == 0 || strcmp(argv[i], "stdc++") == 0) {
200 link_libcpp = true;
201 }
202 } else if (strcmp(arg, "-target") == 0) {
203 target_string = argv[i];
204 } else if (strcmp(arg, "--subsystem") == 0) {
205 if (strcmp(argv[i], "console") == 0) {
206 subsystem = TargetSubsystemConsole;
207 } else if (strcmp(argv[i], "windows") == 0) {
208 subsystem = TargetSubsystemWindows;
209 } else if (strcmp(argv[i], "posix") == 0) {
210 subsystem = TargetSubsystemPosix;
211 } else if (strcmp(argv[i], "native") == 0) {
212 subsystem = TargetSubsystemNative;
213 } else if (strcmp(argv[i], "efi_application") == 0) {
214 subsystem = TargetSubsystemEfiApplication;
215 } else if (strcmp(argv[i], "efi_boot_service_driver") == 0) {
216 subsystem = TargetSubsystemEfiBootServiceDriver;
217 } else if (strcmp(argv[i], "efi_rom") == 0) {
218 subsystem = TargetSubsystemEfiRom;
219 } else if (strcmp(argv[i], "efi_runtime_driver") == 0) {
220 subsystem = TargetSubsystemEfiRuntimeDriver;
221 } else {
222 fprintf(stderr, "invalid: --subsystem %s\n"
223 "Options are:\n"
224 " console\n"
225 " windows\n"
226 " posix\n"
227 " native\n"
228 " efi_application\n"
229 " efi_boot_service_driver\n"
230 " efi_rom\n"
231 " efi_runtime_driver\n"
232 , argv[i]);
233 return EXIT_FAILURE;
234 }
235 } else if (strcmp(arg, "-mcpu") == 0) {
236 mcpu = argv[i];
237 } else {
238 fprintf(stderr, "Invalid argument: %s\n", arg);
239 return print_error_usage(arg0);
240 }
241 }
242 } else if (!in_file) {
243 in_file = arg;
244 } else {
245 fprintf(stderr, "Unexpected extra parameter: %s\n", arg);
246 return print_error_usage(arg0);
247 }
248 }
249
250 if (cur_pkg->parent != nullptr) {
251 fprintf(stderr, "Unmatched --pkg-begin\n");
252 return EXIT_FAILURE;
253 }
254
255 Stage2Progress *progress = stage2_progress_create();
256 Stage2ProgressNode *root_progress_node = stage2_progress_start_root(progress, "", 0, 0);
257 if (color == ErrColorOff) stage2_progress_disable_tty(progress);
258
259 ZigTarget target;
260 if ((err = target_parse_triple(&target, target_string, mcpu, dynamic_linker))) {
261 fprintf(stderr, "invalid target: %s\n", err_str(err));
262 return print_error_usage(arg0);
263 }
264
265 if (in_file == nullptr) {
266 fprintf(stderr, "missing zig file\n");
267 return print_error_usage(arg0);
268 }
269
270 if (out_name == nullptr) {
271 fprintf(stderr, "missing --name\n");
272 return print_error_usage(arg0);
273 }
274
275 ZigStage1 *stage1 = zig_stage1_create(build_mode,
276 main_pkg_path, (main_pkg_path == nullptr) ? 0 : strlen(main_pkg_path),
277 in_file, strlen(in_file),
278 override_lib_dir, strlen(override_lib_dir), &target, false,
279 root_progress_node);
280
281 stage1->root_name_ptr = out_name;
282 stage1->root_name_len = strlen(out_name);
283 stage1->strip = strip;
284 stage1->verbose_tokenize = verbose_tokenize;
285 stage1->verbose_ast = verbose_ast;
286 stage1->verbose_link = verbose_link;
287 stage1->verbose_ir = verbose_ir;
288 stage1->verbose_llvm_ir = verbose_llvm_ir;
289 stage1->verbose_cimport = verbose_cimport;
290 stage1->verbose_cc = verbose_cc;
291 stage1->verbose_llvm_cpu_features = verbose_llvm_cpu_features;
292 stage1->output_dir_ptr = output_dir;
293 stage1->output_dir_len = strlen(output_dir);
294 stage1->root_pkg = cur_pkg;
295 stage1->err_color = color;
296 stage1->link_libc = link_libc;
297 stage1->link_libcpp = link_libcpp;
298 stage1->subsystem = subsystem;
299 stage1->pic = true;
300 stage1->emit_bin = true;
301
302 zig_stage1_build_object(stage1);
303
304 zig_stage1_destroy(stage1);
305
306 return main_exit(root_progress_node, EXIT_SUCCESS);
307}