https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125281

            Bug ID: 125281
           Summary: existing profile reported as missing when source
                    location changed
           Product: gcc
           Version: 14.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: gcov-profile
          Assignee: unassigned at gcc dot gnu.org
          Reporter: christophe.pavageau at nokia dot com
  Target Milestone: ---

Created attachment 64439
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=64439&action=edit
test to reproduce

When using PGO, if .gcda profile files are used in a different location (source
code has been moved to another
directory), some existing profile will be reported as missing.  This happens
for example to anonymous function, in case
absolute path name are used in gcc command line (this is always the case when
using CMake).  Using -ffile-prefix-map
option does not change the behavior. As a consequence, the build will be less
optimized.

Here is a small example, where pgo.cpp is instrumented and profiled on /tmp/A,
then recompiled on /tmp/B after .gcda
profile has been copied.

Note : this can be fixed by remapping the filename used in
coverage_compute_profile_id function.  "Source locations
(....) have changed" error/warning can also be removed by applying the remap in
coverage_compute_lineno_checksum
function.  Proposal patch is attached (-fprofile-id-prefix-map option), tested
on top of gcc 14.2.0


/tmp>tar xf gcc-pgo-test.tgz -C /tmp

/tmp>cd A
/tmp/A>./generate-profile.sh
+ CC=g++
+ g++ -g -O3 -fprofile-generate -o pgo.exe /tmp/A/pgo.cpp
+ ./pgo.exe testOK
Ok (/tmp/A/pgo.cpp) testOK
+ cp pgo.gcda ../B

/tmp/A>cd ../B
/tmp/B>./build.sh
+ CC=g++
+ g++ -g -O3 -fprofile-use -Wno-error=coverage-mismatch
-ffile-prefix-map=/tmp/B=/tmp/A -o pgo.exe /tmp/B/pgo.cpp
/tmp/B/pgo.cpp: In function ‘int main(int, char**)’:
/tmp/B/pgo.cpp:21:5: warning: source locations for function ‘int main(int,
char**)’ have changed, the profile data may be out of date
[-Wcoverage-mismatch]
   21 | int main(int argc, char* argv[])
      |     ^~~~
/tmp/B/pgo.cpp:21:5: warning: source locations for function ‘int main(int,
char**)’ have changed, the profile data may be out of date
[-Wcoverage-mismatch]
/tmp/B/pgo.cpp: In function ‘int {anonymous}::funcToProfile(char*)’:
/tmp/B/pgo.cpp:6:5: warning: profile for function ‘int
{anonymous}::funcToProfile(char*)’ not found in profile data
[-Wmissing-profile]
    6 | int funcToProfile(char *s)
      |     ^~~~~~~~~~~~~


--------------

gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/local/gcc-14.2.0/libexec/gcc/x86_64-redhat-linux/14.2.0/lto-wrapper
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr/local/gcc-14.2.0
--enable-languages=c,c++ --enable-libssp --disable-gtktest --with-system-zlib
--libexecdir=/usr/local/gcc-14.2.0/libexec --disable-libunwind-exceptions
--with-gnu-ld --target=x86_64-redhat-linux --build=x86_64-redhat-linux
--host=x86_64-redhat-linux --enable-lto --libdir=/usr/local/gcc-14.2.0/lib
--disable-multilib
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 14.2.0 (GCC)
  • [Bug gcov-profile/125281... christophe.pavageau at nokia dot com via Gcc-bugs

Reply via email to