cpython icon indicating copy to clipboard operation
cpython copied to clipboard

Python 3.13a5 fails to build on AIX

Open kadler opened this issue 1 year ago • 2 comments

Bug report

Bug description:

gcc -pthread -maix64 -bI:Modules/python.exp -Wl,-blibpath:/QOpenSys/pkgs/lib:/QOpenSys/usr/lib  -lutil  -Wl,-hlibpython3.13.so ...
ld: 0706-012 The -h flag is not recognized.
ld: 0706-006 Cannot find or open library file: -l ibpython3.13.so
	ld:open(): No such file or directory

-h is not a valid linker flag on AIX. This seems to be a regression introduced in fa1d675309c6a08b0833cf25cffe476c6166aba3 as previously on AIX it would have gone in to the else leg and not used this flag.

CPython versions tested on:

CPython main branch

Operating systems tested on:

Other

kadler avatar Mar 20 '24 16:03 kadler

@mhsmith

ned-deily avatar Mar 20 '24 18:03 ned-deily

Apparently AIX doesn't use the ELF format, so this argument (which is the same as -soname) isn't applicable on that platform. If everything worked without it before, then the simplest solution would be to omit that argument on AIX.

mhsmith avatar Mar 20 '24 21:03 mhsmith

Is there any fix available for this issue. ? I am hitting same while building 3.13.2 on AIX @mhsmith @kadler do we need to revert the changes in fa1d675309c6a08b0833cf25cffe476c6166aba3

Ganeshkumhar1 avatar Apr 07 '25 10:04 Ganeshkumhar1

@Ganeshkumhar1 For our local builds, we just patched it to remove the -soname option entirely. Obviously, not an upstreamable change, but for our platform-specific builds it works for us:

--- a/Makefile.pre.in
+++ b/Makefile.pre.in
@@ -910,10 +910,7 @@
 	$(AR) $(ARFLAGS) $@ $(LIBRARY_OBJS)
 
 libpython$(LDVERSION).so: $(LIBRARY_OBJS) $(DTRACE_OBJS)
-	$(BLDSHARED) -Wl,-h$(INSTSONAME) -o $(INSTSONAME) $(LIBRARY_OBJS) $(MODLIBS) $(SHLIBS) $(LIBC) $(LIBM)
-	if test $(INSTSONAME) != $@; then \
-		$(LN) -f $(INSTSONAME) $@; \
-	fi
+	$(BLDSHARED) -o $@ $(LIBRARY_OBJS) $(MODLIBS) $(SHLIBS) $(LIBC) $(LIBM);
 
 libpython3.so:	libpython$(LDVERSION).so
 	$(BLDSHARED) $(NO_AS_NEEDED) -o $@ -Wl,-h$@ $^

I don't understand enough about the reason for removing the if check as part of the Android support PR to know what the proper fix is to support everybody.

kadler avatar Apr 07 '25 15:04 kadler

The if check was removed because on Android the SONAME is the same as the filename (libpython3.13.so), so the library was previously buit with no SONAME at all, which caused problems when linking things against it (i.e. extension modules).

If we need to omit this argument on AIX, then the proper fix would be to simply do that with a platform check.

mhsmith avatar Apr 08 '25 03:04 mhsmith

cc AIX experts: @edelsohn, @ayappanec

encukou avatar Apr 16 '25 09:04 encukou

@encukou Thanks for notifying this. Agree with @mhsmith , that the proper fix would be to do this under a platform check. Let me work on a PR to fix this.

ayappanec avatar Apr 16 '25 10:04 ayappanec

I suppose that the following patch also should fix issue on AIX:

diff --git a/Makefile.pre.in b/Makefile.pre.in
index e41a26e469d..1f9d90ef385 100644
--- a/Makefile.pre.in
+++ b/Makefile.pre.in
@@ -999,9 +999,11 @@ $(LIBRARY): $(LIBRARY_OBJS)
        $(AR) $(ARFLAGS) $@ $(LIBRARY_OBJS)
 
 libpython$(LDVERSION).so: $(LIBRARY_OBJS) $(DTRACE_OBJS)
-       $(BLDSHARED) -Wl,-h$(INSTSONAME) -o $(INSTSONAME) $(LIBRARY_OBJS) $(MODLIBS) $(SHLIBS) $(LIBC) $(LIBM)
        if test $(INSTSONAME) != $@; then \
+               $(BLDSHARED) -Wl,-h$(INSTSONAME) -o $(INSTSONAME) $(LIBRARY_OBJS) $(MODLIBS) $(SHLIBS) $(LIBC) $(LIBM); \
                $(LN) -f $(INSTSONAME) $@; \
+       else \
+               $(BLDSHARED) -o $@ $(LIBRARY_OBJS) $(MODLIBS) $(SHLIBS) $(LIBC) $(LIBM); \
        fi
 
 libpython3.so: libpython$(LDVERSION).so

@mhsmith, does it break Android build?

serhiy-storchaka avatar Apr 16 '25 16:04 serhiy-storchaka

Yes, it would break Android because it would take the else branch and build libpython without an SONAME. This means extension modules linked against it would have no NEEDED entry for libpython, and would be unable to resolve their libpython symbols at runtime.

mhsmith avatar Apr 16 '25 17:04 mhsmith