Tech stocks gain as S&P 500 flirts with record high