Major U.S. indexes posted their biggest gains in months, led by big tech stocks, even as geopolitical tensions and economic uncertainty continue to weigh on markets.