Repository navigation
Conversation
|
Hello @yskzalloc 👋 Thank you for submitting a Pull Request (PR) to the LLVM Project. Since this is your first PR, here are a few useful links covering our main contribution policies and review practices.
Please reply to this message to confirm that you have read these policies, especially the LLVM AI Tool Use Policy, and that any AI tool usage has been noted in the PR description. Frequently asked questionsHow do I add reviewers? This PR will be automatically labeled, and the relevant teams will be notified. For some parts of the project, reviewers may also be added automatically. You can also add reviewers manually using the Reviewers section on this page. If you cannot use that section, it is probably because you do not have write permissions for the repository. In that case, you can request a review by tagging reviewers in a comment using What if there are no comments? If you have not received any comments on your PR after a week, you can request a review by pinging the PR with a comment such as “Ping”. The common courtesy ping rate is once a week. Please remember that you are asking for volunteer time from other developers. Are any special GitHub settings required to contribute to LLVM? We only require contributors to have a public email address associated with their GitHub commits, see this section of LLVM Developer Policy for details. If you have questions, feel free to leave a comment on this PR, or ask on LLVM Discord or LLVM Discourse. Thank you, |
56a3494 to
95c8fc7
Compare
95c8fc7 to
5707f60
Compare
5707f60 to
53e2fb1
Compare
Add two SanitizerCoverage modes that report the values flowing into and
out of instrumented functions. trace-args emits one call per IR argument
at function entry; trace-ret emits one call before every return:
void __sanitizer_cov_trace_args(u64 tag, u64 val, const u64 *offsets);
void __sanitizer_cov_trace_ret(u64 size, u64 val, const u64 *offsets);
`tag` is (arg_idx << 32) | size, where arg_idx is the position in the IR
parameter list. If `offsets` is null, `val` is the value itself,
zero-extended to 64 bits. Otherwise `val` is the address of `size`
bytes, and `offsets` points to a constant table: offsets[0] is the
number N of {byte offset, byte size} pairs that follow, each at most
8 bytes. This form reports byval/byref/inalloca/preallocated arguments
and sret buffers, described by the elements of their IR type, and
pointers that are noundef and dereferenceable(N) or
dereferenceable_or_null(N), snapshotted up to
-sanitizer-coverage-trace-pointee-bytes (default 64). A size of 0 means
nothing was reported.
The modes are enabled through SanitizerCoverageOptions::TraceArgs and
TraceRet or, for opt, -sanitizer-coverage-trace-args and
-sanitizer-coverage-trace-ret. Like the other modes, they need a
coverage level. They do not imply trace-pc-guard.
What is emitted depends only on the IR. Debug information gives the
calls a location and nothing else, so -g does not change the
instrumentation. The pass creates no allocas. The calls are notail and
nomerge, because a runtime identifies an observation by its return
address, as with trace-cmp.
Assisted-by: Kiro CLI (Claude Opus 5.5)
Signed-off-by: Yunseong Kim <[email protected]>
Accept trace-args and trace-ret in -fsanitize-coverage= and forward them to SanitizerCoverageOptions::TraceArgs/TraceRet through the new cc1 flags -fsanitize-coverage-trace-args and -fsanitize-coverage-trace-ret. Like the other instrumentation types, they satisfy the "requires an instrumentation type" check and, without a coverage level, select the edge level. That level alone adds no block callbacks, so -fsanitize-coverage=trace-args emits argument tracing only. hasSanitizeCoverage() now accounts for both flags, so either one on its own runs the pass. Assisted-by: Kiro CLI (Claude Opus 5.5) Signed-off-by: Yunseong Kim <[email protected]>
Add weak, empty definitions of __sanitizer_cov_trace_args and __sanitizer_cov_trace_ret to sanitizer_common, and declare them in sanitizer_interface_internal.h with their contract. A program built with -fsanitize-coverage=trace-args,trace-ret then links against a sanitizer runtime without supplying the callbacks itself. A strong definition overrides the defaults. The new test overrides both callbacks and checks the reported argument and return values at -O2 -g and at -O0. Assisted-by: Kiro CLI (Claude Opus 5.5) Signed-off-by: Yunseong Kim <[email protected]>
Add a "Tracing function arguments and return values" section to SanitizerCoverage.md. It covers: - the callback signatures, the tag encoding, and the offsets table; - how arg_idx relates to source parameters; - which pointers have their pointee snapshotted: noundef with dereferenceable(N) or dereferenceable_or_null(N); - the supported scope. Assisted-by: Kiro CLI (Claude Opus 5.5) Signed-off-by: Yunseong Kim <[email protected]>
53e2fb1 to
e6a4c78
Compare
This is PR 4 of a 4-PR stack:
-fsanitize-coverage=trace-args,trace-retdriver and frontend support, [Clang][SanitizerCoverage] Add -fsanitize-coverage=trace-args,trace-ret #218254The design rule, stated up front: debug information may enrich the interpretation of an observation, but must never determine which instrumentation is emitted. A build with
-gemits the same callbacks, operands and machine code as one without it. Neither flag needs another coverage mode.The two callback signatures. A runtime identifies an observation by its own return address minus one, as with the
trace-cmpcallbacks, and no trace call is a tail call.num_fieldssays whatvalholds:byval,byref,inalloca,preallocated,sret), or a pointee snapshot. The table lists pieces of at most 8 bytes, which covers rustc's opaque[N x i8]objects.A size of zero means there was nothing to report, and a value that may be poison is frozen first. The compiler never creates memory to report a value from.
"IR arguments, not source parameters":
arg_idxis the IR argument position. The section gives x86-64 and AArch64 examples of where it differs from the source parameter number: a split struct, a first-class aggregate,sret,this. It also states which pointers Clang and rustc markdereferenceable."Pointers: values, layouts and snapshots" separates four things about a pointer:
Only an explicit IR dereferenceability contract makes the runtime read behind a pointer:
dereferenceable(N), ordereferenceable_or_null(N)with a null check. The read is at most-sanitizer-coverage-trace-pointee-bytes(64) bytes. Nothing is inferred to stand in for a missing contract.this, CT p[static N], and Rust&Tand&mut Tcarry the contract.T *and a Rust raw pointer do not; they are pointer values only.The section also gives the measured share of pointer arguments with any pointee byte recorded on a Linux kernel build. That is not a share of arguments or structs reconstructed, and the text says so. Recording the values a function loads and stores through a pointer that has no contract is mentioned as possible future work, not as a feature.
"Consumers": compiler-rt's weak defaults and the Linux kernel's RFCed KCOV dataflow support.
"Supported scope": C, C++ and Rust on ELF x86-64 and AArch64, in userspace and in the Linux kernel, with or without
-g, at any optimization level. Other frontends and targets get valid instrumentation.