]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Restore AIX support.
authorTom Lane <tgl@sss.pgh.pa.us>
Mon, 23 Feb 2026 18:34:22 +0000 (13:34 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Mon, 23 Feb 2026 18:34:22 +0000 (13:34 -0500)
The concerns that led us to remove AIX support in commit 0b16bb877
have now been alleviated:

1. IBM has stepped forward to provide support, including buildfarm
animal(s).
2. AIX 7.2 and later seem to be fine with large pg_attribute_aligned
requirements.  Since 7.1 is now EOL anyway, we can just cease to
support it.
3. Tossing xlc support overboard seems okay as well.  It's a bit
sad to drop one of the few remaining non-gcc-alike compilers, but
working around xlc's bugs and idiosyncrasies doesn't seem justified
by the theoretical portability benefits.
4. Likewise, we can stop supporting 32-bit AIX builds.  This is
not so much about whether we could build such executables as that
they're too much of a pain to manage in the field, due to limited
address space available for dynamic library loading.
5. We hit on a way to manage catalog column alignment that doesn't
require continuing developer effort (see commit ecae09725).

Hence, this commit reverts 0b16bb877 and some follow-on commits
such as e6bb491bf, except for not putting back XLC support nor
the changes related to catalog column alignment.

Some other notable changes from the way things were in v16:

Prefer unnamed POSIX semaphores on AIX, rather than the default
choice of SysV semaphores.

Include /opt/freeware/lib in -Wl,-blibpath, even when it is not
mentioned anywhere in LDFLAGS.

Remove platform-specific adjustment of MEMSET_LOOP_LIMIT; maybe
that's still the right thing, but it really ought to be re-tested.

Silence compiler warnings related to getpeereid(), wcstombs_l(),
and PAM conversation procs.

Accept "libpythonXXX.a" as an okay name for the Python shared
library (but only on AIX!).

Author: Aditya Kamath <Aditya.Kamath1@ibm.com>
Author: Srirama Kucherlapati <sriram.rk@in.ibm.com>
Co-authored-by: Peter Eisentraut <peter@eisentraut.org>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/CY5PR11MB63928CC05906F27FB10D74D0FD322@CY5PR11MB6392.namprd11.prod.outlook.com

26 files changed:
Makefile
config/python.m4
configure
configure.ac
doc/src/sgml/installation.sgml
doc/src/sgml/runtime.sgml
meson.build
src/Makefile.shlib
src/backend/Makefile
src/backend/meson.build
src/backend/port/aix/mkldexport.sh [new file with mode: 0755]
src/backend/utils/error/elog.c
src/backend/utils/misc/ps_status.c
src/include/port/aix.h [new file with mode: 0644]
src/interfaces/ecpg/compatlib/meson.build
src/interfaces/ecpg/ecpglib/meson.build
src/interfaces/ecpg/pgtypeslib/meson.build
src/interfaces/libpq/Makefile
src/interfaces/libpq/meson.build
src/makefiles/Makefile.aix [new file with mode: 0644]
src/port/README
src/port/strerror.c
src/template/aix [new file with mode: 0644]
src/test/regress/Makefile
src/tools/gen_export.pl
src/tools/pginclude/headerscheck

index 8a2ec9396b6b446362e6af3ca022a87d80bd1574..9bc1a4ec17b3c0e5402c059ef0850d8ac9b2a2db 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -13,8 +13,6 @@
 
 # AIX make defaults to building *every* target of the first rule.  Start with
 # a single-target, empty rule to make the other targets non-default.
-# (We don't support AIX anymore, but if someone tries to build on AIX anyway,
-# at least they'll get the instructions to run 'configure' first.)
 all:
 
 all check install installdirs installcheck installcheck-parallel uninstall clean distclean maintainer-clean dist distcheck world check-world install-world installcheck-world:
index b295ad3d3a4515dee35a9df1b8add0e311c750cc..ec3c80cf044793bd3ccb8d7af3042b275131ab04 100644 (file)
@@ -97,6 +97,11 @@ python_ldlibrary=`${PYTHON} -c "import sysconfig; print(' '.join(filter(None,sys
 
 # If LDLIBRARY exists and has a shlib extension, use it verbatim.
 ldlibrary=`echo "${python_ldlibrary}" | sed -e 's/\.so$//' -e 's/\.dll$//' -e 's/\.dylib$//' -e 's/\.sl$//'`
+if test "$PORTNAME" = "aix"; then
+  # On AIX, '.a' should also be believed to be a shlib.
+  ldlibrary=`echo "${ldlibrary}" | sed -e 's/\.a$//'`
+fi
+
 if test -e "${python_libdir}/${python_ldlibrary}" -a x"${python_ldlibrary}" != x"${ldlibrary}"
 then
        ldlibrary=`echo "${ldlibrary}" | sed "s/^lib//"`
index 87cea3912d13899537a27eacaaba7c4a52f22536..a285a6ec3d705adf57b856a9d7d696322351ea32 100755 (executable)
--- a/configure
+++ b/configure
@@ -3022,6 +3022,7 @@ else
 # --with-template not given
 
 case $host_os in
+     aix*) template=aix ;;
   cygwin*|msys*) template=cygwin ;;
   darwin*) template=darwin ;;
 dragonfly*) template=netbsd ;;
@@ -10807,6 +10808,11 @@ python_ldlibrary=`${PYTHON} -c "import sysconfig; print(' '.join(filter(None,sys
 
 # If LDLIBRARY exists and has a shlib extension, use it verbatim.
 ldlibrary=`echo "${python_ldlibrary}" | sed -e 's/\.so$//' -e 's/\.dll$//' -e 's/\.dylib$//' -e 's/\.sl$//'`
+if test "$PORTNAME" = "aix"; then
+  # On AIX, '.a' should also be believed to be a shlib.
+  ldlibrary=`echo "${ldlibrary}" | sed -e 's/\.a$//'`
+fi
+
 if test -e "${python_libdir}/${python_ldlibrary}" -a x"${python_ldlibrary}" != x"${ldlibrary}"
 then
        ldlibrary=`echo "${ldlibrary}" | sed "s/^lib//"`
@@ -13481,7 +13487,8 @@ fi
 
 fi
 
-# Note: We can test for libldap_r only after we know PTHREAD_LIBS
+# Note: We can test for libldap_r only after we know PTHREAD_LIBS;
+# also, on AIX, we may need to have openssl in LIBS for this step.
 if test "$with_ldap" = yes ; then
   _LIBS="$LIBS"
   if test "$PORTNAME" != "win32"; then
index c3097343a92637a28210b7ebca2278a853da2c19..476a76c799114c93c8668e162742bce54c278b30 100644 (file)
@@ -62,6 +62,7 @@ PGAC_ARG_REQ(with, template, [NAME], [override operating system template],
 # --with-template not given
 
 case $host_os in
+     aix*) template=aix ;;
   cygwin*|msys*) template=cygwin ;;
   darwin*) template=darwin ;;
 dragonfly*) template=netbsd ;;
