Endoscopy and the cohomology of arithmetic groups