Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kzpSy-0002bB-Hi for pgsql-hackers@arkaria.postgresql.org; Wed, 13 Jan 2021 23:22:16 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kzpSx-0004nK-5G for pgsql-hackers@arkaria.postgresql.org; Wed, 13 Jan 2021 23:22:15 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kzpSw-0004nC-UG for pgsql-hackers@lists.postgresql.org; Wed, 13 Jan 2021 23:22:14 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kzpSs-00073k-CX for pgsql-hackers@postgresql.org; Wed, 13 Jan 2021 23:22:14 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 10DNM23U1341609; Wed, 13 Jan 2021 18:22:03 -0500 From: Tom Lane To: Thomas Munro cc: Sergey Shinderuk , pgsql-hackers Subject: Re: pg_preadv() and pg_pwritev() In-reply-to: <1297389.1610562046@sss.pgh.pa.us> References: <341497.1608420857@sss.pgh.pa.us> <20201220224040.evr5pduibvm6dze5@alap3.anarazel.de> <448b3cb5-0ba0-6dc5-63c7-789e4eebc40b@postgrespro.ru> <1283127.1610554395@sss.pgh.pa.us> <1286060.1610558607@sss.pgh.pa.us> <1297389.1610562046@sss.pgh.pa.us> Comments: In-reply-to Tom Lane message dated "Wed, 13 Jan 2021 13:20:46 -0500" MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0" Content-ID: <1341554.1610580049.0@sss.pgh.pa.us> Date: Wed, 13 Jan 2021 18:22:02 -0500 Message-ID: <1341608.1610580122@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk ------- =_aaaaaaaaaa0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1341554.1610580049.1@sss.pgh.pa.us> 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 ------- =_aaaaaaaaaa0 Content-Type: text/x-diff; name="forbid-weak-linking-on-macos.patch"; charset="us-ascii" Content-ID: <1341554.1610580049.2@sss.pgh.pa.us> Content-Description: forbid-weak-linking-on-macos.patch 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="" ------- =_aaaaaaaaaa0--