From 7f7bc73bd260df2aa4ab82ab561b76a09b7da50c Mon Sep 17 00:00:00 2001 From: Kevin Adler Date: Fri, 9 Nov 2018 10:18:05 -0600 Subject: [PATCH 1/2] bpo-35198 Fix C++ extension compilation on AIX For C++ extensions, distutils tries to replace the C compiler with the C++ compiler, but it assumes that C compiler is the first element after any environment variables set. On AIX, linking goes through ld_so_aix, so it is the first element and the compiler is the next element. Thus the replacement is faulty: ld_so_aix gcc ... -> g++ gcc ... Also, it assumed that self.compiler_cxx had only 1 element or that there were the same number of elements as the linker has and in the same order. This might not be the case, so instead concatenate everything together. --- Lib/distutils/unixccompiler.py | 5 ++++- .../next/Library/2018-11-09-12-45-28.bpo-35198.EJ8keW.rst | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 Misc/NEWS.d/next/Library/2018-11-09-12-45-28.bpo-35198.EJ8keW.rst diff --git a/Lib/distutils/unixccompiler.py b/Lib/distutils/unixccompiler.py index ab4d4de15661985..36c25df34390e3f 100644 --- a/Lib/distutils/unixccompiler.py +++ b/Lib/distutils/unixccompiler.py @@ -188,7 +188,10 @@ def link(self, target_desc, objects, i = 1 while '=' in linker[i]: i += 1 - linker[i] = self.compiler_cxx[i] + if linker[i].endswith('ld_so_aix'): + # Linker is ld_so_aix, so compiler is next arg + i += 1 + linker = linker[:i] + self.compiler_cxx + linker[i+1:] if sys.platform == 'darwin': linker = _osx_support.compiler_fixup(linker, ld_args) diff --git a/Misc/NEWS.d/next/Library/2018-11-09-12-45-28.bpo-35198.EJ8keW.rst b/Misc/NEWS.d/next/Library/2018-11-09-12-45-28.bpo-35198.EJ8keW.rst new file mode 100644 index 000000000000000..4ce7a7e3423c0c0 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2018-11-09-12-45-28.bpo-35198.EJ8keW.rst @@ -0,0 +1 @@ +Fix C++ extension compilation on AIX From 240688b517001c0b96a548666a0bc4b48e895692 Mon Sep 17 00:00:00 2001 From: Kevin Adler Date: Fri, 1 Mar 2019 19:54:55 -0600 Subject: [PATCH 2/2] Simplify AIX C++ extension fix --- Lib/distutils/unixccompiler.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Lib/distutils/unixccompiler.py b/Lib/distutils/unixccompiler.py index 36c25df34390e3f..d10a78da311405f 100644 --- a/Lib/distutils/unixccompiler.py +++ b/Lib/distutils/unixccompiler.py @@ -188,10 +188,15 @@ def link(self, target_desc, objects, i = 1 while '=' in linker[i]: i += 1 - if linker[i].endswith('ld_so_aix'): - # Linker is ld_so_aix, so compiler is next arg - i += 1 - linker = linker[:i] + self.compiler_cxx + linker[i+1:] + + if os.path.basename(linker[i]) == 'ld_so_aix': + # AIX platforms prefix the compiler with the ld_so_aix + # script, so we need to adjust our linker index + offset = 1 + else: + offset = 0 + + linker[i+offset] = self.compiler_cxx[i] if sys.platform == 'darwin': linker = _osx_support.compiler_fixup(linker, ld_args)