From 18da5b654ed30d4e1c8e09ffccd7d77aaba2e185 Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Tue, 9 Jul 2024 12:05:37 +0900 Subject: [PATCH] Add --no-detach to write to a separate debug file in the foreground --detach is the default. --- elf/cmdline.cc | 10 ++++++++++ elf/mold.h | 1 + elf/passes.cc | 2 +- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/elf/cmdline.cc b/elf/cmdline.cc index 5f2b666a..4f70c959 100644 --- a/elf/cmdline.cc +++ b/elf/cmdline.cc @@ -85,6 +85,8 @@ Options: --defsym=SYMBOL=VALUE Define a symbol alias --demangle Demangle C++ symbols in log messages (default) --no-demangle + --detach Create separate debug info file in the background (default) + --no-detach --enable-new-dtags Emit DT_RUNPATH for --rpath (default) --disable-new-dtags Emit DT_RPATH for --rpath --execute-only Make executable segments unreadable @@ -759,6 +761,10 @@ std::vector parse_nonpositional_args(Context &ctx) { ctx.arg.demangle = true; } else if (read_flag("no-demangle")) { ctx.arg.demangle = false; + } else if (read_flag("detach")) { + ctx.arg.detach = true; + } else if (read_flag("no-detach")) { + ctx.arg.detach = false; } else if (read_flag("default-symver")) { ctx.arg.default_symver = true; } else if (read_flag("noinhibit-exec")) { @@ -1413,6 +1419,10 @@ std::vector parse_nonpositional_args(Context &ctx) { if (ctx.arg.shared && warn_shared_textrel) ctx.arg.warn_textrel = true; + // We don't want the background process to write to stdout + if (ctx.arg.stats || ctx.arg.perf) + ctx.arg.detach = false; + ctx.arg.undefined.push_back(ctx.arg.entry); for (i64 i = 0; i < ctx.arg.defsyms.size(); i++) { diff --git a/elf/mold.h b/elf/mold.h index caa4eb9f..64f077dc 100644 --- a/elf/mold.h +++ b/elf/mold.h @@ -1740,6 +1740,7 @@ struct Context { bool color_diagnostics = false; bool default_symver = false; bool demangle = true; + bool detach = true; bool discard_all = false; bool discard_locals = false; bool eh_frame_hdr = true; diff --git a/elf/passes.cc b/elf/passes.cc index dabbb7b8..d4b8a3af 100644 --- a/elf/passes.cc +++ b/elf/passes.cc @@ -3058,7 +3058,7 @@ void write_separate_debug_file(Context &ctx) { // We want to write to the debug info file in background so that the // user doesn't have to wait for it to complete. - if (!ctx.arg.stats && !ctx.arg.perf) + if (ctx.arg.detach) notify_parent(); // A debug info file contains all sections as the original file, though