[Python-checkins] bpo-35198 Fix C++ extension compilation on AIX (GH-10437)

Miss Islington (bot) webhook-mailer at python.org
Mon Mar 4 10:06:40 EST 2019


https://github.com/python/cpython/commit/06e9953d5e3f0144ec8247b61541e7be85d55b50
commit: 06e9953d5e3f0144ec8247b61541e7be85d55b50
branch: 3.7
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: GitHub <noreply at github.com>
date: 2019-03-04T07:06:36-08:00
summary:

bpo-35198 Fix C++ extension compilation on AIX (GH-10437)


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.
(cherry picked from commit 800d5cd75025876d79ab05980925a05d8e36b63d)

Co-authored-by: Kevin Adler <kadler at us.ibm.com>

files:
A Misc/NEWS.d/next/Library/2018-11-09-12-45-28.bpo-35198.EJ8keW.rst
M Lib/distutils/unixccompiler.py

diff --git a/Lib/distutils/unixccompiler.py b/Lib/distutils/unixccompiler.py
index ab4d4de15661..d10a78da3114 100644
--- a/Lib/distutils/unixccompiler.py
+++ b/Lib/distutils/unixccompiler.py
@@ -188,7 +188,15 @@ def link(self, target_desc, objects,
                         i = 1
                         while '=' in linker[i]:
                             i += 1
-                    linker[i] = self.compiler_cxx[i]
+
+                    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)
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 000000000000..4ce7a7e3423c
--- /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



More information about the Python-checkins mailing list