static libpq (and other libraries) overwritten on aix

Started by Andres Freundover 3 years ago13 messages
#1Andres Freund
andres@anarazel.de

Hi,

I was hacking in making aix work with the meson patchset last night when I
noticed this delightful bit:

gmake -C src/interfaces/libpq
...

rm -f libpq.a
ar crs libpq.a fe-auth-scram.o fe-connect.o fe-exec.o fe-lobj.o fe-misc.o fe-print.o fe-protocol3.o fe-secure.o fe-trace.o legacy-pqsignal.o libpq-events.o pqexpbuffer.o fe-auth.o
touch libpq.a

( echo '#! libpq.so.5'; gawk '/^[^#]/ {printf "%s\n",$1}' /home/andres/src/postgres/build-ac/../src/interfaces/libpq/exports.txt ) >libpq.exp
gcc -maix64 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wimplicit-fallthrough=3 -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -Wno-format-truncation -O2 -pthread -D_REENTRANT -D_THREAD_SAFE -o libpq.so.5 libpq.a -Wl,-bE:libpq.exp -L../../../src/port -L../../../src/common -lpgcommon_shlib -lpgport_shlib -Wl,-bbigtoc -Wl,-blibpath:'/usr/local/pgsql/lib:/usr/lib:/lib' -Wl,-bnoentry -Wl,-H512 -Wl,-bM:SRE -lm

rm -f libpq.a
ar crs libpq.a libpq.so.5

we first create a static library libpq.a as normal, but then we overwrite it
with the special aix way of packing up shared libraries, by packing them up in
a static library. That part is correct, it's apparently the easiest way of
getting applications to link to shared libraries on AIX (I think the
-Wl,-bM:SRE is relevant for ensuring it'll be a dynamic link, rather than a
static one).

This likely has been going on for approximately forever.

Two questions:
1) Do we continue building static libraries for libpq etc?
2) Do we care about static libraries not suriving on AIX? There could also be
a race in the buildrules leading to sometimes static libs sometimes shared
libs winning, I think.

Greetings,

Andres Freund

#2Robert Haas
robertmhaas@gmail.com
In reply to: Andres Freund (#1)
Re: static libpq (and other libraries) overwritten on aix

On Wed, Aug 17, 2022 at 3:02 PM Andres Freund <andres@anarazel.de> wrote:

2) Do we care about static libraries not suriving on AIX? There could also be
a race in the buildrules leading to sometimes static libs sometimes shared
libs winning, I think.

Instead of overwriting the same file, can we not use different
filenames for different things?

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

#3Andres Freund
andres@anarazel.de
In reply to: Robert Haas (#2)
Re: static libpq (and other libraries) overwritten on aix

Hi,

On 2022-08-17 15:28:18 -0400, Robert Haas wrote:

On Wed, Aug 17, 2022 at 3:02 PM Andres Freund <andres@anarazel.de> wrote:

2) Do we care about static libraries not suriving on AIX? There could also be
a race in the buildrules leading to sometimes static libs sometimes shared
libs winning, I think.

Instead of overwriting the same file, can we not use different
filenames for different things?

Not easily, as far as I understand. The way one customarily links to shared
libraries on aix is to have an .a archive containing the shared library. That
way the -lpq picks up libpq.a, which then triggers the shared library to be
referenced.

E.g.
andres@gcc119:[/home/andres/src/postgres/build-ac]$ LIBPATH=$(pwd)/src/interfaces/libpq ldd src/bin/scripts/clusterdb
src/bin/scripts/clusterdb needs:
/usr/lib/libc.a(shr_64.o)
/usr/lib/libpthread.a(shr_xpg5_64.o)
/usr/lib/libreadline.a(libreadline.so.6)
/home/andres/src/postgres/build-ac/src/interfaces/libpq/libpq.a(libpq.so.5)
/unix
/usr/lib/libcrypt.a(shr_64.o)
/usr/lib/libcurses.a(shr42_64.o)
/usr/lib/libpthreads.a(shr_xpg5_64.o)

Note the .a(libpq.so.5) bit.

Unfortunately that's exactly how one links to a static library as well.

So we'd have to change the name used as -l$this between linking to a shared
libpq and a static libpq.

Greetings,

Andres Freund

#4Noah Misch
noah@leadboat.com
In reply to: Andres Freund (#1)
Re: static libpq (and other libraries) overwritten on aix

The AIX sections of Makefile.shlib misuse the terms "static" and "shared".
Imagine s/static library/library ending in .a/ and s/shared library/library
ending in .so/. That yields an accurate description of the makefile rules.

On Wed, Aug 17, 2022 at 12:01:54PM -0700, Andres Freund wrote:

Two questions:
1) Do we continue building static libraries for libpq etc?

Essentially, we don't build static libpq today, and we should continue not
building it. (The first-built libpq.a is static, but that file is an
implementation detail of the makefile rules. The surviving libpq.a is a
normal AIX shared library.)

2) Do we care about static libraries not suriving on AIX?

No.

There could also be
a race in the buildrules leading to sometimes static libs sometimes shared
libs winning, I think.

Not since commit e8564ef, to my knowledge.

Along the lines of Robert's comment, it could be a nice code beautification to
use a different suffix for the short-lived .a file. Perhaps _so_inputs.a.

I found this useful years ago:
https://web.archive.org/web/20151003130212/http://seriousbirder.com/blogs/aix-shared-and-static-libraries-explained/