@@ -1483,7 +1484,8 @@ if test "$with_zstd" = yes ; then
   AC_CHECK_LIB(zstd, ZSTD_compress, [], [AC_MSG_ERROR([library 'zstd' is required for ZSTD support])])
 fi
 
-# Note: We can test for libldap_r only after we know PTHREAD_LIBS
+# Note: We can test for libldap_r only after we know PTHREAD_LIBS;
+# also, on AIX, we may need to have openssl in LIBS for this step.
 if test "$with_ldap" = yes ; then
   _LIBS="$LIBS"
   if test "$PORTNAME" != "win32"; then
index 2937c4a8fd0b4f1304efd1225981b8734fc36363..b345a1056740a04d3a56a76040db9eb591d63993 100644 (file)
@@ -3450,7 +3450,7 @@ export MANPATH
   <para>
    <productname>PostgreSQL</productname> can be expected to work on current
    versions of these operating systems: Linux, Windows,
-   FreeBSD, OpenBSD, NetBSD, DragonFlyBSD, macOS, Solaris, and illumos.
+   FreeBSD, OpenBSD, NetBSD, DragonFlyBSD, macOS, AIX, Solaris, and illumos.
    Other Unix-like systems may also work but are not currently
    being tested.  In most cases, all CPU architectures supported by
    a given operating system will work.  Look in
@@ -3472,7 +3472,7 @@ export MANPATH
    Historical versions of <productname>PostgreSQL</productname> or POSTGRES
    also ran on CPU architectures including Alpha, Itanium, M32R, M68K,
    M88K, NS32K, PA-RISC, SuperH, and VAX,
-   and operating systems including 4.3BSD, AIX, BEOS,
+   and operating systems including 4.3BSD, BEOS,
    BSD/OS, DG/UX, Dynix, HP-UX, IRIX, NeXTSTEP, QNX, SCO, SINIX, Sprite, SunOS,
    Tru64 UNIX, and ULTRIX.
   </para>
@@ -3495,6 +3495,42 @@ export MANPATH
    installation issues.
   </para>
 
