From 53fcd6fc8f8d9545e6d069e457b70a6a059dae49 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia Date: Wed, 23 Jun 2021 21:52:25 +0200 Subject: [PATCH] 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. --- Firmware/temperature.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Firmware/temperature.cpp b/Firmware/temperature.cpp index 63eb8a36..3765589b 100755 --- a/Firmware/temperature.cpp +++ b/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;