[binutils-gdb] Fix wrong build tree in python.exp path on AIX

Aditya Kamath via Gdb-cvs <[email protected]>
Newsgroups gmane.comp.gdb.cvs
Message-ID <[email protected]>
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=7063b767cc9c2774e7ead41144e5613bacad6a0d

commit 7063b767cc9c2774e7ead41144e5613bacad6a0d
Author: Aditya Kamath <[email protected]>
Date:   Wed Jul 29 08:07:54 2026 -0500

    Fix wrong build tree in python.exp path on AIX
    
    AIX uses export symbol files (.exp) for linking such that linker knows
    what symbols are exported from a library.
    
    Python records the path to the export file in LINKFORSHARED sysconfig
    variable as a build tree relative path: -Wl,bE:Modules/python.exp
    
    But this will fail in AIX. When configure runs python-config.py --ldflags to test for
    libpython, the linker cannot find Modules/python.exp, the link test
    fails, and GDB is built without Python support.
    
    So in this patch we fix the same by replacing the relative path with LIBPL/python.exp (e.g.
    /opt/freeware/lib64/python3.12/config-3.12/python.exp) on AIX only,
    where LIBPL is the installed config directory that already contains
    the file.
    
    Approved-By: Tom Tromey <[email protected]>

Diff:
---
 gdb/python/python-config.py | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/gdb/python/python-config.py b/gdb/python/python-config.py
index 061eae1ac64..7190f799b0a 100644
--- a/gdb/python/python-config.py
+++ b/gdb/python/python-config.py
@@ -78,5 +78,16 @@ for opt in opt_flags:
                 elif os.name == "nt":
                     libs.insert(0, "-L" + os.path.normpath(sys.prefix) + "/libs")
             if getvar("LINKFORSHARED") is not None:
-                libs.extend(getvar("LINKFORSHARED").split())
+                linkforshared = getvar("LINKFORSHARED")
+                # On AIX, LINKFORSHARED contains "-Wl,-bE:Modules/python.exp"
+                # where "Modules/python.exp" is a build-tree-relative path that
+                # does not exist on installed systems.  Replace it with the
+                # absolute installed path using LIBPL, which always points to
+                # the pythonX.Y/config-X.Y directory where python.exp is kept.
+                if sys.platform.startswith("aix") and getvar("LIBPL") is not None:
+                    linkforshared = linkforshared.replace(
+                        "Modules/python.exp",
+                        getvar("LIBPL") + "/python.exp",
+                    )
+                libs.extend(linkforshared.split())
         print(to_unix_path(" ".join(libs)))
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.