AIX: Symbols are missing in libpq.a

Started by REIX, Tonyover 4 years ago10 messages
#1REIX, Tony
tony.reix@atos.net
1 attachment(s)

Hi,

While porting postgresql-odbc v13 to AIX, we have found that (at least) 2 symbols are missing in libpq.a provided by the port of PostgreSQL v13.1 to AIX 7.1 by the BullFreeware project :

pg_char_to_encoding
pg_encoding_to_char

Looking at details, it appears that these symbols are present in version 12.8 .
They were still missing in 13.4 .
Something has changed between v12 and v13.

Looking at more details, the way libpq.a is built on AIX is different from the way libpq.so is built on Linux.
On Linux, the file "exports.txt" is used for building the list of symbols to be exported.
On AIX, the tool mkldexport.sh is used for dynamically generating the symbols to be exported.
And it appears that 5 symbols (including the 2 above) are missing on AIX. Don't know why.

A solution is to merge the two list of symbols to be exported in one list.
This is done by the patch attached here.
This patch does:
- add a new 11-lines script ./src/backend/port/aix/mergeldexport.sh which makes the merge only if the file exports.txt does exist.
- add the use of this script in: ./src/Makefile.shlib to be used for AIX only
- add the definition of variable MERGELDEXPORT in: ./src/makefiles/Makefile.aix
Very simple.

I suggest to apply the change for v14 .

Regards/Cordialement,

Tony Reix

tony.reix@atos.net

ATOS / Bull SAS
ATOS Expert
IBM-Bull Cooperation Project: Architect & OpenSource Technical Leader
1, rue de Provence - 38432 ECHIROLLES - FRANCE
www.atos.net<https://mail.ad.bull.net/owa/redir.aspx?C=PvphmPvCZkGrAgHVnWGsdMcDKgzl_dEIsM6rX0g4u4v8V81YffzBGkWrtQeAXNovd3ttkJL8JIc.&amp;URL=http%3a%2f%2fwww.atos.net%2f&gt;

Attachments:

postgresql-14.1-MergeExports.patchapplication/octet-stream; name=postgresql-14.1-MergeExports.patchDownload
--- /dev/null	2021-08-25 16:58:29 +0200
+++ ./src/backend/port/aix/mergeldexport.sh	2021-08-25 17:05:35 +0200
@@ -0,0 +1,15 @@
+# $1: *.exp       : manage first line apart
+# $2: exports.txt : remove comment # lines and take first word
+# Merge the 2 files in one if $2 does exist
+
+if [ -f "$2" ]
+then
+	n1=`wc -l $1 | awk '{print $1}'`
+	n1=`expr $n1 - 1`
+	h1=`head -n 1 $1`
+	tail -n $n1 $1 > /tmp/$$
+	grep -v "^#" $2 | awk '{print $1}' >> /tmp/$$
+	echo $h1 > $1
+	sort -u /tmp/$$ >> $1
+	rm -f /tmp/$$
+fi
--- ./src/Makefile.shlib.ORIGIN	2021-08-25 15:48:43 +0200
+++ ./src/Makefile.shlib	2021-08-25 16:58:39 +0200
@@ -330,6 +330,7 @@
 	$(LINK.static) $(stlib) $^
 	$(RANLIB) $(stlib)
 	$(MKLDEXPORT) $(stlib) $(shlib) >$(exports_file)
+	$(MERGELDEXPORT) $(exports_file) $(SHLIB_EXPORTS)
 	$(COMPILER) -o $(shlib) $(stlib) -Wl,-bE:$(exports_file) $(LDFLAGS) $(LDFLAGS_SL) $(SHLIB_LINK)
 	rm -f $(stlib)
 	$(AR) $(AROPT) $(stlib) $(shlib)
--- ./src/makefiles/Makefile.aix.ORIGIN	2021-08-25 16:59:43 +0200
+++ ./src/makefiles/Makefile.aix	2021-08-25 17:00:36 +0200
@@ -37,6 +37,7 @@
 
 MKLDEXPORT_DIR=src/backend/port/aix
 MKLDEXPORT=$(top_srcdir)/$(MKLDEXPORT_DIR)/mkldexport.sh
