Re: Annoying build warnings from latest Apple toolchain

From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Peter Eisentraut <peter(at)eisentraut(dot)org>
Cc: Andres Freund <andres(at)anarazel(dot)de>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Noah Misch <noah(at)leadboat(dot)com>, pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: Annoying build warnings from latest Apple toolchain
Date: 2023-11-28 15:48:04
Message-ID: CA+TgmoYixWx2HXLSJJ1NFeHYdsTPfsyFMq0Jc8cK3vnQtPVA0A@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Tue, Nov 21, 2023 at 9:59 AM Peter Eisentraut <peter(at)eisentraut(dot)org> wrote:
> Btw., I'm also seeing warnings like this. I'm using homebrew. Here is
> a sample:
>
> [145/147] Linking target src/test/modules/test_shm_mq/test_shm_mq.dylib
> -macosx_version_min has been renamed to -macos_version_min
> ld: warning: -undefined error is deprecated
> ld: warning: ignoring duplicate libraries: '-lgcc'
> [146/147] Linking target src/test/modules/test_slru/test_slru.dylib

I poked at this issue a bit more. In meson.build, for Darwin, we have this:

# meson defaults to -Wl,-undefined,dynamic_lookup for modules, which we
# don't want because a) it's different from what we do for autoconf, b) it
# causes warnings starting in macOS Ventura
ldflags_mod += ['-Wl,-undefined,error']

I don't really understand how meson works, but I blindly tried
commenting that out. What I found is that doing so reduces the number
of warnings that I get locally from 226 to 113. The difference seems
to be that, with the unpatched meson.build file, I get warnings both
about binaries and also about loadable modules, but with the patched
version, the loadable modules stop emitting warnings, and the binaries
continue to do so. This gives the flavor:

-[] Linking target contrib/adminpack/adminpack.dylib
-[] Linking target contrib/amcheck/amcheck.dylib
...
-[] Linking target src/backend...version_procs/latin2_and_win1250.dylib
-[] Linking target src/backend...version_procs/utf8_and_iso8859_1.dylib
[] Linking target src/backend/postgres
-[] Linking target src/backend/replication/pgoutput/pgoutput.dylib
-[] Linking target src/backend/snowball/dict_snowball.dylib
[] Linking target src/bin/initdb/initdb
[] Linking target src/bin/pg_amcheck/pg_amcheck
[] Linking target src/bin/pg_archivecleanup/pg_archivecleanup
[] Linking target src/bin/pg_basebackup/pg_basebackup
...

The lines with - at the beginning are the warnings that disappear when
I comment out the addition to ldflags_mod. The lines without a - at
the beginning are the ones that appear either way.

The first, rather inescapable, conclusion is that the comment isn't
completely correct. It claims that we need to add -Wl,-undefined,error
on macOS Ventura to avoid warnings, but on my system it has exactly
the opposite effect: it produces warnings. I think we must have
misdiagnosed what the triggering condition actually is -- maybe it
depends on CPU architecture or choice of compiler or something, but
it's not as simple as "on Ventura you need this" because I am on
Ventura and I anti-need this.

The second conclusion that I draw is that there's something in meson
itself which is adding -Wl,-undefined,error when building binaries.
The snippet above is the only place in the entire source tree where we
specify a -undefined flag for a compile. The fact that the warning
still shows up when I comment that out means that in other cases,
meson itself is adding the flag, seemingly wrongly. But I don't know
how to make it not do that. I tried adding an option to ldflags, but
the linker isn't happy with adding something like
-Wl,-undefined,warning --- then it complains about both
-Wl,-undefined,error and -Wl,-undefined,warning. Apparently, what it
really wants is for the option to not be specified at all:

https://stackoverflow.com/questions/77525544/apple-linker-warning-ld-warning-undefined-error-is-deprecated

See also https://github.com/mesonbuild/meson/issues/12450

What a stupid, annoying decision on Apple's part. It seems like
-Wl,-undefined,error is the default behavior, so they could have just
ignored that flag if present, but instead they complain about being
asked to do what they were going to do anyway.

--
Robert Haas
EDB: http://www.enterprisedb.com

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Drouvot, Bertrand 2023-11-28 15:58:15 Re: Synchronizing slots from primary to standby
Previous Message Andrew Dunstan 2023-11-28 15:48:00 Re: Missing docs on AT TIME ZONE precedence?