+  <sect2 id="installation-notes-aix">
+   <title>AIX</title>
+
+   <indexterm zone="installation-notes-aix">
+    <primary>AIX</primary>
+    <secondary>installation on</secondary>
+   </indexterm>
+
+   <para>
+    You must use GCC
+    to build <productname>PostgreSQL</productname>
+    on <productname>AIX</productname>.
+    The native IBM compiler <command>xlc</command> is not supported.
+   </para>
+
+   <para>
+    Also, only 64-bit builds are supported.  While the make-based build
+    system will automatically create 64-bit executables and libraries,
+    the meson build system requires you to
+    set <varname>OBJECT_MODE</varname> before building:
+<programlisting>
+export OBJECT_MODE=64
+meson setup ...
+</programlisting>
+    Failure to do that will usually manifest as complaints
+    from <application>ar</application> about files having the wrong
+    object file mode.
+   </para>
+
+   <para>
+    <productname>AIX</productname> versions before 7.2 are no longer
+    tested nor supported by the <productname>PostgreSQL</productname>
+    community.
+   </para>
+  </sect2>
+
   <sect2 id="installation-notes-cygwin">
    <title>Cygwin</title>
 
index 0c60bafac635d027078b63f7e36260453e66ebd4..b4914faff1cc97af9bf07a784b39147c1446abf6 100644 (file)
@@ -901,6 +901,29 @@ $ <userinput>postgres -D $PGDATA -C num_os_semaphores</userinput>
 
 
     <variablelist>
+     <varlistentry>
+      <term><systemitem class="osname">AIX</systemitem>
+      <indexterm><primary>AIX</primary><secondary>IPC configuration</secondary></indexterm>
+      </term>
+      <listitem>
+       <para>
+        It should not be necessary to do
+        any special configuration for such parameters as
+        <varname>SHMMAX</varname>, as it appears this is configured to
+        allow all memory to be used as shared memory.  That is the
+        sort of configuration commonly used for other databases such
+        as <application>DB/2</application>.</para>
+
+       <para> It might, however, be necessary to modify the global
+       <command>ulimit</command> information in
+       <filename>/etc/security/limits</filename>, as the default hard
+       limits for file sizes (<varname>fsize</varname>) and numbers of
+       files (<varname>nofiles</varname>) might be too low.
+       </para>
+      </listitem>
+     </varlistentry>
+
+
      <varlistentry>
       <term><systemitem class="osname">FreeBSD</systemitem>
       <indexterm><primary>FreeBSD</primary><secondary>IPC configuration</secondary></indexterm>
index a7207304fd15e3612878aaa5882d2459f852c923..5122706477d9fbec2f06a4a8ee146009acc3681d 100644 (file)
@@ -229,7 +229,38 @@ endif
 # that purpose.
 portname = host_system
 
-if host_system == 'cygwin'
+if host_system == 'aix'
+  sema_kind = 'unnamed_posix'
+  library_path_var = 'LIBPATH'
+  export_file_format = 'aix'
+  export_fmt = '-Wl,-bE:@0@'
+  mod_link_args_fmt = ['-Wl,-bI:@0@']
+  mod_link_with_dir = 'libdir'
+  mod_link_with_name = '@0@.imp'
+
+  # We force 64-bit builds, because AIX doesn't play very nice with dynamic
+  # library loading in 32-bit mode: there's not enough address space.
+  cppflags += '-maix64'
+  ldflags += '-maix64'
+  # Note: it's also necessary to tell programs like 'ar' to work in 64-bit
+  # mode.  Since meson, in its infinite wisdom, doesn't allow us either
+  # to pass '-X64' to ar or to set the OBJECT_MODE environment variable
+  # from here, we have to tell the user to set OBJECT_MODE.
+
+  # M:SRE sets a flag indicating that an object is a shared library.
+  ldflags_sl += '-Wl,-bM:SRE'
+  # -brtllib indicates binaries should use runtime-loaded shared libraries.
+  ldflags_be += '-Wl,-brtllib'
+
+  # On AIX, shared libraries are wrapped in static libraries and can have
+  # the same extension '.a'.  Therefore we must refrain from trying to build
+  # static libraries alongside shared ones, or meson will complain about
+  # duplicate targets.  Note however that we leave dlsuffix with its default
+  # value of '.so'; this results in using '.so' for loadable modules, which
+  # is fine.
+  build_static_lib = false
+
+elif host_system == 'cygwin'
   sema_kind = 'unnamed_posix'
   cppflags += '-D_GNU_SOURCE'
   dlsuffix = '.dll'
index 3825af5b2287271fc5e3953f73879715d583fa6b..cd1543550ca5bf6815fa1fd205d40d427697de11 100644 (file)
@@ -106,6 +106,20 @@ ifdef SO_MAJOR_VERSION
 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)
   ifdef soname
     # linkable library
