Skip to content

Instantly share code, notes, and snippets.

@netj
Created March 2, 2016 21:05
Show Gist options
  • Save netj/d22146213111abcd386a to your computer and use it in GitHub Desktop.
Save netj/d22146213111abcd386a to your computer and use it in GitHub Desktop.

OS X's dyld embarrassingly drops some environment variables it depends on as shown by the dyld-env-drop-test.sh script next to this note. This means you cannot wrap your binaries with shims that fixup environment variables, etc. and hope them to inherit any DYLD_* environment set from another layer of wrapper script. You must call the binary executables immediately after setting up dyld.

$ ./dyld-env-drop-test.sh
does     work: some_random_env_var='foo'
does     work: another_random_name='foo'
does     work: PATH='foo'
does     work: USER='foo'
does     work: LOGNAME='foo'
does     work: HOME='foo'
does NOT work: DYLD_FRAMEWORK_PATH=''
does NOT work: DYLD_FALLBACK_FRAMEWORK_PATH=''
does NOT work: DYLD_VERSIONED_FRAMEWORK_PATH=''
does NOT work: DYLD_LIBRARY_PATH=''
does NOT work: DYLD_FALLBACK_LIBRARY_PATH=''
does NOT work: DYLD_VERSIONED_LIBRARY_PATH=''
does NOT work: DYLD_PRINT_TO_FILE=''
does NOT work: DYLD_ROOT_PATH=''
does NOT work: DYLD_SHARED_REGION=''
does NOT work: DYLD_INSERT_LIBRARIES=''
does NOT work: DYLD_FORCE_FLAT_NAMESPACE=''
does NOT work: DYLD_IMAGE_SUFFIX=''
does NOT work: DYLD_PRINT_OPTS=''
does NOT work: DYLD_PRINT_ENV=''
does NOT work: DYLD_PRINT_LIBRARIES=''
does NOT work: DYLD_PRINT_LIBRARIES_POST_LAUNCH=''
does NOT work: DYLD_BIND_AT_LAUNCH=''
does NOT work: DYLD_DISABLE_DOFS=''
does NOT work: DYLD_PRINT_APIS=''
does NOT work: DYLD_PRINT_BINDINGS=''
does NOT work: DYLD_PRINT_INITIALIZERS=''
does NOT work: DYLD_PRINT_REBASINGS=''
does NOT work: DYLD_PRINT_SEGMENTS=''
does NOT work: DYLD_PRINT_STATISTICS=''
does NOT work: DYLD_PRINT_DOFS=''
does NOT work: DYLD_PRINT_RPATHS=''
does NOT work: DYLD_SHARED_CACHE_DIR=''
does NOT work: DYLD_SHARED_CACHE_DONT_VALIDATE=''
does NOT work: DYLD_LIBRARY_PATH_=''
does NOT work: DYLD_LIBRARY_bar=''
does NOT work: DYLD_bar=''
does     work: DYLDbar='foo'
does     work: _DYLD_LIBRARY_PATH='foo'
does     work: dyld_library_path='foo'
does     work: dyld_bar='foo'
does NOT work: LD_LIBRARY_PATH=''
does     work: LD_LIBRARY_PATH_='foo'
does     work: LD_LIBRARY_baz='foo'
does     work: LD_LIBRARYbaz='foo'
does     work: LD_PRELOAD='foo'
does     work: LD_PRELOAD_baz='foo'
does     work: LD_PRELOAD_='foo'
does     work: LD_LIBRARYbaz='foo'
does     work: LD_baz='foo'
does     work: LDbaz='foo'
does     work: _LD_LIBRARY_PATH='foo'
does     work: ld_library_path='foo'
#!/bin/sh -e
# A script to see what environment variables get dropped by OS X's dyld loader
value=foo
define() { export "$1=$value"; }
show() {
case ${!1} in
"$value")
echo "does work: $1='${!1}'"
;;
*)
echo "does NOT work: $1='${!1}'"
esac
}
[ $# -gt 0 ] || set -- define
test=$1
# sanity check
$test some_random_env_var
$test another_random_name
$test PATH
$test USER
$test LOGNAME
$test HOME
# OS X dyld variables all get dropped
$test DYLD_FRAMEWORK_PATH
$test DYLD_FALLBACK_FRAMEWORK_PATH
$test DYLD_VERSIONED_FRAMEWORK_PATH
$test DYLD_LIBRARY_PATH
$test DYLD_FALLBACK_LIBRARY_PATH
$test DYLD_VERSIONED_LIBRARY_PATH
$test DYLD_PRINT_TO_FILE
$test DYLD_ROOT_PATH
$test DYLD_SHARED_REGION
$test DYLD_INSERT_LIBRARIES
$test DYLD_FORCE_FLAT_NAMESPACE
$test DYLD_IMAGE_SUFFIX
$test DYLD_PRINT_OPTS
$test DYLD_PRINT_ENV
$test DYLD_PRINT_LIBRARIES
$test DYLD_PRINT_LIBRARIES_POST_LAUNCH
$test DYLD_BIND_AT_LAUNCH
$test DYLD_DISABLE_DOFS
$test DYLD_PRINT_APIS
$test DYLD_PRINT_BINDINGS
$test DYLD_PRINT_INITIALIZERS
$test DYLD_PRINT_REBASINGS
$test DYLD_PRINT_SEGMENTS
$test DYLD_PRINT_STATISTICS
$test DYLD_PRINT_DOFS
$test DYLD_PRINT_RPATHS
$test DYLD_SHARED_CACHE_DIR
$test DYLD_SHARED_CACHE_DONT_VALIDATE
# some variants still get dropped
$test DYLD_LIBRARY_PATH_
$test DYLD_LIBRARY_bar
$test DYLD_bar
$test DYLDbar
$test _DYLD_LIBRARY_PATH
$test dyld_library_path
$test dyld_bar
# Linux LD_LIBRARY_PATH also gets dropped
$test LD_LIBRARY_PATH
$test LD_LIBRARY_PATH_
$test LD_LIBRARY_baz
$test LD_LIBRARYbaz
$test LD_PRELOAD
$test LD_PRELOAD_baz
$test LD_PRELOAD_
$test LD_LIBRARYbaz
$test LD_baz
$test LDbaz
$test _LD_LIBRARY_PATH
$test ld_library_path
: ----------------------------------------------------------------------------
case $test in
define) exec "$0" show ;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment