Search code examples
aixlibstdc++mpfrxlc

Compiling mpfr 4.0.2 on AIX fails to configure TLS support


I'm trying to compile mpfr on AIX and get an error finding TLS support. My end goal is to have a working gcc (9.3) with libstdc++ support for threads and TLS. I tried compiling with both an existing gcc on the machine (which is 8.3 and doesn't have TLS support, as it seems) and using the built-in xlC (V12.1) on the machine. I compiled GMP-6.2.0:

(gcc attempt): ./configure --enable-shared --enable-static CFLAGS=-fPIC CXXFLAGS=-fPIC --prefix=$OUTDIR --host=powerpc-ibm-aix7.1.0.0
(xlc attempt): ./configure --enable-shared --enable-static CC=xlc CXX=xlc CFLAGS=-qPIC CXXFLAGS=-qPIC --prefix=$OUTDIR  --host=powerpc-ibm-aix7.1.0.0
gmake all
gmake check
gmake install

In both cases gmp successfully tests and installs. Trying to configure mpfr-4.0.2 results in

(gcc attempt): ./configure --enable-shared --enable-static CFLAGS=-fPIC CXXFLAGS=-fPIC --with-gmp=$OUTDIR --prefix=$OUTDIR --host=powerpc-ibm-aix7.1.0.0
(xlc attempt): ./configure --enable-shared --enable-static CC=xlc CXX=xlc CFLAGS="-qPIC -qtls" CXXFLAGS="-qPIC -qtls" --with-gmp=$OUTDIR --prefix=$OUTDIR --host=powerpc-ibm-aix7.1.0.0

results in the following error in config.log

(gcc attempt):
configure:16567: checking for TLS support
configure:16595: gcc -o conftest -fPIC  -I{OUTDIR}/include -I./src  -L{OUTDIR}/lib conftest.c  >&5
ld: 0711-317 ERROR: Undefined symbol: __tls_get_addr

(xlc attempt):
configure:16567: checking for TLS support
configure:16595: xlc -o conftest -qPIC -qtls  -I{OUTDIR}/include -I./src  -L{OUTDIR}/lib conftest.c  >&5
ld: 0711-317 ERROR: Undefined symbol: .__tls_get_addr

I've tried a dozen different flags and configurations but mostly I don't think I'm in the correct direction - every dependency seems circular. I believe compiling with xlc is the correct idea here, but I just can't figure how to get it properly support TLS. I also thought that I can ignore this and continue, and later compile libstdc++ again with support for TLS - but that also brought me to a dead end.

Edit: Taking more actions on using xlc: I tried compiling the generated conftest.c (https://gist.github.com/NitzanEgozy/265e54e3353aefc79558c860b543a98f) manually:

$ xlc -o conftest -qPIC -qtls -I$OUTDIR/include -I./src -L$OUTDIR/lib conftest.c -bnoquiet
(ld): halt 4
(ld): setfflag 4
(ld): savename conftest
(ld): filelist 6 1
(ld): i /lib/crt0.o
(ld): i conftest.o
(ld): lib /usr/vac/lib/libxlopt.a
(ld): lib /usr/vac/lib/libxlipa.a
(ld): lib /usr/vac/lib/libxl.a
(ld): lib /usr/lib/libc.a
LIBRARY: Shared object libc.a[shr.o]: 3301 symbols imported.
LIBRARY: Shared object libc.a[meth.o]: 2 symbols imported.
LIBRARY: Shared object libc.a[posix_aio.o]: 20 symbols imported.
LIBRARY: Shared object libc.a[aio.o]: 18 symbols imported.
LIBRARY: Shared object libc.a[pse.o]: 8 symbols imported.
LIBRARY: Shared object libc.a[dl.o]: 4 symbols imported.
LIBRARY: Shared object libc.a[pty.o]: 1 symbols imported.
LIBRARY: Shared object libc.a[cthread.o]: 25 symbols imported.
FILELIST: Number of previously inserted files processed: 6
(ld): resolve
RESOLVE: 33 of 7029 symbols were kept.
(ld): addgl /usr/lib/glink.o
ADDGL: Glink code added for 2 symbols.
(ld): er full
ld: 0711-318 ERROR: Undefined symbols were found.
        The following symbols are in error:
 Symbol                    Inpndx  TY CL Source-File(Object-File) OR Import-File{Shared-object}
                              RLD: Address  Section  Rld-type Referencing Symbol
 ----------------------------------------------------------------------------------------------
 .__tls_get_addr           [30]    ER PR conftest.c(conftest.o)
                                   00000010 .text    R_RBA    [16]    .main

Removing -qtls throws The '__thread' keyword is not supported on the target platform. The keyword is ignored.


Solution

  • AFAIK if native TLS is not available gcc emulates it using pthread keys, and i think gcc does not even support native TLS on aix. adding "-pthread" flag to the configuration will enable the appropriate threading support.

    the current gcc from the ibm aixtoolbox has the appropriate default threading model enabled, hope this helps a little bit.

    root@aixbuildhostng: /root # gcc -v
    Using built-in specs.
    COLLECT_GCC=gcc
    COLLECT_LTO_WRAPPER=/opt/freeware/libexec/gcc/powerpc-ibm-aix7.1.0.0/8.3.0/lto-wrapper
    Target: powerpc-ibm-aix7.1.0.0
    Configured with: ../gcc-8.3.0/configure --prefix=/opt/freeware --mandir=/opt/freeware/man --infodir=/opt/freeware/info --with-local-prefix=/opt/freeware --with-as=/usr/bin/as --with-ld=/usr/bin/ld --enable-languages=c,c++,fortran,objc,obj-c++ --enable-version-specific-runtime-libs --disable-nls --enable-decimal-float=dpd --with-cloog=no --with-ppl=no --disable-libstdcxx-pch --enable-__cxa_atexit --host=powerpc-ibm-aix7.1.0.0
    Thread model: aix
    gcc version 8.3.0 (GCC)
    

    mpfr 4.0.2 is also available as an rpm package:

    root@aixbuildhostng: /root # yum search mpfr
    Loaded plugins: aliases, allowdowngrade, basearchonly, changelog, downloadonly, fastestmirror, filter-data, keys, list-data, local, merge-conf, post-transaction-actions, priorities, protectbase, ps, remove-with-leaves, rpm-warm-cache,
                  : show-leaves, tmprepo, tsflags, verify, versionlock
    Loading mirror speeds from cached hostfile
    0 packages excluded due to repository protections
    ============================================================================================================= N/S Matched: mpfr =============================================================================================================
    mpfr-devel.ppc : Development tools A C library for mpfr library
    mpfr.ppc : A C library for multiple-precision floating-point computations
    

    ad bootstrapping gcc via xlc...this quite a sophisticated task, i never managed to make this work.

    https://gcc.gnu.org/install/specific.html#x-ibm-aix