@@ -254,6 +268,14 @@ $(stlib): $(OBJS) | $(SHLIB_PREREQS)
        touch $@
 endif #haslibarule
 
+# AIX wraps shared libraries inside a static library, which 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)))
 
 # Normal case
@@ -267,8 +289,11 @@ 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 # aix
 endif # shlib_bare
 endif # shlib_major
 
@@ -376,6 +401,9 @@ install-lib-static: $(stlib) installdirs-lib
 
 install-lib-shared: $(shlib) installdirs-lib
 ifdef soname
+# we don't install $(shlib) on AIX
+# (see http://archives.postgresql.org/message-id/52EF20B2E3209443BC37736D00C3C1380A6E79FE@EXADV1.host.magwien.gv.at)
+ifneq ($(PORTNAME), aix)
        $(INSTALL_SHLIB) $< '$(DESTDIR)$(libdir)/$(shlib)'
 ifneq ($(PORTNAME), cygwin)
 ifneq ($(PORTNAME), win32)
@@ -391,6 +419,7 @@ ifneq ($(shlib), $(shlib_bare))
 endif
 endif # not win32
 endif # not cygwin
+endif # not aix
 ifneq (,$(findstring $(PORTNAME),win32 cygwin))
        $(INSTALL_SHLIB) $< '$(DESTDIR)$(bindir)/$(shlib)'
 endif
index 05642dc02e39a893ca62cfc874cfde9767325f4b..ba53cd9d998d9f504aebf276fd74acb0072532ab 100644 (file)
@@ -81,16 +81,18 @@ override LDFLAGS := $(LDFLAGS) $(LDFLAGS_EX) $(LDFLAGS_EX_BE)
 
 ##########################################################################
 
-all: submake-libpgport submake-catalog-headers submake-utils-headers postgres
+all: submake-libpgport submake-catalog-headers submake-utils-headers postgres $(POSTGRES_IMP)
 
 ifneq ($(PORTNAME), cygwin)
 ifneq ($(PORTNAME), win32)
+ifneq ($(PORTNAME), aix)
 
 postgres: $(OBJS)
        $(CC) $(CFLAGS) $(call expand_subsys,$^) $(LDFLAGS) $(LIBS) -o $@
 
 endif
 endif
+endif
 
 ifeq ($(PORTNAME), cygwin)
 
@@ -117,6 +119,24 @@ libpostgres.a: postgres
 
 endif # win32
 
+ifeq ($(PORTNAME), aix)
+
+postgres: $(POSTGRES_IMP)
+       $(CC) $(CFLAGS) $(call expand_subsys,$(OBJS)) $(LDFLAGS) -Wl,-bE:$(top_builddir)/src/backend/$(POSTGRES_IMP) $(LIBS) -Wl,-brtllib -o $@
+
+# Linking to a single .o with -r is a lot faster than building a .a or passing
+# all objects to MKLDEXPORT.
+#
+# It looks alluring to use $(CC) -r instead of ld -r, but that doesn't
+# trivially work with gcc, due to gcc specific static libraries linked in with
+# -r.
+$(POSTGRES_IMP): $(OBJS)
+       ld -b64 -r -o SUBSYS.o $(call expand_subsys,$^)
+       $(MKLDEXPORT) SUBSYS.o . > $@
+       @rm -f SUBSYS.o
+
+endif # aix
+
 $(top_builddir)/src/port/libpgport_srv.a: | submake-libpgport
 
 
@@ -210,8 +230,12 @@ install-postgres-bitcode: $(OBJS) all
        $(call install_llvm_module,postgres,$(call expand_subsys, $(filter-out $(top_builddir)/src/timezone/objfiles.txt, $(SUBDIROBJS))))
 endif
 
-install-bin: postgres installdirs
+install-bin: postgres $(POSTGRES_IMP) installdirs
        $(INSTALL_PROGRAM) postgres$(X) '$(DESTDIR)$(bindir)/postgres$(X)'
+ifeq ($(MAKE_EXPORTS), true)
+       $(INSTALL_DATA) $(POSTGRES_IMP) '$(DESTDIR)$(pkglibdir)/$(POSTGRES_IMP)'
+       $(INSTALL_PROGRAM) $(MKLDEXPORT) '$(DESTDIR)$(pgxsdir)/$(MKLDEXPORT_DIR)/mkldexport.sh'
+endif
 
 .PHONY: install-bin
 
@@ -227,12 +251,20 @@ ifeq ($(MAKE_DLL), true)
        $(MKDIR_P) '$(DESTDIR)$(libdir)'
 endif
 endif
