Browse Source

Work-around GCC LTO codegen bug in process_commands()

When building with GCC 4.9.2 (bundled with PF-build-env-1.0.6.*), -Os
and LTO enabled, PID_autotune gets automatically inlined into
process_commands().

Sadly, due to the massive size of process_commands(), it results in
codegen bug doing a partial stack overwrite in process_commands()
itself, manifesting as random behavior depending on the timing of
interrupts and the codepath taken inside the merged function.

Mark the function as noinline and add a note about the affected compiler
version in order to be checked again in the future.
Yuri D'Elia 2 years ago
parent
commit
53fcd6fc8f
1 changed files with 4 additions and 2 deletions
  1. 4 2
      Firmware/temperature.cpp

+ 4 - 2
Firmware/temperature.cpp

@@ -287,8 +287,10 @@ bool checkAllHotends(void)
     return(result);
 }
 
-  void PID_autotune(float temp, int extruder, int ncycles)
-  {
+// WARNING: the following function has been marked noinline to avoid a GCC 4.9.2 LTO
+//          codegen bug causing a stack overwrite issue in process_commands()
+void __attribute__((noinline)) PID_autotune(float temp, int extruder, int ncycles)
+{
   pid_number_of_cycles = ncycles;
   pid_tuning_finished = false;
   float input = 0.0;