From: Tom Lane Date: Mon, 23 Feb 2026 18:34:22 +0000 (-0500) Subject: Restore AIX support. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4a1b05caa55dc14a1f936af78d8d19c843bfd8b9;p=thirdparty%2Fpostgresql.git Restore AIX support. 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 Author: Srirama Kucherlapati Co-authored-by: Peter Eisentraut Reviewed-by: Tom Lane Discussion: https://postgr.es/m/CY5PR11MB63928CC05906F27FB10D74D0FD322@CY5PR11MB6392.namprd11.prod.outlook.com --- diff --git a/Makefile b/Makefile index 8a2ec9396b6..9bc1a4ec17b 100644 --- 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: diff --git a/config/python.m4 b/config/python.m4 index b295ad3d3a4..ec3c80cf044 100644 --- a/config/python.m4 +++ b/config/python.m4 @@ -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//"` diff --git a/configure b/configure index 87cea3912d1..a285a6ec3d7 100755 --- 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 diff --git a/configure.ac b/configure.ac index c3097343a92..476a76c7991 100644 --- a/configure.ac +++ b/configure.ac @@ -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 diff --git a/doc/src/sgml/installation.sgml b/doc/src/sgml/installation.sgml index 2937c4a8fd0..b345a105674 100644 --- a/doc/src/sgml/installation.sgml +++ b/doc/src/sgml/installation.sgml @@ -3450,7 +3450,7 @@ export MANPATH PostgreSQL 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 PostgreSQL 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. @@ -3495,6 +3495,42 @@ export MANPATH installation issues. + + AIX + + + AIX + installation on + + + + You must use GCC + to build PostgreSQL + on AIX. + The native IBM compiler xlc is not supported. + + + + 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 OBJECT_MODE before building: + +export OBJECT_MODE=64 +meson setup ... + + Failure to do that will usually manifest as complaints + from ar about files having the wrong + object file mode. + + + + AIX versions before 7.2 are no longer + tested nor supported by the PostgreSQL + community. + + + Cygwin diff --git a/doc/src/sgml/runtime.sgml b/doc/src/sgml/runtime.sgml index 0c60bafac63..b4914faff1c 100644 --- a/doc/src/sgml/runtime.sgml +++ b/doc/src/sgml/runtime.sgml @@ -901,6 +901,29 @@ $ postgres -D $PGDATA -C num_os_semaphores + + AIX + AIXIPC configuration + + + + It should not be necessary to do + any special configuration for such parameters as + SHMMAX, 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 DB/2. + + It might, however, be necessary to modify the global + ulimit information in + /etc/security/limits, as the default hard + limits for file sizes (fsize) and numbers of + files (nofiles) might be too low. + + + + + FreeBSD FreeBSDIPC configuration diff --git a/meson.build b/meson.build index a7207304fd1..5122706477d 100644 --- a/meson.build +++ b/meson.build @@ -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' diff --git a/src/Makefile.shlib b/src/Makefile.shlib index 3825af5b228..cd1543550ca 100644 --- a/src/Makefile.shlib +++ b/src/Makefile.shlib @@ -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 diff --git a/src/backend/Makefile b/src/backend/Makefile index 05642dc02e3..ba53cd9d998 100644 --- a/src/backend/Makefile +++ b/src/backend/Makefile @@ -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 diff --git a/src/backend/meson.build b/src/backend/meson.build index 712a857cdb4..fec9f1d03b4 100644 --- a/src/backend/meson.build +++ b/src/backend/meson.build @@ -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 index 00000000000..9d016e7afd5 --- /dev/null +++ b/src/backend/port/aix/mkldexport.sh @@ -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 diff --git a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c index cb1c9d85ffe..24e8f37f634 100644 --- a/src/backend/utils/error/elog.c +++ b/src/backend/utils/error/elog.c @@ -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; diff --git a/src/backend/utils/misc/ps_status.c b/src/backend/utils/misc/ps_status.c index 9e55be244f7..51dce24947a 100644 --- a/src/backend/utils/misc/ps_status.c +++ b/src/backend/utils/misc/ps_status.c @@ -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 index 00000000000..211b048cfbf --- /dev/null +++ b/src/include/port/aix.h @@ -0,0 +1,22 @@ +/* + * src/include/port/aix.h + */ +#include /* for size_t */ +#include /* for uid_t and gid_t */ +#include /* 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 diff --git a/src/interfaces/ecpg/compatlib/meson.build b/src/interfaces/ecpg/compatlib/meson.build index d578faefe1c..0efe8a38230 100644 --- a/src/interfaces/ecpg/compatlib/meson.build +++ b/src/interfaces/ecpg/compatlib/meson.build @@ -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()), diff --git a/src/interfaces/ecpg/ecpglib/meson.build b/src/interfaces/ecpg/ecpglib/meson.build index 81e92151945..cb7288f2ee6 100644 --- a/src/interfaces/ecpg/ecpglib/meson.build +++ b/src/interfaces/ecpg/ecpglib/meson.build @@ -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()), diff --git a/src/interfaces/ecpg/pgtypeslib/meson.build b/src/interfaces/ecpg/pgtypeslib/meson.build index de564c63a5b..f62f3b92e49 100644 --- a/src/interfaces/ecpg/pgtypeslib/meson.build +++ b/src/interfaces/ecpg/pgtypeslib/meson.build @@ -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, diff --git a/src/interfaces/libpq/Makefile b/src/interfaces/libpq/Makefile index bf4baa92917..0963995eed4 100644 --- a/src/interfaces/libpq/Makefile +++ b/src/interfaces/libpq/Makefile @@ -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 $@ diff --git a/src/interfaces/libpq/meson.build b/src/interfaces/libpq/meson.build index 2b95098187e..b0ae72167a1 100644 --- a/src/interfaces/libpq/meson.build +++ b/src/interfaces/libpq/meson.build @@ -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 index 00000000000..ecba693b6a9 --- /dev/null +++ b/src/makefiles/Makefile.aix @@ -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) diff --git a/src/port/README b/src/port/README index ed5c54a72fa..97f18a62338 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 +dependency is a problem. Windows, Linux, AIX, and macOS use an export list to control the symbols exported by libpq. diff --git a/src/port/strerror.c b/src/port/strerror.c index 76af67ec2d0..d70734196b2 100644 --- a/src/port/strerror.c +++ b/src/port/strerror.c @@ -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 index 00000000000..9abe1efacd4 --- /dev/null +++ b/src/template/aix @@ -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 diff --git a/src/test/regress/Makefile b/src/test/regress/Makefile index 6409a485e84..7c665ff892d 100644 --- a/src/test/regress/Makefile +++ b/src/test/regress/Makefile @@ -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'." diff --git a/src/tools/gen_export.pl b/src/tools/gen_export.pl index 515f6d4a7a6..c91fa42a675 100644 --- a/src/tools/gen_export.pl +++ b/src/tools/gen_export.pl @@ -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"; } diff --git a/src/tools/pginclude/headerscheck b/src/tools/pginclude/headerscheck index 7a6755991bb..3d3e371a8e1 100755 --- a/src/tools/pginclude/headerscheck +++ b/src/tools/pginclude/headerscheck @@ -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