+ifeq ($(MAKE_EXPORTS), true)
+       $(MKDIR_P) '$(DESTDIR)$(pkglibdir)'
+       $(MKDIR_P) '$(DESTDIR)$(pgxsdir)/$(MKLDEXPORT_DIR)'
+endif
 
 
 ##########################################################################
 
 uninstall:
        rm -f '$(DESTDIR)$(bindir)/postgres$(X)'
+ifeq ($(MAKE_EXPORTS), true)
+       rm -f '$(DESTDIR)$(pkglibdir)/$(POSTGRES_IMP)'
+       rm -f '$(DESTDIR)$(pgxsdir)/$(MKLDEXPORT_DIR)/mkldexport.sh'
+endif
 ifeq ($(PORTNAME), cygwin)
 ifeq ($(MAKE_DLL), true)
        rm -f '$(DESTDIR)$(libdir)/libpostgres.a'
@@ -257,7 +289,7 @@ endif
 ##########################################################################
 
 clean:
-       rm -f $(LOCALOBJS) postgres$(X)
+       rm -f $(LOCALOBJS) postgres$(X) $(POSTGRES_IMP)
 ifeq ($(PORTNAME), cygwin)
        rm -f postgres.dll libpostgres.a
 endif
index 712a857cdb40d715c3d456044b62bbf0961642a5..fec9f1d03b40f236d5548ff5edcac0f3e52ea894 100644 (file)
@@ -91,6 +91,25 @@ if cc.get_id() == 'msvc'
   # be restricted to b_pch=true.
   backend_link_with += postgres_lib
 
+elif host_system == 'aix'
+  # The '.' argument leads mkldexport.sh to emit "#! .", which refers to the
+  # main executable, allowing extension libraries to resolve their undefined
+  # symbols to symbols in the postgres binary.
+  postgres_imp = custom_target('postgres.imp',
+    command: [files('port/aix/mkldexport.sh'), '@INPUT@', '.'],
+    input: postgres_lib,
+    output: 'postgres.imp',
+    capture: true,
+    install: true,
+    install_dir: dir_lib_pkg,
+    build_by_default: false,
+  )
+  # -Wl,-bE:exportfile indicates these symbols are exported by postgres binary
+  backend_link_args += '-Wl,-bE:@0@'.format(postgres_imp.full_path())
+  backend_link_depends += postgres_imp
+  install_data(
+       'port/aix/mkldexport.sh',
+       install_dir: dir_pgxs / 'src/backend/port/aix')
 endif
 
 backend_input = []
diff --git a/src/backend/port/aix/mkldexport.sh b/src/backend/port/aix/mkldexport.sh
new file mode 100755 (executable)
index 0000000..9d016e7
--- /dev/null
@@ -0,0 +1,71 @@
+#!/bin/sh
+#
+# mkldexport
+#      create an AIX exports file from an object file
+#
+# src/backend/port/aix/mkldexport.sh
+#
+# Usage:
+#      mkldexport objectfile [location]
+# where
+#      objectfile is the current location of the object file.
+#      location is the eventual (installed) location of the
+#              object file (if different from the current
+#              working directory).
+#
+# On AIX, executables do not automatically expose their symbols to shared
+# modules. Extensions therefore cannot call functions in the main Postgres
+# binary unless those symbols are explicitly exported. Unlike other platforms,
+# AIX executables are not default symbol providers; each shared module must
+# link against an export list that defines which symbols it can use.
+#
+# The mkldexport.sh script fixes AIX's symbol export issue by generating an
+# explicit export list. It uses nm to gather all symbols from the Postgres
+# object files, then writes them into the export file. When invoked with ".",
+# it outputs #! ., which tells AIX the list applies to the main executable.
+# This way, extension modules can link against that list and resolve their
+# undefined symbols directly from the Postgres binary.
+#
+
+# Search for the nm command binary.
+if [ -x /usr/ucb/nm ]
+then NM=/usr/ucb/nm
+elif [ -x /usr/bin/nm ]
+then NM=/usr/bin/nm
+elif [ -x /usr/ccs/bin/nm ]
+then NM=/usr/ccs/bin/nm
+elif [ -x /usr/usg/bin/nm ]
+then NM=/usr/usg/bin/nm
+else echo "Fatal error: cannot find `nm' ... please check your installation."
+     exit 1
+fi
+
+# instruct nm to process 64-bit objects
+export OBJECT_MODE=64
+
+CMDNAME=`basename $0`
+if [ -z "$1" ]; then
+       echo "Usage: $CMDNAME object [location]"
+       exit 1
+fi
+OBJNAME=`basename $1`
+if [ "`basename $OBJNAME`" != "`basename $OBJNAME .o`" ]; then
+       OBJNAME=`basename $OBJNAME .o`.so
+fi
+if [ -z "$2" ]; then
+       echo '#!'
+else
+       if [ "$2" = "." ]; then
+               # for the base executable (AIX 4.2 and up)
+               echo '#! .'
+       else
+               echo '#!' $2
+       fi
+fi
+$NM -BCg $1 | \
+       egrep ' [TDB] ' | \
+       sed -e 's/.* //' | \
+       egrep -v '\$' | \
+       sed -e 's/^[.]//' | \
+       sort | \
+       uniq
index cb1c9d85ffe46821391737f0593203c010b8baa5..24e8f37f634caaac2e471bad476863b4b13fb70e 100644 (file)
@@ -915,7 +915,9 @@ errcode_for_file_access(void)
                        /* Wrong object type or state */
                case ENOTDIR:                   /* Not a directory */
                case EISDIR:                    /* Is a directory */
