perl5
perl5 copied to clipboard
Add support for AIX openxlc clang compiler
Module: Perl
Description Perl cannot compile on AIX with the openxlc (clang) compiler out of the box.
I was able to get around this with a patch and a workaround. This is the patch. It makes it so clang is treated the same as gcc, and removes -DNEED_PTHREAD_INIT which seems to be incorrectly added, as the definition of pthread_init could not be found when compiling.
--- aix.sh 2025-05-27 14:48:19.499509204 -0500
+++ aix.sh 2025-05-27 15:50:47.991929476 -0500
@@ -94,7 +94,7 @@
ccflags="$ccflags -D_ALL_SOURCE -D_ANSI_C_SOURCE -D_POSIX_SOURCE"
case "$cc" in
- *gcc*|*g++*) ;;
+ *gcc*|*g++*|*clang*) ;;
*) ccflags="$ccflags -qmaxmem=-1 -qnoansialias -qlanglvl=extc99" ;;
esac
nm_opt='-B'
@@ -109,7 +109,7 @@
cccdlflags='none' # All AIX code is position independent
cc_type=xlc # do not export to config.sh
case "$cc" in
- *gcc*|*g++*)
+ *gcc*|*g++*|*clang*)
cc_type=gcc
ccdlflags='-Xlinker'
if [ "X$gccversion" = "X" ]; then
@@ -189,7 +189,7 @@
esac
case "$cc" in
- *gcc*|*g++*) ;;
+ *gcc*|*g++*|*clang*) ;;
cc*|xlc*) # cc should've been set by line 116 or so if empty.
if test ! -x /usr/bin/$cc -a -x /usr/vac/bin/$cc; then
@@ -236,9 +236,8 @@
d_srandom_r='undef'
d_strerror_r='undef'
- ccflags="$ccflags -DNEED_PTHREAD_INIT"
case "$cc" in
- *gcc*|*g++*)
+ *gcc*|*g++*|*clang*)
ccflags="-D_THREAD_SAFE $ccflags"
;;
cc_r)
@@ -429,7 +428,7 @@
ccflags="`echo $ccflags | sed -e 's@-q32@@'`"
ldflags="`echo $ldflags | sed -e 's@-b32@@'`"
case "$cc" in
- *gcc*|*g++*)
+ *gcc*|*g++*|*clang*)
ccflags="`echo $ccflags | sed -e 's@-q64@-maix64@'`"
ccflags_uselargefiles="`echo $ccflags_uselargefiles | sed -e 's@-q64@-maix64@'`"
qacflags="`echo $qacflags | sed -e 's@-q64@-maix64@'`"
@@ -474,10 +473,10 @@
# libraries. AIX allows both .so and .a libraries to
# contain dynamic shared objects.
case "$cc" in
- *gcc*|*g++*) ldflags="$ldflags -Wl,-brtl -Wl,-bdynamic" ;;
+ *gcc*|*g++*|*clang*) ldflags="$ldflags -Wl,-brtl -Wl,-bdynamic" ;;
*) ldflags="$ldflags -brtl -bdynamic" ;;
esac
-elif test -f /lib/libC.a -a X"`$cc -v 2>&1 | grep gcc`" = X; then
+elif test -f /lib/libC.a -a X"`$cc -v 2>&1 | grep -E 'gcc|clang'`" = X; then
# If the C++ libraries, libC and libC_r, are available we will
# prefer them over the vanilla libc, because the libC contain
# loadAndInit() and terminateAndUnload() which work correctly
And the additional workaround is to add -Accflags=-DSWIG to the ./Configure invocation so that PERL_TSA_ACTIVE gets undefined, since leaving that enabled was causing the build to break. I think there needs to be a change to perl.h to check if clang is running under AIX, because it doesn't seem to be able to get all the symbols exported correctly with PERL_TSA_ACTIVE defined. This is the problematic section:
/* clang Thread Safety Analysis/Annotations/Attributes
* http://clang.llvm.org/docs/ThreadSafetyAnalysis.html
*
* Available since clang 3.6-ish (appeared in 3.4, but shaky still in 3.5).
* Apple XCode hijacks __clang_major__ and __clang_minor__
* (6.1 means really clang 3.6), so needs extra hijinks
* (could probably also test the contents of __apple_build_version__).
*/
#if defined(USE_ITHREADS) && defined(I_PTHREAD) && \
defined(__clang__) && \
!defined(SWIG) && \
((!defined(__apple_build_version__) && \
((__clang_major__ == 3 && __clang_minor__ >= 6) || \
(__clang_major__ >= 4))) || \
(defined(__apple_build_version__) && \
((__clang_major__ == 6 && __clang_minor__ >= 1) || \
(__clang_major__ >= 7))))
# define PERL_TSA__(x) __attribute__((x))
# define PERL_TSA_ACTIVE
#else
# define PERL_TSA__(x) /* No TSA, make TSA attributes no-ops. */
# undef PERL_TSA_ACTIVE
#endif
Steps to Reproduce
export OBJECT_MODE=64
./Configure -Dcc=/opt/IBM/openxlC/17.1.3/bin/ibm-clang_r -Dusemorebits -Dusethreads -Doptimize=-O -des
make
Expected behavior It should be able to use the aix hints and gcc flags to configure and build.
Perl configuration N/A
@Tux @khwilliamson or anyone with access to AIX, can you take a look at this issue? Thanks.
It looks like the patch is essentially "treat clang as gcc", which sounds like a generally sensible approach.
I should note that using ibm-clang_r as the C compiler on AIX should eventually be promoted as the primary way to build perl rather than the old xlc compiler.
It's preferred by IBM at this point and uses the same xlc backend so it gets the same optimizations that running cc would provide.
It still makes sense to have gcc as a second option because it hasn't changed - it doesn't use the xlc backend and adds a libgcc dependency.
I have no access to AIX anymore, but I won't object to this change. I agree with @Leont
I agree; I'm thinking this should go in 5.42
Hi, any update on this? Doesn't look like it was included in 5.42.
Hi, any update on this? Doesn't look like it was included in 5.42.
I can't speak for the other commenters on this ticket, but when I read it on May 27, I thought to myself, "Our target date for releasing a new production version of Perl is May 27 -- and we're past that." So, notwithstanding (a) the other commenters' remarks or (b) the fact that we didn't do that release until July 2, I never expected it to make it into 5.42.
Would it be possible to re-do the patch as a pull request? That would be a spur to action on our part. Thanks.
I'd make it into a pull request but I'm not entirely sure how to handle the issues with TSA. That would probably require a code change, not just a change to the hints script. I don't think it's appropriate to include -DSWIG but it worked as a workaround.
For reference this is the error. I'll investigate to see if I can figure out what is causing that.
chmod 755 ../../lib/auto/threads/shared/shared.so
make[1]: Leaving directory '/epic/perl_build/perl5/dist/threads-shared'
./perl -Ilib -I. -f pod/buildtoc -q
Can't load 'lib/auto/re/re.so' for module re: rtld: 0712-001 Symbol perl_tsa_mutex_lock was referenced
from module lib/auto/re/re.so(), but a runtime definition
of the symbol was not found.
rtld: 0712-001 Symbol perl_tsa_mutex_unlock was referenced
from module lib/auto/re/re.so(), but a runtime definition
of the symbol was not found. at lib/XSLoader.pm line 94.
at lib/re.pm line 95.
Compilation failed in require at lib/Text/Wrap.pm line 52.
BEGIN failed--compilation aborted at lib/Text/Wrap.pm line 52.
Compilation failed in require at pod/buildtoc line 6.
BEGIN failed--compilation aborted at pod/buildtoc line 6.
make: *** [makefile:425: pod/perltoc.pod] Error 8
Created #23476