Stocks rallied for a second day on Wednesday, as investors bid up materials and energy shares on rising commodity prices and poured into beaten-down tech names after days of selling.

Stocks continued to recover from a decline that briefly took the S&P 500 into bear-market territory. That turned abruptly on Tuesday, with the S&P 500 gaining 4 percent in the last hour of trading that hit short-sellers hard.

The Nasdaq 100 technology sector index jumped 3.7 percent; it has gained 7.3 percent in the past two sessions.

Among the leaders was Yahoo, up more than 10 percent after Reuters reported Microsoft is considering buying the Internet company.

A lot of people are looking at tech stocks as a good growth sector, said Peter Costa, president of Empire Executions Inc in New York.

Traders cited the relative strength in the S&P 500 after breaking the closely watched 1,100 level Tuesday as a catalyst for short sellers to pocket gains and as a damper on overall selling pressure.

Economic data showed growth in the U.S. service sector was steady in September and private hiring picked up, suggesting the economy was not yet slipping into recession.

Data this morning wasn't horrible ... enough to keep us on this drifting kind of market, Costa said.

A jump in the price of commodities, including crude oil and copper, lifted shares in the materials and energy sectors.

The Dow Jones industrial average gained 131.24 points, or 1.21 percent, to 10,939.95 at the close. The S&P 500 added 20.09 points, or 1.79 percent, to 1,144.04. The Nasdaq Composite rose 55.69 points, or 2.32 percent, to 2,460.51.

Wednesday's gains kept the benchmark S&P 500 near the lower end of a trading range that goes back two months as the deepening debt crisis in Europe remains unresolved. Greece is expected by many to be forced to restructure its debt.

Among the biggest gainers in technology were shares of Yahoo, up 10.1 percent at $15.92 after a Reuters report that Microsoft may be preparing a bid for the search engine company.

Research in Motion was up 12.4 percent at $23.60 on speculation the BlackBerry maker could be acquired.

The U.S. economy's services sector expanded in September, slightly faster than forecast by a Reuters poll, while the private sector added 91,000 jobs in September, increasing optimism about Friday's non-farm payrolls report from the Labor Department.

U.S. crude futures snapped a three-day losing streak with a gain of more than 5 percent, while copper prices added 1.7 percent.

About 9.7 billion shares traded on the New York Stock Exchange, NYSE Amex and Nasdaq, above this year's daily average of 8 billion shares.

Advancing stocks outnumbered declining ones on the NYSE by a ratio of 11 to 4, while on the Nasdaq, about nine stocks rose for every four that fell.