diff options
| author | Jun Wu <quark@fb.com> | 2018-12-30 11:59:03 -0800 |
|---|---|---|
| committer | Jun Wu <quark@fb.com> | 2018-12-30 11:59:03 -0800 |
| commit | 31a5066e0b5f0e7e79b6cc04ae09166de0352c63 (patch) | |
| tree | 734d3c518bbaa8a07aaf49bc8aec9aad20a5e956 /src/librustc_codegen_llvm | |
| parent | a35cf79fcb961d43828aa9f010e7109b60633f52 (diff) | |
| download | rust-31a5066e0b5f0e7e79b6cc04ae09166de0352c63.tar.gz rust-31a5066e0b5f0e7e79b6cc04ae09166de0352c63.zip | |
Add `-Z instrument-mcount`
This flag inserts `mcount` function call to the beginning of every function after inline processing. So tracing tools like uftrace [1] (or ftrace for Linux kernel modules) have a chance to examine function calls. It is similar to the `-pg` flag provided by gcc or clang, but without generating a `__gmon_start__` function for executables. If a program runs without being traced, no `gmon.out` will be written to disk. Under the hood, it simply adds `"instrument-function-entry-inlined"="mcount"` attribute to every function. The `post-inline-ee-instrument` LLVM pass does the actual job. [1]: https://github.com/namhyung/uftrace
Diffstat (limited to 'src/librustc_codegen_llvm')
| -rw-r--r-- | src/librustc_codegen_llvm/attributes.rs | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/librustc_codegen_llvm/attributes.rs b/src/librustc_codegen_llvm/attributes.rs index acd1c4afd2e..226b03c99c0 100644 --- a/src/librustc_codegen_llvm/attributes.rs +++ b/src/librustc_codegen_llvm/attributes.rs @@ -78,6 +78,18 @@ pub fn set_frame_pointer_elimination(cx: &CodegenCx<'ll, '_>, llfn: &'ll Value) } } +/// Tell LLVM what instrument function to insert. +#[inline] +pub fn set_instrument_function(cx: &CodegenCx<'ll, '_>, llfn: &'ll Value) { + if cx.sess().instrument_mcount() { + // Similar to `clang -pg` behavior. Handled by the + // `post-inline-ee-instrument` LLVM pass. + llvm::AddFunctionAttrStringValue( + llfn, llvm::AttributePlace::Function, + const_cstr!("instrument-function-entry-inlined"), const_cstr!("mcount")); + } +} + pub fn set_probestack(cx: &CodegenCx<'ll, '_>, llfn: &'ll Value) { // Only use stack probes if the target specification indicates that we // should be using stack probes @@ -174,6 +186,7 @@ pub fn from_fn_attrs( } set_frame_pointer_elimination(cx, llfn); + set_instrument_function(cx, llfn); set_probestack(cx, llfn); if codegen_fn_attrs.flags.contains(CodegenFnAttrFlags::COLD) { |
