Re: pg_preadv() and pg_pwritev()

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Thomas Munro <thomas(dot)munro(at)gmail(dot)com>
Cc: Sergey Shinderuk <s(dot)shinderuk(at)postgrespro(dot)ru>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: pg_preadv() and pg_pwritev()
Date: 2021-01-13 23:22:02
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

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

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

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

Attachment Content-Type Size
forbid-weak-linking-on-macos.patch text/x-diff 393 bytes

In response to


Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Geoghegan 2021-01-13 23:47:52 Re: Yet another fast GiST build
Previous Message Tomas Vondra 2021-01-13 23:11:40 Re: WIP: BRIN multi-range indexes