The present invention relates to a method for securely protecting the execution of
software code against physical attacks, wherein the
software code comprises calls to a plurality of functions and, prior to a call to a first function among the plurality of functions, an instruction that stores the address of the first function in a
global variable, wherein the method is performed by an electronic
system comprising a hardware processor, non-
volatile memory, and a detection
system configured to detect an
attack on the electronic
system during the execution of a function among the plurality of functions, and comprising: - detecting (S1), by the detection system, during the execution of the first function, an
attack on the electronic system, - after the detection of an
attack, retrieving the address from which the first function was called,Storing the retrieved address in non-
volatile memory and stopping the execution of the first function (S2), - on the next startup of the electronic system (S3): o Determining whether an attack occurred during a previous execution of the first function by checking whether an address of a call to the first function is stored in the non-
volatile memory, o if it is determined that an attack occurred during a previous execution of the first function, updating the
software code in the non-volatile memory by replacing the call to the first function at the address stored in the non-volatile memory with a call to a function that: activates security countermeasures, calls the first function using the address stored in the
global variable, and deactivates the activated security countermeasures after the execution of the first function.