#5Robert Haas
robertmhaas@gmail.com
In reply to: Noah Misch (#4)
Re: static libpq (and other libraries) overwritten on aix

On Thu, Aug 18, 2022 at 12:59 AM Noah Misch <noah@leadboat.com> wrote:

Along the lines of Robert's comment, it could be a nice code beautification to
use a different suffix for the short-lived .a file. Perhaps _so_inputs.a.

Yeah, this is the kind of thing I was thinking about.

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

#6Andrew Dunstan
andrew@dunslane.net
In reply to: Robert Haas (#5)
Re: static libpq (and other libraries) overwritten on aix

On 2022-08-18 Th 10:10, Robert Haas wrote:

On Thu, Aug 18, 2022 at 12:59 AM Noah Misch <noah@leadboat.com> wrote:

Along the lines of Robert's comment, it could be a nice code beautification to
use a different suffix for the short-lived .a file. Perhaps _so_inputs.a.

Yeah, this is the kind of thing I was thinking about.

+1 for that and clarifying Makefile.shlib.

cheers

andrew

--
Andrew Dunstan
EDB: https://www.enterprisedb.com

#7Andres Freund
andres@anarazel.de
In reply to: Noah Misch (#4)
Re: static libpq (and other libraries) overwritten on aix

Hi,

On 2022-08-17 21:59:29 -0700, Noah Misch wrote:

The AIX sections of Makefile.shlib misuse the terms "static" and "shared".

Imagine s/static library/library ending in .a/ and s/shared library/library
ending in .so/. That yields an accurate description of the makefile rules.

I realize that aspect.

My point is that we currently, across most of the other platforms, support
building a "proper" static library, and install it too. But on AIX (and I
think mingw), we don't, but without an explicit comment about not doing so. In
fact, the all-static-lib target on those platforms will build a non-static
library, which seems not great.

There could also be
a race in the buildrules leading to sometimes static libs sometimes shared
libs winning, I think.

Not since commit e8564ef, to my knowledge.

I'd missed that the $(stlib): ... bit is not defined due to haslibarule being
defined...

Along the lines of Robert's comment, it could be a nice code beautification to
use a different suffix for the short-lived .a file. Perhaps _so_inputs.a.

Agreed, it'd be an improvement.

Afaict we could just stop building the intermediary static lib. Afaict the
MKLDEXPORT path isn't needed for libraries without an exports.txt because the
linker defaults to exporting "most" symbols, and for symbols with an
exports.txt we don't need it either.

The only path that really needs MKLDEXPORT is postgres. Not really for the
export side either, but for the import side.

Greetings,

Andres Freund

#8Noah Misch
noah@leadboat.com
In reply to: Andres Freund (#7)
Re: static libpq (and other libraries) overwritten on aix

On Thu, Aug 18, 2022 at 09:03:57AM -0700, Andres Freund wrote:

My point is that we currently, across most of the other platforms, support
building a "proper" static library, and install it too. But on AIX (and I
think mingw), we don't, but without an explicit comment about not doing so. In
fact, the all-static-lib target on those platforms will build a non-static
library, which seems not great.

Yep. If someone had just pushed a correct patch to make AIX match our
GNU/Linux static linking assistance, I wouldn't be arguing to revert that
patch. At the same time, if someone asks me to choose high-value projects for
20 people, doing more for static linking on AIX won't be on the list.

On 2022-08-17 21:59:29 -0700, Noah Misch wrote:

Along the lines of Robert's comment, it could be a nice code beautification to
use a different suffix for the short-lived .a file. Perhaps _so_inputs.a.

Agreed, it'd be an improvement.

Afaict we could just stop building the intermediary static lib. Afaict the
MKLDEXPORT path isn't needed for libraries without an exports.txt because the
linker defaults to exporting "most" symbols

If that works, great.

#9Andres Freund
andres@anarazel.de
In reply to: Noah Misch (#8)
Re: static libpq (and other libraries) overwritten on aix

Hi,

On 2022-08-18 22:56:43 -0700, Noah Misch wrote:

On 2022-08-17 21:59:29 -0700, Noah Misch wrote:

Along the lines of Robert's comment, it could be a nice code beautification to
use a different suffix for the short-lived .a file. Perhaps _so_inputs.a.

Agreed, it'd be an improvement.

Afaict we could just stop building the intermediary static lib. Afaict the
MKLDEXPORT path isn't needed for libraries without an exports.txt because the
linker defaults to exporting "most" symbols

If that works, great.

I looked at that. It's not too hard to make it work. But while doing so I
encountered some funny bits.

As far as I can tell the way we build shared libraries on aix with gcc isn't
correct:

Without -shared gcc won't know that it's building a shared library, which
afaict will prevent gcc from generating correct unwind info and we end up with
a statically linked copy of libgcc each time.

The naive thing of just adding -shared fails, but that's our fault:

ldd pgoutput.so
pgoutput.so needs:
Cannot find libgcc_s.a(shr.o)
/usr/lib/libc.a(shr_64.o)
/unix
/usr/lib/libcrypt.a(shr_64.o)

Makefile.aix has:
# -blibpath must contain ALL directories where we should look for libraries
libpath := $(shell echo $(subst -L,:,$(filter -L/%,$(LDFLAGS))) | sed -e's/ //g'):/usr/lib:/lib

but that's insufficient for gcc, because it won't find gcc's runtime lib. We
could force a build of the statically linked libgcc, but once it knows it's
generating with a shared library, a static libgcc unfortunately blows up the
size of the output considerably.

So I think we need something like

ifeq ($(GCC), yes)
libpath := $(libpath):$(dir $(shell gcc -print-libgcc-file-name))
endif

although deferring the computation of that would be nicer, but would require
some cleanup before.

With that libraries do shrink a bit. E.g. cube.so goes from 140k to 96k.

Afaict there's no reason to generate lib<name>.a for extension .so's, right?

We have plenty of detritus that's vaguely AIX related. The common.mk rule to
generate SUBSYS.o isn't used (mea culpa), and backend/Makefile's postgres.o
rule hasn't been used for well over 20 years.

I'll send in a patch series tomorrow, too tired for today.

Greetings,

Andres Freund

#10Noah Misch
noah@leadboat.com
In reply to: Andres Freund (#9)
Re: static libpq (and other libraries) overwritten on aix

On Sat, Aug 20, 2022 at 01:35:22AM -0700, Andres Freund wrote:

Afaict there's no reason to generate lib<name>.a for extension .so's, right?

Right. We install cube.so, not any *cube.a file.

#11Andres Freund
andres@anarazel.de
In reply to: Andres Freund (#9)
6 attachment(s)
Re: static libpq (and other libraries) overwritten on aix

Hi,

On 2022-08-20 01:35:22 -0700, Andres Freund wrote:

I'll send in a patch series tomorrow, too tired for today.

Here it goes.

0001 aix: Fix SHLIB_EXPORTS reference in VPATH builds

That's mostly so I could even build. It's not quite right in the sense that
we don't depend on the file, but that's a preexisting issue. Could be folded
in with 0005, which fixes that aspect. Or it could be backpatched as the
minimal fix.

0002 Remove SUBSYS.o rule in common.mk, hasn't been used in a long time
0003 Remove rule to generate postgres.o, not needed for 20+ years

Both obvious, I think.

0004 aix: when building with gcc, tell gcc we're building a shared library

That's the gcc -shared issue I explained in the email I'm replying to.

We should probably consider building executables with -shared-libgcc too,
that shrinks them a decent amount (e.g. 1371684 -> 1126765 for psql). But
I've not done that here.

0005 aix: No need to use mkldexport when we want to export all symbols

This makes the building of shared libraries a lot more similar to other
platforms. Export files are only used when an exports.txt is present and
there's no more intermediary static libraries.

0006 configure: Expand -fvisibility checks to more compilers, add -qvisibility

This isn't strictly speaking part of the same "thread" of work, but I don't
want to touch aix more often than I have too... I'll post it in the other
thread too.

I did just test that this passes at least some tests on aix with xlc and
solaris with sunpro.

Greetings,

Andres

Attachments:

v1-0001-aix-Fix-SHLIB_EXPORTS-reference-in-VPATH-builds.patchtext/x-diff; charset=us-asciiDownload
From 0569092ec6f33ddf002ad73fb2630bbb80ffbe75 Mon Sep 17 00:00:00 2001
From: Andres Freund <andres@anarazel.de>
Date: Wed, 17 Aug 2022 13:04:33 -0700
Subject: [PATCH v1 1/6] aix: Fix SHLIB_EXPORTS reference in VPATH builds

The dependencies here aren't quite right independent of vpath builds or not,
but this at least makes vpath builds succeed. And it's pretty rare to change
the exports.txt file anyway...
---
 src/Makefile.shlib | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/Makefile.shlib b/src/Makefile.shlib
index 2af6192f0f3..6624fa79615 100644
--- a/src/Makefile.shlib
+++ b/src/Makefile.shlib
@@ -302,7 +302,7 @@ $(shlib): $(OBJS) | $(SHLIB_PREREQS)
 ifeq (,$(SHLIB_EXPORTS))
 	$(MKLDEXPORT) $(stlib) $(shlib) >$(exports_file)
 else
-	( echo '#! $(shlib)'; $(AWK) '/^[^#]/ {printf "%s\n",$$1}' $(SHLIB_EXPORTS) ) >$(exports_file)
+	( echo '#! $(shlib)'; $(AWK) '/^[^#]/ {printf "%s\n",$$1}' ${srcdir}/$(SHLIB_EXPORTS) ) >$(exports_file)
 endif
 	$(COMPILER) -o $(shlib) $(stlib) -Wl,-bE:$(exports_file) $(LDFLAGS) $(LDFLAGS_SL) $(SHLIB_LINK)
 	rm -f $(stlib)
-- 
2.37.0.3.g30cc8d0f14

v1-0002-Remove-SUBSYS.o-rule-in-common.mk-hasn-t-been-use.patchtext/x-diff; charset=us-asciiDownload
From 3fb77733bd862f7f7a0929353d9aa5b94a685d91 Mon Sep 17 00:00:00 2001
From: Andres Freund <andres@anarazel.de>
Date: Fri, 19 Aug 2022 17:32:12 -0700
Subject: [PATCH v1 2/6] Remove SUBSYS.o rule in common.mk, hasn't been used in
 a long time

Apparently I missed that this SUBSYS.o rule isn't needed anymore in
a4ebbd27527, likely because there still is a reference to it due to AIX - but
that's self contained in src/backend/Makefile
---
 src/backend/common.mk | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/src/backend/common.mk b/src/backend/common.mk
index 663e9f886ce..fa96a82b1a0 100644
--- a/src/backend/common.mk
+++ b/src/backend/common.mk
@@ -17,9 +17,6 @@ ifneq ($(subdir), src/backend)
 all: $(subsysfilename)
 endif
 
-SUBSYS.o: $(SUBDIROBJS) $(OBJS)
-	$(LD) $(LDREL) $(LDOUT) $@ $^
-
 objfiles.txt: Makefile $(SUBDIROBJS) $(OBJS)
 # Don't rebuild the list if only the OBJS have changed.
 	$(if $(filter-out $(OBJS),$?),( $(if $(SUBDIROBJS),cat $(SUBDIROBJS); )echo $(addprefix $(subdir)/,$(OBJS)) ) >$@,touch $@)
-- 
2.37.0.3.g30cc8d0f14

v1-0003-Remove-rule-to-generate-postgres.o-not-needed-for.patchtext/x-diff; charset=us-asciiDownload
From d02c3479e9c0255a60cd0b61969a2973278f122a Mon Sep 17 00:00:00 2001
From: Andres Freund <andres@anarazel.de>
Date: Fri, 19 Aug 2022 19:06:44 -0700
Subject: [PATCH v1 3/6] Remove rule to generate postgres.o, not needed for 20+
 years

---
 src/backend/Makefile | 6 ------
 1 file changed, 6 deletions(-)

diff --git a/src/backend/Makefile b/src/backend/Makefile
index 3f01c655927..f498cfd5930 100644
--- a/src/backend/Makefile
+++ b/src/backend/Makefile
@@ -110,12 +110,6 @@ endif # aix
 $(top_builddir)/src/port/libpgport_srv.a: | submake-libpgport
 
 
-# The postgres.o target is needed by the rule in Makefile.global that
-# creates the exports file when MAKE_EXPORTS = true.
-postgres.o: $(OBJS)
-	$(CC) $(LDREL) $(call expand_subsys,$^) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@
-
-
 # The following targets are specified in make commands that appear in
 # the make files in our subdirectories. Note that it's important we
 # match the dependencies shown in the subdirectory makefiles!
-- 
2.37.0.3.g30cc8d0f14

v1-0004-aix-when-building-with-gcc-tell-gcc-we-re-buildin.patchtext/x-diff; charset=us-asciiDownload
From e08492cdaa9cdac45302d6d25943bd527b687ff0 Mon Sep 17 00:00:00 2001
From: Andres Freund <andres@anarazel.de>
Date: Sat, 20 Aug 2022 08:30:22 -0700
Subject: [PATCH v1 4/6] aix: when building with gcc, tell gcc we're building a
 shared library

Not passing -shared to gcc when building a shared library triggers linking to
the wrong libgcc (libgcc.a instead of libgcc_s.a) and prevents emitting
correct unwind information. It's somewhat surprising that this hasn't caused
known problems so far.

Doing so requires adding path to libgcc to libpath, or linking statically to
libgcc - as the latter increases .so size substantially (for not entirely
obvious reasons), shared linking seems preferrable.
---
 src/makefiles/Makefile.aix | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/src/makefiles/Makefile.aix b/src/makefiles/Makefile.aix
index 4cf2cc52d45..9408c1e2913 100644
--- a/src/makefiles/Makefile.aix
+++ b/src/makefiles/Makefile.aix
@@ -8,10 +8,21 @@ AROPT = crs
 # -blibpath must contain ALL directories where we should look for libraries
 libpath := $(shell echo $(subst -L,:,$(filter -L/%,$(LDFLAGS))) | sed -e's/ //g'):/usr/lib:/lib
 
+# when building with gcc, need to make sure that libgcc can be found
+ifeq ($(GCC), yes)
+libpath := $(libpath):$(dir $(shell gcc -print-libgcc-file-name))
+endif
+
 rpath = -Wl,-blibpath:'$(rpathdir)$(libpath)'
 
 LDFLAGS_SL += -Wl,-bnoentry -Wl,-H512 -Wl,-bM:SRE
 
+# gcc needs to know it's building a shared lib, otherwise it'll not emit
+# correct code / link to the right support libraries
+ifeq ($(GCC), yes)
+LDFLAGS_SL += -shared
+endif
+
 # env var name to use in place of LD_LIBRARY_PATH
 ld_library_path_var = LIBPATH
 
-- 
2.37.0.3.g30cc8d0f14

v1-0005-aix-No-need-to-use-mkldexport-when-we-want-to-exp.patchtext/x-diff; charset=us-asciiDownload
From 5d3bef050cc92081e5aaff8f324075d039d352a6 Mon Sep 17 00:00:00 2001
From: Andres Freund <andres@anarazel.de>
Date: Sat, 20 Aug 2022 08:43:28 -0700
Subject: [PATCH v1 5/6] aix: No need to use mkldexport when we want to export
 all symbols

When building a shared library with an exports.txt there's no need to build an
intermediary static library, we can just pass -Wl,-bE:... when generating the
.so.

When building a shared library without an exports.txt, there's no need to call
mkldexport.sh to export all symbols, because all symbols are exported anyway,
and we don't need the export file on the import side (like we do for
postgres.imp).

This makes building .so's on aix a lot more similar to building on other
platforms. In particular, we don't create and remove a .a of the same name but
different contents anymore.
---
 src/makefiles/Makefile.aix |  8 ++-----
 src/Makefile.shlib         | 45 +++++++++++++++-----------------------
 2 files changed, 20 insertions(+), 33 deletions(-)

diff --git a/src/makefiles/Makefile.aix b/src/makefiles/Makefile.aix
index 9408c1e2913..56d7f22aff6 100644
--- a/src/makefiles/Makefile.aix
+++ b/src/makefiles/Makefile.aix
@@ -38,9 +38,5 @@ endif
 MKLDEXPORT_DIR=src/backend/port/aix
 MKLDEXPORT=$(top_srcdir)/$(MKLDEXPORT_DIR)/mkldexport.sh
 
-%.exp: %.o
-	$(MKLDEXPORT) $^ >$@
-
-# Rule for building a shared library from a single .o file
-%$(DLSUFFIX): %.o %.exp
-	$(CC) $(CFLAGS) $*.o $(LDFLAGS) $(LDFLAGS_SL) -o $@ -Wl,-bE:$*.exp $(BE_DLLLIBS)
+%$(DLSUFFIX): %.o
+	$(CC) $(CFLAGS) $*.o $(LDFLAGS) $(LDFLAGS_SL) -o $@ $(BE_DLLLIBS)
diff --git a/src/Makefile.shlib b/src/Makefile.shlib
index 6624fa79615..45979e518d4 100644
--- a/src/Makefile.shlib
+++ b/src/Makefile.shlib
@@ -107,12 +107,17 @@ override CPPFLAGS += -DSO_MAJOR_VERSION=$(SO_MAJOR_VERSION)
 endif
 
 ifeq ($(PORTNAME), aix)
+  LINK.shared		= $(COMPILER)
   ifdef SO_MAJOR_VERSION
     shlib		= lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
   endif
   haslibarule   = yes
   # $(exports_file) is also usable as an import file
   exports_file		= lib$(NAME).exp
+  BUILD.exports		= ( echo '\#! $(shlib)'; $(AWK) '/^[^\#]/ {printf "%s\n",$$1}' $< ) > $@
+  ifneq (,$(SHLIB_EXPORTS))
+    LINK.shared		+= -Wl,-bE:$(exports_file)
+  endif
 endif
 
 ifeq ($(PORTNAME), darwin)
@@ -254,9 +259,15 @@ $(stlib): $(OBJS) | $(SHLIB_PREREQS)
 	touch $@
 endif #haslibarule
 
+# AIX wraps shared libraries inside a static library, can be used both
+# for static and shared linking
+ifeq ($(PORTNAME), aix)
+$(stlib): $(shlib)
+	rm -f $(stlib)
+	$(AR) $(AROPT) $(stlib) $(shlib)
+endif # aix
 
 ifeq (,$(filter cygwin win32,$(PORTNAME)))
-ifneq ($(PORTNAME), aix)
 
 # Normal case
 $(shlib): $(OBJS) | $(SHLIB_PREREQS)
@@ -269,9 +280,12 @@ ifneq ($(shlib), $(shlib_major))
 endif
 # Make sure we have a link to a name without any version numbers
 ifneq ($(shlib), $(shlib_bare))
+# except on AIX, where that's not a thing
+ifneq ($(PORTNAME), aix)
 	rm -f $(shlib_bare)
 	$(LN_S) $(shlib) $(shlib_bare)
-endif
+endif # aix
+endif # shlib_bare
 endif # shlib_major
 
 # Where possible, restrict the symbols exported by the library to just the
@@ -280,36 +294,13 @@ endif # shlib_major
 # libpgport along with libpq.
 ifneq (,$(SHLIB_EXPORTS))
 ifdef BUILD.exports
-$(shlib): $(SHLIB_EXPORTS:%.txt=%.list)
+$(shlib): $(exports_file)
 
-$(SHLIB_EXPORTS:%.txt=%.list): %.list: %.txt
+$(exports_file): $(SHLIB_EXPORTS)
 	$(BUILD.exports)
 endif
 endif
 
-else # PORTNAME == aix
-
-# AIX case
-
-# See notes in src/backend/parser/Makefile about the following two rules
-$(stlib): $(shlib)
-	touch $@
-
-$(shlib): $(OBJS) | $(SHLIB_PREREQS)
-	rm -f $(stlib)
-	$(LINK.static) $(stlib) $^
-	$(RANLIB) $(stlib)
-ifeq (,$(SHLIB_EXPORTS))
-	$(MKLDEXPORT) $(stlib) $(shlib) >$(exports_file)
-else
-	( echo '#! $(shlib)'; $(AWK) '/^[^#]/ {printf "%s\n",$$1}' ${srcdir}/$(SHLIB_EXPORTS) ) >$(exports_file)
-endif
-	$(COMPILER) -o $(shlib) $(stlib) -Wl,-bE:$(exports_file) $(LDFLAGS) $(LDFLAGS_SL) $(SHLIB_LINK)
-	rm -f $(stlib)
-	$(AR) $(AROPT) $(stlib) $(shlib)
-
-endif # PORTNAME == aix
-
 else # PORTNAME == cygwin || PORTNAME == win32
 
 ifeq ($(PORTNAME), cygwin)
-- 
2.37.0.3.g30cc8d0f14

v1-0006-configure-Expand-fvisibility-checks-to-more-compi.patchtext/x-diff; charset=us-asciiDownload
From 8b26ae46ccd166ff61268ced999fe7d24e66aeb2 Mon Sep 17 00:00:00 2001
From: Andres Freund <andres@anarazel.de>
Date: Mon, 18 Jul 2022 15:05:58 -0700
Subject: [PATCH v1 6/6] configure: Expand -fvisibility checks to more
 compilers, add -qvisibility

It looks like icc and sunpro both support -fvisibility=hidden and xlc supports
-qvisibility=hidden.
---
 configure    | 398 ++++++++++++++++++++++++++++++++-------------------
 configure.ac |  37 +++--
 2 files changed, 276 insertions(+), 159 deletions(-)

diff --git a/configure b/configure
index b28fccbc470..d93b4058874 100755
--- a/configure
+++ b/configure
@@ -6302,154 +6302,6 @@ if test x"$pgac_cv_prog_CC_cflags__ftree_vectorize" = x"yes"; then
 fi
 
 
-  #
-  # If the compiler knows how to hide symbols add the switch needed for that
-  # to CFLAGS_SL_MODULE and define HAVE_VISIBILITY_ATTRIBUTE.
-  { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${CC} supports -fvisibility=hidden, for CFLAGS_SL_MODULE" >&5
-$as_echo_n "checking whether ${CC} supports -fvisibility=hidden, for CFLAGS_SL_MODULE... " >&6; }
-if ${pgac_cv_prog_CC_cflags__fvisibility_hidden+:} false; then :
-  $as_echo_n "(cached) " >&6
-else
-  pgac_save_CFLAGS=$CFLAGS
-pgac_save_CC=$CC
-CC=${CC}
-CFLAGS="${CFLAGS_SL_MODULE} -fvisibility=hidden"
-ac_save_c_werror_flag=$ac_c_werror_flag
-ac_c_werror_flag=yes
-cat confdefs.h - <<_ACEOF >conftest.$ac_ext
-/* end confdefs.h.  */
-
-int
-main ()
-{
-
-  ;
-  return 0;
-}
-_ACEOF
-if ac_fn_c_try_compile "$LINENO"; then :
-  pgac_cv_prog_CC_cflags__fvisibility_hidden=yes
-else
-  pgac_cv_prog_CC_cflags__fvisibility_hidden=no
-fi
-rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
-ac_c_werror_flag=$ac_save_c_werror_flag
-CFLAGS="$pgac_save_CFLAGS"
-CC="$pgac_save_CC"
-fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv_prog_CC_cflags__fvisibility_hidden" >&5
-$as_echo "$pgac_cv_prog_CC_cflags__fvisibility_hidden" >&6; }
-if test x"$pgac_cv_prog_CC_cflags__fvisibility_hidden" = x"yes"; then
-  CFLAGS_SL_MODULE="${CFLAGS_SL_MODULE} -fvisibility=hidden"
-fi
-
-
-  if test "$pgac_cv_prog_CC_cflags__fvisibility_hidden" = yes; then
-
-$as_echo "#define HAVE_VISIBILITY_ATTRIBUTE 1" >>confdefs.h
-
-  fi
-  # For C++ we additionally want -fvisibility-inlines-hidden
-  { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${CXX} supports -fvisibility=hidden, for CXXFLAGS_SL_MODULE" >&5
-$as_echo_n "checking whether ${CXX} supports -fvisibility=hidden, for CXXFLAGS_SL_MODULE... " >&6; }
-if ${pgac_cv_prog_CXX_cxxflags__fvisibility_hidden+:} false; then :
-  $as_echo_n "(cached) " >&6
-else
-  pgac_save_CXXFLAGS=$CXXFLAGS
-pgac_save_CXX=$CXX
-CXX=${CXX}
-CXXFLAGS="${CXXFLAGS_SL_MODULE} -fvisibility=hidden"
-ac_save_cxx_werror_flag=$ac_cxx_werror_flag
-ac_cxx_werror_flag=yes
-ac_ext=cpp
-ac_cpp='$CXXCPP $CPPFLAGS'
-ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5'
-ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
-ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
-
-cat confdefs.h - <<_ACEOF >conftest.$ac_ext
-/* end confdefs.h.  */
-
-int
-main ()
-{
-
-  ;
-  return 0;
-}
-_ACEOF
-if ac_fn_cxx_try_compile "$LINENO"; then :
-  pgac_cv_prog_CXX_cxxflags__fvisibility_hidden=yes
-else
-  pgac_cv_prog_CXX_cxxflags__fvisibility_hidden=no
-fi
-rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
-ac_ext=c
-ac_cpp='$CPP $CPPFLAGS'
-ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
-ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
-ac_compiler_gnu=$ac_cv_c_compiler_gnu
-
-ac_cxx_werror_flag=$ac_save_cxx_werror_flag
-CXXFLAGS="$pgac_save_CXXFLAGS"
-CXX="$pgac_save_CXX"
-fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv_prog_CXX_cxxflags__fvisibility_hidden" >&5
-$as_echo "$pgac_cv_prog_CXX_cxxflags__fvisibility_hidden" >&6; }
-if test x"$pgac_cv_prog_CXX_cxxflags__fvisibility_hidden" = x"yes"; then
-  CXXFLAGS_SL_MODULE="${CXXFLAGS_SL_MODULE} -fvisibility=hidden"
-fi
-
-  { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${CXX} supports -fvisibility-inlines-hidden, for CXXFLAGS_SL_MODULE" >&5
-$as_echo_n "checking whether ${CXX} supports -fvisibility-inlines-hidden, for CXXFLAGS_SL_MODULE... " >&6; }
-if ${pgac_cv_prog_CXX_cxxflags__fvisibility_inlines_hidden+:} false; then :
-  $as_echo_n "(cached) " >&6
-else
-  pgac_save_CXXFLAGS=$CXXFLAGS
-pgac_save_CXX=$CXX
-CXX=${CXX}
-CXXFLAGS="${CXXFLAGS_SL_MODULE} -fvisibility-inlines-hidden"
-ac_save_cxx_werror_flag=$ac_cxx_werror_flag
-ac_cxx_werror_flag=yes
-ac_ext=cpp
-ac_cpp='$CXXCPP $CPPFLAGS'
-ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5'
-ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
-ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
-
-cat confdefs.h - <<_ACEOF >conftest.$ac_ext
-/* end confdefs.h.  */
-
-int
-main ()
-{
-
-  ;
-  return 0;
-}
-_ACEOF
-if ac_fn_cxx_try_compile "$LINENO"; then :
-  pgac_cv_prog_CXX_cxxflags__fvisibility_inlines_hidden=yes
-else
-  pgac_cv_prog_CXX_cxxflags__fvisibility_inlines_hidden=no
-fi
-rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
-ac_ext=c
-ac_cpp='$CPP $CPPFLAGS'
-ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
-ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
-ac_compiler_gnu=$ac_cv_c_compiler_gnu
-
-ac_cxx_werror_flag=$ac_save_cxx_werror_flag
-CXXFLAGS="$pgac_save_CXXFLAGS"
-CXX="$pgac_save_CXX"
-fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv_prog_CXX_cxxflags__fvisibility_inlines_hidden" >&5
-$as_echo "$pgac_cv_prog_CXX_cxxflags__fvisibility_inlines_hidden" >&6; }
-if test x"$pgac_cv_prog_CXX_cxxflags__fvisibility_inlines_hidden" = x"yes"; then
-  CXXFLAGS_SL_MODULE="${CXXFLAGS_SL_MODULE} -fvisibility-inlines-hidden"
-fi
-
   #
   # The following tests want to suppress various unhelpful warnings by adding
   # -Wno-foo switches.  But gcc won't complain about unrecognized -Wno-foo
@@ -7005,6 +6857,256 @@ fi
 
 fi
 
+# If the compiler knows how to hide symbols, add the switch needed for that to
+# CFLAGS_SL_MODULE and define HAVE_VISIBILITY_ATTRIBUTE.
+#
+# This is done separately from the above because -fvisibility is supported by
+# quite a few different compilers, making the required repetition bothersome.
+#
+# We might need to add a separate test to check if
+# __attribute__((visibility("hidden"))) is supported, if we encounter a
+# compiler that supports one of the supported variants of -fvisibility=hidden
+# but uses a different syntax to mark a symbol as exported.
+if test "$GCC" = yes -o "$SUN_STUDIO_CC" = yes ; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${CC} supports -fvisibility=hidden, for CFLAGS_SL_MODULE" >&5
+$as_echo_n "checking whether ${CC} supports -fvisibility=hidden, for CFLAGS_SL_MODULE... " >&6; }
+if ${pgac_cv_prog_CC_cflags__fvisibility_hidden+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  pgac_save_CFLAGS=$CFLAGS
+pgac_save_CC=$CC
+CC=${CC}
+CFLAGS="${CFLAGS_SL_MODULE} -fvisibility=hidden"
+ac_save_c_werror_flag=$ac_c_werror_flag
+ac_c_werror_flag=yes
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  pgac_cv_prog_CC_cflags__fvisibility_hidden=yes
+else
+  pgac_cv_prog_CC_cflags__fvisibility_hidden=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+ac_c_werror_flag=$ac_save_c_werror_flag
+CFLAGS="$pgac_save_CFLAGS"
+CC="$pgac_save_CC"
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv_prog_CC_cflags__fvisibility_hidden" >&5
+$as_echo "$pgac_cv_prog_CC_cflags__fvisibility_hidden" >&6; }
+if test x"$pgac_cv_prog_CC_cflags__fvisibility_hidden" = x"yes"; then
+  CFLAGS_SL_MODULE="${CFLAGS_SL_MODULE} -fvisibility=hidden"
+fi
+
+
+  # For C++ we additionally want -fvisibility-inlines-hidden
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${CXX} supports -fvisibility=hidden, for CXXFLAGS_SL_MODULE" >&5
+$as_echo_n "checking whether ${CXX} supports -fvisibility=hidden, for CXXFLAGS_SL_MODULE... " >&6; }
+if ${pgac_cv_prog_CXX_cxxflags__fvisibility_hidden+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  pgac_save_CXXFLAGS=$CXXFLAGS
+pgac_save_CXX=$CXX
+CXX=${CXX}
+CXXFLAGS="${CXXFLAGS_SL_MODULE} -fvisibility=hidden"
+ac_save_cxx_werror_flag=$ac_cxx_werror_flag
+ac_cxx_werror_flag=yes
+ac_ext=cpp
+ac_cpp='$CXXCPP $CPPFLAGS'
+ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
+
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_cxx_try_compile "$LINENO"; then :
+  pgac_cv_prog_CXX_cxxflags__fvisibility_hidden=yes
+else
+  pgac_cv_prog_CXX_cxxflags__fvisibility_hidden=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+ac_cxx_werror_flag=$ac_save_cxx_werror_flag
+CXXFLAGS="$pgac_save_CXXFLAGS"
+CXX="$pgac_save_CXX"
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv_prog_CXX_cxxflags__fvisibility_hidden" >&5
+$as_echo "$pgac_cv_prog_CXX_cxxflags__fvisibility_hidden" >&6; }
+if test x"$pgac_cv_prog_CXX_cxxflags__fvisibility_hidden" = x"yes"; then
+  CXXFLAGS_SL_MODULE="${CXXFLAGS_SL_MODULE} -fvisibility=hidden"
+fi
+
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${CXX} supports -fvisibility-inlines-hidden, for CXXFLAGS_SL_MODULE" >&5
+$as_echo_n "checking whether ${CXX} supports -fvisibility-inlines-hidden, for CXXFLAGS_SL_MODULE... " >&6; }
+if ${pgac_cv_prog_CXX_cxxflags__fvisibility_inlines_hidden+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  pgac_save_CXXFLAGS=$CXXFLAGS
+pgac_save_CXX=$CXX
+CXX=${CXX}
+CXXFLAGS="${CXXFLAGS_SL_MODULE} -fvisibility-inlines-hidden"
+ac_save_cxx_werror_flag=$ac_cxx_werror_flag
+ac_cxx_werror_flag=yes
+ac_ext=cpp
+ac_cpp='$CXXCPP $CPPFLAGS'
+ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
+
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_cxx_try_compile "$LINENO"; then :
+  pgac_cv_prog_CXX_cxxflags__fvisibility_inlines_hidden=yes
+else
+  pgac_cv_prog_CXX_cxxflags__fvisibility_inlines_hidden=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+ac_cxx_werror_flag=$ac_save_cxx_werror_flag
+CXXFLAGS="$pgac_save_CXXFLAGS"
+CXX="$pgac_save_CXX"
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv_prog_CXX_cxxflags__fvisibility_inlines_hidden" >&5
+$as_echo "$pgac_cv_prog_CXX_cxxflags__fvisibility_inlines_hidden" >&6; }
+if test x"$pgac_cv_prog_CXX_cxxflags__fvisibility_inlines_hidden" = x"yes"; then
+  CXXFLAGS_SL_MODULE="${CXXFLAGS_SL_MODULE} -fvisibility-inlines-hidden"
+fi
+
+elif test "$PORTNAME" = "aix"; then
+  # Note that xlc accepts -fvisibility=hidden as a file.
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${CC} supports -qvisibility=hidden, for CFLAGS_SL_MODULE" >&5
+$as_echo_n "checking whether ${CC} supports -qvisibility=hidden, for CFLAGS_SL_MODULE... " >&6; }
+if ${pgac_cv_prog_CC_cflags__qvisibility_hidden+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  pgac_save_CFLAGS=$CFLAGS
+pgac_save_CC=$CC
+CC=${CC}
+CFLAGS="${CFLAGS_SL_MODULE} -qvisibility=hidden"
+ac_save_c_werror_flag=$ac_c_werror_flag
+ac_c_werror_flag=yes
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  pgac_cv_prog_CC_cflags__qvisibility_hidden=yes
+else
+  pgac_cv_prog_CC_cflags__qvisibility_hidden=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+ac_c_werror_flag=$ac_save_c_werror_flag
+CFLAGS="$pgac_save_CFLAGS"
+CC="$pgac_save_CC"
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv_prog_CC_cflags__qvisibility_hidden" >&5
+$as_echo "$pgac_cv_prog_CC_cflags__qvisibility_hidden" >&6; }
+if test x"$pgac_cv_prog_CC_cflags__qvisibility_hidden" = x"yes"; then
+  CFLAGS_SL_MODULE="${CFLAGS_SL_MODULE} -qvisibility=hidden"
+fi
+
+
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${CXX} supports -qvisibility=hidden, for CXXFLAGS_SL_MODULE" >&5
+$as_echo_n "checking whether ${CXX} supports -qvisibility=hidden, for CXXFLAGS_SL_MODULE... " >&6; }
+if ${pgac_cv_prog_CXX_cxxflags__qvisibility_hidden+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  pgac_save_CXXFLAGS=$CXXFLAGS
+pgac_save_CXX=$CXX
+CXX=${CXX}
+CXXFLAGS="${CXXFLAGS_SL_MODULE} -qvisibility=hidden"
+ac_save_cxx_werror_flag=$ac_cxx_werror_flag
+ac_cxx_werror_flag=yes
+ac_ext=cpp
+ac_cpp='$CXXCPP $CPPFLAGS'
+ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
+
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_cxx_try_compile "$LINENO"; then :
+  pgac_cv_prog_CXX_cxxflags__qvisibility_hidden=yes
+else
+  pgac_cv_prog_CXX_cxxflags__qvisibility_hidden=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+ac_cxx_werror_flag=$ac_save_cxx_werror_flag
+CXXFLAGS="$pgac_save_CXXFLAGS"
+CXX="$pgac_save_CXX"
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv_prog_CXX_cxxflags__qvisibility_hidden" >&5
+$as_echo "$pgac_cv_prog_CXX_cxxflags__qvisibility_hidden" >&6; }
+if test x"$pgac_cv_prog_CXX_cxxflags__qvisibility_hidden" = x"yes"; then
+  CXXFLAGS_SL_MODULE="${CXXFLAGS_SL_MODULE} -qvisibility=hidden"
+fi
+
+fi
+
+if test -n "${CFLAGS_SL_MODULE}"; then
+
+$as_echo "#define HAVE_VISIBILITY_ATTRIBUTE 1" >>confdefs.h
+
+fi
+
 
 
 
