From: Jan Hubicka Date: Wed, 30 Jul 2025 14:09:12 +0000 (+0200) Subject: Report read errors when reading auto-profile X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=994feb9edd8a243283d5996667f89351c2c66e26;p=thirdparty%2Fgcc.git Report read errors when reading auto-profile currently -fauto-profile will happily read truncated file without any warning and interpret it as a zero profile which will in turn result in slow code. This patch exports gcov_is_error and adds checks so truncated files are detected. gcc/ChangeLog: * auto-profile.cc (string_table::read): Check gcov_is_error. (read_profile): Likewise. * gcov-io.cc (gcov_is_error): Export for gcc linkage. * gcov-io.h (gcov_is_error): Declare. --- diff --git a/gcc/auto-profile.cc b/gcc/auto-profile.cc index 53e7b51e883..7ff952632c3 100644 --- a/gcc/auto-profile.cc +++ b/gcc/auto-profile.cc @@ -885,6 +885,8 @@ string_table::read () { vector_.quick_push (xstrdup (gcov_read_string ())); map_[vector_.last ()] = i; + if (gcov_is_error ()) + return false; } return true; } @@ -2747,14 +2749,22 @@ read_profile (void) /* autofdo_source_profile. */ afdo_source_profile = autofdo_source_profile::create (); - if (afdo_source_profile == NULL) + if (afdo_source_profile == NULL + || gcov_is_error ()) { error ("cannot read function profile from %s", auto_profile_file); + delete afdo_source_profile; + afdo_source_profile = NULL; return; } /* autofdo_module_profile. */ fake_read_autofdo_module_profile (); + if (gcov_is_error ()) + { + error ("cannot read module profile from %s", auto_profile_file); + return; + } } /* From AutoFDO profiles, find values inside STMT for that we want to measure diff --git a/gcc/gcov-io.cc b/gcc/gcov-io.cc index f39b4bd565a..dd3fc88f4b5 100644 --- a/gcc/gcov-io.cc +++ b/gcc/gcov-io.cc @@ -69,7 +69,7 @@ gcov_position (void) /* Return nonzero if the error flag is set. */ /* We need to expose this function when compiling for gcov-tool. */ -#ifndef IN_GCOV_TOOL +#if !defined (IN_GCOV_TOOL) && !defined (IN_GCC) static inline #endif int diff --git a/gcc/gcov-io.h b/gcc/gcov-io.h index f3e3a1c08da..313c15cecbb 100644 --- a/gcc/gcov-io.h +++ b/gcc/gcov-io.h @@ -387,6 +387,7 @@ char *mangle_path (char const *base); /* Available outside gcov */ GCOV_LINKAGE void gcov_write (const void *, unsigned) ATTRIBUTE_HIDDEN; GCOV_LINKAGE void gcov_write_unsigned (gcov_unsigned_t) ATTRIBUTE_HIDDEN; +GCOV_LINKAGE int gcov_is_error (void); #endif #if !IN_GCOV && !IN_LIBGCOV