Constraining the density dependence of the symmetry energy from nuclear masses