在 AIX 上编译 mpfr 4.0.2 无法配置 TLS 支持

Compiling mpfr 4.0.2 on AIX fails to configure TLS support

我试图在 AIX 上编译 mpfr,但发现 TLS 支持时出错。我的最终目标是让 libstdc++ 支持线程和 TLS 的工作 gcc (9.3)。 我尝试使用机器上的现有 gcc(它是 8.3,看起来不支持 TLS)和使用机器上的内置 xlC (V12.1) 进行编译。 我编译了 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

在这两种情况下,gmp 均成功测试和安装。 尝试配置 mpfr-4.0.2 结果

(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

导致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

我已经尝试了十几种不同的标志和配置,但大多数情况下我认为我的方向不正确 - 每个依赖项似乎都是循环的。我相信在这里使用 xlc 进行编译是正确的想法,但我只是不知道如何让它正确支持 TLS。 我还认为我可以忽略它并继续,然后在支持 TLS 的情况下再次编译 libstdc++ - 但这也让我陷入了死胡同。

编辑: 对使用 xlc 采取更多行动:我尝试手动编译生成的 conftest.c (https://gist.github.com/NitzanEgozy/265e54e3353aefc79558c860b543a98f):

$ 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

删除 -qtls 会引发 The '__thread' keyword is not supported on the target platform. The keyword is ignored.

AFAIK 如果本机 TLS 不可用,gcc 使用 pthread 键模拟它,我认为 gcc 甚至不支持 aix 上的本机 TLS。在配置中添加“-pthread”标志将启用适当的线程支持。

来自 ibm aixtoolbox 的当前 gcc 启用了适当的默认线程模型,希望这能有所帮助。

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 也可以作为 rpm 包使用:

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

广告通过 xlc 引导 gcc...这是一项相当复杂的任务,我从来没有设法完成这项工作。

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