Bug 49340 - read_couts_file() not called for -fbranch-probabilities
Summary: read_couts_file() not called for -fbranch-probabilities
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: gcov-profile (show other bugs)
Version: 4.5.2
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-06-09 11:47 UTC by Martin von Gagern
Modified: 2016-08-05 11:48 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2012-07-22 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Martin von Gagern 2011-06-09 11:47:51 UTC
$ cat test.c
#include <stdio.h>

int main(int argc, char** argv) {
  int i;
  for (i = 0; i < argc; ++i) {
    printf("argv[%d] = \"%s\"\n", i, argv[i]);
  }
  return 0;
}

$ rm -f test.gcda
$ gcc -o prof -fprofile-arcs test.c
$ ./prof
argv[0] = "./prof"
$ test -f test.gcda && gcc -o final -fbranch-probabilities test.c
test.c: In function ‘main’:   test.c:9:1: note: file $PWD/test.gcda not found,
execution counts assumed to be zero

Identified the relevant command via strace and ran it through gdb:
$ gdb --args /usr/libexec/gcc/x86_64-pc-linux-gnu/4.5.2/cc1 -quiet test.c \
  -D_FORTIFY_SOURCE=2 -quiet -dumpbase test.c -mtune=generic -march=x86-64 \
  -auxbase test -fbranch-probabilities -o test.s
It appears that coverage_init does not call read_counts_file because flag_profile_use is zero. So cc1 doesn't even attempt to read the file for which it claims it wasn't found.

It appears that this is a problem introduced by gcc 4.4.0 in this commit:
http://gcc.gnu.org/viewcvs/trunk/gcc/coverage.c?r1=133773&r2=133774

GCC version is "gcc (Gentoo 4.5.2 p1.1, pie-0.4.5) 4.5.2", my system is x86_64-pc-linux-gnu. The Gentoo build was configured using USE=vanilla, so there should be no Gentoo-specific patches involved. If you have any trouble reproducing the issue, let me know and I'll see what other details I can provide.
Comment 1 Steven Bosscher 2012-07-22 00:04:44 UTC
The best way around this, is to use -fprofile-generate and -fprofile-use.
But it's a bug, for sure.
Comment 2 Mike Frysinger 2014-11-01 06:52:31 UTC
seems to work with gcc-4.9 at least ?
Comment 3 Martin Liška 2016-08-05 11:48:38 UTC
All active branches (5,6,7) work fine, closing as invalid.