Variational approach to first- and second-order sensitivity analysis of elastic structures