]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Report read errors when reading auto-profile
authorJan Hubicka <jh@suse.cz>
Wed, 30 Jul 2025 14:09:12 +0000 (16:09 +0200)
committerJan Hubicka <jh@suse.cz>
Wed, 30 Jul 2025 14:09:35 +0000 (16:09 +0200)
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.

gcc/auto-profile.cc
gcc/gcov-io.cc
gcc/gcov-io.h

index 53e7b51e88321849dea27047d773de99045be553..7ff952632c35d05a75f6de4ebb3bd99b184eae45 100644 (file)
@@ -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
index f39b4bd565ad7d8914d4b76915c1211f704eeef4..dd3fc88f4b51664421989f6ecbb1835e7bd9edae 100644 (file)
@@ -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
index f3e3a1c08da8b5a327c0fe12635c4db31a40edf4..313c15cecbb84798fd275e8b92fbc8571b17c1f9 100644 (file)
@@ -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