diff --git a/configure.ac b/configure.ac
index dd368290a62..6bcbc0f0be4 100644
--- a/configure.ac
+++ b/configure.ac
@@ -525,17 +525,6 @@ if test "$GCC" = yes -a "$ICC" = no; then
   # Optimization flags for specific files that benefit from vectorization
   PGAC_PROG_CC_VAR_OPT(CFLAGS_VECTORIZE, [-ftree-vectorize])
   #
-  # If the compiler knows how to hide symbols add the switch needed for that
-  # to CFLAGS_SL_MODULE and define HAVE_VISIBILITY_ATTRIBUTE.
-  PGAC_PROG_CC_VAR_OPT(CFLAGS_SL_MODULE, [-fvisibility=hidden])
-  if test "$pgac_cv_prog_CC_cflags__fvisibility_hidden" = yes; then
-     AC_DEFINE([HAVE_VISIBILITY_ATTRIBUTE], 1,
-               [Define to 1 if your compiler knows the visibility("hidden") attribute.])
-  fi
-  # For C++ we additionally want -fvisibility-inlines-hidden
-  PGAC_PROG_VARCXX_VARFLAGS_OPT(CXX, CXXFLAGS_SL_MODULE, [-fvisibility=hidden])
-  PGAC_PROG_VARCXX_VARFLAGS_OPT(CXX, CXXFLAGS_SL_MODULE, [-fvisibility-inlines-hidden])
-  #
   # The following tests want to suppress various unhelpful warnings by adding
   # -Wno-foo switches.  But gcc won't complain about unrecognized -Wno-foo
   # switches, so we have to test for the positive form and if that works,
