Skip to content

Instantly share code, notes, and snippets.

@japaric
Created February 17, 2017 23:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save japaric/a643e1ac134a335a554ab40079e5dddb to your computer and use it in GitHub Desktop.
Save japaric/a643e1ac134a335a554ab40079e5dddb to your computer and use it in GitHub Desktop.
set -ex
main() {
rustup default stable
rustup component add rust-src
rm -rf hello
cargo new --bin hello
cd hello
build_libprofiler
RUSTFLAGS="-C passes=insert-gcov-profiling" cargo rustc -- \
-C link-arg=-lprofiler \
-C link-arg=-L$(pwd)
target/debug/hello
# OUTPUT main.gcda main.gcno
ls *.gc*
}
build_libprofiler() {
local sources=(
GCDAProfiling.c
InstrProfiling.c
InstrProfilingBuffer.c
InstrProfilingFile.c
InstrProfilingMerge.c
InstrProfilingMergeFile.c
InstrProfilingPlatformLinux.c
InstrProfilingRuntime.cc
InstrProfilingUtil.c
InstrProfilingValue.c
InstrProfilingWriter.c
)
local src_dir=$(rustc --print sysroot)/lib/rustlib/src/rust/src/compiler-rt/lib/profile
local td=$(mktemp -d)
for source in ${sources[@]}; do
gcc \
-fPIC \
-DVISIBILITY_HIDDEN \
-c \
-ffreestanding \
-fno-builtin \
-fomit-frame-pointer \
-fvisibility=hidden \
$src_dir/$source \
-o $td/${source%.*}.o
done
local objs=( ${sources[@]/%.*/.o} )
ar crus libprofiler.a ${objs[@]/#/$td/}
rm -rf $td
}
main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment