This makes "make check" work on Mac OS X. Without this patch, on Mac OS X a
default "./configure; make; make check" fails with errors like:

dyld[65265]: Library not loaded: /usr/local/pgsql/lib/libpq.5.dylib
  Referenced from: <59A2EAF9-6298-3112-BEDB-EA9A62A9DB53>
/Users/evan.jones/postgresql-clean/tmp_install/usr/local/pgsql/bin/initdb
  Reason: tried: '/usr/local/pgsql/lib/libpq.5.dylib' (no such file),
'/System/Volumes/Preboot/Cryptexes/OS/usr/local/pgsql/lib/libpq.5.dylib'
(no such file), '/usr/local/pgsql/lib/libpq.5.dylib' (no such file),
'/usr/local/lib/libpq.5.dylib' (no such file), '/usr/lib/libpq.5.dylib' (no
such file, not in dyld cache)

The reason is that at some point, Mac OS X started removing the
DYLD_LIBRARY_PATH environment variable for "untrusted" executables [1]:
"Any dynamic linker (dyld) environment variables, such as
DYLD_LIBRARY_PATH, are purged when launching protected processes."

[1]
https://developer.apple.com/library/archive/documentation/Security/Conceptual/System_Integrity_Protection_Guide/RuntimeProtections/RuntimeProtections.html

One solution is to explicitly pass the DYLD_LIBRARY_PATH environment
variable to to the sub-process shell scripts that are run by pg_regress. To
do this, I created an extra_envvars global variable which is set to the
empty string "", but on Mac OS X, is filled in with "DYLD_LIBRARY_PATH=%s",
where the %s is the current environment variable. The "make check" Makefile
sets this environment variable to the temporary install directory, so this
fixes the above errors.

I tested this on Mac OS X and on Linux (Ubuntu 23.04).

Thanks!

Evan Jones

Attachment: pg_regress_mac_os_x_dyld.patch
Description: Binary data

Reply via email to