@@ -582,6 +571,32 @@ elif test "$PORTNAME" = "aix"; then
   PGAC_PROG_CXX_CFLAGS_OPT([-qlonglong])
 fi
 
+# If the compiler knows how to hide symbols, add the switch needed for that to
+# CFLAGS_SL_MODULE and define HAVE_VISIBILITY_ATTRIBUTE.
+#
+# This is done separately from the above because -fvisibility is supported by
+# quite a few different compilers, making the required repetition bothersome.
+#
+# We might need to add a separate test to check if
+# __attribute__((visibility("hidden"))) is supported, if we encounter a
+# compiler that supports one of the supported variants of -fvisibility=hidden
+# but uses a different syntax to mark a symbol as exported.
+if test "$GCC" = yes -o "$SUN_STUDIO_CC" = yes ; then
+  PGAC_PROG_CC_VAR_OPT(CFLAGS_SL_MODULE, [-fvisibility=hidden])
+  # For C++ we additionally want -fvisibility-inlines-hidden
+  PGAC_PROG_VARCXX_VARFLAGS_OPT(CXX, CXXFLAGS_SL_MODULE, [-fvisibility=hidden])
+  PGAC_PROG_VARCXX_VARFLAGS_OPT(CXX, CXXFLAGS_SL_MODULE, [-fvisibility-inlines-hidden])
+elif test "$PORTNAME" = "aix"; then
+  # Note that xlc accepts -fvisibility=hidden as a file.
+  PGAC_PROG_CC_VAR_OPT(CFLAGS_SL_MODULE, [-qvisibility=hidden])
+  PGAC_PROG_VARCXX_VARFLAGS_OPT(CXX, CXXFLAGS_SL_MODULE, [-qvisibility=hidden])
+fi
+
+if test -n "${CFLAGS_SL_MODULE}"; then
+  AC_DEFINE([HAVE_VISIBILITY_ATTRIBUTE], 1,
+            [Define to 1 if your compiler knows the visibility("hidden") attribute.])
+fi
+
 AC_SUBST(CFLAGS_UNROLL_LOOPS)
 AC_SUBST(CFLAGS_VECTORIZE)
 AC_SUBST(CFLAGS_SL_MODULE)
