Darwin build fixes
Includes fixes cherry-picked from the following upstream PRs:
- bitcoin/bitcoin#7136
- Only the third commit (to avoid a merge conflict)
- bitcoin/bitcoin#7302
- Excluding the first commit, which is unnecessary (we use Boost 1.62)
- bitcoin/bitcoin#7487
- bitcoin/bitcoin#7606
- bitcoin/bitcoin#7711
- bitcoin/bitcoin#7165
- bitcoin/bitcoin#8002
- bitcoin/bitcoin#8210
- Only the second commit
- bitcoin/bitcoin#9114