[mach-o] reduce duplicate source code by using a templated method.  No functionality change.