Address Space Layout Randomization
Another possible way to prevent such these attacks is to provide a random address. With Address Sace Layout Randomization (ASLR), the address of every function or data between every run of program is random so that it is hard for an attacker to exploit the system to know where to return.
ASLR is a software feature. It is supported by operating systems today.