Fixes for compilation on OSX

Moved here from https://github.com/JuliaLang/julia/pull/3801