BEYOND ENDOSCOPY FOR THE RELATIVE TRACE FORMULA II: GLOBAL THEORY