-- 
2.37.0.3.g30cc8d0f14

#12Andres Freund
andres@anarazel.de
In reply to: Andres Freund (#11)
Re: static libpq (and other libraries) overwritten on aix

Hi,

On 2022-08-20 10:42:13 -0700, Andres Freund wrote:

On 2022-08-20 01:35:22 -0700, Andres Freund wrote:

I'll send in a patch series tomorrow, too tired for today.

Here it goes.

0001 aix: Fix SHLIB_EXPORTS reference in VPATH builds

That's mostly so I could even build. It's not quite right in the sense that
we don't depend on the file, but that's a preexisting issue. Could be folded
in with 0005, which fixes that aspect. Or it could be backpatched as the
minimal fix.

0002 Remove SUBSYS.o rule in common.mk, hasn't been used in a long time
0003 Remove rule to generate postgres.o, not needed for 20+ years

Both obvious, I think.

Pushed these, given that they're all pretty trivial.

0004 aix: when building with gcc, tell gcc we're building a shared library

That's the gcc -shared issue I explained in the email I'm replying to.

We should probably consider building executables with -shared-libgcc too,
that shrinks them a decent amount (e.g. 1371684 -> 1126765 for psql). But
I've not done that here.

0005 aix: No need to use mkldexport when we want to export all symbols

This makes the building of shared libraries a lot more similar to other
platforms. Export files are only used when an exports.txt is present and
there's no more intermediary static libraries.

0006 configure: Expand -fvisibility checks to more compilers, add -qvisibility

This isn't strictly speaking part of the same "thread" of work, but I don't
want to touch aix more often than I have too... I'll post it in the other
thread too.

I did just test that this passes at least some tests on aix with xlc and
solaris with sunpro.

Any comments here?

Greetings,

Andres Freund

#13Noah Misch
noah@leadboat.com
In reply to: Andres Freund (#12)
Re: static libpq (and other libraries) overwritten on aix

On Wed, Aug 24, 2022 at 08:43:04PM -0700, Andres Freund wrote:

On 2022-08-20 10:42:13 -0700, Andres Freund wrote:

0004 aix: when building with gcc, tell gcc we're building a shared library

That's the gcc -shared issue I explained in the email I'm replying to.

We should probably consider building executables with -shared-libgcc too,
that shrinks them a decent amount (e.g. 1371684 -> 1126765 for psql). But
I've not done that here.

0005 aix: No need to use mkldexport when we want to export all symbols

This makes the building of shared libraries a lot more similar to other
platforms. Export files are only used when an exports.txt is present and
there's no more intermediary static libraries.

0006 configure: Expand -fvisibility checks to more compilers, add -qvisibility

This isn't strictly speaking part of the same "thread" of work, but I don't
want to touch aix more often than I have too... I'll post it in the other
thread too.

I did just test that this passes at least some tests on aix with xlc and
solaris with sunpro.

Any comments here?

I don't know much about them, but they sound like the sort of thing that can't
cause subtle bugs. If they build and test the first time, they're probably
valid. You may as well push them.