From 0c603f1ca33e4efff0ffb89322d6b755cb5d53e3 Mon Sep 17 00:00:00 2001 From: David Gonzalez Martin Date: Fri, 1 Mar 2024 22:19:12 -0600 Subject: [PATCH] Compile and link with musl libc --- bootstrap/Compilation.zig | 2065 ++++++++++++++++++++++++++- bootstrap/backend/llvm.zig | 17 +- bootstrap/backend/llvm_bindings.zig | 5 +- bootstrap/library.zig | 6 + bootstrap/main.zig | 20 +- build.zig | 125 +- src/llvm/ar.cpp | 1470 +++++++++++++++++++ src/llvm/lld.cpp | 65 +- 8 files changed, 3659 insertions(+), 114 deletions(-) create mode 100644 src/llvm/ar.cpp diff --git a/bootstrap/Compilation.zig b/bootstrap/Compilation.zig index eff89dc..d3e1f7d 100644 --- a/bootstrap/Compilation.zig +++ b/bootstrap/Compilation.zig @@ -5,6 +5,7 @@ const Allocator = std.mem.Allocator; const data_structures = @import("library.zig"); const assert = data_structures.assert; const byte_equal = data_structures.byte_equal; +const byte_equal_terminated = data_structures.byte_equal_terminated; const UnpinnedArray = data_structures.UnpinnedArray; const BlockList = data_structures.BlockList; const MyAllocator = data_structures.MyAllocator; @@ -15,7 +16,6 @@ const lexer = @import("frontend/lexer.zig"); const parser = @import("frontend/parser.zig"); const Node = parser.Node; const llvm = @import("backend/llvm.zig"); - const cache_dir_name = "cache"; const installation_dir_name = "installation"; @@ -66,9 +66,22 @@ pub fn compileBuildExecutable(context: *const Context, arguments: [][*:0]u8) !vo unit.* = .{ .descriptor = .{ .main_package_path = "build.nat", - .arch = @import("builtin").cpu.arch, - .os = @import("builtin").os.tag, - .abi = @import("builtin").abi, + .arch = switch (@import("builtin").cpu.arch) { + .x86_64 => .x86_64, + .aarch64 => .aarch64, + else => |t| @panic(@tagName(t)), + }, + .os = switch (@import("builtin").os.tag) { + .linux => .linux, + .macos => .macos, + else => |t| @panic(@tagName(t)), + }, + .abi = switch (@import("builtin").abi) { + .none => .none, + .gnu => .gnu, + .musl => .musl, + else => |t| @panic(@tagName(t)), + }, .only_parse = false, .executable_path = "nat/build", .link_libc = @import("builtin").os.tag == .macos, @@ -101,16 +114,2044 @@ pub fn compileBuildExecutable(context: *const Context, arguments: [][*:0]u8) !vo } } +fn clang_job(arguments: []const []const u8) !void { + const exit_code = try clangMain(std.heap.page_allocator, arguments); + if (exit_code != 0) unreachable; +} + +pub fn compileCSourceFile(context: *const Context, arguments: [][*:0]u8) !void { + assert(arguments.len > 0); + if (byte_equal_terminated(arguments[0], "-c")) { + unreachable; + } else { + const arch_include_path = "lib/libc/musl/arch/x86_64"; + const arch_generic_include_path = "lib/libc/musl/arch/generic"; + const src_include_path = "lib/libc/musl/src/include"; + const src_internal_path = "lib/libc/musl/src/internal"; + const include_path = "lib/libc/musl/include"; + const triple_include_path = "lib/libc/include/x86_64-linux-musl"; + const generic_include_path = "lib/libc/include/generic-musl"; + + if (std.fs.cwd().makeDir("nat/musl")) { + var buffer: [65]u8 = undefined; + const out_dir = "nat/musl/"; + var ar_args = try UnpinnedArray([]const u8).initialize_with_capacity(context.my_allocator, @intCast(generic_musl_source_files.len + musl_x86_64_source_files.len + 3)); + ar_args.append_with_capacity("ar"); + ar_args.append_with_capacity("rcs"); + ar_args.append_with_capacity(out_dir ++ "libc.a"); + + for (generic_musl_source_files) |src_file| { + const src_file_path = try std.mem.concat(context.allocator, u8, &.{"lib/libc/musl/", src_file}); + const basename = std.fs.path.basename(src_file); + const target = try context.allocator.dupe(u8, basename); + target[target.len - 1] = 'o'; + const hash = data_structures.my_hash(src_file); + const hash_string = data_structures.format_int(&buffer, hash, 16, false); + const target_path = try std.mem.concat(context.allocator, u8, &.{out_dir, hash_string, target}); + const args: []const []const u8 = &.{ context.executable_absolute_path, "--no-default-config", "-fno-caret-diagnostics", "-target", "x86_64-unknown-linux-musl", "-std=c99", "-ffreestanding", "-mred-zone", "-fno-omit-frame-pointer", "-fno-stack-protector", "-O2", "-fno-unwind-tables", "-fno-asynchronous-unwind-tables", "-ffunction-sections", "-fdata-sections", "-gdwarf-4", "-gdwarf32", "-Wa,--noexecstack", "-D_XOPEN_SOURCE=700", + "-I", arch_include_path, + "-I", arch_generic_include_path, + "-I", src_include_path, + "-I", src_internal_path, + "-I", include_path, + "-I", triple_include_path, + "-I", generic_include_path, + "-c", src_file_path, + "-o", target_path, + }; + const exit_code = try clangMain(context.allocator, args); + if (exit_code != 0) unreachable; + + ar_args.append_with_capacity(target_path); + } + + for (musl_x86_64_source_files) |src_file| { + const src_file_path = try std.mem.concat(context.allocator, u8, &.{"lib/libc/musl/", src_file}); + const basename = std.fs.path.basename(src_file); + const target = try context.allocator.dupe(u8, basename); + target[target.len - 1] = 'o'; + const hash = data_structures.my_hash(src_file); + const hash_string = data_structures.format_int(&buffer, hash, 16, false); + const target_path = try std.mem.concat(context.allocator, u8, &.{out_dir, hash_string, target}); + const args: []const []const u8 = &.{ context.executable_absolute_path, "--no-default-config", "-fno-caret-diagnostics", "-target", "x86_64-unknown-linux-musl", "-std=c99", "-ffreestanding", "-mred-zone", "-fno-omit-frame-pointer", "-fno-stack-protector", "-O2", "-fno-unwind-tables", "-fno-asynchronous-unwind-tables", "-ffunction-sections", "-fdata-sections", "-gdwarf-4", "-gdwarf32", "-Wa,--noexecstack", "-D_XOPEN_SOURCE=700", + "-I", arch_include_path, + "-I", arch_generic_include_path, + "-I", src_include_path, + "-I", src_internal_path, + "-I", include_path, + "-I", triple_include_path, + "-I", generic_include_path, + "-c", src_file_path, + "-o", target_path, + }; + const exit_code = try clangMain(context.allocator, args); + if (exit_code != 0) unreachable; + ar_args.append_with_capacity(target_path); + } + + if (try arMain(context.allocator, ar_args.slice()) != 0) { + unreachable; + } + } else |e| { + e catch {}; + } + + const crt1_output_path = "nat/musl/crt1.o"; + { + const crt_path = "lib/libc/musl/crt/crt1.c"; + const args: []const []const u8 = &.{ context.executable_absolute_path, "--no-default-config", "-fno-caret-diagnostics", "-target", "x86_64-unknown-linux-musl", "-std=c99", "-ffreestanding", "-mred-zone", "-fno-omit-frame-pointer", "-fno-stack-protector", "-O2", "-fno-unwind-tables", "-fno-asynchronous-unwind-tables", "-ffunction-sections", "-fdata-sections", "-gdwarf-4", "-gdwarf32", "-Wa,--noexecstack", "-D_XOPEN_SOURCE=700", "-DCRT", + "-I", arch_include_path, + "-I", arch_generic_include_path, + "-I", src_include_path, + "-I", src_internal_path, + "-I", include_path, + "-I", triple_include_path, + "-I", generic_include_path, + "-c", crt_path, + "-o", crt1_output_path, + }; + const exit_code = try clangMain(context.allocator, args); + if (exit_code != 0) { + unreachable; + } + } + + const crti_output_path = "nat/musl/crti.o"; + { + const crt_path = "lib/libc/musl/crt/x86_64/crti.s"; + const args: []const []const u8 = &.{ context.executable_absolute_path, "--no-default-config", "-fno-caret-diagnostics", "-target", "x86_64-unknown-linux-musl", "-std=c99", "-ffreestanding", "-mred-zone", "-fno-omit-frame-pointer", "-fno-stack-protector", "-O2", "-fno-unwind-tables", "-fno-asynchronous-unwind-tables", "-ffunction-sections", "-fdata-sections", "-gdwarf-4", "-gdwarf32", "-Wa,--noexecstack", "-D_XOPEN_SOURCE=700", + "-I", arch_include_path, + "-I", arch_generic_include_path, + "-I", src_include_path, + "-I", src_internal_path, + "-I", include_path, + "-I", triple_include_path, + "-I", generic_include_path, + "-c", crt_path, + "-o", crti_output_path, + }; + const exit_code = try clangMain(context.allocator, args); + if (exit_code != 0) { + unreachable; + } + } + + const crtn_output_path = "nat/musl/crtn.o"; + { + const crt_path = "lib/libc/musl/crt/x86_64/crtn.s"; + const args: []const []const u8 = &.{ context.executable_absolute_path, "--no-default-config", "-fno-caret-diagnostics", "-target", "x86_64-unknown-linux-musl", "-std=c99", "-ffreestanding", "-mred-zone", "-fno-omit-frame-pointer", "-fno-stack-protector", "-O2", "-fno-unwind-tables", "-fno-asynchronous-unwind-tables", "-ffunction-sections", "-fdata-sections", "-gdwarf-4", "-gdwarf32", "-Wa,--noexecstack", "-D_XOPEN_SOURCE=700", + "-I", arch_include_path, + "-I", arch_generic_include_path, + "-I", src_include_path, + "-I", src_internal_path, + "-I", include_path, + "-I", triple_include_path, + "-I", generic_include_path, + "-c", crt_path, + "-o", crtn_output_path, + }; + const exit_code = try clangMain(context.allocator, args); + if (exit_code != 0) { + unreachable; + } + } + + assert(arguments.len == 1); + const argument = span(arguments[0]); + + const output_object_file = "nat/main.o"; + const exit_code = try clangMain(context.allocator, &.{ context.executable_absolute_path, "--no-default-config", "-target", "x86_64-unknown-linux-musl", "-c", argument, "-o", output_object_file}); + if (exit_code != 0) { + unreachable; + } + + var lld_args = UnpinnedArray([*:0]const u8){}; + try lld_args.append(context.my_allocator, "ld.lld"); + try lld_args.append(context.my_allocator, "--error-limit=0"); + try lld_args.append(context.my_allocator, "--entry"); + try lld_args.append(context.my_allocator, "_start"); + try lld_args.append(context.my_allocator, "-z"); + try lld_args.append(context.my_allocator, "stack-size=16777216"); + try lld_args.append(context.my_allocator, "--image-base=16777216"); + try lld_args.append(context.my_allocator, "-m"); + try lld_args.append(context.my_allocator, "elf_x86_64"); + try lld_args.append(context.my_allocator, "-static"); + try lld_args.append(context.my_allocator, "-o"); + try lld_args.append(context.my_allocator, "nat/main"); + try lld_args.append(context.my_allocator, crt1_output_path); + try lld_args.append(context.my_allocator, crti_output_path); + try lld_args.append(context.my_allocator, output_object_file); + try lld_args.append(context.my_allocator, "--as-needed"); + try lld_args.append(context.my_allocator, "nat/musl/libc.a"); + try lld_args.append(context.my_allocator, crtn_output_path); + + var stdout_ptr: [*]const u8 = undefined; + var stdout_len: usize = 0; + var stderr_ptr: [*]const u8 = undefined; + var stderr_len: usize = 0; + const result = llvm.bindings.NativityLLDLinkELF(lld_args.pointer, lld_args.length, &stdout_ptr, &stdout_len, &stderr_ptr, &stderr_len); + if (!result) { + unreachable; + } + // const thread = try std.Thread.spawn(.{}, clang_job, .{args}); + // thread.join(); + } +} + +const generic_musl_source_files = [_][]const u8{ + "src/aio/aio.c", + "src/aio/aio_suspend.c", + "src/aio/lio_listio.c", + "src/complex/__cexp.c", + "src/complex/__cexpf.c", + "src/complex/cabs.c", + "src/complex/cabsf.c", + "src/complex/cabsl.c", + "src/complex/cacos.c", + "src/complex/cacosf.c", + "src/complex/cacosh.c", + "src/complex/cacoshf.c", + "src/complex/cacoshl.c", + "src/complex/cacosl.c", + "src/complex/carg.c", + "src/complex/cargf.c", + "src/complex/cargl.c", + "src/complex/casin.c", + "src/complex/casinf.c", + "src/complex/casinh.c", + "src/complex/casinhf.c", + "src/complex/casinhl.c", + "src/complex/casinl.c", + "src/complex/catan.c", + "src/complex/catanf.c", + "src/complex/catanh.c", + "src/complex/catanhf.c", + "src/complex/catanhl.c", + "src/complex/catanl.c", + "src/complex/ccos.c", + "src/complex/ccosf.c", + "src/complex/ccosh.c", + "src/complex/ccoshf.c", + "src/complex/ccoshl.c", + "src/complex/ccosl.c", + "src/complex/cexp.c", + "src/complex/cexpf.c", + "src/complex/cexpl.c", + "src/complex/cimag.c", + "src/complex/cimagf.c", + "src/complex/cimagl.c", + "src/complex/clog.c", + "src/complex/clogf.c", + "src/complex/clogl.c", + "src/complex/conj.c", + "src/complex/conjf.c", + "src/complex/conjl.c", + "src/complex/cpow.c", + "src/complex/cpowf.c", + "src/complex/cpowl.c", + "src/complex/cproj.c", + "src/complex/cprojf.c", + "src/complex/cprojl.c", + "src/complex/creal.c", + "src/complex/crealf.c", + "src/complex/creall.c", + "src/complex/csin.c", + "src/complex/csinf.c", + "src/complex/csinh.c", + "src/complex/csinhf.c", + "src/complex/csinhl.c", + "src/complex/csinl.c", + "src/complex/csqrt.c", + "src/complex/csqrtf.c", + "src/complex/csqrtl.c", + "src/complex/ctan.c", + "src/complex/ctanf.c", + "src/complex/ctanh.c", + "src/complex/ctanhf.c", + "src/complex/ctanhl.c", + "src/complex/ctanl.c", + "src/conf/confstr.c", + "src/conf/fpathconf.c", + "src/conf/legacy.c", + "src/conf/pathconf.c", + "src/conf/sysconf.c", + "src/crypt/crypt.c", + "src/crypt/crypt_blowfish.c", + "src/crypt/crypt_des.c", + "src/crypt/crypt_md5.c", + "src/crypt/crypt_r.c", + "src/crypt/crypt_sha256.c", + "src/crypt/crypt_sha512.c", + "src/crypt/encrypt.c", + "src/ctype/__ctype_b_loc.c", + "src/ctype/__ctype_get_mb_cur_max.c", + "src/ctype/__ctype_tolower_loc.c", + "src/ctype/__ctype_toupper_loc.c", + "src/ctype/isalnum.c", + "src/ctype/isalpha.c", + "src/ctype/isascii.c", + "src/ctype/isblank.c", + "src/ctype/iscntrl.c", + "src/ctype/isdigit.c", + "src/ctype/isgraph.c", + "src/ctype/islower.c", + "src/ctype/isprint.c", + "src/ctype/ispunct.c", + "src/ctype/isspace.c", + "src/ctype/isupper.c", + "src/ctype/iswalnum.c", + "src/ctype/iswalpha.c", + "src/ctype/iswblank.c", + "src/ctype/iswcntrl.c", + "src/ctype/iswctype.c", + "src/ctype/iswdigit.c", + "src/ctype/iswgraph.c", + "src/ctype/iswlower.c", + "src/ctype/iswprint.c", + "src/ctype/iswpunct.c", + "src/ctype/iswspace.c", + "src/ctype/iswupper.c", + "src/ctype/iswxdigit.c", + "src/ctype/isxdigit.c", + "src/ctype/toascii.c", + "src/ctype/tolower.c", + "src/ctype/toupper.c", + "src/ctype/towctrans.c", + "src/ctype/wcswidth.c", + "src/ctype/wctrans.c", + "src/ctype/wcwidth.c", + "src/dirent/alphasort.c", + "src/dirent/closedir.c", + "src/dirent/dirfd.c", + "src/dirent/fdopendir.c", + "src/dirent/opendir.c", + "src/dirent/readdir.c", + "src/dirent/readdir_r.c", + "src/dirent/rewinddir.c", + "src/dirent/scandir.c", + "src/dirent/seekdir.c", + "src/dirent/telldir.c", + "src/dirent/versionsort.c", + "src/env/__environ.c", + "src/env/__init_tls.c", + "src/env/__libc_start_main.c", + "src/env/__reset_tls.c", + "src/env/__stack_chk_fail.c", + "src/env/clearenv.c", + "src/env/getenv.c", + "src/env/putenv.c", + "src/env/secure_getenv.c", + "src/env/setenv.c", + "src/env/unsetenv.c", + "src/errno/__errno_location.c", + "src/errno/strerror.c", + "src/exit/_Exit.c", + "src/exit/abort.c", + "src/exit/abort_lock.c", + "src/exit/arm/__aeabi_atexit.c", + "src/exit/assert.c", + "src/exit/at_quick_exit.c", + "src/exit/atexit.c", + "src/exit/exit.c", + "src/exit/quick_exit.c", + "src/fcntl/creat.c", + "src/fcntl/fcntl.c", + "src/fcntl/open.c", + "src/fcntl/openat.c", + "src/fcntl/posix_fadvise.c", + "src/fcntl/posix_fallocate.c", + "src/fenv/__flt_rounds.c", + "src/fenv/fegetexceptflag.c", + "src/fenv/feholdexcept.c", + "src/fenv/fenv.c", + "src/fenv/fesetexceptflag.c", + "src/fenv/fesetround.c", + "src/fenv/feupdateenv.c", + "src/internal/defsysinfo.c", + "src/internal/floatscan.c", + "src/internal/intscan.c", + "src/internal/libc.c", + "src/internal/procfdname.c", + "src/internal/shgetc.c", + "src/internal/syscall_ret.c", + "src/internal/vdso.c", + "src/internal/version.c", + "src/ipc/ftok.c", + "src/ipc/msgctl.c", + "src/ipc/msgget.c", + "src/ipc/msgrcv.c", + "src/ipc/msgsnd.c", + "src/ipc/semctl.c", + "src/ipc/semget.c", + "src/ipc/semop.c", + "src/ipc/semtimedop.c", + "src/ipc/shmat.c", + "src/ipc/shmctl.c", + "src/ipc/shmdt.c", + "src/ipc/shmget.c", + "src/ldso/__dlsym.c", + "src/ldso/dl_iterate_phdr.c", + "src/ldso/dladdr.c", + "src/ldso/dlclose.c", + "src/ldso/dlerror.c", + "src/ldso/dlinfo.c", + "src/ldso/dlopen.c", + "src/ldso/dlsym.c", + "src/legacy/cuserid.c", + "src/legacy/daemon.c", + "src/legacy/err.c", + "src/legacy/euidaccess.c", + "src/legacy/ftw.c", + "src/legacy/futimes.c", + "src/legacy/getdtablesize.c", + "src/legacy/getloadavg.c", + "src/legacy/getpagesize.c", + "src/legacy/getpass.c", + "src/legacy/getusershell.c", + "src/legacy/isastream.c", + "src/legacy/lutimes.c", + "src/legacy/ulimit.c", + "src/legacy/utmpx.c", + "src/legacy/valloc.c", + "src/linux/adjtime.c", + "src/linux/adjtimex.c", + "src/linux/arch_prctl.c", + "src/linux/brk.c", + "src/linux/cache.c", + "src/linux/cap.c", + "src/linux/chroot.c", + "src/linux/clock_adjtime.c", + "src/linux/clone.c", + "src/linux/copy_file_range.c", + "src/linux/epoll.c", + "src/linux/eventfd.c", + "src/linux/fallocate.c", + "src/linux/fanotify.c", + "src/linux/flock.c", + "src/linux/getdents.c", + "src/linux/getrandom.c", + "src/linux/gettid.c", + "src/linux/inotify.c", + "src/linux/ioperm.c", + "src/linux/iopl.c", + "src/linux/klogctl.c", + "src/linux/membarrier.c", + "src/linux/memfd_create.c", + "src/linux/mlock2.c", + "src/linux/module.c", + "src/linux/mount.c", + "src/linux/name_to_handle_at.c", + "src/linux/open_by_handle_at.c", + "src/linux/personality.c", + "src/linux/pivot_root.c", + "src/linux/ppoll.c", + "src/linux/prctl.c", + "src/linux/prlimit.c", + "src/linux/process_vm.c", + "src/linux/ptrace.c", + "src/linux/quotactl.c", + "src/linux/readahead.c", + "src/linux/reboot.c", + "src/linux/remap_file_pages.c", + "src/linux/sbrk.c", + "src/linux/sendfile.c", + "src/linux/setfsgid.c", + "src/linux/setfsuid.c", + "src/linux/setgroups.c", + "src/linux/sethostname.c", + "src/linux/setns.c", + "src/linux/settimeofday.c", + "src/linux/signalfd.c", + "src/linux/splice.c", + "src/linux/stime.c", + "src/linux/swap.c", + "src/linux/sync_file_range.c", + "src/linux/syncfs.c", + "src/linux/sysinfo.c", + "src/linux/tee.c", + "src/linux/timerfd.c", + "src/linux/unshare.c", + "src/linux/utimes.c", + "src/linux/vhangup.c", + "src/linux/vmsplice.c", + "src/linux/wait3.c", + "src/linux/wait4.c", + "src/linux/xattr.c", + "src/locale/__lctrans.c", + "src/locale/__mo_lookup.c", + "src/locale/bind_textdomain_codeset.c", + "src/locale/c_locale.c", + "src/locale/catclose.c", + "src/locale/catgets.c", + "src/locale/catopen.c", + "src/locale/dcngettext.c", + "src/locale/duplocale.c", + "src/locale/freelocale.c", + "src/locale/iconv.c", + "src/locale/iconv_close.c", + "src/locale/langinfo.c", + "src/locale/locale_map.c", + "src/locale/localeconv.c", + "src/locale/newlocale.c", + "src/locale/pleval.c", + "src/locale/setlocale.c", + "src/locale/strcoll.c", + "src/locale/strfmon.c", + "src/locale/strtod_l.c", + "src/locale/strxfrm.c", + "src/locale/textdomain.c", + "src/locale/uselocale.c", + "src/locale/wcscoll.c", + "src/locale/wcsxfrm.c", + "src/malloc/calloc.c", + "src/malloc/free.c", + "src/malloc/libc_calloc.c", + "src/malloc/lite_malloc.c", + "src/malloc/mallocng/aligned_alloc.c", + "src/malloc/mallocng/donate.c", + "src/malloc/mallocng/free.c", + "src/malloc/mallocng/malloc.c", + "src/malloc/mallocng/malloc_usable_size.c", + "src/malloc/mallocng/realloc.c", + "src/malloc/memalign.c", + "src/malloc/oldmalloc/aligned_alloc.c", + "src/malloc/oldmalloc/malloc.c", + "src/malloc/oldmalloc/malloc_usable_size.c", + "src/malloc/posix_memalign.c", + "src/malloc/realloc.c", + "src/malloc/reallocarray.c", + "src/malloc/replaced.c", + "src/math/__cos.c", + "src/math/__cosdf.c", + "src/math/__cosl.c", + "src/math/__expo2.c", + "src/math/__expo2f.c", + "src/math/__fpclassify.c", + "src/math/__fpclassifyf.c", + "src/math/__fpclassifyl.c", + "src/math/__invtrigl.c", + "src/math/__math_divzero.c", + "src/math/__math_divzerof.c", + "src/math/__math_invalid.c", + "src/math/__math_invalidf.c", + "src/math/__math_invalidl.c", + "src/math/__math_oflow.c", + "src/math/__math_oflowf.c", + "src/math/__math_uflow.c", + "src/math/__math_uflowf.c", + "src/math/__math_xflow.c", + "src/math/__math_xflowf.c", + "src/math/__polevll.c", + "src/math/__rem_pio2.c", + "src/math/__rem_pio2_large.c", + "src/math/__rem_pio2f.c", + "src/math/__rem_pio2l.c", + "src/math/__signbit.c", + "src/math/__signbitf.c", + "src/math/__signbitl.c", + "src/math/__sin.c", + "src/math/__sindf.c", + "src/math/__sinl.c", + "src/math/__tan.c", + "src/math/__tandf.c", + "src/math/__tanl.c", + "src/math/acos.c", + "src/math/acosf.c", + "src/math/acosh.c", + "src/math/acoshf.c", + "src/math/acoshl.c", + "src/math/acosl.c", + "src/math/asin.c", + "src/math/asinf.c", + "src/math/asinh.c", + "src/math/asinhf.c", + "src/math/asinhl.c", + "src/math/asinl.c", + "src/math/atan.c", + "src/math/atan2.c", + "src/math/atan2f.c", + "src/math/atan2l.c", + "src/math/atanf.c", + "src/math/atanh.c", + "src/math/atanhf.c", + "src/math/atanhl.c", + "src/math/atanl.c", + "src/math/cbrt.c", + "src/math/cbrtf.c", + "src/math/cbrtl.c", + "src/math/ceil.c", + "src/math/ceilf.c", + "src/math/ceill.c", + "src/math/copysign.c", + "src/math/copysignf.c", + "src/math/copysignl.c", + "src/math/cos.c", + "src/math/cosf.c", + "src/math/cosh.c", + "src/math/coshf.c", + "src/math/coshl.c", + "src/math/cosl.c", + "src/math/erf.c", + "src/math/erff.c", + "src/math/erfl.c", + "src/math/exp.c", + "src/math/exp10.c", + "src/math/exp10f.c", + "src/math/exp10l.c", + "src/math/exp2.c", + "src/math/exp2f.c", + "src/math/exp2f_data.c", + "src/math/exp2l.c", + "src/math/exp_data.c", + "src/math/expf.c", + "src/math/expl.c", + "src/math/expm1.c", + "src/math/expm1f.c", + "src/math/expm1l.c", + "src/math/fabs.c", + "src/math/fabsf.c", + "src/math/fabsl.c", + "src/math/fdim.c", + "src/math/fdimf.c", + "src/math/fdiml.c", + "src/math/finite.c", + "src/math/finitef.c", + "src/math/floor.c", + "src/math/floorf.c", + "src/math/floorl.c", + "src/math/fma.c", + "src/math/fmaf.c", + "src/math/fmal.c", + "src/math/fmax.c", + "src/math/fmaxf.c", + "src/math/fmaxl.c", + "src/math/fmin.c", + "src/math/fminf.c", + "src/math/fminl.c", + "src/math/fmod.c", + "src/math/fmodf.c", + "src/math/fmodl.c", + "src/math/frexp.c", + "src/math/frexpf.c", + "src/math/frexpl.c", + "src/math/hypot.c", + "src/math/hypotf.c", + "src/math/hypotl.c", + "src/math/ilogb.c", + "src/math/ilogbf.c", + "src/math/ilogbl.c", + "src/math/j0.c", + "src/math/j0f.c", + "src/math/j1.c", + "src/math/j1f.c", + "src/math/jn.c", + "src/math/jnf.c", + "src/math/ldexp.c", + "src/math/ldexpf.c", + "src/math/ldexpl.c", + "src/math/lgamma.c", + "src/math/lgamma_r.c", + "src/math/lgammaf.c", + "src/math/lgammaf_r.c", + "src/math/lgammal.c", + "src/math/llrint.c", + "src/math/llrintf.c", + "src/math/llrintl.c", + "src/math/llround.c", + "src/math/llroundf.c", + "src/math/llroundl.c", + "src/math/log.c", + "src/math/log10.c", + "src/math/log10f.c", + "src/math/log10l.c", + "src/math/log1p.c", + "src/math/log1pf.c", + "src/math/log1pl.c", + "src/math/log2.c", + "src/math/log2_data.c", + "src/math/log2f.c", + "src/math/log2f_data.c", + "src/math/log2l.c", + "src/math/log_data.c", + "src/math/logb.c", + "src/math/logbf.c", + "src/math/logbl.c", + "src/math/logf.c", + "src/math/logf_data.c", + "src/math/logl.c", + "src/math/lrint.c", + "src/math/lrintf.c", + "src/math/lrintl.c", + "src/math/lround.c", + "src/math/lroundf.c", + "src/math/lroundl.c", + "src/math/modf.c", + "src/math/modff.c", + "src/math/modfl.c", + "src/math/nan.c", + "src/math/nanf.c", + "src/math/nanl.c", + "src/math/nearbyint.c", + "src/math/nearbyintf.c", + "src/math/nearbyintl.c", + "src/math/nextafter.c", + "src/math/nextafterf.c", + "src/math/nextafterl.c", + "src/math/nexttoward.c", + "src/math/nexttowardf.c", + "src/math/nexttowardl.c", + "src/math/pow.c", + "src/math/pow_data.c", + "src/math/powf.c", + "src/math/powf_data.c", + "src/math/powl.c", + "src/math/remainder.c", + "src/math/remainderf.c", + "src/math/remainderl.c", + "src/math/remquo.c", + "src/math/remquof.c", + "src/math/remquol.c", + "src/math/rint.c", + "src/math/rintf.c", + "src/math/rintl.c", + "src/math/round.c", + "src/math/roundf.c", + "src/math/roundl.c", + "src/math/scalb.c", + "src/math/scalbf.c", + "src/math/scalbln.c", + "src/math/scalblnf.c", + "src/math/scalblnl.c", + "src/math/scalbn.c", + "src/math/scalbnf.c", + "src/math/scalbnl.c", + "src/math/signgam.c", + "src/math/significand.c", + "src/math/significandf.c", + "src/math/sin.c", + "src/math/sincos.c", + "src/math/sincosf.c", + "src/math/sincosl.c", + "src/math/sinf.c", + "src/math/sinh.c", + "src/math/sinhf.c", + "src/math/sinhl.c", + "src/math/sinl.c", + "src/math/sqrt.c", + "src/math/sqrt_data.c", + "src/math/sqrtf.c", + "src/math/sqrtl.c", + "src/math/tan.c", + "src/math/tanf.c", + "src/math/tanh.c", + "src/math/tanhf.c", + "src/math/tanhl.c", + "src/math/tanl.c", + "src/math/tgamma.c", + "src/math/tgammaf.c", + "src/math/tgammal.c", + "src/math/trunc.c", + "src/math/truncf.c", + "src/math/truncl.c", + "src/misc/a64l.c", + "src/misc/basename.c", + "src/misc/dirname.c", + "src/misc/ffs.c", + "src/misc/ffsl.c", + "src/misc/ffsll.c", + "src/misc/fmtmsg.c", + "src/misc/forkpty.c", + "src/misc/get_current_dir_name.c", + "src/misc/getauxval.c", + "src/misc/getdomainname.c", + "src/misc/getentropy.c", + "src/misc/gethostid.c", + "src/misc/getopt.c", + "src/misc/getopt_long.c", + "src/misc/getpriority.c", + "src/misc/getresgid.c", + "src/misc/getresuid.c", + "src/misc/getrlimit.c", + "src/misc/getrusage.c", + "src/misc/getsubopt.c", + "src/misc/initgroups.c", + "src/misc/ioctl.c", + "src/misc/issetugid.c", + "src/misc/lockf.c", + "src/misc/login_tty.c", + "src/misc/mntent.c", + "src/misc/nftw.c", + "src/misc/openpty.c", + "src/misc/ptsname.c", + "src/misc/pty.c", + "src/misc/realpath.c", + "src/misc/setdomainname.c", + "src/misc/setpriority.c", + "src/misc/setrlimit.c", + "src/misc/syscall.c", + "src/misc/syslog.c", + "src/misc/uname.c", + "src/misc/wordexp.c", + "src/mman/madvise.c", + "src/mman/mincore.c", + "src/mman/mlock.c", + "src/mman/mlockall.c", + "src/mman/mmap.c", + "src/mman/mprotect.c", + "src/mman/mremap.c", + "src/mman/msync.c", + "src/mman/munlock.c", + "src/mman/munlockall.c", + "src/mman/munmap.c", + "src/mman/posix_madvise.c", + "src/mman/shm_open.c", + "src/mq/mq_close.c", + "src/mq/mq_getattr.c", + "src/mq/mq_notify.c", + "src/mq/mq_open.c", + "src/mq/mq_receive.c", + "src/mq/mq_send.c", + "src/mq/mq_setattr.c", + "src/mq/mq_timedreceive.c", + "src/mq/mq_timedsend.c", + "src/mq/mq_unlink.c", + "src/multibyte/btowc.c", + "src/multibyte/c16rtomb.c", + "src/multibyte/c32rtomb.c", + "src/multibyte/internal.c", + "src/multibyte/mblen.c", + "src/multibyte/mbrlen.c", + "src/multibyte/mbrtoc16.c", + "src/multibyte/mbrtoc32.c", + "src/multibyte/mbrtowc.c", + "src/multibyte/mbsinit.c", + "src/multibyte/mbsnrtowcs.c", + "src/multibyte/mbsrtowcs.c", + "src/multibyte/mbstowcs.c", + "src/multibyte/mbtowc.c", + "src/multibyte/wcrtomb.c", + "src/multibyte/wcsnrtombs.c", + "src/multibyte/wcsrtombs.c", + "src/multibyte/wcstombs.c", + "src/multibyte/wctob.c", + "src/multibyte/wctomb.c", + "src/network/accept.c", + "src/network/accept4.c", + "src/network/bind.c", + "src/network/connect.c", + "src/network/dn_comp.c", + "src/network/dn_expand.c", + "src/network/dn_skipname.c", + "src/network/dns_parse.c", + "src/network/ent.c", + "src/network/ether.c", + "src/network/freeaddrinfo.c", + "src/network/gai_strerror.c", + "src/network/getaddrinfo.c", + "src/network/gethostbyaddr.c", + "src/network/gethostbyaddr_r.c", + "src/network/gethostbyname.c", + "src/network/gethostbyname2.c", + "src/network/gethostbyname2_r.c", + "src/network/gethostbyname_r.c", + "src/network/getifaddrs.c", + "src/network/getnameinfo.c", + "src/network/getpeername.c", + "src/network/getservbyname.c", + "src/network/getservbyname_r.c", + "src/network/getservbyport.c", + "src/network/getservbyport_r.c", + "src/network/getsockname.c", + "src/network/getsockopt.c", + "src/network/h_errno.c", + "src/network/herror.c", + "src/network/hstrerror.c", + "src/network/htonl.c", + "src/network/htons.c", + "src/network/if_freenameindex.c", + "src/network/if_indextoname.c", + "src/network/if_nameindex.c", + "src/network/if_nametoindex.c", + "src/network/in6addr_any.c", + "src/network/in6addr_loopback.c", + "src/network/inet_addr.c", + "src/network/inet_aton.c", + "src/network/inet_legacy.c", + "src/network/inet_ntoa.c", + "src/network/inet_ntop.c", + "src/network/inet_pton.c", + "src/network/listen.c", + "src/network/lookup_ipliteral.c", + "src/network/lookup_name.c", + "src/network/lookup_serv.c", + "src/network/netlink.c", + "src/network/netname.c", + "src/network/ns_parse.c", + "src/network/ntohl.c", + "src/network/ntohs.c", + "src/network/proto.c", + "src/network/recv.c", + "src/network/recvfrom.c", + "src/network/recvmmsg.c", + "src/network/recvmsg.c", + "src/network/res_init.c", + "src/network/res_mkquery.c", + "src/network/res_msend.c", + "src/network/res_query.c", + "src/network/res_querydomain.c", + "src/network/res_send.c", + "src/network/res_state.c", + "src/network/resolvconf.c", + "src/network/send.c", + "src/network/sendmmsg.c", + "src/network/sendmsg.c", + "src/network/sendto.c", + "src/network/serv.c", + "src/network/setsockopt.c", + "src/network/shutdown.c", + "src/network/sockatmark.c", + "src/network/socket.c", + "src/network/socketpair.c", + "src/passwd/fgetgrent.c", + "src/passwd/fgetpwent.c", + "src/passwd/fgetspent.c", + "src/passwd/getgr_a.c", + "src/passwd/getgr_r.c", + "src/passwd/getgrent.c", + "src/passwd/getgrent_a.c", + "src/passwd/getgrouplist.c", + "src/passwd/getpw_a.c", + "src/passwd/getpw_r.c", + "src/passwd/getpwent.c", + "src/passwd/getpwent_a.c", + "src/passwd/getspent.c", + "src/passwd/getspnam.c", + "src/passwd/getspnam_r.c", + "src/passwd/lckpwdf.c", + "src/passwd/nscd_query.c", + "src/passwd/putgrent.c", + "src/passwd/putpwent.c", + "src/passwd/putspent.c", + "src/prng/__rand48_step.c", + "src/prng/__seed48.c", + "src/prng/drand48.c", + "src/prng/lcong48.c", + "src/prng/lrand48.c", + "src/prng/mrand48.c", + "src/prng/rand.c", + "src/prng/rand_r.c", + "src/prng/random.c", + "src/prng/seed48.c", + "src/prng/srand48.c", + "src/process/_Fork.c", + "src/process/execl.c", + "src/process/execle.c", + "src/process/execlp.c", + "src/process/execv.c", + "src/process/execve.c", + "src/process/execvp.c", + "src/process/fexecve.c", + "src/process/fork.c", + "src/process/posix_spawn.c", + "src/process/posix_spawn_file_actions_addchdir.c", + "src/process/posix_spawn_file_actions_addclose.c", + "src/process/posix_spawn_file_actions_adddup2.c", + "src/process/posix_spawn_file_actions_addfchdir.c", + "src/process/posix_spawn_file_actions_addopen.c", + "src/process/posix_spawn_file_actions_destroy.c", + "src/process/posix_spawn_file_actions_init.c", + "src/process/posix_spawnattr_destroy.c", + "src/process/posix_spawnattr_getflags.c", + "src/process/posix_spawnattr_getpgroup.c", + "src/process/posix_spawnattr_getsigdefault.c", + "src/process/posix_spawnattr_getsigmask.c", + "src/process/posix_spawnattr_init.c", + "src/process/posix_spawnattr_sched.c", + "src/process/posix_spawnattr_setflags.c", + "src/process/posix_spawnattr_setpgroup.c", + "src/process/posix_spawnattr_setsigdefault.c", + "src/process/posix_spawnattr_setsigmask.c", + "src/process/posix_spawnp.c", + "src/regex/fnmatch.c", + "src/regex/glob.c", + "src/regex/regcomp.c", + "src/regex/regerror.c", + "src/regex/regexec.c", + "src/regex/tre-mem.c", + "src/sched/affinity.c", + "src/sched/sched_cpucount.c", + "src/sched/sched_get_priority_max.c", + "src/sched/sched_getcpu.c", + "src/sched/sched_getparam.c", + "src/sched/sched_getscheduler.c", + "src/sched/sched_rr_get_interval.c", + "src/sched/sched_setparam.c", + "src/sched/sched_setscheduler.c", + "src/sched/sched_yield.c", + "src/search/hsearch.c", + "src/search/insque.c", + "src/search/lsearch.c", + "src/search/tdelete.c", + "src/search/tdestroy.c", + "src/search/tfind.c", + "src/search/tsearch.c", + "src/search/twalk.c", + "src/select/poll.c", + "src/select/pselect.c", + "src/select/select.c", + "src/setjmp/longjmp.c", + "src/setjmp/setjmp.c", + "src/signal/block.c", + "src/signal/getitimer.c", + "src/signal/kill.c", + "src/signal/killpg.c", + "src/signal/psiginfo.c", + "src/signal/psignal.c", + "src/signal/raise.c", + "src/signal/restore.c", + "src/signal/sigaction.c", + "src/signal/sigaddset.c", + "src/signal/sigaltstack.c", + "src/signal/sigandset.c", + "src/signal/sigdelset.c", + "src/signal/sigemptyset.c", + "src/signal/sigfillset.c", + "src/signal/sighold.c", + "src/signal/sigignore.c", + "src/signal/siginterrupt.c", + "src/signal/sigisemptyset.c", + "src/signal/sigismember.c", + "src/signal/siglongjmp.c", + "src/signal/signal.c", + "src/signal/sigorset.c", + "src/signal/sigpause.c", + "src/signal/sigpending.c", + "src/signal/sigprocmask.c", + "src/signal/sigqueue.c", + "src/signal/sigrelse.c", + "src/signal/sigrtmax.c", + "src/signal/sigrtmin.c", + "src/signal/sigset.c", + "src/signal/sigsetjmp.c", + "src/signal/sigsetjmp_tail.c", + "src/signal/sigsuspend.c", + "src/signal/sigtimedwait.c", + "src/signal/sigwait.c", + "src/signal/sigwaitinfo.c", + "src/stat/__xstat.c", + "src/stat/chmod.c", + "src/stat/fchmod.c", + "src/stat/fchmodat.c", + "src/stat/fstat.c", + "src/stat/fstatat.c", + "src/stat/futimens.c", + "src/stat/futimesat.c", + "src/stat/lchmod.c", + "src/stat/lstat.c", + "src/stat/mkdir.c", + "src/stat/mkdirat.c", + "src/stat/mkfifo.c", + "src/stat/mkfifoat.c", + "src/stat/mknod.c", + "src/stat/mknodat.c", + "src/stat/stat.c", + "src/stat/statvfs.c", + "src/stat/umask.c", + "src/stat/utimensat.c", + "src/stdio/__fclose_ca.c", + "src/stdio/__fdopen.c", + "src/stdio/__fmodeflags.c", + "src/stdio/__fopen_rb_ca.c", + "src/stdio/__lockfile.c", + "src/stdio/__overflow.c", + "src/stdio/__stdio_close.c", + "src/stdio/__stdio_exit.c", + "src/stdio/__stdio_read.c", + "src/stdio/__stdio_seek.c", + "src/stdio/__stdio_write.c", + "src/stdio/__stdout_write.c", + "src/stdio/__toread.c", + "src/stdio/__towrite.c", + "src/stdio/__uflow.c", + "src/stdio/asprintf.c", + "src/stdio/clearerr.c", + "src/stdio/dprintf.c", + "src/stdio/ext.c", + "src/stdio/ext2.c", + "src/stdio/fclose.c", + "src/stdio/feof.c", + "src/stdio/ferror.c", + "src/stdio/fflush.c", + "src/stdio/fgetc.c", + "src/stdio/fgetln.c", + "src/stdio/fgetpos.c", + "src/stdio/fgets.c", + "src/stdio/fgetwc.c", + "src/stdio/fgetws.c", + "src/stdio/fileno.c", + "src/stdio/flockfile.c", + "src/stdio/fmemopen.c", + "src/stdio/fopen.c", + "src/stdio/fopencookie.c", + "src/stdio/fprintf.c", + "src/stdio/fputc.c", + "src/stdio/fputs.c", + "src/stdio/fputwc.c", + "src/stdio/fputws.c", + "src/stdio/fread.c", + "src/stdio/freopen.c", + "src/stdio/fscanf.c", + "src/stdio/fseek.c", + "src/stdio/fsetpos.c", + "src/stdio/ftell.c", + "src/stdio/ftrylockfile.c", + "src/stdio/funlockfile.c", + "src/stdio/fwide.c", + "src/stdio/fwprintf.c", + "src/stdio/fwrite.c", + "src/stdio/fwscanf.c", + "src/stdio/getc.c", + "src/stdio/getc_unlocked.c", + "src/stdio/getchar.c", + "src/stdio/getchar_unlocked.c", + "src/stdio/getdelim.c", + "src/stdio/getline.c", + "src/stdio/gets.c", + "src/stdio/getw.c", + "src/stdio/getwc.c", + "src/stdio/getwchar.c", + "src/stdio/ofl.c", + "src/stdio/ofl_add.c", + "src/stdio/open_memstream.c", + "src/stdio/open_wmemstream.c", + "src/stdio/pclose.c", + "src/stdio/perror.c", + "src/stdio/popen.c", + "src/stdio/printf.c", + "src/stdio/putc.c", + "src/stdio/putc_unlocked.c", + "src/stdio/putchar.c", + "src/stdio/putchar_unlocked.c", + "src/stdio/puts.c", + "src/stdio/putw.c", + "src/stdio/putwc.c", + "src/stdio/putwchar.c", + "src/stdio/remove.c", + "src/stdio/rename.c", + "src/stdio/rewind.c", + "src/stdio/scanf.c", + "src/stdio/setbuf.c", + "src/stdio/setbuffer.c", + "src/stdio/setlinebuf.c", + "src/stdio/setvbuf.c", + "src/stdio/snprintf.c", + "src/stdio/sprintf.c", + "src/stdio/sscanf.c", + "src/stdio/stderr.c", + "src/stdio/stdin.c", + "src/stdio/stdout.c", + "src/stdio/swprintf.c", + "src/stdio/swscanf.c", + "src/stdio/tempnam.c", + "src/stdio/tmpfile.c", + "src/stdio/tmpnam.c", + "src/stdio/ungetc.c", + "src/stdio/ungetwc.c", + "src/stdio/vasprintf.c", + "src/stdio/vdprintf.c", + "src/stdio/vfprintf.c", + "src/stdio/vfscanf.c", + "src/stdio/vfwprintf.c", + "src/stdio/vfwscanf.c", + "src/stdio/vprintf.c", + "src/stdio/vscanf.c", + "src/stdio/vsnprintf.c", + "src/stdio/vsprintf.c", + "src/stdio/vsscanf.c", + "src/stdio/vswprintf.c", + "src/stdio/vswscanf.c", + "src/stdio/vwprintf.c", + "src/stdio/vwscanf.c", + "src/stdio/wprintf.c", + "src/stdio/wscanf.c", + "src/stdlib/abs.c", + "src/stdlib/atof.c", + "src/stdlib/atoi.c", + "src/stdlib/atol.c", + "src/stdlib/atoll.c", + "src/stdlib/bsearch.c", + "src/stdlib/div.c", + "src/stdlib/ecvt.c", + "src/stdlib/fcvt.c", + "src/stdlib/gcvt.c", + "src/stdlib/imaxabs.c", + "src/stdlib/imaxdiv.c", + "src/stdlib/labs.c", + "src/stdlib/ldiv.c", + "src/stdlib/llabs.c", + "src/stdlib/lldiv.c", + "src/stdlib/qsort.c", + "src/stdlib/qsort_nr.c", + "src/stdlib/strtod.c", + "src/stdlib/strtol.c", + "src/stdlib/wcstod.c", + "src/stdlib/wcstol.c", + "src/string/bcmp.c", + "src/string/bcopy.c", + "src/string/bzero.c", + "src/string/explicit_bzero.c", + "src/string/index.c", + "src/string/memccpy.c", + "src/string/memchr.c", + "src/string/memcmp.c", + "src/string/memcpy.c", + "src/string/memmem.c", + "src/string/memmove.c", + "src/string/mempcpy.c", + "src/string/memrchr.c", + "src/string/memset.c", + "src/string/rindex.c", + "src/string/stpcpy.c", + "src/string/stpncpy.c", + "src/string/strcasecmp.c", + "src/string/strcasestr.c", + "src/string/strcat.c", + "src/string/strchr.c", + "src/string/strchrnul.c", + "src/string/strcmp.c", + "src/string/strcpy.c", + "src/string/strcspn.c", + "src/string/strdup.c", + "src/string/strerror_r.c", + "src/string/strlcat.c", + "src/string/strlcpy.c", + "src/string/strlen.c", + "src/string/strncasecmp.c", + "src/string/strncat.c", + "src/string/strncmp.c", + "src/string/strncpy.c", + "src/string/strndup.c", + "src/string/strnlen.c", + "src/string/strpbrk.c", + "src/string/strrchr.c", + "src/string/strsep.c", + "src/string/strsignal.c", + "src/string/strspn.c", + "src/string/strstr.c", + "src/string/strtok.c", + "src/string/strtok_r.c", + "src/string/strverscmp.c", + "src/string/swab.c", + "src/string/wcpcpy.c", + "src/string/wcpncpy.c", + "src/string/wcscasecmp.c", + "src/string/wcscasecmp_l.c", + "src/string/wcscat.c", + "src/string/wcschr.c", + "src/string/wcscmp.c", + "src/string/wcscpy.c", + "src/string/wcscspn.c", + "src/string/wcsdup.c", + "src/string/wcslen.c", + "src/string/wcsncasecmp.c", + "src/string/wcsncasecmp_l.c", + "src/string/wcsncat.c", + "src/string/wcsncmp.c", + "src/string/wcsncpy.c", + "src/string/wcsnlen.c", + "src/string/wcspbrk.c", + "src/string/wcsrchr.c", + "src/string/wcsspn.c", + "src/string/wcsstr.c", + "src/string/wcstok.c", + "src/string/wcswcs.c", + "src/string/wmemchr.c", + "src/string/wmemcmp.c", + "src/string/wmemcpy.c", + "src/string/wmemmove.c", + "src/string/wmemset.c", + "src/temp/__randname.c", + "src/temp/mkdtemp.c", + "src/temp/mkostemp.c", + "src/temp/mkostemps.c", + "src/temp/mkstemp.c", + "src/temp/mkstemps.c", + "src/temp/mktemp.c", + "src/termios/cfgetospeed.c", + "src/termios/cfmakeraw.c", + "src/termios/cfsetospeed.c", + "src/termios/tcdrain.c", + "src/termios/tcflow.c", + "src/termios/tcflush.c", + "src/termios/tcgetattr.c", + "src/termios/tcgetsid.c", + "src/termios/tcgetwinsize.c", + "src/termios/tcsendbreak.c", + "src/termios/tcsetattr.c", + "src/termios/tcsetwinsize.c", + "src/thread/__lock.c", + // "src/thread/__set_thread_area.c", + "src/thread/__syscall_cp.c", + "src/thread/__timedwait.c", + "src/thread/__tls_get_addr.c", + "src/thread/__unmapself.c", + "src/thread/__wait.c", + "src/thread/call_once.c", + "src/thread/clone.c", + "src/thread/cnd_broadcast.c", + "src/thread/cnd_destroy.c", + "src/thread/cnd_init.c", + "src/thread/cnd_signal.c", + "src/thread/cnd_timedwait.c", + "src/thread/cnd_wait.c", + "src/thread/default_attr.c", + "src/thread/lock_ptc.c", + "src/thread/mtx_destroy.c", + "src/thread/mtx_init.c", + "src/thread/mtx_lock.c", + "src/thread/mtx_timedlock.c", + "src/thread/mtx_trylock.c", + "src/thread/mtx_unlock.c", + "src/thread/pthread_atfork.c", + "src/thread/pthread_attr_destroy.c", + "src/thread/pthread_attr_get.c", + "src/thread/pthread_attr_init.c", + "src/thread/pthread_attr_setdetachstate.c", + "src/thread/pthread_attr_setguardsize.c", + "src/thread/pthread_attr_setinheritsched.c", + "src/thread/pthread_attr_setschedparam.c", + "src/thread/pthread_attr_setschedpolicy.c", + "src/thread/pthread_attr_setscope.c", + "src/thread/pthread_attr_setstack.c", + "src/thread/pthread_attr_setstacksize.c", + "src/thread/pthread_barrier_destroy.c", + "src/thread/pthread_barrier_init.c", + "src/thread/pthread_barrier_wait.c", + "src/thread/pthread_barrierattr_destroy.c", + "src/thread/pthread_barrierattr_init.c", + "src/thread/pthread_barrierattr_setpshared.c", + "src/thread/pthread_cancel.c", + "src/thread/pthread_cleanup_push.c", + "src/thread/pthread_cond_broadcast.c", + "src/thread/pthread_cond_destroy.c", + "src/thread/pthread_cond_init.c", + "src/thread/pthread_cond_signal.c", + "src/thread/pthread_cond_timedwait.c", + "src/thread/pthread_cond_wait.c", + "src/thread/pthread_condattr_destroy.c", + "src/thread/pthread_condattr_init.c", + "src/thread/pthread_condattr_setclock.c", + "src/thread/pthread_condattr_setpshared.c", + "src/thread/pthread_create.c", + "src/thread/pthread_detach.c", + "src/thread/pthread_equal.c", + "src/thread/pthread_getattr_np.c", + "src/thread/pthread_getconcurrency.c", + "src/thread/pthread_getcpuclockid.c", + "src/thread/pthread_getname_np.c", + "src/thread/pthread_getschedparam.c", + "src/thread/pthread_getspecific.c", + "src/thread/pthread_join.c", + "src/thread/pthread_key_create.c", + "src/thread/pthread_kill.c", + "src/thread/pthread_mutex_consistent.c", + "src/thread/pthread_mutex_destroy.c", + "src/thread/pthread_mutex_getprioceiling.c", + "src/thread/pthread_mutex_init.c", + "src/thread/pthread_mutex_lock.c", + "src/thread/pthread_mutex_setprioceiling.c", + "src/thread/pthread_mutex_timedlock.c", + "src/thread/pthread_mutex_trylock.c", + "src/thread/pthread_mutex_unlock.c", + "src/thread/pthread_mutexattr_destroy.c", + "src/thread/pthread_mutexattr_init.c", + "src/thread/pthread_mutexattr_setprotocol.c", + "src/thread/pthread_mutexattr_setpshared.c", + "src/thread/pthread_mutexattr_setrobust.c", + "src/thread/pthread_mutexattr_settype.c", + "src/thread/pthread_once.c", + "src/thread/pthread_rwlock_destroy.c", + "src/thread/pthread_rwlock_init.c", + "src/thread/pthread_rwlock_rdlock.c", + "src/thread/pthread_rwlock_timedrdlock.c", + "src/thread/pthread_rwlock_timedwrlock.c", + "src/thread/pthread_rwlock_tryrdlock.c", + "src/thread/pthread_rwlock_trywrlock.c", + "src/thread/pthread_rwlock_unlock.c", + "src/thread/pthread_rwlock_wrlock.c", + "src/thread/pthread_rwlockattr_destroy.c", + "src/thread/pthread_rwlockattr_init.c", + "src/thread/pthread_rwlockattr_setpshared.c", + "src/thread/pthread_self.c", + "src/thread/pthread_setattr_default_np.c", + "src/thread/pthread_setcancelstate.c", + "src/thread/pthread_setcanceltype.c", + "src/thread/pthread_setconcurrency.c", + "src/thread/pthread_setname_np.c", + "src/thread/pthread_setschedparam.c", + "src/thread/pthread_setschedprio.c", + "src/thread/pthread_setspecific.c", + "src/thread/pthread_sigmask.c", + "src/thread/pthread_spin_destroy.c", + "src/thread/pthread_spin_init.c", + "src/thread/pthread_spin_lock.c", + "src/thread/pthread_spin_trylock.c", + "src/thread/pthread_spin_unlock.c", + "src/thread/pthread_testcancel.c", + "src/thread/sem_destroy.c", + "src/thread/sem_getvalue.c", + "src/thread/sem_init.c", + "src/thread/sem_open.c", + "src/thread/sem_post.c", + "src/thread/sem_timedwait.c", + "src/thread/sem_trywait.c", + "src/thread/sem_unlink.c", + "src/thread/sem_wait.c", + "src/thread/synccall.c", + "src/thread/syscall_cp.c", + "src/thread/thrd_create.c", + "src/thread/thrd_exit.c", + "src/thread/thrd_join.c", + "src/thread/thrd_sleep.c", + "src/thread/thrd_yield.c", + "src/thread/tls.c", + "src/thread/tss_create.c", + "src/thread/tss_delete.c", + "src/thread/tss_set.c", + "src/thread/vmlock.c", + "src/time/__map_file.c", + "src/time/__month_to_secs.c", + "src/time/__secs_to_tm.c", + "src/time/__tm_to_secs.c", + "src/time/__tz.c", + "src/time/__year_to_secs.c", + "src/time/asctime.c", + "src/time/asctime_r.c", + "src/time/clock.c", + "src/time/clock_getcpuclockid.c", + "src/time/clock_getres.c", + "src/time/clock_gettime.c", + "src/time/clock_nanosleep.c", + "src/time/clock_settime.c", + "src/time/ctime.c", + "src/time/ctime_r.c", + "src/time/difftime.c", + "src/time/ftime.c", + "src/time/getdate.c", + "src/time/gettimeofday.c", + "src/time/gmtime.c", + "src/time/gmtime_r.c", + "src/time/localtime.c", + "src/time/localtime_r.c", + "src/time/mktime.c", + "src/time/nanosleep.c", + "src/time/strftime.c", + "src/time/strptime.c", + "src/time/time.c", + "src/time/timegm.c", + "src/time/timer_create.c", + "src/time/timer_delete.c", + "src/time/timer_getoverrun.c", + "src/time/timer_gettime.c", + "src/time/timer_settime.c", + "src/time/times.c", + "src/time/timespec_get.c", + "src/time/utime.c", + "src/time/wcsftime.c", + "src/unistd/_exit.c", + "src/unistd/access.c", + "src/unistd/acct.c", + "src/unistd/alarm.c", + "src/unistd/chdir.c", + "src/unistd/chown.c", + "src/unistd/close.c", + "src/unistd/ctermid.c", + "src/unistd/dup.c", + "src/unistd/dup2.c", + "src/unistd/dup3.c", + "src/unistd/faccessat.c", + "src/unistd/fchdir.c", + "src/unistd/fchown.c", + "src/unistd/fchownat.c", + "src/unistd/fdatasync.c", + "src/unistd/fsync.c", + "src/unistd/ftruncate.c", + "src/unistd/getcwd.c", + "src/unistd/getegid.c", + "src/unistd/geteuid.c", + "src/unistd/getgid.c", + "src/unistd/getgroups.c", + "src/unistd/gethostname.c", + "src/unistd/getlogin.c", + "src/unistd/getlogin_r.c", + "src/unistd/getpgid.c", + "src/unistd/getpgrp.c", + "src/unistd/getpid.c", + "src/unistd/getppid.c", + "src/unistd/getsid.c", + "src/unistd/getuid.c", + "src/unistd/isatty.c", + "src/unistd/lchown.c", + "src/unistd/link.c", + "src/unistd/linkat.c", + "src/unistd/lseek.c", + "src/unistd/nice.c", + "src/unistd/pause.c", + "src/unistd/pipe.c", + "src/unistd/pipe2.c", + "src/unistd/posix_close.c", + "src/unistd/pread.c", + "src/unistd/preadv.c", + "src/unistd/pwrite.c", + "src/unistd/pwritev.c", + "src/unistd/read.c", + "src/unistd/readlink.c", + "src/unistd/readlinkat.c", + "src/unistd/readv.c", + "src/unistd/renameat.c", + "src/unistd/rmdir.c", + "src/unistd/setegid.c", + "src/unistd/seteuid.c", + "src/unistd/setgid.c", + "src/unistd/setpgid.c", + "src/unistd/setpgrp.c", + "src/unistd/setregid.c", + "src/unistd/setresgid.c", + "src/unistd/setresuid.c", + "src/unistd/setreuid.c", + "src/unistd/setsid.c", + "src/unistd/setuid.c", + "src/unistd/setxid.c", + "src/unistd/sleep.c", + "src/unistd/symlink.c", + "src/unistd/symlinkat.c", + "src/unistd/sync.c", + "src/unistd/tcgetpgrp.c", + "src/unistd/tcsetpgrp.c", + "src/unistd/truncate.c", + "src/unistd/ttyname.c", + "src/unistd/ttyname_r.c", + "src/unistd/ualarm.c", + "src/unistd/unlink.c", + "src/unistd/unlinkat.c", + "src/unistd/usleep.c", + "src/unistd/write.c", + "src/unistd/writev.c", +}; + +const musl_x86_64_source_files = [_][]const u8{ + "src/fenv/x86_64/fenv.s", + "src/ldso/x86_64/dlsym.s", + "src/ldso/x86_64/tlsdesc.s", + "src/math/x86_64/__invtrigl.s", + "src/math/x86_64/acosl.s", + "src/math/x86_64/asinl.s", + "src/math/x86_64/atan2l.s", + "src/math/x86_64/atanl.s", + "src/math/x86_64/ceill.s", + "src/math/x86_64/exp2l.s", + "src/math/x86_64/expl.s", + "src/math/x86_64/expm1l.s", + "src/math/x86_64/fabs.c", + "src/math/x86_64/fabsf.c", + "src/math/x86_64/fabsl.c", + "src/math/x86_64/floorl.s", + "src/math/x86_64/fma.c", + "src/math/x86_64/fmaf.c", + "src/math/x86_64/fmodl.c", + "src/math/x86_64/llrint.c", + "src/math/x86_64/llrintf.c", + "src/math/x86_64/llrintl.c", + "src/math/x86_64/log10l.s", + "src/math/x86_64/log1pl.s", + "src/math/x86_64/log2l.s", + "src/math/x86_64/logl.s", + "src/math/x86_64/lrint.c", + "src/math/x86_64/lrintf.c", + "src/math/x86_64/lrintl.c", + "src/math/x86_64/remainderl.c", + "src/math/x86_64/remquol.c", + "src/math/x86_64/rintl.c", + "src/math/x86_64/sqrt.c", + "src/math/x86_64/sqrtf.c", + "src/math/x86_64/sqrtl.c", + "src/math/x86_64/truncl.s", + "src/process/x86_64/vfork.s", + "src/setjmp/x86_64/longjmp.s", + "src/setjmp/x86_64/setjmp.s", + "src/signal/x86_64/restore.s", + "src/signal/x86_64/sigsetjmp.s", + "src/string/x86_64/memcpy.s", + "src/string/x86_64/memmove.s", + "src/string/x86_64/memset.s", + "src/thread/x86_64/__set_thread_area.s", + "src/thread/x86_64/__unmapself.s", + "src/thread/x86_64/clone.s", + "src/thread/x86_64/syscall_cp.s", +}; + +const musl_arch_files = [_][]const u8{ + "src/fenv/aarch64/fenv.s", + "src/fenv/arm/fenv-hf.S", + "src/fenv/arm/fenv.c", + "src/fenv/i386/fenv.s", + "src/fenv/m68k/fenv.c", + "src/fenv/mips/fenv-sf.c", + "src/fenv/mips/fenv.S", + "src/fenv/mips64/fenv-sf.c", + "src/fenv/mips64/fenv.S", + "src/fenv/mipsn32/fenv-sf.c", + "src/fenv/mipsn32/fenv.S", + "src/fenv/powerpc/fenv-sf.c", + "src/fenv/powerpc/fenv.S", + "src/fenv/powerpc64/fenv.c", + "src/fenv/riscv64/fenv-sf.c", + "src/fenv/riscv64/fenv.S", + "src/fenv/s390x/fenv.c", + "src/fenv/sh/fenv-nofpu.c", + "src/fenv/sh/fenv.S", + "src/fenv/x32/fenv.s", + "src/internal/i386/defsysinfo.s", + "src/internal/sh/__shcall.c", + "src/ldso/aarch64/dlsym.s", + "src/ldso/aarch64/tlsdesc.s", + "src/ldso/arm/dlsym.s", + "src/ldso/arm/dlsym_time64.S", + "src/ldso/arm/find_exidx.c", + "src/ldso/arm/tlsdesc.S", + "src/ldso/i386/dlsym.s", + "src/ldso/i386/dlsym_time64.S", + "src/ldso/i386/tlsdesc.s", + "src/ldso/m68k/dlsym.s", + "src/ldso/m68k/dlsym_time64.S", + "src/ldso/microblaze/dlsym.s", + "src/ldso/microblaze/dlsym_time64.S", + "src/ldso/mips/dlsym.s", + "src/ldso/mips/dlsym_time64.S", + "src/ldso/mips64/dlsym.s", + "src/ldso/mipsn32/dlsym.s", + "src/ldso/mipsn32/dlsym_time64.S", + "src/ldso/or1k/dlsym.s", + "src/ldso/or1k/dlsym_time64.S", + "src/ldso/powerpc/dlsym.s", + "src/ldso/powerpc/dlsym_time64.S", + "src/ldso/powerpc64/dlsym.s", + "src/ldso/riscv64/dlsym.s", + "src/ldso/s390x/dlsym.s", + "src/ldso/sh/dlsym.s", + "src/ldso/sh/dlsym_time64.S", + "src/ldso/tlsdesc.c", + "src/ldso/x32/dlsym.s", + "src/linux/x32/sysinfo.c", + "src/math/aarch64/ceil.c", + "src/math/aarch64/ceilf.c", + "src/math/aarch64/fabs.c", + "src/math/aarch64/fabsf.c", + "src/math/aarch64/floor.c", + "src/math/aarch64/floorf.c", + "src/math/aarch64/fma.c", + "src/math/aarch64/fmaf.c", + "src/math/aarch64/fmax.c", + "src/math/aarch64/fmaxf.c", + "src/math/aarch64/fmin.c", + "src/math/aarch64/fminf.c", + "src/math/aarch64/llrint.c", + "src/math/aarch64/llrintf.c", + "src/math/aarch64/llround.c", + "src/math/aarch64/llroundf.c", + "src/math/aarch64/lrint.c", + "src/math/aarch64/lrintf.c", + "src/math/aarch64/lround.c", + "src/math/aarch64/lroundf.c", + "src/math/aarch64/nearbyint.c", + "src/math/aarch64/nearbyintf.c", + "src/math/aarch64/rint.c", + "src/math/aarch64/rintf.c", + "src/math/aarch64/round.c", + "src/math/aarch64/roundf.c", + "src/math/aarch64/sqrt.c", + "src/math/aarch64/sqrtf.c", + "src/math/aarch64/trunc.c", + "src/math/aarch64/truncf.c", + "src/math/arm/fabs.c", + "src/math/arm/fabsf.c", + "src/math/arm/fma.c", + "src/math/arm/fmaf.c", + "src/math/arm/sqrt.c", + "src/math/arm/sqrtf.c", + "src/math/i386/__invtrigl.s", + "src/math/i386/acos.s", + "src/math/i386/acosf.s", + "src/math/i386/acosl.s", + "src/math/i386/asin.s", + "src/math/i386/asinf.s", + "src/math/i386/asinl.s", + "src/math/i386/atan.s", + "src/math/i386/atan2.s", + "src/math/i386/atan2f.s", + "src/math/i386/atan2l.s", + "src/math/i386/atanf.s", + "src/math/i386/atanl.s", + "src/math/i386/ceil.s", + "src/math/i386/ceilf.s", + "src/math/i386/ceill.s", + "src/math/i386/exp2l.s", + "src/math/i386/exp_ld.s", + "src/math/i386/expl.s", + "src/math/i386/expm1l.s", + "src/math/i386/fabs.c", + "src/math/i386/fabsf.c", + "src/math/i386/fabsl.c", + "src/math/i386/floor.s", + "src/math/i386/floorf.s", + "src/math/i386/floorl.s", + "src/math/i386/fmod.c", + "src/math/i386/fmodf.c", + "src/math/i386/fmodl.c", + "src/math/i386/hypot.s", + "src/math/i386/hypotf.s", + "src/math/i386/ldexp.s", + "src/math/i386/ldexpf.s", + "src/math/i386/ldexpl.s", + "src/math/i386/llrint.c", + "src/math/i386/llrintf.c", + "src/math/i386/llrintl.c", + "src/math/i386/log.s", + "src/math/i386/log10.s", + "src/math/i386/log10f.s", + "src/math/i386/log10l.s", + "src/math/i386/log1p.s", + "src/math/i386/log1pf.s", + "src/math/i386/log1pl.s", + "src/math/i386/log2.s", + "src/math/i386/log2f.s", + "src/math/i386/log2l.s", + "src/math/i386/logf.s", + "src/math/i386/logl.s", + "src/math/i386/lrint.c", + "src/math/i386/lrintf.c", + "src/math/i386/lrintl.c", + "src/math/i386/remainder.c", + "src/math/i386/remainderf.c", + "src/math/i386/remainderl.c", + "src/math/i386/remquo.s", + "src/math/i386/remquof.s", + "src/math/i386/remquol.s", + "src/math/i386/rint.c", + "src/math/i386/rintf.c", + "src/math/i386/rintl.c", + "src/math/i386/scalbln.s", + "src/math/i386/scalblnf.s", + "src/math/i386/scalblnl.s", + "src/math/i386/scalbn.s", + "src/math/i386/scalbnf.s", + "src/math/i386/scalbnl.s", + "src/math/i386/sqrt.c", + "src/math/i386/sqrtf.c", + "src/math/i386/sqrtl.c", + "src/math/i386/trunc.s", + "src/math/i386/truncf.s", + "src/math/i386/truncl.s", + "src/math/m68k/sqrtl.c", + "src/math/mips/fabs.c", + "src/math/mips/fabsf.c", + "src/math/mips/sqrt.c", + "src/math/mips/sqrtf.c", + "src/math/powerpc/fabs.c", + "src/math/powerpc/fabsf.c", + "src/math/powerpc/fma.c", + "src/math/powerpc/fmaf.c", + "src/math/powerpc/sqrt.c", + "src/math/powerpc/sqrtf.c", + "src/math/powerpc64/ceil.c", + "src/math/powerpc64/ceilf.c", + "src/math/powerpc64/fabs.c", + "src/math/powerpc64/fabsf.c", + "src/math/powerpc64/floor.c", + "src/math/powerpc64/floorf.c", + "src/math/powerpc64/fma.c", + "src/math/powerpc64/fmaf.c", + "src/math/powerpc64/fmax.c", + "src/math/powerpc64/fmaxf.c", + "src/math/powerpc64/fmin.c", + "src/math/powerpc64/fminf.c", + "src/math/powerpc64/lrint.c", + "src/math/powerpc64/lrintf.c", + "src/math/powerpc64/lround.c", + "src/math/powerpc64/lroundf.c", + "src/math/powerpc64/round.c", + "src/math/powerpc64/roundf.c", + "src/math/powerpc64/sqrt.c", + "src/math/powerpc64/sqrtf.c", + "src/math/powerpc64/trunc.c", + "src/math/powerpc64/truncf.c", + "src/math/riscv64/copysign.c", + "src/math/riscv64/copysignf.c", + "src/math/riscv64/fabs.c", + "src/math/riscv64/fabsf.c", + "src/math/riscv64/fma.c", + "src/math/riscv64/fmaf.c", + "src/math/riscv64/fmax.c", + "src/math/riscv64/fmaxf.c", + "src/math/riscv64/fmin.c", + "src/math/riscv64/fminf.c", + "src/math/riscv64/sqrt.c", + "src/math/riscv64/sqrtf.c", + "src/math/s390x/ceil.c", + "src/math/s390x/ceilf.c", + "src/math/s390x/ceill.c", + "src/math/s390x/fabs.c", + "src/math/s390x/fabsf.c", + "src/math/s390x/fabsl.c", + "src/math/s390x/floor.c", + "src/math/s390x/floorf.c", + "src/math/s390x/floorl.c", + "src/math/s390x/fma.c", + "src/math/s390x/fmaf.c", + "src/math/s390x/nearbyint.c", + "src/math/s390x/nearbyintf.c", + "src/math/s390x/nearbyintl.c", + "src/math/s390x/rint.c", + "src/math/s390x/rintf.c", + "src/math/s390x/rintl.c", + "src/math/s390x/round.c", + "src/math/s390x/roundf.c", + "src/math/s390x/roundl.c", + "src/math/s390x/sqrt.c", + "src/math/s390x/sqrtf.c", + "src/math/s390x/sqrtl.c", + "src/math/s390x/trunc.c", + "src/math/s390x/truncf.c", + "src/math/s390x/truncl.c", + "src/math/x32/__invtrigl.s", + "src/math/x32/acosl.s", + "src/math/x32/asinl.s", + "src/math/x32/atan2l.s", + "src/math/x32/atanl.s", + "src/math/x32/ceill.s", + "src/math/x32/exp2l.s", + "src/math/x32/expl.s", + "src/math/x32/expm1l.s", + "src/math/x32/fabs.s", + "src/math/x32/fabsf.s", + "src/math/x32/fabsl.s", + "src/math/x32/floorl.s", + "src/math/x32/fma.c", + "src/math/x32/fmaf.c", + "src/math/x32/fmodl.s", + "src/math/x32/llrint.s", + "src/math/x32/llrintf.s", + "src/math/x32/llrintl.s", + "src/math/x32/log10l.s", + "src/math/x32/log1pl.s", + "src/math/x32/log2l.s", + "src/math/x32/logl.s", + "src/math/x32/lrint.s", + "src/math/x32/lrintf.s", + "src/math/x32/lrintl.s", + "src/math/x32/remainderl.s", + "src/math/x32/rintl.s", + "src/math/x32/sqrt.s", + "src/math/x32/sqrtf.s", + "src/math/x32/sqrtl.s", + "src/math/x32/truncl.s", + "src/process/aarch64/vfork.s", + "src/process/arm/vfork.s", + "src/process/i386/vfork.s", + "src/process/riscv64/vfork.s", + "src/process/s390x/vfork.s", + "src/process/sh/vfork.s", + "src/process/system.c", + "src/process/vfork.c", + "src/process/wait.c", + "src/process/waitid.c", + "src/process/waitpid.c", + "src/process/x32/vfork.s", + "src/setjmp/aarch64/longjmp.s", + "src/setjmp/aarch64/setjmp.s", + "src/setjmp/arm/longjmp.S", + "src/setjmp/arm/setjmp.S", + "src/setjmp/i386/longjmp.s", + "src/setjmp/i386/setjmp.s", + "src/setjmp/m68k/longjmp.s", + "src/setjmp/m68k/setjmp.s", + "src/setjmp/microblaze/longjmp.s", + "src/setjmp/microblaze/setjmp.s", + "src/setjmp/mips/longjmp.S", + "src/setjmp/mips/setjmp.S", + "src/setjmp/mips64/longjmp.S", + "src/setjmp/mips64/setjmp.S", + "src/setjmp/mipsn32/longjmp.S", + "src/setjmp/mipsn32/setjmp.S", + "src/setjmp/or1k/longjmp.s", + "src/setjmp/or1k/setjmp.s", + "src/setjmp/powerpc/longjmp.S", + "src/setjmp/powerpc/setjmp.S", + "src/setjmp/powerpc64/longjmp.s", + "src/setjmp/powerpc64/setjmp.s", + "src/setjmp/riscv64/longjmp.S", + "src/setjmp/riscv64/setjmp.S", + "src/setjmp/s390x/longjmp.s", + "src/setjmp/s390x/setjmp.s", + "src/setjmp/sh/longjmp.S", + "src/setjmp/sh/setjmp.S", + "src/setjmp/x32/longjmp.s", + "src/setjmp/x32/setjmp.s", + "src/signal/aarch64/restore.s", + "src/signal/aarch64/sigsetjmp.s", + "src/signal/arm/restore.s", + "src/signal/arm/sigsetjmp.s", + "src/signal/i386/restore.s", + "src/signal/i386/sigsetjmp.s", + "src/signal/m68k/sigsetjmp.s", + "src/signal/microblaze/restore.s", + "src/signal/microblaze/sigsetjmp.s", + "src/signal/mips/sigsetjmp.s", + "src/signal/mips64/sigsetjmp.s", + "src/signal/mipsn32/sigsetjmp.s", + "src/signal/or1k/sigsetjmp.s", + "src/signal/powerpc/restore.s", + "src/signal/powerpc/sigsetjmp.s", + "src/signal/powerpc64/restore.s", + "src/signal/powerpc64/sigsetjmp.s", + "src/signal/riscv64/restore.s", + "src/signal/riscv64/sigsetjmp.s", + "src/signal/s390x/restore.s", + "src/signal/s390x/sigsetjmp.s", + "src/signal/setitimer.c", + "src/signal/sh/restore.s", + "src/signal/sh/sigsetjmp.s", + "src/signal/x32/getitimer.c", + "src/signal/x32/restore.s", + "src/signal/x32/setitimer.c", + "src/signal/x32/sigsetjmp.s", + "src/string/aarch64/memcpy.S", + "src/string/aarch64/memset.S", + "src/string/arm/__aeabi_memcpy.s", + "src/string/arm/__aeabi_memset.s", + "src/string/arm/memcpy.S", + "src/string/i386/memcpy.s", + "src/string/i386/memmove.s", + "src/string/i386/memset.s", + "src/thread/aarch64/__set_thread_area.s", + "src/thread/aarch64/__unmapself.s", + "src/thread/aarch64/clone.s", + "src/thread/aarch64/syscall_cp.s", + "src/thread/arm/__aeabi_read_tp.s", + "src/thread/arm/__set_thread_area.c", + "src/thread/arm/__unmapself.s", + "src/thread/arm/atomics.s", + "src/thread/arm/clone.s", + "src/thread/arm/syscall_cp.s", + "src/thread/i386/__set_thread_area.s", + "src/thread/i386/__unmapself.s", + "src/thread/i386/clone.s", + "src/thread/i386/syscall_cp.s", + "src/thread/i386/tls.s", + "src/thread/m68k/__m68k_read_tp.s", + "src/thread/m68k/clone.s", + "src/thread/m68k/syscall_cp.s", + "src/thread/microblaze/__set_thread_area.s", + "src/thread/microblaze/__unmapself.s", + "src/thread/microblaze/clone.s", + "src/thread/microblaze/syscall_cp.s", + "src/thread/mips/__unmapself.s", + "src/thread/mips/clone.s", + "src/thread/mips/syscall_cp.s", + "src/thread/mips64/__unmapself.s", + "src/thread/mips64/clone.s", + "src/thread/mips64/syscall_cp.s", + "src/thread/mipsn32/__unmapself.s", + "src/thread/mipsn32/clone.s", + "src/thread/mipsn32/syscall_cp.s", + "src/thread/or1k/__set_thread_area.s", + "src/thread/or1k/__unmapself.s", + "src/thread/or1k/clone.s", + "src/thread/or1k/syscall_cp.s", + "src/thread/powerpc/__set_thread_area.s", + "src/thread/powerpc/__unmapself.s", + "src/thread/powerpc/clone.s", + "src/thread/powerpc/syscall_cp.s", + "src/thread/powerpc64/__set_thread_area.s", + "src/thread/powerpc64/__unmapself.s", + "src/thread/powerpc64/clone.s", + "src/thread/powerpc64/syscall_cp.s", + "src/thread/riscv64/__set_thread_area.s", + "src/thread/riscv64/__unmapself.s", + "src/thread/riscv64/clone.s", + "src/thread/riscv64/syscall_cp.s", + "src/thread/s390x/__set_thread_area.s", + "src/thread/s390x/__tls_get_offset.s", + "src/thread/s390x/__unmapself.s", + "src/thread/s390x/clone.s", + "src/thread/s390x/syscall_cp.s", + "src/thread/sh/__set_thread_area.c", + "src/thread/sh/__unmapself.c", + "src/thread/sh/__unmapself_mmu.s", + "src/thread/sh/atomics.s", + "src/thread/sh/clone.s", + "src/thread/sh/syscall_cp.s", + "src/thread/x32/__set_thread_area.s", + "src/thread/x32/__unmapself.s", + "src/thread/x32/clone.s", + "src/thread/x32/syscall_cp.s", + "src/unistd/mips/pipe.s", + "src/unistd/mips64/pipe.s", + "src/unistd/mipsn32/lseek.c", + "src/unistd/mipsn32/pipe.s", + "src/unistd/sh/pipe.s", + "src/unistd/x32/lseek.c", +}; + + +fn argsCopyZ(alloc: Allocator, args: []const []const u8) ![:null]?[*:0]u8 { + var argv = try alloc.allocSentinel(?[*:0]u8, args.len, null); + for (args, 0..) |arg, i| { + argv[i] = try alloc.dupeZ(u8, arg); // TODO If there was an argsAllocZ we could avoid this allocation. + } + return argv; +} + +extern "c" fn NativityLLVMArchiverMain(argc: c_int, argv: [*:null]?[*:0]u8) c_int; +fn arMain(allocator: Allocator, arguments: []const []const u8) !u8 { + const argv = try argsCopyZ(allocator, arguments); + const exit_code = NativityLLVMArchiverMain(@as(c_int, @intCast(arguments.len)), argv.ptr); + return @as(u8, @bitCast(@as(i8, @truncate(exit_code)))); +} + +extern "c" fn NativityClangMain(argc: c_int, argv: [*:null]?[*:0]u8) c_int; +fn clangMain(allocator: Allocator, arguments: []const []const u8) !u8 { + const argv = try argsCopyZ(allocator, arguments); + const exit_code = NativityClangMain(@as(c_int, @intCast(arguments.len)), argv.ptr); + return @as(u8, @bitCast(@as(i8, @truncate(exit_code)))); +} + const ExecutableOptions = struct { is_test: bool, }; +const Arch = enum{ + x86_64, + aarch64, +}; + +const Os = enum{ + linux, + macos, +}; + +const Abi = enum{ + none, + gnu, + musl, +}; + pub fn buildExecutable(context: *const Context, arguments: [][*:0]u8, options: ExecutableOptions) !void { var maybe_executable_path: ?[]const u8 = null; var maybe_main_package_path: ?[]const u8 = null; - var arch: std.Target.Cpu.Arch = undefined; - var os: std.Target.Os.Tag = undefined; - var abi: std.Target.Abi = undefined; + var arch: Arch = undefined; + var os: Os = undefined; + var abi: Abi = undefined; switch (@import("builtin").os.tag) { .linux => { @@ -270,8 +2311,8 @@ pub fn buildExecutable(context: *const Context, arguments: [][*:0]u8, options: E .link_libc = switch (os) { .linux => link_libc, .macos => true, - .windows => link_libc, - else => unreachable, + // .windows => link_libc, + // else => unreachable, }, .generate_debug_information = generate_debug_information, .name = executable_name, @@ -9709,9 +11750,9 @@ pub const FixedKeyword = enum { pub const Descriptor = struct { main_package_path: []const u8, executable_path: []const u8, - arch: std.Target.Cpu.Arch, - os: std.Target.Os.Tag, - abi: std.Target.Abi, + arch: Arch, + os: Os, + abi: Abi, only_parse: bool, link_libc: bool, is_test: bool, diff --git a/bootstrap/backend/llvm.zig b/bootstrap/backend/llvm.zig index c29e295..48cf3e8 100644 --- a/bootstrap/backend/llvm.zig +++ b/bootstrap/backend/llvm.zig @@ -9,7 +9,7 @@ const data_structures = @import("../library.zig"); const MyHashMap = data_structures.MyHashMap; const UnpinnedArray = data_structures.UnpinnedArray; -const bindings = @import("llvm_bindings.zig"); +pub const bindings = @import("llvm_bindings.zig"); pub const Logger = enum { print_module, @@ -3245,7 +3245,6 @@ pub fn codegen(unit: *Compilation.Unit, context: *const Compilation.Context) !vo const target_triple = switch (unit.descriptor.os) { .linux => "x86_64-linux-none", .macos => "aarch64-apple-macosx-none", - else => |t| @panic(@tagName(t)), }; const cpu = "generic"; const features = ""; @@ -3286,10 +3285,10 @@ pub fn codegen(unit: *Compilation.Unit, context: *const Compilation.Context) !vo } const format: Format = switch (unit.descriptor.os) { - .windows => .coff, + // .windows => .coff, .macos => .macho, .linux => .elf, - else => unreachable, + // else => unreachable, }; const driver_program = switch (format) { @@ -3347,8 +3346,8 @@ pub fn codegen(unit: *Compilation.Unit, context: *const Compilation.Context) !vo // try arguments.append_slice(context.allocator, &.{ "-lc" }); // } }, - .windows => {}, - else => |t| @panic(@tagName(t)), + // .windows => {}, + // else => |t| @panic(@tagName(t)), } var stdout_ptr: [*]const u8 = undefined; @@ -3356,7 +3355,11 @@ pub fn codegen(unit: *Compilation.Unit, context: *const Compilation.Context) !vo var stderr_ptr: [*]const u8 = undefined; var stderr_len: usize = 0; - const linking_result = bindings.NativityLLDLink(format, arguments.pointer, arguments.length, &stdout_ptr, &stdout_len, &stderr_ptr, &stderr_len); + const linking_result = switch (format) { + .elf => bindings.NativityLLDLinkELF(arguments.pointer, arguments.length, &stdout_ptr, &stdout_len, &stderr_ptr, &stderr_len), + .coff => bindings.NativityLLDLinkCOFF(arguments.pointer, arguments.length, &stdout_ptr, &stdout_len, &stderr_ptr, &stderr_len), + .macho => bindings.NativityLLDLinkMachO(arguments.pointer, arguments.length, &stdout_ptr, &stdout_len, &stderr_ptr, &stderr_len), + }; if (stdout_len > 0) { // std.debug.print("{s}\n", .{stdout_ptr[0..stdout_len]}); diff --git a/bootstrap/backend/llvm_bindings.zig b/bootstrap/backend/llvm_bindings.zig index d2bce64..9481be4 100644 --- a/bootstrap/backend/llvm_bindings.zig +++ b/bootstrap/backend/llvm_bindings.zig @@ -141,4 +141,7 @@ pub extern fn NativityLLVMTargetCreateTargetMachine(target: *LLVM.Target, target pub extern fn NativityLLVMModuleSetTargetMachineDataLayout(module: *LLVM.Module, target_machine: *LLVM.Target.Machine) void; pub extern fn NativityLLVMModuleSetTargetTriple(module: *LLVM.Module, target_triple_ptr: [*]const u8, target_triple_len: usize) void; pub extern fn NativityLLVMModuleAddPassesToEmitFile(module: *LLVM.Module, target_machine: *LLVM.Target.Machine, object_file_path_ptr: [*]const u8, object_file_path_len: usize, codegen_file_type: LLVM.CodeGenFileType, disable_verify: bool) bool; -pub extern fn NativityLLDLink(format: llvm.Format, argument_ptr: [*]const [*:0]const u8, argument_count: usize, stdout_ptr: *[*]const u8, stdout_len: *usize, stderr_ptr: *[*]const u8, stderr_len: *usize) bool; +pub extern fn NativityLLDLinkELF(argument_ptr: [*]const [*:0]const u8, argument_count: usize, stdout_ptr: *[*]const u8, stdout_len: *usize, stderr_ptr: *[*]const u8, stderr_len: *usize) bool; +pub extern fn NativityLLDLinkCOFF(argument_ptr: [*]const [*:0]const u8, argument_count: usize, stdout_ptr: *[*]const u8, stdout_len: *usize, stderr_ptr: *[*]const u8, stderr_len: *usize) bool; +pub extern fn NativityLLDLinkMachO(argument_ptr: [*]const [*:0]const u8, argument_count: usize, stdout_ptr: *[*]const u8, stdout_len: *usize, stderr_ptr: *[*]const u8, stderr_len: *usize) bool; +pub extern fn NativityLLDLinkWasm(argument_ptr: [*]const [*:0]const u8, argument_count: usize, stdout_ptr: *[*]const u8, stdout_len: *usize, stderr_ptr: *[*]const u8, stderr_len: *usize) bool; diff --git a/bootstrap/library.zig b/bootstrap/library.zig index b7bd0c2..bb97642 100644 --- a/bootstrap/library.zig +++ b/bootstrap/library.zig @@ -204,6 +204,12 @@ pub fn byte_equal(a: []const u8, b: []const u8) bool { return true; } +pub fn byte_equal_terminated(a: [*:0]const u8, b: [*:0]const u8) bool { + const a_slice = span(a); + const b_slice = span(b); + return byte_equal(a_slice, b_slice); +} + const MapResult = struct{ key_pointer: *anyopaque, value_pointer: *anyopaque, diff --git a/bootstrap/main.zig b/bootstrap/main.zig index 61643af..8f71173 100644 --- a/bootstrap/main.zig +++ b/bootstrap/main.zig @@ -30,7 +30,9 @@ pub export fn main(c_argc: c_int, c_argv: [*][*:0]c_char, c_envp: [*:null]?[*:0] return 0; } else |err| { const error_name: []const u8 = @errorName(err); - _ = error_name; // autofix + std.io.getStdOut().writeAll("Error: ") catch {}; + std.io.getStdOut().writeAll(error_name) catch {}; + std.io.getStdOut().writeAll("\n") catch {}; return 1; } } @@ -59,7 +61,7 @@ pub fn entry_point(arguments: [][*:0]u8) !void { // std.process.exit(exit_code); } else if (byte_equal(command, "cc")) { // TODO: transform our arguments to Clang and invoke it - todo(); + try Compilation.compileCSourceFile(context, command_arguments); } else if (byte_equal(command, "c++")) { // TODO: transform our arguments to Clang and invoke it todo(); @@ -80,17 +82,3 @@ pub fn entry_point(arguments: [][*:0]u8) !void { } } -fn argsCopyZ(alloc: Allocator, args: []const []const u8) ![:null]?[*:0]u8 { - var argv = try alloc.allocSentinel(?[*:0]u8, args.len, null); - for (args, 0..) |arg, i| { - argv[i] = try alloc.dupeZ(u8, arg); // TODO If there was an argsAllocZ we could avoid this allocation. - } - return argv; -} - -extern "c" fn NativityClangMain(argc: c_int, argv: [*:null]?[*:0]u8) c_int; -fn clangMain(allocator: Allocator, arguments: []const []const u8) !u8 { - const argv = try argsCopyZ(allocator, arguments); - const exit_code = NativityClangMain(@as(c_int, @intCast(arguments.len)), argv.ptr); - return @as(u8, @bitCast(@as(i8, @truncate(exit_code)))); -} diff --git a/build.zig b/build.zig index 06145fc..5a471f5 100644 --- a/build.zig +++ b/build.zig @@ -91,38 +91,33 @@ pub fn build(b: *std.Build) !void { } }; - if (os == .linux) { - const directory = "musl-libc-main"; - var maybe_dir = std.fs.cwd().openDir(prefix ++ "/" ++ directory, .{}); - _ = &maybe_dir; - if (maybe_dir) |*dir| { - dir.close(); - } else |err| { - _ = &err; // autofix - const url = "https://github.com/birth-software/musl-libc/archive/refs/heads/main.tar.gz"; - const run = b.addRunArtifact(fetcher); - compiler.step.dependOn(&run.step); - run.addArg("-prefix"); - run.addArg(prefix); - run.addArg("-url"); - run.addArg(url); - } - } - - const llvm_include_dir = try std.mem.concat(b.allocator, u8, &.{ llvm_path, "/include" }); const llvm_lib_dir = try std.mem.concat(b.allocator, u8, &.{ llvm_path, "/lib" }); compiler.addIncludePath(std.Build.LazyPath.relative(llvm_include_dir)); const cpp_files = .{ "src/llvm/llvm.cpp", "src/llvm/lld.cpp", - // "src/llvm/clang_main.cpp", - // "src/llvm/clang_cc1.cpp", - // "src/llvm/clang_cc1as.cpp", + "src/llvm/clang_main.cpp", + "src/llvm/clang_cc1.cpp", + "src/llvm/clang_cc1as.cpp", + "src/llvm/ar.cpp", }; compiler.addCSourceFiles(.{ .files = &cpp_files, - .flags = &.{"-g"}, + .flags = &.{ + "-g", + "-std=c++17", + "-D__STDC_CONSTANT_MACROS", + "-D__STDC_FORMAT_MACROS", + "-D__STDC_LIMIT_MACROS", + "-D_GNU_SOURCE", + "-fvisibility-inlines-hidden", + "-fno-exceptions", + "-fno-rtti", + "-Werror=type-limits", + "-Wno-missing-braces", + "-Wno-comment", + }, }); const zlib = if (target.result.os.tag == .windows) "zstd.lib" else "libzstd.a"; @@ -320,48 +315,48 @@ pub fn build(b: *std.Build) !void { zlib, "libz.a", // Clang - // "libclangAnalysis.a", - // "libclangAnalysisFlowSensitive.a", - // "libclangAnalysisFlowSensitiveModels.a", - // "libclangAPINotes.a", - // "libclangARCMigrate.a", - // "libclangAST.a", - // "libclangASTMatchers.a", - // "libclangBasic.a", - // "libclangCodeGen.a", - // "libclangCrossTU.a", - // "libclangDependencyScanning.a", - // "libclangDirectoryWatcher.a", - // "libclangDriver.a", - // "libclangDynamicASTMatchers.a", - // "libclangEdit.a", - // "libclangExtractAPI.a", - // "libclangFormat.a", - // "libclangFrontend.a", - // "libclangFrontendTool.a", - // "libclangHandleCXX.a", - // "libclangHandleLLVM.a", - // "libclangIndex.a", - // "libclangIndexSerialization.a", - // "libclangInterpreter.a", - // "libclangLex.a", - // "libclangParse.a", - // "libclangRewrite.a", - // "libclangRewriteFrontend.a", - // "libclangSema.a", - // "libclangSerialization.a", - // "libclangStaticAnalyzerCheckers.a", - // "libclangStaticAnalyzerCore.a", - // "libclangStaticAnalyzerFrontend.a", - // "libclangSupport.a", - // "libclangTooling.a", - // "libclangToolingASTDiff.a", - // "libclangToolingCore.a", - // "libclangToolingInclusions.a", - // "libclangToolingInclusionsStdlib.a", - // "libclangToolingRefactoring.a", - // "libclangToolingSyntax.a", - // "libclangTransformer.a", + "libclangAnalysis.a", + "libclangAnalysisFlowSensitive.a", + "libclangAnalysisFlowSensitiveModels.a", + "libclangAPINotes.a", + "libclangARCMigrate.a", + "libclangAST.a", + "libclangASTMatchers.a", + "libclangBasic.a", + "libclangCodeGen.a", + "libclangCrossTU.a", + "libclangDependencyScanning.a", + "libclangDirectoryWatcher.a", + "libclangDriver.a", + "libclangDynamicASTMatchers.a", + "libclangEdit.a", + "libclangExtractAPI.a", + "libclangFormat.a", + "libclangFrontend.a", + "libclangFrontendTool.a", + "libclangHandleCXX.a", + "libclangHandleLLVM.a", + "libclangIndex.a", + "libclangIndexSerialization.a", + "libclangInterpreter.a", + "libclangLex.a", + "libclangParse.a", + "libclangRewrite.a", + "libclangRewriteFrontend.a", + "libclangSema.a", + "libclangSerialization.a", + "libclangStaticAnalyzerCheckers.a", + "libclangStaticAnalyzerCore.a", + "libclangStaticAnalyzerFrontend.a", + "libclangSupport.a", + "libclangTooling.a", + "libclangToolingASTDiff.a", + "libclangToolingCore.a", + "libclangToolingInclusions.a", + "libclangToolingInclusionsStdlib.a", + "libclangToolingRefactoring.a", + "libclangToolingSyntax.a", + "libclangTransformer.a", }; for (llvm_libraries) |llvm_library| { diff --git a/src/llvm/ar.cpp b/src/llvm/ar.cpp new file mode 100644 index 0000000..ae3124d --- /dev/null +++ b/src/llvm/ar.cpp @@ -0,0 +1,1470 @@ +//===-- llvm-ar.cpp - LLVM archive librarian utility ----------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// Builds up (relatively) standard unix archive files (.a) containing LLVM +// bitcode or other files. +// +//===----------------------------------------------------------------------===// + +#include "llvm/ADT/StringExtras.h" +#include "llvm/ADT/StringSwitch.h" +#include "llvm/BinaryFormat/Magic.h" +#include "llvm/IR/LLVMContext.h" +#include "llvm/Object/Archive.h" +#include "llvm/Object/ArchiveWriter.h" +#include "llvm/Object/SymbolicFile.h" +#include "llvm/Support/Chrono.h" +#include "llvm/Support/CommandLine.h" +#include "llvm/Support/ConvertUTF.h" +#include "llvm/Support/Errc.h" +#include "llvm/Support/FileSystem.h" +#include "llvm/Support/Format.h" +#include "llvm/Support/FormatVariadic.h" +#include "llvm/Support/InitLLVM.h" +#include "llvm/Support/LLVMDriver.h" +#include "llvm/Support/LineIterator.h" +#include "llvm/Support/MemoryBuffer.h" +#include "llvm/Support/Path.h" +#include "llvm/Support/Process.h" +#include "llvm/Support/StringSaver.h" +#include "llvm/Support/TargetSelect.h" +#include "llvm/Support/ToolOutputFile.h" +#include "llvm/Support/WithColor.h" +#include "llvm/Support/raw_ostream.h" +#include "llvm/TargetParser/Host.h" +#include "llvm/TargetParser/Triple.h" +#include "llvm/ToolDrivers/llvm-dlltool/DlltoolDriver.h" +#include "llvm/ToolDrivers/llvm-lib/LibDriver.h" + +#if !defined(_MSC_VER) && !defined(__MINGW32__) +#include +#else +#include +#endif + +#ifdef _WIN32 +#include "llvm/Support/Windows/WindowsSupport.h" +#endif + +using namespace llvm; +using namespace llvm::object; + +// The name this program was invoked as. +static StringRef ToolName; + +// The basename of this program. +static StringRef Stem; + +static void printRanLibHelp(StringRef ToolName) { + outs() << "OVERVIEW: LLVM ranlib\n\n" + << "Generate an index for archives\n\n" + << "USAGE: " + ToolName + " archive...\n\n" + << "OPTIONS:\n" + << " -h --help - Display available options\n" + << " -v --version - Display the version of this program\n" + << " -D - Use zero for timestamps and uids/gids " + "(default)\n" + << " -U - Use actual timestamps and uids/gids\n"; +} + +static void printArHelp(StringRef ToolName) { + const char ArOptions[] = + R"(OPTIONS: + --format - archive format to create + =default - default + =gnu - gnu + =darwin - darwin + =bsd - bsd + =bigarchive - big archive (AIX OS) + --plugin= - ignored for compatibility + -h --help - display this help and exit + --output - the directory to extract archive members to + --rsp-quoting - quoting style for response files + =posix - posix + =windows - windows + --thin - create a thin archive + --version - print the version and exit + -X{32|64|32_64|any} - object mode (only for AIX OS) + @ - read options from + +OPERATIONS: + d - delete [files] from the archive + m - move [files] in the archive + p - print contents of [files] found in the archive + q - quick append [files] to the archive + r - replace or insert [files] into the archive + s - act as ranlib + t - display list of files in archive + x - extract [files] from the archive + +MODIFIERS: + [a] - put [files] after [relpos] + [b] - put [files] before [relpos] (same as [i]) + [c] - do not warn if archive had to be created + [D] - use zero for timestamps and uids/gids (default) + [h] - display this help and exit + [i] - put [files] before [relpos] (same as [b]) + [l] - ignored for compatibility + [L] - add archive's contents + [N] - use instance [count] of name + [o] - preserve original dates + [O] - display member offsets + [P] - use full names when matching (implied for thin archives) + [s] - create an archive index (cf. ranlib) + [S] - do not build a symbol table + [T] - deprecated, use --thin instead + [u] - update only [files] newer than archive contents + [U] - use actual timestamps and uids/gids + [v] - be verbose about actions taken + [V] - display the version and exit +)"; + + outs() << "OVERVIEW: LLVM Archiver\n\n" + << "USAGE: " + ToolName + + " [options] [-][modifiers] [relpos] " + "[count] [files]\n" + << " " + ToolName + " -M [ PositionalArgs; + +static bool MRI; + +namespace { +enum Format { Default, GNU, BSD, DARWIN, BIGARCHIVE, Unknown }; +} + +static Format FormatType = Default; + +static std::string Options; + +// This enumeration delineates the kinds of operations on an archive +// that are permitted. +enum ArchiveOperation { + Print, ///< Print the contents of the archive + Delete, ///< Delete the specified members + Move, ///< Move members to end or as given by {a,b,i} modifiers + QuickAppend, ///< Quickly append to end of archive + ReplaceOrInsert, ///< Replace or Insert members + DisplayTable, ///< Display the table of contents + Extract, ///< Extract files back to file system + CreateSymTab ///< Create a symbol table in an existing archive +}; + +enum class BitModeTy { Bit32, Bit64, Bit32_64, Any, Unknown }; + +static BitModeTy BitMode = BitModeTy::Bit32; + +// Modifiers to follow operation to vary behavior +static bool AddAfter = false; ///< 'a' modifier +static bool AddBefore = false; ///< 'b' modifier +static bool Create = false; ///< 'c' modifier +static bool OriginalDates = false; ///< 'o' modifier +static bool DisplayMemberOffsets = false; ///< 'O' modifier +static bool CompareFullPath = false; ///< 'P' modifier +static bool OnlyUpdate = false; ///< 'u' modifier +static bool Verbose = false; ///< 'v' modifier +static bool Symtab = true; ///< 's' modifier +static bool Deterministic = true; ///< 'D' and 'U' modifiers +static bool Thin = false; ///< 'T' modifier +static bool AddLibrary = false; ///< 'L' modifier + +// Relative Positional Argument (for insert/move). This variable holds +// the name of the archive member to which the 'a', 'b' or 'i' modifier +// refers. Only one of 'a', 'b' or 'i' can be specified so we only need +// one variable. +static std::string RelPos; + +// Count parameter for 'N' modifier. This variable specifies which file should +// match for extract/delete operations when there are multiple matches. This is +// 1-indexed. A value of 0 is invalid, and implies 'N' is not used. +static int CountParam = 0; + +// This variable holds the name of the archive file as given on the +// command line. +static std::string ArchiveName; + +// Output directory specified by --output. +static std::string OutputDir; + +static std::vector> ArchiveBuffers; +static std::vector> Archives; + +// This variable holds the list of member files to proecess, as given +// on the command line. +static std::vector Members; + +// Static buffer to hold StringRefs. +static BumpPtrAllocator Alloc; + +// Extract the member filename from the command line for the [relpos] argument +// associated with a, b, and i modifiers +static void getRelPos() { + if (PositionalArgs.empty()) + fail("expected [relpos] for 'a', 'b', or 'i' modifier"); + RelPos = PositionalArgs[0]; + PositionalArgs.erase(PositionalArgs.begin()); +} + +// Extract the parameter from the command line for the [count] argument +// associated with the N modifier +static void getCountParam() { + if (PositionalArgs.empty()) + badUsage("expected [count] for 'N' modifier"); + auto CountParamArg = StringRef(PositionalArgs[0]); + if (CountParamArg.getAsInteger(10, CountParam)) + badUsage("value for [count] must be numeric, got: " + CountParamArg); + if (CountParam < 1) + badUsage("value for [count] must be positive, got: " + CountParamArg); + PositionalArgs.erase(PositionalArgs.begin()); +} + +// Get the archive file name from the command line +static void getArchive() { + if (PositionalArgs.empty()) + badUsage("an archive name must be specified"); + ArchiveName = PositionalArgs[0]; + PositionalArgs.erase(PositionalArgs.begin()); +} + +static object::Archive &readLibrary(const Twine &Library) { + auto BufOrErr = MemoryBuffer::getFile(Library, /*IsText=*/false, + /*RequiresNullTerminator=*/false); + failIfError(BufOrErr.getError(), "could not open library " + Library); + ArchiveBuffers.push_back(std::move(*BufOrErr)); + auto LibOrErr = + object::Archive::create(ArchiveBuffers.back()->getMemBufferRef()); + failIfError(errorToErrorCode(LibOrErr.takeError()), + "could not parse library"); + Archives.push_back(std::move(*LibOrErr)); + return *Archives.back(); +} + +static void runMRIScript(); + +// Parse the command line options as presented and return the operation +// specified. Process all modifiers and check to make sure that constraints on +// modifier/operation pairs have not been violated. +static ArchiveOperation parseCommandLine() { + if (MRI) { + if (!PositionalArgs.empty() || !Options.empty()) + badUsage("cannot mix -M and other options"); + runMRIScript(); + } + + // Keep track of number of operations. We can only specify one + // per execution. + unsigned NumOperations = 0; + + // Keep track of the number of positional modifiers (a,b,i). Only + // one can be specified. + unsigned NumPositional = 0; + + // Keep track of which operation was requested + ArchiveOperation Operation; + + bool MaybeJustCreateSymTab = false; + + for (unsigned i = 0; i < Options.size(); ++i) { + switch (Options[i]) { + case 'd': + ++NumOperations; + Operation = Delete; + break; + case 'm': + ++NumOperations; + Operation = Move; + break; + case 'p': + ++NumOperations; + Operation = Print; + break; + case 'q': + ++NumOperations; + Operation = QuickAppend; + break; + case 'r': + ++NumOperations; + Operation = ReplaceOrInsert; + break; + case 't': + ++NumOperations; + Operation = DisplayTable; + break; + case 'x': + ++NumOperations; + Operation = Extract; + break; + case 'c': + Create = true; + break; + case 'l': /* accepted but unused */ + break; + case 'o': + OriginalDates = true; + break; + case 'O': + DisplayMemberOffsets = true; + break; + case 'P': + CompareFullPath = true; + break; + case 's': + Symtab = true; + MaybeJustCreateSymTab = true; + break; + case 'S': + Symtab = false; + break; + case 'u': + OnlyUpdate = true; + break; + case 'v': + Verbose = true; + break; + case 'a': + getRelPos(); + AddAfter = true; + NumPositional++; + break; + case 'b': + getRelPos(); + AddBefore = true; + NumPositional++; + break; + case 'i': + getRelPos(); + AddBefore = true; + NumPositional++; + break; + case 'D': + Deterministic = true; + break; + case 'U': + Deterministic = false; + break; + case 'N': + getCountParam(); + break; + case 'T': + Thin = true; + break; + case 'L': + AddLibrary = true; + break; + case 'V': + cl::PrintVersionMessage(); + exit(0); + case 'h': + printHelpMessage(); + exit(0); + default: + badUsage(std::string("unknown option ") + Options[i]); + } + } + + // Thin archives store path names, so P should be forced. + if (Thin) + CompareFullPath = true; + + // At this point, the next thing on the command line must be + // the archive name. + getArchive(); + + // Everything on the command line at this point is a member. + Members.assign(PositionalArgs.begin(), PositionalArgs.end()); + + if (NumOperations == 0 && MaybeJustCreateSymTab) { + NumOperations = 1; + Operation = CreateSymTab; + if (!Members.empty()) + badUsage("the 's' operation takes only an archive as argument"); + } + + // Perform various checks on the operation/modifier specification + // to make sure we are dealing with a legal request. + if (NumOperations == 0) + badUsage("you must specify at least one of the operations"); + if (NumOperations > 1) + badUsage("only one operation may be specified"); + if (NumPositional > 1) + badUsage("you may only specify one of 'a', 'b', and 'i' modifiers"); + if (AddAfter || AddBefore) + if (Operation != Move && Operation != ReplaceOrInsert) + badUsage("the 'a', 'b' and 'i' modifiers can only be specified with " + "the 'm' or 'r' operations"); + if (CountParam) + if (Operation != Extract && Operation != Delete) + badUsage("the 'N' modifier can only be specified with the 'x' or 'd' " + "operations"); + if (OriginalDates && Operation != Extract) + badUsage("the 'o' modifier is only applicable to the 'x' operation"); + if (OnlyUpdate && Operation != ReplaceOrInsert) + badUsage("the 'u' modifier is only applicable to the 'r' operation"); + if (AddLibrary && Operation != QuickAppend) + badUsage("the 'L' modifier is only applicable to the 'q' operation"); + + if (!OutputDir.empty()) { + if (Operation != Extract) + badUsage("--output is only applicable to the 'x' operation"); + bool IsDir = false; + // If OutputDir is not a directory, create_directories may still succeed if + // all components of the path prefix are directories. Test is_directory as + // well. + if (!sys::fs::create_directories(OutputDir)) + sys::fs::is_directory(OutputDir, IsDir); + if (!IsDir) + fail("'" + OutputDir + "' is not a directory"); + } + + // Return the parsed operation to the caller + return Operation; +} + +// Implements the 'p' operation. This function traverses the archive +// looking for members that match the path list. +static void doPrint(StringRef Name, const object::Archive::Child &C) { + if (Verbose) + outs() << "Printing " << Name << "\n"; + + Expected DataOrErr = C.getBuffer(); + failIfError(DataOrErr.takeError()); + StringRef Data = *DataOrErr; + outs().write(Data.data(), Data.size()); +} + +// Utility function for printing out the file mode when the 't' operation is in +// verbose mode. +static void printMode(unsigned mode) { + outs() << ((mode & 004) ? "r" : "-"); + outs() << ((mode & 002) ? "w" : "-"); + outs() << ((mode & 001) ? "x" : "-"); +} + +// Implement the 't' operation. This function prints out just +// the file names of each of the members. However, if verbose mode is requested +// ('v' modifier) then the file type, permission mode, user, group, size, and +// modification time are also printed. +static void doDisplayTable(StringRef Name, const object::Archive::Child &C) { + if (Verbose) { + Expected ModeOrErr = C.getAccessMode(); + failIfError(ModeOrErr.takeError()); + sys::fs::perms Mode = ModeOrErr.get(); + printMode((Mode >> 6) & 007); + printMode((Mode >> 3) & 007); + printMode(Mode & 007); + Expected UIDOrErr = C.getUID(); + failIfError(UIDOrErr.takeError()); + outs() << ' ' << UIDOrErr.get(); + Expected GIDOrErr = C.getGID(); + failIfError(GIDOrErr.takeError()); + outs() << '/' << GIDOrErr.get(); + Expected Size = C.getSize(); + failIfError(Size.takeError()); + outs() << ' ' << format("%6llu", Size.get()); + auto ModTimeOrErr = C.getLastModified(); + failIfError(ModTimeOrErr.takeError()); + // Note: formatv() only handles the default TimePoint<>, which is in + // nanoseconds. + // TODO: fix format_provider> to allow other units. + sys::TimePoint<> ModTimeInNs = ModTimeOrErr.get(); + outs() << ' ' << formatv("{0:%b %e %H:%M %Y}", ModTimeInNs); + outs() << ' '; + } + + if (C.getParent()->isThin()) { + if (!sys::path::is_absolute(Name)) { + StringRef ParentDir = sys::path::parent_path(ArchiveName); + if (!ParentDir.empty()) + outs() << sys::path::convert_to_slash(ParentDir) << '/'; + } + outs() << Name; + } else { + outs() << Name; + if (DisplayMemberOffsets) + outs() << " 0x" << utohexstr(C.getDataOffset(), true); + } + outs() << '\n'; +} + +static std::string normalizePath(StringRef Path) { + return CompareFullPath ? sys::path::convert_to_slash(Path) + : std::string(sys::path::filename(Path)); +} + +static bool comparePaths(StringRef Path1, StringRef Path2) { +// When on Windows this function calls CompareStringOrdinal +// as Windows file paths are case-insensitive. +// CompareStringOrdinal compares two Unicode strings for +// binary equivalence and allows for case insensitivity. +#ifdef _WIN32 + SmallVector WPath1, WPath2; + failIfError(sys::windows::UTF8ToUTF16(normalizePath(Path1), WPath1)); + failIfError(sys::windows::UTF8ToUTF16(normalizePath(Path2), WPath2)); + + return CompareStringOrdinal(WPath1.data(), WPath1.size(), WPath2.data(), + WPath2.size(), true) == CSTR_EQUAL; +#else + return normalizePath(Path1) == normalizePath(Path2); +#endif +} + +// Implement the 'x' operation. This function extracts files back to the file +// system. +static void doExtract(StringRef Name, const object::Archive::Child &C) { + // Retain the original mode. + Expected ModeOrErr = C.getAccessMode(); + failIfError(ModeOrErr.takeError()); + sys::fs::perms Mode = ModeOrErr.get(); + + StringRef outputFilePath; + SmallString<128> path; + if (OutputDir.empty()) { + outputFilePath = sys::path::filename(Name); + } else { + sys::path::append(path, OutputDir, sys::path::filename(Name)); + outputFilePath = path.str(); + } + + if (Verbose) + outs() << "x - " << outputFilePath << '\n'; + + int FD; + failIfError(sys::fs::openFileForWrite(outputFilePath, FD, + sys::fs::CD_CreateAlways, + sys::fs::OF_None, Mode), + Name); + + { + raw_fd_ostream file(FD, false); + + // Get the data and its length + Expected BufOrErr = C.getBuffer(); + failIfError(BufOrErr.takeError()); + StringRef Data = BufOrErr.get(); + + // Write the data. + file.write(Data.data(), Data.size()); + } + + // If we're supposed to retain the original modification times, etc. do so + // now. + if (OriginalDates) { + auto ModTimeOrErr = C.getLastModified(); + failIfError(ModTimeOrErr.takeError()); + failIfError( + sys::fs::setLastAccessAndModificationTime(FD, ModTimeOrErr.get())); + } + + if (close(FD)) + fail("Could not close the file"); +} + +static bool shouldCreateArchive(ArchiveOperation Op) { + switch (Op) { + case Print: + case Delete: + case Move: + case DisplayTable: + case Extract: + case CreateSymTab: + return false; + + case QuickAppend: + case ReplaceOrInsert: + return true; + } + + llvm_unreachable("Missing entry in covered switch."); +} + +static bool isValidInBitMode(Binary &Bin) { + if (BitMode == BitModeTy::Bit32_64 || BitMode == BitModeTy::Any) + return true; + + if (SymbolicFile *SymFile = dyn_cast(&Bin)) { + bool Is64Bit = SymFile->is64Bit(); + if ((Is64Bit && (BitMode == BitModeTy::Bit32)) || + (!Is64Bit && (BitMode == BitModeTy::Bit64))) + return false; + } + // In AIX "ar", non-object files are always considered to have a valid bit + // mode. + return true; +} + +Expected> getAsBinary(const NewArchiveMember &NM, + LLVMContext *Context) { + auto BinaryOrErr = createBinary(NM.Buf->getMemBufferRef(), Context); + if (BinaryOrErr) + return std::move(*BinaryOrErr); + return BinaryOrErr.takeError(); +} + +Expected> getAsBinary(const Archive::Child &C, + LLVMContext *Context) { + return C.getAsBinary(Context); +} + +template static bool isValidInBitMode(const A &Member) { + if (object::Archive::getDefaultKindForHost() != object::Archive::K_AIXBIG) + return true; + LLVMContext Context; + Expected> BinOrErr = getAsBinary(Member, &Context); + // In AIX "ar", if there is a non-object file member, it is never ignored due + // to the bit mode setting. + if (!BinOrErr) { + consumeError(BinOrErr.takeError()); + return true; + } + return isValidInBitMode(*BinOrErr.get()); +} + +static void warnInvalidObjectForFileMode(Twine Name) { + warn("'" + Name + "' is not valid with the current object file mode"); +} + +static void performReadOperation(ArchiveOperation Operation, + object::Archive *OldArchive) { + if (Operation == Extract && OldArchive->isThin()) + fail("extracting from a thin archive is not supported"); + + bool Filter = !Members.empty(); + StringMap MemberCount; + { + Error Err = Error::success(); + for (auto &C : OldArchive->children(Err)) { + Expected NameOrErr = C.getName(); + failIfError(NameOrErr.takeError()); + StringRef Name = NameOrErr.get(); + + // Check whether to ignore this object due to its bitness. + if (!isValidInBitMode(C)) + continue; + + if (Filter) { + auto I = find_if(Members, [Name](StringRef Path) { + return comparePaths(Name, Path); + }); + if (I == Members.end()) + continue; + if (CountParam && ++MemberCount[Name] != CountParam) + continue; + Members.erase(I); + } + + switch (Operation) { + default: + llvm_unreachable("Not a read operation"); + case Print: + doPrint(Name, C); + break; + case DisplayTable: + doDisplayTable(Name, C); + break; + case Extract: + doExtract(Name, C); + break; + } + } + failIfError(std::move(Err)); + } + + if (Members.empty()) + return; + for (StringRef Name : Members) + WithColor::error(errs(), ToolName) << "'" << Name << "' was not found\n"; + exit(1); +} + +static void addChildMember(std::vector &Members, + const object::Archive::Child &M, + bool FlattenArchive = false) { + Expected NMOrErr = + NewArchiveMember::getOldMember(M, Deterministic); + failIfError(NMOrErr.takeError()); + // If the child member we're trying to add is thin, use the path relative to + // the archive it's in, so the file resolves correctly. + if (Thin && FlattenArchive) { + StringSaver Saver(Alloc); + Expected FileNameOrErr(M.getName()); + failIfError(FileNameOrErr.takeError()); + if (sys::path::is_absolute(*FileNameOrErr)) { + NMOrErr->MemberName = Saver.save(sys::path::convert_to_slash(*FileNameOrErr)); + } else { + FileNameOrErr = M.getFullName(); + failIfError(FileNameOrErr.takeError()); + Expected PathOrErr = + computeArchiveRelativePath(ArchiveName, *FileNameOrErr); + NMOrErr->MemberName = Saver.save( + PathOrErr ? *PathOrErr : sys::path::convert_to_slash(*FileNameOrErr)); + } + } + if (FlattenArchive && + identify_magic(NMOrErr->Buf->getBuffer()) == file_magic::archive) { + Expected FileNameOrErr = M.getFullName(); + failIfError(FileNameOrErr.takeError()); + object::Archive &Lib = readLibrary(*FileNameOrErr); + // When creating thin archives, only flatten if the member is also thin. + if (!Thin || Lib.isThin()) { + Error Err = Error::success(); + // Only Thin archives are recursively flattened. + for (auto &Child : Lib.children(Err)) + addChildMember(Members, Child, /*FlattenArchive=*/Thin); + failIfError(std::move(Err)); + return; + } + } + Members.push_back(std::move(*NMOrErr)); +} + +static NewArchiveMember getArchiveMember(StringRef FileName) { + Expected NMOrErr = + NewArchiveMember::getFile(FileName, Deterministic); + failIfError(NMOrErr.takeError(), FileName); + StringSaver Saver(Alloc); + // For regular archives, use the basename of the object path for the member + // name. For thin archives, use the full relative paths so the file resolves + // correctly. + if (!Thin) { + NMOrErr->MemberName = sys::path::filename(NMOrErr->MemberName); + } else { + if (sys::path::is_absolute(FileName)) + NMOrErr->MemberName = Saver.save(sys::path::convert_to_slash(FileName)); + else { + Expected PathOrErr = + computeArchiveRelativePath(ArchiveName, FileName); + NMOrErr->MemberName = Saver.save( + PathOrErr ? *PathOrErr : sys::path::convert_to_slash(FileName)); + } + } + return std::move(*NMOrErr); +} + +static void addMember(std::vector &Members, + NewArchiveMember &NM) { + Members.push_back(std::move(NM)); +} + +static void addMember(std::vector &Members, + StringRef FileName, bool FlattenArchive = false) { + NewArchiveMember NM = getArchiveMember(FileName); + if (!isValidInBitMode(NM)) { + warnInvalidObjectForFileMode(FileName); + return; + } + + if (FlattenArchive && + identify_magic(NM.Buf->getBuffer()) == file_magic::archive) { + object::Archive &Lib = readLibrary(FileName); + // When creating thin archives, only flatten if the member is also thin. + if (!Thin || Lib.isThin()) { + Error Err = Error::success(); + // Only Thin archives are recursively flattened. + for (auto &Child : Lib.children(Err)) + addChildMember(Members, Child, /*FlattenArchive=*/Thin); + failIfError(std::move(Err)); + return; + } + } + Members.push_back(std::move(NM)); +} + +enum InsertAction { + IA_AddOldMember, + IA_AddNewMember, + IA_Delete, + IA_MoveOldMember, + IA_MoveNewMember +}; + +static InsertAction computeInsertAction(ArchiveOperation Operation, + const object::Archive::Child &Member, + StringRef Name, + std::vector::iterator &Pos, + StringMap &MemberCount) { + if (!isValidInBitMode(Member)) + return IA_AddOldMember; + + if (Operation == QuickAppend || Members.empty()) + return IA_AddOldMember; + + auto MI = find_if(Members, [Name](StringRef Path) { + if (Thin && !sys::path::is_absolute(Path)) { + Expected PathOrErr = + computeArchiveRelativePath(ArchiveName, Path); + return comparePaths(Name, PathOrErr ? *PathOrErr : Path); + } else { + return comparePaths(Name, Path); + } + }); + + if (MI == Members.end()) + return IA_AddOldMember; + + Pos = MI; + + if (Operation == Delete) { + if (CountParam && ++MemberCount[Name] != CountParam) + return IA_AddOldMember; + return IA_Delete; + } + + if (Operation == Move) + return IA_MoveOldMember; + + if (Operation == ReplaceOrInsert) { + if (!OnlyUpdate) { + if (RelPos.empty()) + return IA_AddNewMember; + return IA_MoveNewMember; + } + + // We could try to optimize this to a fstat, but it is not a common + // operation. + sys::fs::file_status Status; + failIfError(sys::fs::status(*MI, Status), *MI); + auto ModTimeOrErr = Member.getLastModified(); + failIfError(ModTimeOrErr.takeError()); + if (Status.getLastModificationTime() < ModTimeOrErr.get()) { + if (RelPos.empty()) + return IA_AddOldMember; + return IA_MoveOldMember; + } + + if (RelPos.empty()) + return IA_AddNewMember; + return IA_MoveNewMember; + } + llvm_unreachable("No such operation"); +} + +// We have to walk this twice and computing it is not trivial, so creating an +// explicit std::vector is actually fairly efficient. +static std::vector +computeNewArchiveMembers(ArchiveOperation Operation, + object::Archive *OldArchive) { + std::vector Ret; + std::vector Moved; + int InsertPos = -1; + if (OldArchive) { + Error Err = Error::success(); + StringMap MemberCount; + for (auto &Child : OldArchive->children(Err)) { + int Pos = Ret.size(); + Expected NameOrErr = Child.getName(); + failIfError(NameOrErr.takeError()); + std::string Name = std::string(NameOrErr.get()); + if (comparePaths(Name, RelPos) && isValidInBitMode(Child)) { + assert(AddAfter || AddBefore); + if (AddBefore) + InsertPos = Pos; + else + InsertPos = Pos + 1; + } + + std::vector::iterator MemberI = Members.end(); + InsertAction Action = + computeInsertAction(Operation, Child, Name, MemberI, MemberCount); + + auto HandleNewMember = [](auto Member, auto &Members, auto &Child) { + NewArchiveMember NM = getArchiveMember(*Member); + if (isValidInBitMode(NM)) + addMember(Members, NM); + else { + // If a new member is not a valid object for the bit mode, add + // the old member back. + warnInvalidObjectForFileMode(*Member); + addChildMember(Members, Child, /*FlattenArchive=*/Thin); + } + }; + + switch (Action) { + case IA_AddOldMember: + addChildMember(Ret, Child, /*FlattenArchive=*/Thin); + break; + case IA_AddNewMember: + HandleNewMember(MemberI, Ret, Child); + break; + case IA_Delete: + break; + case IA_MoveOldMember: + addChildMember(Moved, Child, /*FlattenArchive=*/Thin); + break; + case IA_MoveNewMember: + HandleNewMember(MemberI, Moved, Child); + break; + } + // When processing elements with the count param, we need to preserve the + // full members list when iterating over all archive members. For + // instance, "llvm-ar dN 2 archive.a member.o" should delete the second + // file named member.o it sees; we are not done with member.o the first + // time we see it in the archive. + if (MemberI != Members.end() && !CountParam) + Members.erase(MemberI); + } + failIfError(std::move(Err)); + } + + if (Operation == Delete) + return Ret; + + if (!RelPos.empty() && InsertPos == -1) + fail("insertion point not found"); + + if (RelPos.empty()) + InsertPos = Ret.size(); + + assert(unsigned(InsertPos) <= Ret.size()); + int Pos = InsertPos; + for (auto &M : Moved) { + Ret.insert(Ret.begin() + Pos, std::move(M)); + ++Pos; + } + + if (AddLibrary) { + assert(Operation == QuickAppend); + for (auto &Member : Members) + addMember(Ret, Member, /*FlattenArchive=*/true); + return Ret; + } + + std::vector NewMembers; + for (auto &Member : Members) + addMember(NewMembers, Member, /*FlattenArchive=*/Thin); + Ret.reserve(Ret.size() + NewMembers.size()); + std::move(NewMembers.begin(), NewMembers.end(), + std::inserter(Ret, std::next(Ret.begin(), InsertPos))); + + return Ret; +} + +static void performWriteOperation(ArchiveOperation Operation, + object::Archive *OldArchive, + std::unique_ptr OldArchiveBuf, + std::vector *NewMembersP) { + if (OldArchive) { + if (Thin && !OldArchive->isThin()) + fail("cannot convert a regular archive to a thin one"); + + if (OldArchive->isThin()) + Thin = true; + } + + std::vector NewMembers; + if (!NewMembersP) + NewMembers = computeNewArchiveMembers(Operation, OldArchive); + + object::Archive::Kind Kind; + switch (FormatType) { + case Default: + if (Thin) + Kind = object::Archive::K_GNU; + else if (OldArchive) { + Kind = OldArchive->kind(); + if (Kind == object::Archive::K_BSD) { + auto InferredKind = object::Archive::K_BSD; + if (NewMembersP && !NewMembersP->empty()) + InferredKind = NewMembersP->front().detectKindFromObject(); + else if (!NewMembers.empty()) + InferredKind = NewMembers.front().detectKindFromObject(); + if (InferredKind == object::Archive::K_DARWIN) + Kind = object::Archive::K_DARWIN; + } + } else if (NewMembersP) + Kind = !NewMembersP->empty() ? NewMembersP->front().detectKindFromObject() + : object::Archive::getDefaultKindForHost(); + else + Kind = !NewMembers.empty() ? NewMembers.front().detectKindFromObject() + : object::Archive::getDefaultKindForHost(); + break; + case GNU: + Kind = object::Archive::K_GNU; + break; + case BSD: + if (Thin) + fail("only the gnu format has a thin mode"); + Kind = object::Archive::K_BSD; + break; + case DARWIN: + if (Thin) + fail("only the gnu format has a thin mode"); + Kind = object::Archive::K_DARWIN; + break; + case BIGARCHIVE: + if (Thin) + fail("only the gnu format has a thin mode"); + Kind = object::Archive::K_AIXBIG; + break; + case Unknown: + llvm_unreachable(""); + } + + Error E = + writeArchive(ArchiveName, NewMembersP ? *NewMembersP : NewMembers, Symtab, + Kind, Deterministic, Thin, std::move(OldArchiveBuf)); + failIfError(std::move(E), ArchiveName); +} + +static void createSymbolTable(object::Archive *OldArchive) { + // When an archive is created or modified, if the s option is given, the + // resulting archive will have a current symbol table. If the S option + // is given, it will have no symbol table. + // In summary, we only need to update the symbol table if we have none. + // This is actually very common because of broken build systems that think + // they have to run ranlib. + if (OldArchive->hasSymbolTable()) + return; + + if (OldArchive->isThin()) + Thin = true; + performWriteOperation(CreateSymTab, OldArchive, nullptr, nullptr); +} + +static void performOperation(ArchiveOperation Operation, + object::Archive *OldArchive, + std::unique_ptr OldArchiveBuf, + std::vector *NewMembers) { + switch (Operation) { + case Print: + case DisplayTable: + case Extract: + performReadOperation(Operation, OldArchive); + return; + + case Delete: + case Move: + case QuickAppend: + case ReplaceOrInsert: + performWriteOperation(Operation, OldArchive, std::move(OldArchiveBuf), + NewMembers); + return; + case CreateSymTab: + createSymbolTable(OldArchive); + return; + } + llvm_unreachable("Unknown operation."); +} + +static int performOperation(ArchiveOperation Operation) { + // Create or open the archive object. + ErrorOr> Buf = MemoryBuffer::getFile( + ArchiveName, /*IsText=*/false, /*RequiresNullTerminator=*/false); + std::error_code EC = Buf.getError(); + if (EC && EC != errc::no_such_file_or_directory) + fail("unable to open '" + ArchiveName + "': " + EC.message()); + + if (!EC) { + Expected> ArchiveOrError = + object::Archive::create(Buf.get()->getMemBufferRef()); + if (!ArchiveOrError) + failIfError(ArchiveOrError.takeError(), + "unable to load '" + ArchiveName + "'"); + + std::unique_ptr Archive = std::move(ArchiveOrError.get()); + if (Archive->isThin()) + CompareFullPath = true; + performOperation(Operation, Archive.get(), std::move(Buf.get()), + /*NewMembers=*/nullptr); + return 0; + } + + assert(EC == errc::no_such_file_or_directory); + + if (!shouldCreateArchive(Operation)) { + failIfError(EC, Twine("unable to load '") + ArchiveName + "'"); + } else { + if (!Create) { + // Produce a warning if we should and we're creating the archive + warn("creating " + ArchiveName); + } + } + + performOperation(Operation, nullptr, nullptr, /*NewMembers=*/nullptr); + return 0; +} + +static void runMRIScript() { + enum class MRICommand { AddLib, AddMod, Create, CreateThin, Delete, Save, End, Invalid }; + + ErrorOr> Buf = MemoryBuffer::getSTDIN(); + failIfError(Buf.getError()); + const MemoryBuffer &Ref = *Buf.get(); + bool Saved = false; + std::vector NewMembers; + ParsingMRIScript = true; + + for (line_iterator I(Ref, /*SkipBlanks*/ false), E; I != E; ++I) { + ++MRILineNumber; + StringRef Line = *I; + Line = Line.split(';').first; + Line = Line.split('*').first; + Line = Line.trim(); + if (Line.empty()) + continue; + StringRef CommandStr, Rest; + std::tie(CommandStr, Rest) = Line.split(' '); + Rest = Rest.trim(); + if (!Rest.empty() && Rest.front() == '"' && Rest.back() == '"') + Rest = Rest.drop_front().drop_back(); + auto Command = StringSwitch(CommandStr.lower()) + .Case("addlib", MRICommand::AddLib) + .Case("addmod", MRICommand::AddMod) + .Case("create", MRICommand::Create) + .Case("createthin", MRICommand::CreateThin) + .Case("delete", MRICommand::Delete) + .Case("save", MRICommand::Save) + .Case("end", MRICommand::End) + .Default(MRICommand::Invalid); + + switch (Command) { + case MRICommand::AddLib: { + if (!Create) + fail("no output archive has been opened"); + object::Archive &Lib = readLibrary(Rest); + { + if (Thin && !Lib.isThin()) + fail("cannot add a regular archive's contents to a thin archive"); + Error Err = Error::success(); + for (auto &Member : Lib.children(Err)) + addChildMember(NewMembers, Member, /*FlattenArchive=*/Thin); + failIfError(std::move(Err)); + } + break; + } + case MRICommand::AddMod: + if (!Create) + fail("no output archive has been opened"); + addMember(NewMembers, Rest); + break; + case MRICommand::CreateThin: + Thin = true; + [[fallthrough]]; + case MRICommand::Create: + Create = true; + if (!ArchiveName.empty()) + fail("editing multiple archives not supported"); + if (Saved) + fail("file already saved"); + ArchiveName = std::string(Rest); + if (ArchiveName.empty()) + fail("missing archive name"); + break; + case MRICommand::Delete: { + llvm::erase_if(NewMembers, [=](NewArchiveMember &M) { + return comparePaths(M.MemberName, Rest); + }); + break; + } + case MRICommand::Save: + Saved = true; + break; + case MRICommand::End: + break; + case MRICommand::Invalid: + fail("unknown command: " + CommandStr); + } + } + + ParsingMRIScript = false; + + // Nothing to do if not saved. + if (Saved) + performOperation(ReplaceOrInsert, /*OldArchive=*/nullptr, + /*OldArchiveBuf=*/nullptr, &NewMembers); + exit(0); +} + +static bool handleGenericOption(StringRef arg) { + if (arg == "--help" || arg == "-h") { + printHelpMessage(); + return true; + } + if (arg == "--version") { + cl::PrintVersionMessage(); + return true; + } + return false; +} + +static BitModeTy getBitMode(const char *RawBitMode) { + return StringSwitch(RawBitMode) + .Case("32", BitModeTy::Bit32) + .Case("64", BitModeTy::Bit64) + .Case("32_64", BitModeTy::Bit32_64) + .Case("any", BitModeTy::Any) + .Default(BitModeTy::Unknown); +} + +static const char *matchFlagWithArg(StringRef Expected, + ArrayRef::iterator &ArgIt, + ArrayRef Args) { + StringRef Arg = *ArgIt; + + if (Arg.startswith("--")) + Arg = Arg.substr(2); + + size_t len = Expected.size(); + if (Arg == Expected) { + if (++ArgIt == Args.end()) + fail(std::string(Expected) + " requires an argument"); + + return *ArgIt; + } + if (Arg.startswith(Expected) && Arg.size() > len && Arg[len] == '=') + return Arg.data() + len + 1; + + return nullptr; +} + +static cl::TokenizerCallback getRspQuoting(ArrayRef ArgsArr) { + cl::TokenizerCallback Ret = + Triple(sys::getProcessTriple()).getOS() == Triple::Win32 + ? cl::TokenizeWindowsCommandLine + : cl::TokenizeGNUCommandLine; + + for (ArrayRef::iterator ArgIt = ArgsArr.begin(); + ArgIt != ArgsArr.end(); ++ArgIt) { + if (const char *Match = matchFlagWithArg("rsp-quoting", ArgIt, ArgsArr)) { + StringRef MatchRef = Match; + if (MatchRef == "posix") + Ret = cl::TokenizeGNUCommandLine; + else if (MatchRef == "windows") + Ret = cl::TokenizeWindowsCommandLine; + else + fail(std::string("Invalid response file quoting style ") + Match); + } + } + + return Ret; +} + +static int ar_main(int argc, char **argv) { + SmallVector Argv(argv + 1, argv + argc); + StringSaver Saver(Alloc); + + cl::ExpandResponseFiles(Saver, getRspQuoting(ArrayRef(argv, argc)), Argv); + + // Get BitMode from enviorment variable "OBJECT_MODE" for AIX OS, if + // specified. + if (object::Archive::getDefaultKindForHost() == object::Archive::K_AIXBIG) { + BitMode = getBitMode(getenv("OBJECT_MODE")); + if (BitMode == BitModeTy::Unknown) + BitMode = BitModeTy::Bit32; + } + + for (ArrayRef::iterator ArgIt = Argv.begin(); + ArgIt != Argv.end(); ++ArgIt) { + const char *Match = nullptr; + + if (handleGenericOption(*ArgIt)) + return 0; + if (strcmp(*ArgIt, "--") == 0) { + ++ArgIt; + for (; ArgIt != Argv.end(); ++ArgIt) + PositionalArgs.push_back(*ArgIt); + break; + } + + if (*ArgIt[0] != '-') { + if (Options.empty()) + Options += *ArgIt; + else + PositionalArgs.push_back(*ArgIt); + continue; + } + + if (strcmp(*ArgIt, "-M") == 0) { + MRI = true; + continue; + } + + if (strcmp(*ArgIt, "--thin") == 0) { + Thin = true; + continue; + } + + Match = matchFlagWithArg("format", ArgIt, Argv); + if (Match) { + FormatType = StringSwitch(Match) + .Case("default", Default) + .Case("gnu", GNU) + .Case("darwin", DARWIN) + .Case("bsd", BSD) + .Case("bigarchive", BIGARCHIVE) + .Default(Unknown); + if (FormatType == Unknown) + fail(std::string("Invalid format ") + Match); + continue; + } + + if ((Match = matchFlagWithArg("output", ArgIt, Argv))) { + OutputDir = Match; + continue; + } + + if (matchFlagWithArg("plugin", ArgIt, Argv) || + matchFlagWithArg("rsp-quoting", ArgIt, Argv)) + continue; + + if (strncmp(*ArgIt, "-X", 2) == 0) { + if (object::Archive::getDefaultKindForHost() == + object::Archive::K_AIXBIG) { + Match = *(*ArgIt + 2) != '\0' ? *ArgIt + 2 : *(++ArgIt); + BitMode = getBitMode(Match); + if (BitMode == BitModeTy::Unknown) + fail(Twine("invalid bit mode: ") + Match); + continue; + } else { + fail(Twine(*ArgIt) + " option not supported on non AIX OS"); + } + } + + Options += *ArgIt + 1; + } + + return performOperation(parseCommandLine()); +} + +static int ranlib_main(int argc, char **argv) { + std::vector Archives; + for (int i = 1; i < argc; ++i) { + StringRef arg(argv[i]); + if (handleGenericOption(arg)) { + return 0; + } else if (arg.consume_front("-")) { + // Handle the -D/-U flag + while (!arg.empty()) { + if (arg.front() == 'D') { + Deterministic = true; + } else if (arg.front() == 'U') { + Deterministic = false; + } else if (arg.front() == 'h') { + printHelpMessage(); + return 0; + } else if (arg.front() == 'v') { + cl::PrintVersionMessage(); + return 0; + } else { + // TODO: GNU ranlib also supports a -t flag + fail("Invalid option: '-" + arg + "'"); + } + arg = arg.drop_front(1); + } + } else { + Archives.push_back(arg); + } + } + + for (StringRef Archive : Archives) { + ArchiveName = Archive.str(); + performOperation(CreateSymTab); + } + if (Archives.empty()) + badUsage("an archive name must be specified"); + return 0; +} + +static int llvm_ar_main(int argc, char **argv, const llvm::ToolContext &) { + // ZIG PATCH: On Windows, InitLLVM calls GetCommandLineW(), + // and overwrites the args. We don't want it to do that, + // and we also don't need the signal handlers it installs + // (we have our own already), so we just use llvm_shutdown_obj + // instead. + // InitLLVM X(argc, argv); + llvm::llvm_shutdown_obj X; + + ToolName = argv[0]; + + llvm::InitializeAllTargetInfos(); + llvm::InitializeAllTargetMCs(); + llvm::InitializeAllAsmParsers(); + + Stem = sys::path::stem(ToolName); + auto Is = [](StringRef Tool) { + // We need to recognize the following filenames. + // + // Lib.exe -> lib (see D44808, MSBuild runs Lib.exe) + // dlltool.exe -> dlltool + // arm-pokymllib32-linux-gnueabi-llvm-ar-10 -> ar + auto I = Stem.rfind_insensitive(Tool); + return I != StringRef::npos && + (I + Tool.size() == Stem.size() || !isAlnum(Stem[I + Tool.size()])); + }; + + if (Is("dlltool")) + return dlltoolDriverMain(ArrayRef(argv, argc)); + if (Is("ranlib")) + return ranlib_main(argc, argv); + if (Is("lib")) + return libDriverMain(ArrayRef(argv, argc)); + if (Is("ar")) + return ar_main(argc, argv); + + fail("not ranlib, ar, lib or dlltool"); +} + +extern "C" int NativityLLVMArchiverMain(int argc, char ** argv) { + return llvm_ar_main(argc, argv, {argv[0], nullptr, false}); +} diff --git a/src/llvm/lld.cpp b/src/llvm/lld.cpp index 4b38073..5de9616 100644 --- a/src/llvm/lld.cpp +++ b/src/llvm/lld.cpp @@ -28,7 +28,7 @@ namespace lld { extern "C" void stream_to_string(raw_string_ostream& stream, const char** message_ptr, size_t* message_len); -extern "C" bool NativityLLDLink(Format format, const char** argument_ptr, size_t argument_count, const char** stdout_ptr, size_t* stdout_len, const char** stderr_ptr, size_t* stderr_len) +extern "C" bool NativityLLDLinkELF(const char** argument_ptr, size_t argument_count, const char** stdout_ptr, size_t* stdout_len, const char** stderr_ptr, size_t* stderr_len) { auto arguments = ArrayRef(argument_ptr, argument_count); std::string stdout_string; @@ -37,18 +37,7 @@ extern "C" bool NativityLLDLink(Format format, const char** argument_ptr, size_t std::string stderr_string; raw_string_ostream stderr_stream(stderr_string); - bool success = false; - switch (format) { - case Format::elf: - success = lld::elf::link(arguments, stdout_stream, stderr_stream, true, false); - break; - case Format::coff: - success = lld::coff::link(arguments, stdout_stream, stderr_stream, true, false); - case Format::macho: - success = lld::macho::link(arguments, stdout_stream, stderr_stream, true, false); - default: - break; - } + bool success = lld::elf::link(arguments, stdout_stream, stderr_stream, true, false); stream_to_string(stdout_stream, stdout_ptr, stdout_len); stream_to_string(stderr_stream, stderr_ptr, stderr_len); @@ -56,3 +45,53 @@ extern "C" bool NativityLLDLink(Format format, const char** argument_ptr, size_t return success; } +extern "C" bool NativityLLDLinkCOFF(const char** argument_ptr, size_t argument_count, const char** stdout_ptr, size_t* stdout_len, const char** stderr_ptr, size_t* stderr_len) +{ + auto arguments = ArrayRef(argument_ptr, argument_count); + std::string stdout_string; + raw_string_ostream stdout_stream(stdout_string); + + std::string stderr_string; + raw_string_ostream stderr_stream(stderr_string); + + bool success = lld::coff::link(arguments, stdout_stream, stderr_stream, true, false); + + stream_to_string(stdout_stream, stdout_ptr, stdout_len); + stream_to_string(stderr_stream, stderr_ptr, stderr_len); + + return success; +} + +extern "C" bool NativityLLDLinkMachO(const char** argument_ptr, size_t argument_count, const char** stdout_ptr, size_t* stdout_len, const char** stderr_ptr, size_t* stderr_len) +{ + auto arguments = ArrayRef(argument_ptr, argument_count); + std::string stdout_string; + raw_string_ostream stdout_stream(stdout_string); + + std::string stderr_string; + raw_string_ostream stderr_stream(stderr_string); + + bool success = lld::macho::link(arguments, stdout_stream, stderr_stream, true, false); + + stream_to_string(stdout_stream, stdout_ptr, stdout_len); + stream_to_string(stderr_stream, stderr_ptr, stderr_len); + + return success; +} + +extern "C" bool NativityLLDLinkWasm(const char** argument_ptr, size_t argument_count, const char** stdout_ptr, size_t* stdout_len, const char** stderr_ptr, size_t* stderr_len) +{ + auto arguments = ArrayRef(argument_ptr, argument_count); + std::string stdout_string; + raw_string_ostream stdout_stream(stdout_string); + + std::string stderr_string; + raw_string_ostream stderr_stream(stderr_string); + + bool success = lld::wasm::link(arguments, stdout_stream, stderr_stream, true, false); + + stream_to_string(stdout_stream, stdout_ptr, stdout_len); + stream_to_string(stderr_stream, stderr_ptr, stderr_len); + + return success; +}