S&P 500, Nasdaq post record highs as tech-related shares gain