It's also quite a challenging control problem, which at the end of the day turns into a software problem.
You can see what spacex (probably) does to turn it into a tractable problem for real time control in http://www.larsblackmore.com/iee_tcst13.pdf (Blackmore leads entry, descent, and landing at spacex).