+#if defined(ENOTEMPTY) && (ENOTEMPTY != EEXIST) /* same code on AIX */
                case ENOTEMPTY:                 /* Directory not empty */
+#endif
                        edata->sqlerrcode = ERRCODE_WRONG_OBJECT_TYPE;
                        break;
 
index 9e55be244f79d7c23b729f469d6739555ffccdbb..51dce24947a8cf62d5da9c15ebd23e916001fe9c 100644 (file)
@@ -52,7 +52,7 @@ bool          update_process_title = DEFAULT_UPDATE_PROCESS_TITLE;
 #define PS_USE_SETPROCTITLE_FAST
 #elif defined(HAVE_SETPROCTITLE)
 #define PS_USE_SETPROCTITLE
-#elif defined(__linux__) || defined(__sun) || defined(__darwin__) || defined(__GNU__)
+#elif defined(__linux__) || defined(_AIX) || defined(__sun) || defined(__darwin__) || defined(__GNU__)
 #define PS_USE_CLOBBER_ARGV
 #elif defined(WIN32)
 #define PS_USE_WIN32
@@ -62,7 +62,7 @@ bool          update_process_title = DEFAULT_UPDATE_PROCESS_TITLE;
 
 
 /* Different systems want the buffer padded differently */
-#if defined(__linux__) || defined(__darwin__) || defined(__GNU__)
+#if defined(_AIX) || defined(__linux__) || defined(__darwin__) || defined(__GNU__)
 #define PS_PADDING '\0'
 #else
 #define PS_PADDING ' '
