Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate gcov coverage data #690

Closed
brson opened this issue Jul 14, 2011 · 26 comments
Closed

Generate gcov coverage data #690

brson opened this issue Jul 14, 2011 · 26 comments
Labels
A-debuginfo Area: Debugging information in compiled programs (DWARF, PDB, etc.) A-testsuite Area: The testsuite used to check the correctness of rustc

Comments

@brson
Copy link
Contributor

brson commented Jul 14, 2011

It would be nice to know what our test coverage looks like. I believe this depends on #689.

@msullivan
Copy link
Contributor

Depends on #237.

@kud1ing
Copy link

kud1ing commented Dec 20, 2011

Should this issue be tagged with "debuginfo"?

@brson
Copy link
Contributor Author

brson commented Dec 20, 2011

Yes

@ghost ghost assigned brson Mar 15, 2012
@brson brson mentioned this issue Apr 18, 2012
@eholk
Copy link
Contributor

eholk commented Jul 25, 2012

According to a comment in #2234, this bug is unblocked now.

@brson
Copy link
Contributor Author

brson commented Jan 11, 2013

This is definitely blocked again on functioning debug info.

@bblum
Copy link
Contributor

bblum commented Jul 3, 2013

revisiting for triage. this would be especially great to have in the concurrency tests, where covering all the branches is a function of scheduling rather than input values.

@bblum
Copy link
Contributor

bblum commented Aug 16, 2013

i was already here, but now i am here again

@jdm
Copy link
Contributor

jdm commented Sep 22, 2013

This would be super-interesting to dig into now, since we have quite functional debug symbols after this summer's GSOC.

@catamorphism
Copy link
Contributor

Would be awesome, but not 1.0

@mletterle
Copy link
Contributor

On a related note, I found this project today: https://github.com/SimonKagstrom/kcov

kcov uses the DWARF debug-info to generate coverage data, I've verified that it appears to work with test crates. It also generates cobertura xml files of the coverage data. Might be a nice stop gap for getting coverage numbers on rust itself.

@emberian
Copy link
Member

kcov looks much nicer than gcov overall.

@pongad
Copy link
Contributor

pongad commented Feb 3, 2014

I'm not sure how relevant this is, but Go did it in a pretty interesting way: http://blog.golang.org/cover
Not sure if everyone wants to do it the way they did.

@emberian
Copy link
Member

emberian commented Feb 3, 2014

I was recently looking at this. llvm has built-in gcov generation passes.

On Mon, Feb 3, 2014 at 12:54 AM, Michael Darakananda <
notifications@github.com> wrote:

I'm not sure how relevant this is, but Go did it in a pretty interesting
way: http://blog.golang.org/cover
Not sure if everyone wants to do it the way they did.


Reply to this email directly or view it on GitHubhttps://github.com//issues/690#issuecomment-33926365
.

@huonw
Copy link
Member

huonw commented Feb 5, 2014

I tested kcov, it seems to (mostly) just work with -Z extra-debug-info (output for extratest).

