U.S. stocks rallied to the brink of a record after more companies reported fatter profits than expected.