[lld-macho] Fix parsing of --time-trace-{granularity,file}

Summary: We needed to use `Joined` instead of `Flag`. This wasn't caught
because the relevant test that was copied from LLD-ELF was still
invoking LLD-ELF instead of LLD-MachO...

Differential Revision: https://reviews.llvm.org/D99313
This commit is contained in:
Jez Ng 2021-03-24 21:05:26 -04:00
parent 45cdceb40c
commit 94e369400e
4 changed files with 13 additions and 11 deletions

View File

@ -86,7 +86,7 @@ struct Configuration {
uint32_t headerPad;
uint32_t dylibCompatibilityVersion = 0;
uint32_t dylibCurrentVersion = 0;
uint32_t timeTraceGranularity = 0;
uint32_t timeTraceGranularity = 500;
std::string progName;
llvm::StringRef installName;
llvm::StringRef mapFile;

View File

@ -998,13 +998,15 @@ bool macho::link(ArrayRef<const char *> argsArr, bool canExitEarly,
config->progName = argsArr[0];
config->timeTraceEnabled = args.hasArg(OPT_time_trace);
config->timeTraceGranularity =
args::getInteger(args, OPT_time_trace_granularity_eq, 500);
// Initialize time trace profiler.
if (config->timeTraceEnabled)
timeTraceProfilerInitialize(config->timeTraceGranularity, config->progName);
{
TimeTraceScope timeScope("Link", StringRef("ExecuteLinker"));
TimeTraceScope timeScope("ExecuteLinker");
initLLVM(); // must be run before any call to addFile()
createFiles(args);

View File

@ -39,9 +39,9 @@ def no_lto_legacy_pass_manager : Flag<["--"], "no-lto-legacy-pass-manager">,
HelpText<"Use the new pass manager in LLVM">,
Group<grp_lld>;
def time_trace: Flag<["--"], "time-trace">, HelpText<"Record time trace">;
def time_trace_granularity: Flag<["--"], "time-trace-granularity">,
def time_trace_granularity_eq: Joined<["--"], "time-trace-granularity=">,
HelpText<"Minimum time granularity (in microseconds) traced by time profiler">;
def time_trace_file_eq: Flag<["--"], "time-trace-file=">, HelpText<"Specify time trace output file">;
def time_trace_file_eq: Joined<["--"], "time-trace-file=">, HelpText<"Specify time trace output file">;
// This is a complete Options.td compiled from Apple's ld(1) manpage
// dated 2018-03-07 and cross checked with ld64 source code in repo

View File

@ -1,20 +1,20 @@
# REQUIRES: x86
# RUN: llvm-mc -filetype=obj -triple=x86_64 %s -o %t.o
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %s -o %t.o
# Test implicit trace file name
# RUN: ld.lld --time-trace --time-trace-granularity=0 -o %t1.macho %t.o
# RUN: %lld --time-trace --time-trace-granularity=0 -o %t1.macho %t.o
# RUN: cat %t1.macho.time-trace \
# RUN: | %python -c 'import json, sys; json.dump(json.loads(sys.stdin.read()), sys.stdout, sort_keys=True, indent=2)' \
# RUN: | FileCheck %s
# Test specified trace file name
# RUN: ld.lld --time-trace --time-trace-file=%t2.json --time-trace-granularity=0 -o %t2.macho %t.o
# RUN: %lld --time-trace --time-trace-file=%t2.json --time-trace-granularity=0 -o %t2.macho %t.o
# RUN: cat %t2.json \
# RUN: | %python -c 'import json, sys; json.dump(json.loads(sys.stdin.read()), sys.stdout, sort_keys=True, indent=2)' \
# RUN: | FileCheck %s
# Test trace requested to stdout
# RUN: ld.lld --time-trace --time-trace-file=- --time-trace-granularity=0 -o %t3.macho %t.o \
# RUN: %lld --time-trace --time-trace-file=- --time-trace-granularity=0 -o %t3.macho %t.o \
# RUN: | %python -c 'import json, sys; json.dump(json.loads(sys.stdin.read()), sys.stdout, sort_keys=True, indent=2)' \
# RUN: | FileCheck %s
@ -33,10 +33,10 @@
# CHECK: "name": "ExecuteLinker"
# Check process_name entry field
# CHECK: "name": "ld.lld{{(.exe)?}}"
# CHECK: "name": "ld64.lld{{(.exe)?}}"
# CHECK: "name": "process_name"
# CHECK: "name": "thread_name"
.globl _start
_start:
.globl _main
_main:
ret