I wrote: > So I'm a little confused as to why this test is failing to fail > with (I assume) newer Xcode. Can we see the relevant part of > config.log on your machine?
After further digging I believe I understand what's happening, and it's a bit surprising we've not been bit by it before. If the compiler believes (thanks to __API_AVAILABLE macros in Apple's system headers) that a given library symbol might not exist in the lowest macOS version it is compiling for, it will still emit a normal call to that function ... but it also emits .weak_reference _preadv marking the call as a weak reference. If the linker then fails to link that call, it doesn't throw an error, it just replaces the call instruction with a NOP :-(. This is why configure's test appears to succeed, since it only checks whether you can link not whether the call would work at runtime. Apple's assumption evidently is that you'll guard the call with a run-time check to see if the function exists before you use it, and you don't want your link to fail if it doesn't. The solution to this, according to "man ld", is -no_weak_imports Error if any symbols are weak imports (i.e. allowed to be unresolved (NULL) at runtime). Useful for config based projects that assume they are built and run on the same OS version. I don't particularly care that Apple is looking down their nose at people who don't want to make their builds run on multiple OS versions, so I think we should just use this and call it good. Attached is an untested quick hack to make that happen --- Sergey, can you verify that this fixes configure's results on your setup? (This is not quite committable as-is, it needs something to avoid adding -Wl,-no_weak_imports on ancient macOS versions. But it will do to see if the fix works on modern versions.) regards, tom lane
diff --git a/src/template/darwin b/src/template/darwin index 32414d21a9..22d04e7ba7 100644 --- a/src/template/darwin +++ b/src/template/darwin @@ -17,6 +17,9 @@ if test x"$PG_SYSROOT" != x"" ; then fi fi +# Disable weak linking, else configure's checks will misbehave +LDFLAGS="-Wl,-no_weak_imports $LDFLAGS" + # Extra CFLAGS for code that will go into a shared library CFLAGS_SL=""