In preparation for range extension thunks introduce a function that will check whether a branch identified by a relocation type at a source address can reach a destination.
For targets where range extension thunks are not supported the function will return true as it is not expected that branches are out of range. An implementation has been provided for ARM.
This is patch 7/11 of range thunks although as it is not hooked up it can be applied independently.
In this function, you computed the exact distance between two instructions, but does this much preciseness actually needed? A few bytes difference seems negligible when you want to know whether two instructions are in +-16MiB, for example.