diff --git a/src/include/port/aix.h b/src/include/port/aix.h
new file mode 100644 (file)
index 0000000..211b048
--- /dev/null
@@ -0,0 +1,22 @@
+/*
+ * src/include/port/aix.h
+ */
+#include <stddef.h>                            /* for size_t */
+#include <sys/types.h>                 /* for uid_t and gid_t */
+#include <wchar.h>                             /* for wchar_t and locale_t */
+
+/* AIX has getpeereid(), but fails to declare it as of 7.3 */
+extern int     getpeereid(int socket, uid_t *euid, gid_t *egid);
+
+/* AIX has wcstombs_l(), but fails to declare it as of 7.3 */
+extern size_t wcstombs_l(char *dest, const wchar_t *src, size_t n,
+                                                locale_t loc);
+
+/*
+ * AIX doesn't seem to have ever modernized pam_appl.h to include
+ * "const" in the declaration of PAM conversation procs.  We can avoid
+ * a compile error by setting _PAM_LEGACY_NONCONST; that doesn't do
+ * anything in AIX's system headers, but it makes us omit the "const"
+ * in our own code.  (Compare solaris.h.)
+ */
+#define _PAM_LEGACY_NONCONST 1
index d578faefe1c875db8e9458af4dc0f11df0d16587..0efe8a382302caa654491a17664b83e2cdf9aedf 100644 (file)
@@ -35,7 +35,7 @@ ecpg_compat_so = shared_library('libecpg_compat',
   c_args: ecpg_compat_c_args,
   dependencies: [frontend_shlib_code, thread_dep],
   link_with: [ecpglib_so, ecpg_pgtypes_so],
-  soversion: host_system != 'windows' ? '3' : '',
+  soversion: host_system not in ['aix', 'windows'] ? '3' : '',
   darwin_versions: ['3', '3.' + pg_version_major.to_string()],
   version: '3.' + pg_version_major.to_string(),
   link_args: export_fmt.format(export_file.full_path()),
index 81e921519452f2ce4f0154e152be1fc80617544b..cb7288f2ee6ef7d63c09e5323d5f1a373422827e 100644 (file)
@@ -46,7 +46,7 @@ ecpglib_so = shared_library('libecpg',
   c_pch: pch_postgres_fe_h,
   dependencies: [frontend_shlib_code, libpq, thread_dep],
   link_with: ecpg_pgtypes_so,
-  soversion: host_system != 'windows' ? '6' : '',
+  soversion: host_system not in ['aix', 'windows'] ? '6' : '',
   darwin_versions: ['6', '6.' + pg_version_major.to_string()],
   version: '6.' + pg_version_major.to_string(),
   link_args: export_fmt.format(export_file.full_path()),
index de564c63a5b1cabac846667577c26ab5d4f49521..f62f3b92e4967cac0b164f002a09ad977e1f8b50 100644 (file)
@@ -41,7 +41,7 @@ ecpg_pgtypes_so = shared_library('libpgtypes',
   c_pch: pch_postgres_fe_h,
   dependencies: frontend_shlib_code,
   version: '3.' + pg_version_major.to_string(),
-  soversion: host_system != 'windows' ? '3' : '',
+  soversion: host_system not in ['aix', 'windows'] ? '3' : '',
   darwin_versions: ['3', '3.' + pg_version_major.to_string()],
   link_args: export_fmt.format(export_file.full_path()),
   link_depends: export_file,
index bf4baa929173a32724394007b5d847ddafc6fa7d..0963995eed4222b813acc9f7abee34be558e9d8d 100644 (file)
@@ -136,7 +136,9 @@ $(stlib): $(OBJS_STATIC)
 # expect them to honor this coding rule.
 libpq-refs-stamp: $(shlib)
 ifneq ($(enable_coverage), yes)
+ifeq (,$(filter aix,$(PORTNAME)))
        $(PERL) $(srcdir)/libpq_check.pl --input_file $< --nm='$(NM)'
+endif
 endif
        touch $@
 
index 2b95098187e927f812e943ee5cc27637828e66ba..b0ae72167a1ca09740d2cb9f47c5df7fd134dbcc 100644 (file)
@@ -55,8 +55,9 @@ libpq_so_c_args = ['-DUSE_DYNAMIC_OAUTH']
 #    libpq_st, and {pgport,common}_shlib for libpq_sh
 #
 # We could try to avoid building the source files twice, but it probably adds
-# more complexity than its worth (reusing object files requires also linking
-# to the library on windows or breaks precompiled headers).
+# more complexity than its worth (AIX doesn't support link_whole yet, reusing
+# object files requires also linking to the library on windows or breaks
+# precompiled headers).
 if build_static_lib
 libpq_st = static_library('libpq',
   libpq_sources,
@@ -76,7 +77,7 @@ libpq_so = shared_library('libpq',
   c_args: libpq_c_args + libpq_so_c_args,
   c_pch: pch_postgres_fe_h,
   version: '5.' + pg_version_major.to_string(),
-  soversion: host_system != 'windows' ? '5' : '',
+  soversion: host_system not in ['aix', 'windows'] ? '5' : '',
   darwin_versions: ['5', '5.' + pg_version_major.to_string()],
   dependencies: [frontend_shlib_code, libpq_deps],
   link_depends: export_file,
diff --git a/src/makefiles/Makefile.aix b/src/makefiles/Makefile.aix
new file mode 100644 (file)
index 0000000..ecba693
--- /dev/null
@@ -0,0 +1,42 @@
+# MAKE_EXPORTS is required for svr4 loaders that want a file of
+# symbol names to tell them what to export/import.
+MAKE_EXPORTS= true
+
+# -blibpath must contain ALL directories where we should look for libraries
+libpath := $(shell echo $(subst -L,:,$(filter -L/%,$(LDFLAGS))) | sed -e's/ //g'):/opt/freeware/lib:/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
+
+# instruct ar to process 64-bit objects
+AROPT := -X64 $(AROPT)
+
+# env var name to use in place of LD_LIBRARY_PATH
+ld_library_path_var = LIBPATH
+
+
+POSTGRES_IMP= postgres.imp
+
+ifdef PGXS
+BE_DLLLIBS= -Wl,-bI:$(pkglibdir)/$(POSTGRES_IMP)
+else
+BE_DLLLIBS= -Wl,-bI:$(top_builddir)/src/backend/$(POSTGRES_IMP)
+endif
+
+MKLDEXPORT_DIR=src/backend/port/aix
+MKLDEXPORT=$(top_srcdir)/$(MKLDEXPORT_DIR)/mkldexport.sh
+
+%$(DLSUFFIX): %.o
+       $(CC) $(CFLAGS) $*.o $(LDFLAGS) $(LDFLAGS_SL) -o $@ $(BE_DLLLIBS)
index ed5c54a72fac77023967ef8bd08ac26b1ec2af87..97f18a623382ae6bf7ece9424c526e90ac44bea7 100644 (file)
@@ -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
+dependency is a problem.  Windows, Linux, AIX, and macOS use an export
 list to control the symbols exported by libpq.
index 76af67ec2d05d857a57af0830250eb09fa72a360..d70734196b2ab1ba40e292c46de603139fc59fea 100644 (file)
@@ -214,8 +214,10 @@ get_errno_symbol(int errnum)
                        return "ENOTCONN";
                case ENOTDIR:
                        return "ENOTDIR";
+#if defined(ENOTEMPTY) && (ENOTEMPTY != EEXIST) /* same code on AIX */
                case ENOTEMPTY:
                        return "ENOTEMPTY";
+#endif
                case ENOTSOCK:
                        return "ENOTSOCK";
 #ifdef ENOTSUP
diff --git a/src/template/aix b/src/template/aix
new file mode 100644 (file)
index 0000000..9abe1ef
--- /dev/null
@@ -0,0 +1,19 @@
+# src/template/aix
+
+# Prefer unnamed POSIX semaphores if available, unless user overrides choice
+if test x"$PREFERRED_SEMAPHORES" = x"" ; then
+  PREFERRED_SEMAPHORES=UNNAMED_POSIX
+fi
+
+# Extra CFLAGS for code that will go into a shared library
+CFLAGS_SL=""
+
+if test "$GCC" = yes; then
+  # We force 64-bit builds, because AIX doesn't play very nice with dynamic
+  # library loading in 32-bit mode: there's not enough address space.
+  CPPFLAGS="$CPPFLAGS -maix64"
+
+  # For large binaries/libraries, there will be TOC overflows in AIX. To
+  # avoid this, pass -bbigtoc linker option to enlarge TOC access range.
+  LDFLAGS="$LDFLAGS -maix64 -Wl,-bbigtoc"
+fi
index 6409a485e8441a144d9d39aebdf8b3cccc889e24..7c665ff892d3ced2bc6709d71ecc2b7ae6c79100 100644 (file)
@@ -7,6 +7,11 @@
 # GNU make uses a make file named "GNUmakefile" in preference to "Makefile"
 # if it exists.  Postgres is shipped with a "GNUmakefile".
 
+
+# AIX make defaults to building *every* target of the first rule.  Start with
+# a single-target, empty rule to make the other targets non-default.
+all:
+
 all install clean check installcheck:
        @echo "You must use GNU make to use Postgres.  It may be installed"
        @echo "on your system with the name 'gmake'."
index 515f6d4a7a607f7381d4ab825b9f46ab8057bcc9..c91fa42a67519c0cc4c93f21eaefcb395c9d4359 100644 (file)
@@ -16,11 +16,12 @@ GetOptions(
        'input:s' => \$input,
        'output:s' => \$output) or die "wrong arguments";
 
-if (not(   $format eq 'darwin'
+if (not(   $format eq 'aix'
+               or $format eq 'darwin'
                or $format eq 'gnu'
                or $format eq 'win'))
 {
-       die "$0: $format is not yet handled (only darwin, gnu, win are)\n";
+       die "$0: $format is not yet handled (only aix, darwin, gnu, win are)\n";
 }
 
 open(my $input_handle, '<', $input)
@@ -30,7 +31,11 @@ open(my $output_handle, '>', $output)
   or die "$0: could not open output file '$output': $!\n";
 
 
-if ($format eq 'gnu')
+if ($format eq 'aix')
+{
+       print $output_handle "#!\n";
+}
+elsif ($format eq 'gnu')
 {
        print $output_handle "{
   global:
@@ -55,7 +60,11 @@ while (<$input_handle>)
        }
        elsif (/^(\S+)\s+(\S+)/)
        {
-               if ($format eq 'darwin')
+               if ($format eq 'aix')
+               {
+                       print $output_handle "$1\n";
+               }
+               elsif ($format eq 'darwin')
                {
                        print $output_handle "_$1\n";
                }
index 7a6755991bbaa53bbc69c41f4ccdfb98fafb6290..3d3e371a8e1b584f0780f103033950ff6fa10e75 100755 (executable)
@@ -89,6 +89,7 @@ do
 
        # These files are platform-specific, and c.h will include the
        # one that's relevant for our current platform anyway.
+       test "$f" = src/include/port/aix.h && continue
        test "$f" = src/include/port/cygwin.h && continue
        test "$f" = src/include/port/darwin.h && continue
        test "$f" = src/include/port/freebsd.h && continue