+MERGELDEXPORT=$(top_srcdir)/$(MKLDEXPORT_DIR)/mergeldexport.sh
 
 %.exp: %.o
 	$(MKLDEXPORT) $^ >$@
#2Noah Misch
noah@leadboat.com
In reply to: REIX, Tony (#1)
Re: AIX: Symbols are missing in libpq.a

On Thu, Aug 26, 2021 at 12:49:01PM +0000, REIX, Tony wrote:

While porting postgresql-odbc v13 to AIX, we have found that (at least) 2 symbols are missing in libpq.a provided by the port of PostgreSQL v13.1 to AIX 7.1 by the BullFreeware project :

pg_char_to_encoding
pg_encoding_to_char

Looking at details, it appears that these symbols are present in version 12.8 .
They were still missing in 13.4 .
Something has changed between v12 and v13.

Looking at more details, the way libpq.a is built on AIX is different from the way libpq.so is built on Linux.
On Linux, the file "exports.txt" is used for building the list of symbols to be exported.
On AIX, the tool mkldexport.sh is used for dynamically generating the symbols to be exported.
And it appears that 5 symbols (including the 2 above) are missing on AIX. Don't know why.

Would you study why it changed? If $(MKLDEXPORT) is no longer able to find
all symbols, then we're likely to have problems in more libraries than libpq,
including libraries that don't use a $(SHLIB_EXPORTS) file.

#3REIX, Tony
tony.reix@atos.net
In reply to: Noah Misch (#2)
RE: AIX: Symbols are missing in libpq.a

Hi Noah,

It appears that the Makefile in src/interfaces/libpq has been modified between v12 and v13, removing encnames.o (and wchar.o) from the object files being used for creating the static libpq.a file which is used for creating the libpq.so and libpq.a AIX shared-library files.
And, since pg_encoding_to_char() is defined in encnames.o , it has disappeared from the libpq.exp file .

# diff postgresql-12.8/32bit/src/interfaces/libpq/Makefile postgresql-13.1/32bit/src/interfaces/libpq/Makefile | grep encnames
< OBJS += encnames.o wchar.o
< encnames.c wchar.c: % : $(backend_src)/utils/mb/%
< rm -f encnames.c wchar.c

Remember how the final libpq.a is built on AIX:

rm -f libpq.a
/usr/bin/ar crs libpq.a fe-auth-scram.o ...
touch libpq.a
../../../src/backend/port/aix/mkldexport.sh libpq.a libpq.so.5 >libpq.exp
/opt/freeware/bin/gcc -maix64 -O3 ..... -o libpq.so.5 libpq.a -Wl,-bE:libpq.exp .......
rm -f libpq.a
/usr/bin/ar crs libpq.a libpq.so.5

12.8 : /usr/bin/ar crs libpq.a fe-auth.o fe-auth-scram.o fe-connect.o fe-exec.o fe-lobj.o fe-misc.o fe-print.o fe-protocol2.o fe-protocol3.o
pqexpbuffer.o fe-secure.o legacy-pqsignal.o libpq-events.o encnames.o wchar.o fe-secure-openssl.o fe-secure-common.o

13.1 : /usr/bin/ar crs libpq.a fe-auth.o fe-auth-scram.o fe-connect.o fe-exec.o fe-lobj.o fe-misc.o fe-print.o fe-protocol2.o fe-protocol3.o
pqexpbuffer.o fe-secure.o legacy-pqsignal.o libpq-events.o fe-secure-common.o fe-secure-openssl.o

Maybe you can discover why these changes were made in v13 for src/interfaces/libpq/Makefile .
And mkldexport.sh , unchanged between v12 and v13, works perfectly.

Regards/Cordialement,

Tony Reix

tony.reix@atos.net

ATOS / Bull SAS
ATOS Expert
IBM-Bull Cooperation Project: Architect & OpenSource Technical Leader
1, rue de Provence - 38432 ECHIROLLES - FRANCE
www.atos.net<https://mail.ad.bull.net/owa/redir.aspx?C=PvphmPvCZkGrAgHVnWGsdMcDKgzl_dEIsM6rX0g4u4v8V81YffzBGkWrtQeAXNovd3ttkJL8JIc.&amp;URL=http%3a%2f%2fwww.atos.net%2f&gt;
________________________________
De : Noah Misch <noah@leadboat.com>
Envoyé : dimanche 29 août 2021 17:46
À : REIX, Tony <tony.reix@atos.net>
Cc : pgsql-hackers@lists.postgresql.org <pgsql-hackers@lists.postgresql.org>
Objet : Re: AIX: Symbols are missing in libpq.a

Caution! External email. Do not open attachments or click links, unless this email comes from a known sender and you know the content is safe.

On Thu, Aug 26, 2021 at 12:49:01PM +0000, REIX, Tony wrote:

While porting postgresql-odbc v13 to AIX, we have found that (at least) 2 symbols are missing in libpq.a provided by the port of PostgreSQL v13.1 to AIX 7.1 by the BullFreeware project :

pg_char_to_encoding
pg_encoding_to_char

Looking at details, it appears that these symbols are present in version 12.8 .
They were still missing in 13.4 .
Something has changed between v12 and v13.

Looking at more details, the way libpq.a is built on AIX is different from the way libpq.so is built on Linux.
On Linux, the file "exports.txt" is used for building the list of symbols to be exported.
On AIX, the tool mkldexport.sh is used for dynamically generating the symbols to be exported.
And it appears that 5 symbols (including the 2 above) are missing on AIX. Don't know why.

Would you study why it changed? If $(MKLDEXPORT) is no longer able to find
all symbols, then we're likely to have problems in more libraries than libpq,
including libraries that don't use a $(SHLIB_EXPORTS) file.

#4Noah Misch
noah@leadboat.com
In reply to: REIX, Tony (#3)
Re: AIX: Symbols are missing in libpq.a

On Mon, Aug 30, 2021 at 02:33:32PM +0000, REIX, Tony wrote:

It appears that the Makefile in src/interfaces/libpq has been modified between v12 and v13, removing encnames.o (and wchar.o) from the object files being used for creating the static libpq.a file which is used for creating the libpq.so and libpq.a AIX shared-library files.
And, since pg_encoding_to_char() is defined in encnames.o , it has disappeared from the libpq.exp file .

# diff postgresql-12.8/32bit/src/interfaces/libpq/Makefile postgresql-13.1/32bit/src/interfaces/libpq/Makefile | grep encnames
< OBJS += encnames.o wchar.o
< encnames.c wchar.c: % : $(backend_src)/utils/mb/%
< rm -f encnames.c wchar.c

Remember how the final libpq.a is built on AIX:

rm -f libpq.a
/usr/bin/ar crs libpq.a fe-auth-scram.o ...
touch libpq.a
../../../src/backend/port/aix/mkldexport.sh libpq.a libpq.so.5 >libpq.exp
/opt/freeware/bin/gcc -maix64 -O3 ..... -o libpq.so.5 libpq.a -Wl,-bE:libpq.exp .......
rm -f libpq.a
/usr/bin/ar crs libpq.a libpq.so.5

12.8 : /usr/bin/ar crs libpq.a fe-auth.o fe-auth-scram.o fe-connect.o fe-exec.o fe-lobj.o fe-misc.o fe-print.o fe-protocol2.o fe-protocol3.o
pqexpbuffer.o fe-secure.o legacy-pqsignal.o libpq-events.o encnames.o wchar.o fe-secure-openssl.o fe-secure-common.o

13.1 : /usr/bin/ar crs libpq.a fe-auth.o fe-auth-scram.o fe-connect.o fe-exec.o fe-lobj.o fe-misc.o fe-print.o fe-protocol2.o fe-protocol3.o
pqexpbuffer.o fe-secure.o legacy-pqsignal.o libpq-events.o fe-secure-common.o fe-secure-openssl.o

Maybe you can discover why these changes were made in v13 for src/interfaces/libpq/Makefile .
And mkldexport.sh , unchanged between v12 and v13, works perfectly.

Thanks; that makes sense. Those files moved to libpgcommon_shlib.a. The
$(MKLDEXPORT) call sees symbols in the .o files, but it doesn't see symbols
pulled in via libpg*.a. Let's fix this by having Makefile.shlib skip
$(MKLDEXPORT) when a $(SHLIB_EXPORTS) file is available and have it instead
create lib$(NAME).exp from $(SHLIB_EXPORTS). That's more correct than
merging, and it's simpler. Would you like to try that?

#5REIX, Tony
tony.reix@atos.net
In reply to: Noah Misch (#4)
RE: AIX: Symbols are missing in libpq.a

Hi Noah,

Yes, trying to use the create lib$(NAME).exp from $(SHLIB_EXPORTS) when it exists was my first idea, too.
However, I do not master (or I forgot) this kind of "if...." in a Makefile and I was unable to find a solution by reading Makefile manuals or by searching for a similar example. So, I did it in an easier (to me!) and quicker way: merge with a new command line in the Makefile rule.
Now that we have a clear understanding of what is happenning, I may have a deeper look at a clean Makefile solution. However, if you know how to manage this, I would really appreciate some example. I'm asking my colleague too if he can help me here.

Thx

Tony

________________________________
De : Noah Misch <noah@leadboat.com>
Envoyé : lundi 30 août 2021 16:52
À : REIX, Tony <tony.reix@atos.net>
Cc : pgsql-hackers@lists.postgresql.org <pgsql-hackers@lists.postgresql.org>
Objet : Re: AIX: Symbols are missing in libpq.a

Caution! External email. Do not open attachments or click links, unless this email comes from a known sender and you know the content is safe.

On Mon, Aug 30, 2021 at 02:33:32PM +0000, REIX, Tony wrote:

It appears that the Makefile in src/interfaces/libpq has been modified between v12 and v13, removing encnames.o (and wchar.o) from the object files being used for creating the static libpq.a file which is used for creating the libpq.so and libpq.a AIX shared-library files.
And, since pg_encoding_to_char() is defined in encnames.o , it has disappeared from the libpq.exp file .

# diff postgresql-12.8/32bit/src/interfaces/libpq/Makefile postgresql-13.1/32bit/src/interfaces/libpq/Makefile | grep encnames
< OBJS += encnames.o wchar.o
< encnames.c wchar.c: % : $(backend_src)/utils/mb/%
< rm -f encnames.c wchar.c

Remember how the final libpq.a is built on AIX:

rm -f libpq.a
/usr/bin/ar crs libpq.a fe-auth-scram.o ...
touch libpq.a
../../../src/backend/port/aix/mkldexport.sh libpq.a libpq.so.5 >libpq.exp
/opt/freeware/bin/gcc -maix64 -O3 ..... -o libpq.so.5 libpq.a -Wl,-bE:libpq.exp .......
rm -f libpq.a
/usr/bin/ar crs libpq.a libpq.so.5

12.8 : /usr/bin/ar crs libpq.a fe-auth.o fe-auth-scram.o fe-connect.o fe-exec.o fe-lobj.o fe-misc.o fe-print.o fe-protocol2.o fe-protocol3.o
pqexpbuffer.o fe-secure.o legacy-pqsignal.o libpq-events.o encnames.o wchar.o fe-secure-openssl.o fe-secure-common.o

13.1 : /usr/bin/ar crs libpq.a fe-auth.o fe-auth-scram.o fe-connect.o fe-exec.o fe-lobj.o fe-misc.o fe-print.o fe-protocol2.o fe-protocol3.o
pqexpbuffer.o fe-secure.o legacy-pqsignal.o libpq-events.o fe-secure-common.o fe-secure-openssl.o

Maybe you can discover why these changes were made in v13 for src/interfaces/libpq/Makefile .
And mkldexport.sh , unchanged between v12 and v13, works perfectly.

Thanks; that makes sense. Those files moved to libpgcommon_shlib.a. The
$(MKLDEXPORT) call sees symbols in the .o files, but it doesn't see symbols
pulled in via libpg*.a. Let's fix this by having Makefile.shlib skip
$(MKLDEXPORT) when a $(SHLIB_EXPORTS) file is available and have it instead
create lib$(NAME).exp from $(SHLIB_EXPORTS). That's more correct than
merging, and it's simpler. Would you like to try that?

#6Noah Misch
noah@leadboat.com
In reply to: REIX, Tony (#5)
Re: AIX: Symbols are missing in libpq.a

On Mon, Aug 30, 2021 at 03:35:23PM +0000, REIX, Tony wrote:

Yes, trying to use the create lib$(NAME).exp from $(SHLIB_EXPORTS) when it exists was my first idea, too.
However, I do not master (or I forgot) this kind of "if...." in a Makefile and I was unable to find a solution by reading Makefile manuals or by searching for a similar example. So, I did it in an easier (to me!) and quicker way: merge with a new command line in the Makefile rule.
Now that we have a clear understanding of what is happenning, I may have a deeper look at a clean Makefile solution. However, if you know how to manage this, I would really appreciate some example. I'm asking my colleague too if he can help me here.

Here's an example from elsewhere in Makefile.shlib:

# If SHLIB_EXPORTS is set, the rules below will build a .def file from that.
# Else we just use --export-all-symbols.
ifeq (,$(SHLIB_EXPORTS))
$(shlib): $(OBJS) | $(SHLIB_PREREQS)
$(CC) $(CFLAGS) -shared -static-libgcc -o $@ $(OBJS) $(LDFLAGS) $(LDFLAGS_SL) $(SHLIB_LINK) $(LIBS) -Wl,--export-all-symbols -Wl,--out-implib=$(stlib)
else
DLL_DEFFILE = lib$(NAME)dll.def

$(shlib): $(OBJS) $(DLL_DEFFILE) | $(SHLIB_PREREQS)
$(CC) $(CFLAGS) -shared -static-libgcc -o $@ $(OBJS) $(DLL_DEFFILE) $(LDFLAGS) $(LDFLAGS_SL) $(SHLIB_LINK) $(LIBS) -Wl,--out-implib=$(stlib)

UC_NAME = $(shell echo $(NAME) | tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')

$(DLL_DEFFILE): $(SHLIB_EXPORTS)
echo 'LIBRARY LIB$(UC_NAME).dll' >$@
echo 'EXPORTS' >>$@
sed -e '/^#/d' -e 's/^\(.*[ ]\)\([0-9][0-9]*\)/ \1@ \2/' $< >>$@
endif

#7REIX, Tony
tony.reix@atos.net
In reply to: Noah Misch (#6)
1 attachment(s)
RE: AIX: Symbols are missing in libpq.a

Thanks for your help!
That wasn't so difficult, once I've refreshed my memory.
Here is a new patch, using the export.txt whenever it does exist.
I have tested it with v13.4 : it's OK.
Patch for 14beta3 should be the same since there was no change for src/Makefile.shlib between v13 and v14.

Regards/Cordialement,

Tony Reix

tony.reix@atos.net

ATOS / Bull SAS
ATOS Expert
IBM-Bull Cooperation Project: Architect & OpenSource Technical Leader
1, rue de Provence - 38432 ECHIROLLES - FRANCE
www.atos.net<https://mail.ad.bull.net/owa/redir.aspx?C=PvphmPvCZkGrAgHVnWGsdMcDKgzl_dEIsM6rX0g4u4v8V81YffzBGkWrtQeAXNovd3ttkJL8JIc.&amp;URL=http%3a%2f%2fwww.atos.net%2f&gt;
________________________________
De : Noah Misch <noah@leadboat.com>
Envoyé : mardi 31 août 2021 05:33
À : REIX, Tony <tony.reix@atos.net>
Cc : pgsql-hackers@lists.postgresql.org <pgsql-hackers@lists.postgresql.org>; CHIGOT, CLEMENT <clement.chigot@atos.net>
Objet : Re: AIX: Symbols are missing in libpq.a

Caution! External email. Do not open attachments or click links, unless this email comes from a known sender and you know the content is safe.

On Mon, Aug 30, 2021 at 03:35:23PM +0000, REIX, Tony wrote:

Yes, trying to use the create lib$(NAME).exp from $(SHLIB_EXPORTS) when it exists was my first idea, too.
However, I do not master (or I forgot) this kind of "if...." in a Makefile and I was unable to find a solution by reading Makefile manuals or by searching for a similar example. So, I did it in an easier (to me!) and quicker way: merge with a new command line in the Makefile rule.
Now that we have a clear understanding of what is happenning, I may have a deeper look at a clean Makefile solution. However, if you know how to manage this, I would really appreciate some example. I'm asking my colleague too if he can help me here.

Here's an example from elsewhere in Makefile.shlib:

# If SHLIB_EXPORTS is set, the rules below will build a .def file from that.
# Else we just use --export-all-symbols.
ifeq (,$(SHLIB_EXPORTS))
$(shlib): $(OBJS) | $(SHLIB_PREREQS)
$(CC) $(CFLAGS) -shared -static-libgcc -o $@ $(OBJS) $(LDFLAGS) $(LDFLAGS_SL) $(SHLIB_LINK) $(LIBS) -Wl,--export-all-symbols -Wl,--out-implib=$(stlib)
else
DLL_DEFFILE = lib$(NAME)dll.def

$(shlib): $(OBJS) $(DLL_DEFFILE) | $(SHLIB_PREREQS)
$(CC) $(CFLAGS) -shared -static-libgcc -o $@ $(OBJS) $(DLL_DEFFILE) $(LDFLAGS) $(LDFLAGS_SL) $(SHLIB_LINK) $(LIBS) -Wl,--out-implib=$(stlib)

UC_NAME = $(shell echo $(NAME) | tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')

$(DLL_DEFFILE): $(SHLIB_EXPORTS)
echo 'LIBRARY LIB$(UC_NAME).dll' >$@
echo 'EXPORTS' >>$@
sed -e '/^#/d' -e 's/^\(.*[ ]\)\([0-9][0-9]*\)/ \1@ \2/' $< >>$@
endif

Attachments:

postgresql-13.4-exports.txt.patchapplication/octet-stream; name=postgresql-13.4-exports.txt.patchDownload
--- ./src/Makefile.shlib.ORIGIN	2021-09-01 09:10:05 +0200
+++ ./src/Makefile.shlib	2021-09-01 10:08:28 +0200
@@ -329,7 +329,11 @@
 	rm -f $(stlib)
 	$(LINK.static) $(stlib) $^
 	$(RANLIB) $(stlib)
-	$(MKLDEXPORT) $(stlib) $(shlib) >$(exports_file)
+ifeq (,$(SHLIB_EXPORTS))
+	$(MKLDEXPORT) $(stlib) $(shlib) > $(exports_file)
+else
+	( echo '#! $(shlib)'; $(AWK) '/^[^#]/ {printf "%s\n",$$1}' $(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)
#8Tony Reix
tony.reix@atos.net
In reply to: REIX, Tony (#7)
Re: AIX: Symbols are missing in libpq.a

A new patch, using exports.txt file instead of building the list of symbols to be exported and merging the 2 files, has been provided. This seems much better.

#9Noah Misch
noah@leadboat.com
In reply to: REIX, Tony (#7)
1 attachment(s)
Re: AIX: Symbols are missing in libpq.a

On Wed, Sep 01, 2021 at 08:59:57AM +0000, REIX, Tony wrote:

Here is a new patch, using the export.txt whenever it does exist.
I have tested it with v13.4 : it's OK.
Patch for 14beta3 should be the same since there was no change for src/Makefile.shlib between v13 and v14.

Thanks. This looks good. I'm attaching what I intend to push, which just
adds a log message and some cosmetic changes compared to your version. Here
are the missing symbols restored by the patch:

pg_encoding_to_char
pg_utf_mblen
pg_char_to_encoding
pg_valid_server_encoding
pg_valid_server_encoding_id

I was ambivalent about whether to back-patch to v13 or to stop at v14, but I
decided that v13 should have this change. We should expect sad users when
libpq lacks a documented symbol. Complaints about loss of undocumented
symbols (e.g. pqParseInput3) are unlikely, and we're even less likely to have
users opposing reintroduction of long-documented symbols. An alternative
would be to have v13 merge the symbol lists, like your original proposal, so
we're not removing even undocumented symbols. I doubt applications have
accrued dependencies on libpq-internal symbols in the year since v13 appeared,
particularly since those symbols are inaccessible on Linux. Our AIX export
lists never included libpgport or libpgcommon symbols.

Attachments:

aix-SHLIB_EXPORTS-v2.patchtext/plain; charset=us-asciiDownload
Author:     Noah Misch <noah@leadboat.com>
Commit:     Noah Misch <noah@leadboat.com>

    AIX: Fix missing libpq symbols by respecting SHLIB_EXPORTS.
    
    We make each AIX shared library export all globals found in .o files
    that originate in the library.  That doesn't include symbols acquired by
    -lpgcommon_shlib.  That is good on average, but it became a problem for
    libpq when commit e6afa8918c461c1dd80c5063a950518fa4e950cd moved five
    official libpq API symbols into src/common.  Fix this by implementing
    the SHLIB_EXPORTS mechanism for AIX, so affected libraries export the
    same symbols that they export on Linux.  This reintroduces symbols
    pg_encoding_to_char, pg_utf_mblen, pg_char_to_encoding,
    pg_valid_server_encoding, and pg_valid_server_encoding_id.  Back-patch
    to v13, where the aforementioned commit first appeared.  While a minor
    release is usually the wrong time to add or remove symbol exports in
    libpq or libecpg, we should expect users to want each documented symbol.
    
    Tony Reix
    
    Discussion: https://postgr.es/m/PR3PR02MB6396742E2FC3E77D37A920BC86C79@PR3PR02MB6396.eurprd02.prod.outlook.com

diff --git a/src/Makefile.shlib b/src/Makefile.shlib
index 29a7f6d..6b79db1 100644
--- a/src/Makefile.shlib
+++ b/src/Makefile.shlib
@@ -329,7 +329,11 @@ $(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}' $(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)
diff --git a/src/port/README b/src/port/README
index c446b46..97f18a6 100644
--- a/src/port/README
+++ b/src/port/README
@@ -28,5 +28,5 @@ applications.
 from libpgport are linked first.  This avoids having applications
 dependent on symbols that are _used_ by libpq, but not intended to be
 exported by libpq.  libpq's libpgport usage changes over time, so such a
-dependency is a problem.  Windows, Linux, and macOS use an export list to
-control the symbols exported by libpq.
+dependency is a problem.  Windows, Linux, AIX, and macOS use an export
+list to control the symbols exported by libpq.
#10REIX, Tony
tony.reix@atos.net
In reply to: Noah Misch (#9)
RE: AIX: Symbols are missing in libpq.a

That seems good for me.
Thx !

Regards/Cordialement,

Tony Reix

tony.reix@atos.net

ATOS / Bull SAS
ATOS Expert
IBM-Bull Cooperation Project: Architect & OpenSource Technical Leader
1, rue de Provence - 38432 ECHIROLLES - FRANCE
www.atos.net<https://mail.ad.bull.net/owa/redir.aspx?C=PvphmPvCZkGrAgHVnWGsdMcDKgzl_dEIsM6rX0g4u4v8V81YffzBGkWrtQeAXNovd3ttkJL8JIc.&amp;URL=http%3a%2f%2fwww.atos.net%2f&gt;
________________________________
De : Noah Misch <noah@leadboat.com>
Envoyé : vendredi 3 septembre 2021 04:58
À : REIX, Tony <tony.reix@atos.net>
Cc : pgsql-hackers@lists.postgresql.org <pgsql-hackers@lists.postgresql.org>; CHIGOT, CLEMENT <clement.chigot@atos.net>
Objet : Re: AIX: Symbols are missing in libpq.a

Caution! External email. Do not open attachments or click links, unless this email comes from a known sender and you know the content is safe.

On Wed, Sep 01, 2021 at 08:59:57AM +0000, REIX, Tony wrote:

Here is a new patch, using the export.txt whenever it does exist.
I have tested it with v13.4 : it's OK.
Patch for 14beta3 should be the same since there was no change for src/Makefile.shlib between v13 and v14.

Thanks. This looks good. I'm attaching what I intend to push, which just
adds a log message and some cosmetic changes compared to your version. Here
are the missing symbols restored by the patch:

pg_encoding_to_char
pg_utf_mblen
pg_char_to_encoding
pg_valid_server_encoding
pg_valid_server_encoding_id

I was ambivalent about whether to back-patch to v13 or to stop at v14, but I
decided that v13 should have this change. We should expect sad users when
libpq lacks a documented symbol. Complaints about loss of undocumented
symbols (e.g. pqParseInput3) are unlikely, and we're even less likely to have
users opposing reintroduction of long-documented symbols. An alternative
would be to have v13 merge the symbol lists, like your original proposal, so
we're not removing even undocumented symbols. I doubt applications have
accrued dependencies on libpq-internal symbols in the year since v13 appeared,
particularly since those symbols are inaccessible on Linux. Our AIX export
lists never included libpgport or libpgcommon symbols.