diff --git a/lib/libc/glibc/abi.txt b/lib/libc/glibc/abi.txt index 089b9c077e..4d8d6f5255 100644 --- a/lib/libc/glibc/abi.txt +++ b/lib/libc/glibc/abi.txt @@ -193,6 +193,7 @@ aarch64-linux-gnu aarch64_be-linux-gnu 29 + 29 29 @@ -514,6 +515,7 @@ aarch64-linux-gnu aarch64_be-linux-gnu 29 29 29 +29 29 @@ -697,6 +699,7 @@ aarch64-linux-gnu aarch64_be-linux-gnu 29 29 29 + 29 29 29 @@ -819,6 +822,7 @@ aarch64-linux-gnu aarch64_be-linux-gnu 29 29 29 +29 29 29 @@ -904,6 +908,9 @@ aarch64-linux-gnu aarch64_be-linux-gnu 29 29 29 +29 + + 29 29 29 @@ -1004,6 +1011,7 @@ aarch64-linux-gnu aarch64_be-linux-gnu 29 29 29 +29 29 29 @@ -1033,6 +1041,7 @@ aarch64-linux-gnu aarch64_be-linux-gnu 29 29 29 +29 29 29 @@ -3920,6 +3929,7 @@ s390x-linux-gnu 5 + 27 27 @@ -4241,6 +4251,7 @@ s390x-linux-gnu 5 5 5 +5 11 27 @@ -4424,6 +4435,7 @@ s390x-linux-gnu 19 19 5 + 5 5 28 @@ -4543,6 +4555,7 @@ s390x-linux-gnu 27 16 + 5 5 15 @@ -4631,6 +4644,9 @@ s390x-linux-gnu 16 5 5 + + +12 5 5 5 @@ -4731,6 +4747,7 @@ s390x-linux-gnu 5 5 5 +5 5 5 @@ -4756,6 +4773,7 @@ s390x-linux-gnu 5 5 5 +5 31 5 24 5 12 16 24 5 12 16 @@ -7645,6 +7663,7 @@ arm-linux-gnueabi armeb-linux-gnueabi arm-linux-gnueabihf armeb-linux-gnueabihf + 27 @@ -7968,6 +7987,7 @@ arm-linux-gnueabi armeb-linux-gnueabi arm-linux-gnueabihf armeb-linux-gnueabihf 16 16 16 +16 27 @@ -8151,6 +8171,7 @@ arm-linux-gnueabi armeb-linux-gnueabi arm-linux-gnueabihf armeb-linux-gnueabihf 19 19 16 + 16 16 28 @@ -8273,6 +8294,7 @@ arm-linux-gnueabi armeb-linux-gnueabi arm-linux-gnueabihf armeb-linux-gnueabihf 16 16 16 +16 16 16 @@ -8358,6 +8380,9 @@ arm-linux-gnueabi armeb-linux-gnueabi arm-linux-gnueabihf armeb-linux-gnueabihf 16 16 16 +16 + + 16 16 16 @@ -8458,6 +8483,7 @@ arm-linux-gnueabi armeb-linux-gnueabi arm-linux-gnueabihf armeb-linux-gnueabihf 16 16 16 +16 16 16 @@ -8484,6 +8510,7 @@ arm-linux-gnueabi armeb-linux-gnueabi arm-linux-gnueabihf armeb-linux-gnueabihf 16 16 16 +16 24 16 24 16 16 @@ -11374,6 +11401,7 @@ sparc-linux-gnu sparcel-linux-gnu 0 + 27 27 @@ -11693,6 +11721,7 @@ sparc-linux-gnu sparcel-linux-gnu 0 0 1 +1 0 0 3 11 @@ -11878,6 +11907,7 @@ sparc-linux-gnu sparcel-linux-gnu 19 19 0 + 0 1 28 @@ -11997,6 +12027,7 @@ sparc-linux-gnu sparcel-linux-gnu 33 16 + 5 0 15 @@ -12085,6 +12116,9 @@ sparc-linux-gnu sparcel-linux-gnu 16 0 0 +12 + + 1 1 1 @@ -12183,6 +12217,7 @@ sparc-linux-gnu sparcel-linux-gnu 1 1 1 +1 0 0 @@ -12207,6 +12242,7 @@ sparc-linux-gnu sparcel-linux-gnu 0 0 0 +0 5 0 0 @@ -15101,6 +15137,7 @@ sparcv9-linux-gnu 5 5 + 27 27 @@ -15422,6 +15459,7 @@ sparcv9-linux-gnu 5 5 5 +5 11 27 @@ -15605,6 +15643,7 @@ sparcv9-linux-gnu 19 19 5 + 5 5 28 @@ -15724,6 +15763,7 @@ sparcv9-linux-gnu 27 16 + 5 5 15 @@ -15812,6 +15852,9 @@ sparcv9-linux-gnu 16 5 5 +12 + + 5 5 5 @@ -15912,6 +15955,7 @@ sparcv9-linux-gnu 5 5 5 +5 5 5 @@ -15938,6 +15982,7 @@ sparcv9-linux-gnu 5 5 5 +5 24 28 5 12 16 24 28 5 12 16 5 14 @@ -18828,6 +18873,7 @@ mips64el-linux-gnuabi64 mips64-linux-gnuabi64 0 + 27 27 @@ -19147,6 +19193,7 @@ mips64el-linux-gnuabi64 mips64-linux-gnuabi64 0 0 5 +5 0 0 11 @@ -19332,6 +19379,7 @@ mips64el-linux-gnuabi64 mips64-linux-gnuabi64 19 19 0 + 0 5 28 @@ -19450,6 +19498,7 @@ mips64el-linux-gnuabi64 mips64-linux-gnuabi64 27 27 +16 16 5 0 @@ -19539,6 +19588,9 @@ mips64el-linux-gnuabi64 mips64-linux-gnuabi64 16 0 0 +12 + + 5 5 5 @@ -19637,6 +19689,7 @@ mips64el-linux-gnuabi64 mips64-linux-gnuabi64 5 5 5 +5 0 0 0 @@ -19661,6 +19714,7 @@ mips64el-linux-gnuabi64 mips64-linux-gnuabi64 0 0 0 +0 5 0 0 @@ -22555,6 +22609,7 @@ mips64el-linux-gnuabin32 mips64-linux-gnuabin32 0 + 27 27 @@ -22874,6 +22929,7 @@ mips64el-linux-gnuabin32 mips64-linux-gnuabin32 0 0 5 +5 0 0 11 @@ -23059,6 +23115,7 @@ mips64el-linux-gnuabin32 mips64-linux-gnuabin32 19 19 0 + 0 5 28 @@ -23177,6 +23234,7 @@ mips64el-linux-gnuabin32 mips64-linux-gnuabin32 27 27 +16 16 5 0 @@ -23266,6 +23324,9 @@ mips64el-linux-gnuabin32 mips64-linux-gnuabin32 16 0 0 +12 + + 5 5 5 @@ -23364,6 +23425,7 @@ mips64el-linux-gnuabin32 mips64-linux-gnuabin32 5 5 5 +5 0 0 0 @@ -23388,6 +23450,7 @@ mips64el-linux-gnuabin32 mips64-linux-gnuabin32 0 0 0 +0 5 0 0 @@ -26282,6 +26345,7 @@ mipsel-linux-gnueabihf mips-linux-gnueabihf 0 + 27 27 @@ -26601,6 +26665,7 @@ mipsel-linux-gnueabihf mips-linux-gnueabihf 0 0 5 +5 0 0 11 @@ -26786,6 +26851,7 @@ mipsel-linux-gnueabihf mips-linux-gnueabihf 19 19 0 + 0 5 28 @@ -26904,6 +26970,7 @@ mipsel-linux-gnueabihf mips-linux-gnueabihf 27 +16 16 5 0 @@ -26993,6 +27060,9 @@ mipsel-linux-gnueabihf mips-linux-gnueabihf 16 0 0 +12 + + 5 5 5 @@ -27091,6 +27161,7 @@ mipsel-linux-gnueabihf mips-linux-gnueabihf 5 5 5 +5 0 0 0 @@ -27115,6 +27186,7 @@ mipsel-linux-gnueabihf mips-linux-gnueabihf 0 0 0 +0 5 0 0 @@ -30009,6 +30081,7 @@ mipsel-linux-gnueabi mips-linux-gnueabi 0 + 27 27 @@ -30328,6 +30401,7 @@ mipsel-linux-gnueabi mips-linux-gnueabi 0 0 5 +5 0 0 11 @@ -30513,6 +30587,7 @@ mipsel-linux-gnueabi mips-linux-gnueabi 19 19 0 + 0 5 28 @@ -30631,6 +30706,7 @@ mipsel-linux-gnueabi mips-linux-gnueabi 27 +16 16 5 0 @@ -30720,6 +30796,9 @@ mipsel-linux-gnueabi mips-linux-gnueabi 16 0 0 +12 + + 5 5 5 @@ -30818,6 +30897,7 @@ mipsel-linux-gnueabi mips-linux-gnueabi 5 5 5 +5 0 0 0 @@ -30842,6 +30922,7 @@ mipsel-linux-gnueabi mips-linux-gnueabi 0 0 0 +0 5 0 0 @@ -33734,6 +33815,7 @@ x86_64-linux-gnu + 27 @@ -34057,6 +34139,7 @@ x86_64-linux-gnu 10 10 10 +10 11 27 36 @@ -34240,6 +34323,7 @@ x86_64-linux-gnu 19 19 10 + 10 10 28 @@ -34359,6 +34443,7 @@ x86_64-linux-gnu 27 16 + 10 10 15 @@ -34447,6 +34532,9 @@ x86_64-linux-gnu 16 10 10 +12 + + 10 10 10 @@ -34547,6 +34635,7 @@ x86_64-linux-gnu 10 10 10 +10 10 10 @@ -34573,6 +34662,7 @@ x86_64-linux-gnu 10 10 10 +10 24 10 12 16 24 10 12 16 10 14 @@ -37461,6 +37551,7 @@ x86_64-linux-gnux32 + 28 @@ -37784,6 +37875,7 @@ x86_64-linux-gnux32 28 28 28 +28 28 36 @@ -37967,6 +38059,7 @@ x86_64-linux-gnux32 28 28 28 + 28 28 28 @@ -38086,6 +38179,7 @@ x86_64-linux-gnux32 28 28 + 28 28 28 @@ -38174,6 +38268,9 @@ x86_64-linux-gnux32 28 28 28 +28 + + 28 28 28 @@ -38274,6 +38371,7 @@ x86_64-linux-gnux32 28 28 28 +28 28 28 @@ -38303,6 +38401,7 @@ x86_64-linux-gnux32 28 28 28 +28 28 28 @@ -41190,6 +41289,7 @@ i386-linux-gnu 0 +12 27 36 27 @@ -41509,6 +41609,7 @@ i386-linux-gnu 0 0 1 +1 0 0 3 11 @@ -41694,6 +41795,7 @@ i386-linux-gnu 19 19 0 + 0 1 28 @@ -41813,6 +41915,7 @@ i386-linux-gnu 27 16 + 5 0 15 @@ -41901,6 +42004,9 @@ i386-linux-gnu 16 0 0 +12 + + 1 1 1 @@ -41999,6 +42105,7 @@ i386-linux-gnu 1 1 1 +1 0 0 @@ -42023,6 +42130,7 @@ i386-linux-gnu 0 0 0 +0 5 0 0 @@ -44915,6 +45023,7 @@ powerpc64le-linux-gnu + 29 @@ -45238,6 +45347,7 @@ powerpc64le-linux-gnu 29 29 29 +29 29 36 @@ -45421,6 +45531,7 @@ powerpc64le-linux-gnu 29 29 29 +33 29 29 29 @@ -45540,6 +45651,7 @@ powerpc64le-linux-gnu 29 29 + 29 29 29 @@ -45628,6 +45740,9 @@ powerpc64le-linux-gnu 29 29 29 +29 +32 + 29 29 29 @@ -45728,6 +45843,7 @@ powerpc64le-linux-gnu 29 29 29 +29 29 29 @@ -45757,6 +45873,7 @@ powerpc64le-linux-gnu 29 29 29 +29 29 29 @@ -48642,6 +48759,7 @@ powerpc64-linux-gnu + 27 @@ -48965,6 +49083,7 @@ powerpc64-linux-gnu 12 12 12 +12 27 @@ -49148,6 +49267,7 @@ powerpc64-linux-gnu 19 19 12 +33 12 12 28 @@ -49267,6 +49387,7 @@ powerpc64-linux-gnu 27 16 + 12 12 15 @@ -49355,6 +49476,9 @@ powerpc64-linux-gnu 16 12 12 +12 +32 + 12 12 12 @@ -49455,6 +49579,7 @@ powerpc64-linux-gnu 12 12 12 +12 12 12 @@ -49480,6 +49605,7 @@ powerpc64-linux-gnu 12 12 12 +12 12 15 24 12 16 24 12 16 @@ -52369,6 +52495,7 @@ powerpc-linux-gnueabi powerpc-linux-gnueabihf + 27 @@ -52690,6 +52817,7 @@ powerpc-linux-gnueabi powerpc-linux-gnueabihf 0 0 1 +1 0 0 3 11 @@ -52875,6 +53003,7 @@ powerpc-linux-gnueabi powerpc-linux-gnueabihf 19 19 0 +33 0 1 28 @@ -52994,6 +53123,7 @@ powerpc-linux-gnueabi powerpc-linux-gnueabihf 27 13 16 + 5 0 15 @@ -53082,6 +53212,9 @@ powerpc-linux-gnueabi powerpc-linux-gnueabihf 16 0 0 +12 +32 + 1 1 1 @@ -53180,6 +53313,7 @@ powerpc-linux-gnueabi powerpc-linux-gnueabihf 1 1 1 +1 0 0 @@ -53204,6 +53338,7 @@ powerpc-linux-gnueabi powerpc-linux-gnueabihf 0 0 0 +0 5 0 0 diff --git a/lib/libc/glibc/fns.txt b/lib/libc/glibc/fns.txt index 32dc37ce17..4e2e126b0e 100644 --- a/lib/libc/glibc/fns.txt +++ b/lib/libc/glibc/fns.txt @@ -192,6 +192,7 @@ _Qp_uitoq c _Qp_uxtoq c _Qp_xtoq c ___brk_addr c +___tls_get_addr ld __acos_finite m __acosf128_finite m __acosf_finite m @@ -511,6 +512,7 @@ __libc_memalign c __libc_pvalloc c __libc_realloc c __libc_sa_len c +__libc_stack_end ld __libc_start_main c __libc_valloc c __libpthread_version_placeholder pthread @@ -696,6 +698,7 @@ __open_2 c __openat64_2 c __openat_2 c __overflow c +__parse_hwcap_and_convert_at_platform ld __pipe c __poll c __poll_chk c @@ -815,6 +818,7 @@ __sqrtf_finite m __sqrtl_finite m __sqrtsf2 c __stack_chk_fail c +__stack_chk_guard ld __statfs c __stpcpy c __stpcpy_chk c @@ -903,6 +907,9 @@ __sysctl c __syslog_chk c __sysv_signal c __timezone c +__tls_get_addr ld +__tls_get_addr_opt ld +__tls_get_offset ld __toascii_l c __tolower_l c __toupper_l c @@ -999,6 +1006,7 @@ __ynf128_finite m __ynf_finite m __ynl_finite m _authenticate c +_dl_mcount ld _dl_mcount_wrapper c _dl_mcount_wrapper_check c _environ c @@ -1024,6 +1032,7 @@ _pthread_cleanup_pop pthread _pthread_cleanup_pop_restore pthread _pthread_cleanup_push pthread _pthread_cleanup_push_defer pthread +_r_debug ld _res c _res_hconf c _rpc_dtablesize c diff --git a/lib/std/debug.zig b/lib/std/debug.zig index 0a7a0dee7e..5600990924 100644 --- a/lib/std/debug.zig +++ b/lib/std/debug.zig @@ -235,9 +235,17 @@ pub fn panic(comptime format: []const u8, args: var) noreturn { panicExtra(null, first_trace_addr, format, args); } -/// TODO multithreaded awareness +/// Non-zero whenever the program triggered a panic. +/// The counter is incremented/decremented atomically. var panicking: u8 = 0; +// Locked to avoid interleaving panic messages from multiple threads. +var panic_mutex = std.Mutex.init(); + +/// Counts how many times the panic handler is invoked by this thread. +/// This is used to catch and handle panics triggered by the panic handler. +threadlocal var panic_stage: usize = 0; + pub fn panicExtra(trace: ?*const builtin.StackTrace, first_trace_addr: ?usize, comptime format: []const u8, args: var) noreturn { @setCold(true); @@ -247,25 +255,50 @@ pub fn panicExtra(trace: ?*const builtin.StackTrace, first_trace_addr: ?usize, c resetSegfaultHandler(); } - switch (@atomicRmw(u8, &panicking, .Add, 1, .SeqCst)) { + switch (panic_stage) { 0 => { - const stderr = getStderrStream(); - noasync stderr.print(format ++ "\n", args) catch os.abort(); - if (trace) |t| { - dumpStackTrace(t.*); + panic_stage = 1; + + _ = @atomicRmw(u8, &panicking, .Add, 1, .SeqCst); + + // Make sure to release the mutex when done + { + const held = panic_mutex.acquire(); + defer held.release(); + + const stderr = getStderrStream(); + noasync stderr.print(format ++ "\n", args) catch os.abort(); + if (trace) |t| { + dumpStackTrace(t.*); + } + dumpCurrentStackTrace(first_trace_addr); + } + + if (@atomicRmw(u8, &panicking, .Sub, 1, .SeqCst) != 1) { + // Another thread is panicking, wait for the last one to finish + // and call abort() + + // Sleep forever without hammering the CPU + var event = std.ResetEvent.init(); + event.wait(); + + unreachable; } - dumpCurrentStackTrace(first_trace_addr); }, 1 => { - // TODO detect if a different thread caused the panic, because in that case - // we would want to return here instead of calling abort, so that the thread - // which first called panic can finish printing a stack trace. - warn("Panicked during a panic. Aborting.\n", .{}); + panic_stage = 2; + + // A panic happened while trying to print a previous panic message, + // we're still holding the mutex but that's fine as we're going to + // call abort() + const stderr = getStderrStream(); + noasync stderr.print("Panicked during a panic. Aborting.\n", .{}) catch os.abort(); }, else => { // Panicked while printing "Panicked during a panic." }, } + os.abort(); } diff --git a/src-self-hosted/stage2.zig b/src-self-hosted/stage2.zig index a1d741bc9b..78aa278005 100644 --- a/src-self-hosted/stage2.zig +++ b/src-self-hosted/stage2.zig @@ -909,6 +909,7 @@ const Stage2Target = extern struct { os_builtin_str: ?[*:0]const u8, dynamic_linker: ?[*:0]const u8, + standard_dynamic_linker_path: ?[*:0]const u8, fn fromTarget(self: *Stage2Target, cross_target: CrossTarget) !void { const allocator = std.heap.c_allocator; @@ -1119,6 +1120,12 @@ const Stage2Target = extern struct { } }; + const std_dl = target.standardDynamicLinkerPath(); + const std_dl_z = if (std_dl.get()) |dl| + (try mem.dupeZ(std.heap.c_allocator, u8, dl)).ptr + else + null; + const cache_hash_slice = cache_hash.toOwnedSlice(); self.* = .{ .arch = @enumToInt(target.cpu.arch) + 1, // skip over ZigLLVM_UnknownArch @@ -1134,6 +1141,7 @@ const Stage2Target = extern struct { .is_native = cross_target.isNative(), .glibc_or_darwin_version = glibc_or_darwin_version, .dynamic_linker = dynamic_linker, + .standard_dynamic_linker_path = std_dl_z, }; } }; diff --git a/src/all_types.hpp b/src/all_types.hpp index 6719d78a92..3f143b35c1 100644 --- a/src/all_types.hpp +++ b/src/all_types.hpp @@ -2267,6 +2267,7 @@ struct CodeGen { Buf *zig_lib_dir; Buf *zig_std_dir; Buf *version_script_path; + Buf *override_soname; const char **llvm_argv; size_t llvm_argv_len; diff --git a/src/codegen.cpp b/src/codegen.cpp index 8fae16e551..c2ce2ac3eb 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -10510,6 +10510,7 @@ static Error check_cache(CodeGen *g, Buf *manifest_dir, Buf *digest) { cache_str(ch, g->libc->kernel32_lib_dir); } cache_buf_opt(ch, g->version_script_path); + cache_buf_opt(ch, g->override_soname); // gen_c_objects appends objects to g->link_objects which we want to include in the hash gen_c_objects(g); diff --git a/src/glibc.cpp b/src/glibc.cpp index da5c1d5290..75b77ec122 100644 --- a/src/glibc.cpp +++ b/src/glibc.cpp @@ -16,6 +16,7 @@ static const ZigGLibCLib glibc_libs[] = { {"pthread", 0}, {"dl", 2}, {"rt", 1}, + {"ld", 2}, }; Error glibc_load_metadata(ZigGLibCAbi **out_result, Buf *zig_lib_dir, bool verbose) { @@ -330,6 +331,8 @@ Error glibc_build_dummies_and_maps(CodeGen *g, const ZigGLibCAbi *glibc_abi, con return err; } + bool is_ld = (strcmp(lib->name, "ld") == 0); + CodeGen *child_gen = create_child_codegen(g, zig_file_path, OutTypeLib, nullptr, lib->name, progress_node); codegen_set_lib_version(child_gen, lib->sover, 0, 0); child_gen->is_dynamic = true; @@ -337,6 +340,13 @@ Error glibc_build_dummies_and_maps(CodeGen *g, const ZigGLibCAbi *glibc_abi, con child_gen->version_script_path = map_file_path; child_gen->enable_cache = false; child_gen->output_dir = dummy_dir; + if (is_ld) { + assert(g->zig_target->standard_dynamic_linker_path != nullptr); + Buf *ld_basename = buf_alloc(); + os_path_split(buf_create_from_str(g->zig_target->standard_dynamic_linker_path), + nullptr, ld_basename); + child_gen->override_soname = ld_basename; + } codegen_build_and_link(child_gen); } diff --git a/src/link.cpp b/src/link.cpp index 3f7772bb08..0ae47c8432 100644 --- a/src/link.cpp +++ b/src/link.cpp @@ -1651,7 +1651,6 @@ static void construct_linker_job_elf(LinkJob *lj) { bool is_lib = g->out_type == OutTypeLib; bool is_dyn_lib = g->is_dynamic && is_lib; - Buf *soname = nullptr; if (!g->have_dynamic_link) { if (g->zig_target->arch == ZigLLVM_arm || g->zig_target->arch == ZigLLVM_armeb || g->zig_target->arch == ZigLLVM_thumb || g->zig_target->arch == ZigLLVM_thumbeb) @@ -1662,15 +1661,13 @@ static void construct_linker_job_elf(LinkJob *lj) { } } else if (is_dyn_lib) { lj->args.append("-shared"); - - assert(buf_len(&g->bin_file_output_path) != 0); - soname = buf_sprintf("lib%s.so.%" ZIG_PRI_usize, buf_ptr(g->root_out_name), g->version_major); } if (target_requires_pie(g->zig_target) && g->out_type == OutTypeExe) { lj->args.append("-pie"); } + assert(buf_len(&g->bin_file_output_path) != 0); lj->args.append("-o"); lj->args.append(buf_ptr(&g->bin_file_output_path)); @@ -1740,6 +1737,9 @@ static void construct_linker_job_elf(LinkJob *lj) { } if (is_dyn_lib) { + Buf *soname = (g->override_soname == nullptr) ? + buf_sprintf("lib%s.so.%" ZIG_PRI_usize, buf_ptr(g->root_out_name), g->version_major) : + g->override_soname; lj->args.append("-soname"); lj->args.append(buf_ptr(soname)); diff --git a/src/stage2.h b/src/stage2.h index 24fd664b3c..9ba7e062b1 100644 --- a/src/stage2.h +++ b/src/stage2.h @@ -291,6 +291,7 @@ struct ZigTarget { size_t cache_hash_len; const char *os_builtin_str; const char *dynamic_linker; + const char *standard_dynamic_linker_path; }; // ABI warning diff --git a/tools/update_glibc.zig b/tools/update_glibc.zig index 84522aabe4..4a5b1751a2 100644 --- a/tools/update_glibc.zig +++ b/tools/update_glibc.zig @@ -20,6 +20,7 @@ const lib_names = [_][]const u8{ "m", "pthread", "rt", + "ld", }; // fpu/nofpu are hardcoded elsewhere, based on .gnueabi/.gnueabihf with an exception for .arm @@ -154,22 +155,24 @@ pub fn main() !void { const fn_set = &target_funcs_gop.kv.value.list; for (lib_names) |lib_name, lib_name_index| { - const basename = try fmt.allocPrint(allocator, "lib{}.abilist", .{lib_name}); + const lib_prefix = if (std.mem.eql(u8, lib_name, "ld")) "" else "lib"; + const basename = try fmt.allocPrint(allocator, "{}{}.abilist", .{ lib_prefix, lib_name }); const abi_list_filename = blk: { - if (abi_list.targets[0].abi == .gnuabi64 and std.mem.eql(u8, lib_name, "c")) { + const is_c = std.mem.eql(u8, lib_name, "c"); + const is_m = std.mem.eql(u8, lib_name, "m"); + const is_ld = std.mem.eql(u8, lib_name, "ld"); + if (abi_list.targets[0].abi == .gnuabi64 and (is_c or is_ld)) { break :blk try fs.path.join(allocator, &[_][]const u8{ prefix, abi_list.path, "n64", basename }); - } else if (abi_list.targets[0].abi == .gnuabin32 and std.mem.eql(u8, lib_name, "c")) { + } else if (abi_list.targets[0].abi == .gnuabin32 and (is_c or is_ld)) { break :blk try fs.path.join(allocator, &[_][]const u8{ prefix, abi_list.path, "n32", basename }); } else if (abi_list.targets[0].arch != .arm and abi_list.targets[0].abi == .gnueabihf and - (std.mem.eql(u8, lib_name, "c") or - (std.mem.eql(u8, lib_name, "m") and abi_list.targets[0].arch == .powerpc))) + (is_c or (is_m and abi_list.targets[0].arch == .powerpc))) { break :blk try fs.path.join(allocator, &[_][]const u8{ prefix, abi_list.path, "fpu", basename }); } else if (abi_list.targets[0].arch != .arm and abi_list.targets[0].abi == .gnueabi and - (std.mem.eql(u8, lib_name, "c") or - (std.mem.eql(u8, lib_name, "m") and abi_list.targets[0].arch == .powerpc))) + (is_c or (is_m and abi_list.targets[0].arch == .powerpc))) { break :blk try fs.path.join(allocator, &[_][]const u8{ prefix, abi_list.path, "nofpu", basename }); } else if (abi_list.targets[0].arch == .arm) { @@ -234,8 +237,8 @@ pub fn main() !void { const vers_txt_path = try fs.path.join(allocator, &[_][]const u8{ glibc_out_dir, "vers.txt" }); const vers_txt_file = try fs.cwd().createFile(vers_txt_path, .{}); defer vers_txt_file.close(); - var buffered = std.io.BufferedOutStream(fs.File.WriteError).init(&vers_txt_file.outStream().stream); - const vers_txt = &buffered.stream; + var buffered = std.io.bufferedOutStream(vers_txt_file.outStream()); + const vers_txt = buffered.outStream(); for (global_ver_list) |name, i| { _ = global_ver_set.put(name, i) catch unreachable; try vers_txt.print("{}\n", .{name}); @@ -246,8 +249,8 @@ pub fn main() !void { const fns_txt_path = try fs.path.join(allocator, &[_][]const u8{ glibc_out_dir, "fns.txt" }); const fns_txt_file = try fs.cwd().createFile(fns_txt_path, .{}); defer fns_txt_file.close(); - var buffered = std.io.BufferedOutStream(fs.File.WriteError).init(&fns_txt_file.outStream().stream); - const fns_txt = &buffered.stream; + var buffered = std.io.bufferedOutStream(fns_txt_file.outStream()); + const fns_txt = buffered.outStream(); for (global_fn_list) |name, i| { const kv = global_fn_set.get(name).?; kv.value.index = i; @@ -277,8 +280,8 @@ pub fn main() !void { const abilist_txt_path = try fs.path.join(allocator, &[_][]const u8{ glibc_out_dir, "abi.txt" }); const abilist_txt_file = try fs.cwd().createFile(abilist_txt_path, .{}); defer abilist_txt_file.close(); - var buffered = std.io.BufferedOutStream(fs.File.WriteError).init(&abilist_txt_file.outStream().stream); - const abilist_txt = &buffered.stream; + var buffered = std.io.bufferedOutStream(abilist_txt_file.outStream()); + const abilist_txt = buffered.outStream(); // first iterate over the abi lists for (abi_lists) |*abi_list, abi_index| {