Re: pg_preadv() and pg_pwritev()
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Thomas Munro <thomas.munro@gmail.com>
Cc: Sergey Shinderuk <s.shinderuk@postgrespro.ru>,
pgsql-hackers <pgsql-hackers@postgresql.org>
Date: 2021-01-13T23:22:02Z
Lists: pgsql-hackers
Attachments
- forbid-weak-linking-on-macos.patch (text/x-diff) patch
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
Commits
-
Improve our heuristic for selecting PG_SYSROOT on macOS.
- 3934543c2bb0 9.5.25 landed
- fc6d08b27a33 9.6.21 landed
- 5fa060c8f593 10.16 landed
- 046c8facecee 11.11 landed
- f5d044eaeff0 12.6 landed
- f44ae4db5fec 13.2 landed
- 4823621db312 14.0 landed
-
Move our p{read,write}v replacements into their own files.
- 0d56acfbaa79 14.0 landed
-
Don't use elog() in src/port/pwrite.c.
- df10ac625c16 14.0 landed
-
Use vectored I/O to fill new WAL segments.
- ce6a71fa5300 14.0 landed
-
Provide pg_preadv() and pg_pwritev().
- 13a021f3e8c9 14.0 landed