Giants rally past A's 5-4 in 9th, rescue Lincecum