stdtest hits runtime aborts when running under kcov (possibly threading stuff, haven't had a chance to test) and it doesn't seem to understand our debug-info perfectly (or we have slightly misaligned/mislabeled debug-info) since sometimes lines inside ifs are marked as executed while the condition is, apparently, never run.

However, all-in-all kcov seems pretty good.

@alexcrichton
Copy link
Member

(drive-by-triage)

LLVM's gcov pass requires some runtime support in the form of compiler-rt. We're currently bundling compiler-rt with rust, but it doesn't have gcov support compiled into it. It's plausible that we could add a first-class flag to generate gcov information which would link to this special library.

@thehydroimpulse
Copy link
Contributor

/cc me

@farcaller
Copy link
Contributor

Tinkered with insert-gcov-profiling a bit. If you add it as a pass:

-C passes=insert-gcov-profiling

it fails to find the appropriate runtime support (llvm_gcda_start_file, llvm_gcda_emit_function, etc.). So I tried adding those from clang's compiler-rt:

-C link-args=/usr/lib/clang/3.4/lib/linux/libclang_rt.profile-x86_64.a

Fails with

undefined reference to `atexit'

Well, at that point I just linked everything to -lc as well 😄 and surprisingly that compiled and the binary works.

Now the problem is that those two binaries have different timestamps:

% hexdump -e '"%x\n"' -s8 -n4 test.gcno
9ad3f7b9
% hexdump -e '"%x\n"' -s8 -n4 test.gcda
4c4c564d

Any ideas what to do with that?

@emberian
Copy link
Member

@farcaller do they need to have the same timestamp?

@farcaller
Copy link
Contributor

Yes, that's how they check that gcda output corresponds to gcno provided by complier. It might be because of some differences in clang's libclang_rt.profile-x86_64.a and whatever llvm generates in there at compile time, I'm rebuilding rustc with matching version of compiler-rt's profile now to verify.

@farcaller
Copy link
Contributor

With matching profile part of compiler-rt:

make -C $RUST_SRC/src/compiler-rt" ProjSrcRoot="$RUST_SRC/src/compiler-rt" ProjObjRoot="$RUST_SRC/x86_64-apple-darwin/rt/compiler-rt" CC="clang" AR="ar" RANLIB="ar s" CFLAGS="-Wall -Werror -g -fPIC  -Qunused-arguments" TargetTriple=x86_64-apple-darwin clang_darwin-profile_osx

you can get gcov profiling generated by

-C passes=insert-gcov-profiling -C link-args=$RUST_SRC/x86_64-apple-darwin/rt/compiler-rt/clang_darwin/profile_osx/libcompiler_rt.a

Now, there are two more problems.

The compiler can't find __morestack_allocate_stack_space symbol. Not sure if this is directly related to the gcov though.

The bigger issue is that the file is still not parseable:

% gcov lib.gcda
Function identifiers do not match: 2 != 0 (in _ZN4zinc7drivers3lcd4test11TestLCD.LCD5clearE).
Invalid .gcda File!

@farcaller
Copy link
Contributor

It actually works fine on extremely simple "hello world" binary. Could it be the case that insert-gcov-profiling pass should be inserted at another time in the pipeline?

@farcaller
Copy link
Contributor

FWIW, kcov actually seems to work if -C relocation-model=static is passed to rustc (as seen in hackndev/zinc#168)

@reem
Copy link
Contributor

reem commented Oct 1, 2014

/cc me

@steveklabnik
Copy link
Member

Triage bump: anyone know the status of this today?

@farcaller
Copy link
Contributor

rustc nightly (dcaeb6a), ubuntu 14.10, x86_64.

  • a binary built with rustc -g test.rs produces empty output for kcov;
  • a binary built with rustc -g -C relocation-model=static test.rs fails to link:
error: linking with `cc` failed: exit code: 1
note: cc '-Wl,--as-needed' '-m64' '-L' '/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib' '-o' 'test' 'test.o' '-Wl,--whole-archive' '-lmorestack' '-Wl,--no-whole-archive' '-Wl,--gc-sections' '-pie' '-nodefaultlibs' '/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-4e7c5e5c.rlib' '/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcollections-4e7c5e5c.rlib' '/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunicode-4e7c5e5c.rlib' '/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib/librand-4e7c5e5c.rlib' '/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc-4e7c5e5c.rlib' '/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-4e7c5e5c.rlib' '/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-4e7c5e5c.rlib' '-L' '/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib' '-L' '/.rust/lib/x86_64-unknown-linux-gnu' '-L' '/lib/x86_64-unknown-linux-gnu' '-Wl,--whole-archive' '-Wl,-Bstatic' '-Wl,--no-whole-archive' '-Wl,-Bdynamic' '-ldl' '-lpthread' '-lrt' '-lgcc_s' '-lpthread' '-lc' '-lm' '-lcompiler-rt'
note: /usr/bin/ld: test.o: relocation R_X86_64_32S against `.rodata.str1905' can not be used when making a shared object; recompile with -fPIC
test.o: error adding symbols: Bad value
collect2: error: ld returned 1 exit status

Building with rustc -g -C passes=insert-gcov-profiling -C link-args=/usr/lib/clang/3.4/lib/linux/libclang_rt.profile-x86_64.a test.rs still works but Coverstory reports:

File checksums do not match: 2561096886 != 1280071245.
(null):Invalid .gcda File!

and gcov test.gcda:

test.gcno:version '402*', prefer '408*'

gcov: out of memory allocating 7020426464 bytes after a total of 135168 bytes

So there is no way to generate coverage data for rust that I'm aware of at the moment (that's bad).

@steveklabnik
Copy link
Member

I'm pulling a massive triage effort to get us ready for 1.0. As part of this, I'm moving stuff that's wishlist-like to the RFCs repo, as that's where major new things should get discussed/prioritized.

This issue has been moved to the RFCs repo: rust-lang/rfcs#646

pdietl pushed a commit to pdietl/rust that referenced this issue Apr 23, 2020
Update for "modern" `meta` matcher.
ZuseZ4 pushed a commit to EnzymeAD/rust that referenced this issue Mar 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-debuginfo Area: Debugging information in compiled programs (DWARF, PDB, etc.) A-testsuite Area: The testsuite used to check the correctness of rustc
Projects
None yet
Development

No branches or pull requests