Building of "Tests" incorrectly does not detect static build.
This report concerns building CMake itself, from source. I am unsure as to whether this applies to projects that use CMake.
My objective is to cross-compile CMake itself, statically, for a number of platforms. I posted to the mailing list yesterday with a statement that most, but not all of my desired platforms, work without issue. The remaining 19 (of 48) do not build without the workaround I am proposing below, which I believe to be a bug.
Let me be clear, first and foremost, that I am using toolchains that favor static builds, and use the musl library.
On these Linux-based platforms (and likely others):
- microblaze-linux-musl
- microblazeel-linux-musl
- mips-linux-musl
- mips-linux-musln32sf
- mips-linux-muslsf
- mips64-linux-musln32
- mips64-linux-musln32sf
- mips64el-linux-musln32
- mips64el-linux-musln32sf
- mipsel-linux-musl
- mipsel-linux-musln32
- mipsel-linux-musln32sf
- mipsel-linux-muslsf
- or1k-linux-musl
- riscv32-linux-musl
- riscv64-linux-musl
The primary issue in building these is something of this nature:
/lib/gcc/microblaze-linux-musl/8.2.0/../../../../microblaze-linux-musl/bin/ld: BFD (GNU Binutils) 2.31.1 assertion fail ../../src_binutils/bfd/elf32-microblaze.c:1542
/lib/gcc/microblaze-linux-musl/8.2.0/../../../../microblaze-linux-musl/bin/ld: /lib/gcc/microblaze-linux-musl/8.2.0/crtbeginT.o: probably compiled without -fPIC?
/lib/gcc/microblaze-linux-musl/8.2.0/../../../../microblaze-linux-musl/bin/ld: final link failed: bad value
which is odd, because I've explicitly set gcc
and g++
to be
wrappers which append -static --static
to their invocations. I
have verified using the -v
flag the following:
[ 1%] Built target cmsys_c
[ 2%] Built target cmsysTestsC
[ 4%] Built target cmsys
[ 4%] Built target testConsoleBufChild
[ 4%] Linking C shared module libcmsysTestDynload.so
Using built-in specs.
COLLECT_GCC=gcc.orig
COLLECT_LTO_WRAPPER=/libexec/gcc/microblaze-linux-musl/8.2.0/lto-wrapper
Target: microblaze-linux-musl
Configured with: ../src_gcc/configure --enable-languages=c,c++,fortran --enable-languages=c,c++ CC='gcc -static --static' CXX='g++ -static --static' FC='gfortran -static --static' CFLAGS='-g0 -Os' CXXFLAGS='-g0 -Os' FFLAGS='-g0 -Os' LDFLAGS='-s -static --static' --disable-nls --disable-werror --target=microblaze-linux-musl --prefix= --libdir=/lib --disable-multilib --with-sysroot=/microblaze-linux-musl --enable-tls --disable-libmudflap --disable-libsanitizer --disable-gnu-indirect-function --disable-libmpx --enable-deterministic-archives --enable-libstdcxx-time --disable-libquadmath --disable-libquadmath-support --disable-decimal-float --with-build-sysroot=/kale/musl-cross-make/build/local/microblaze-linux-musl/obj_sysroot AR_FOR_TARGET=/kale/musl-cross-make/build/local/microblaze-linux-musl/obj_binutils/binutils/ar AS_FOR_TARGET=/kale/musl-cross-make/build/local/microblaze-linux-musl/obj_binutils/gas/as-new LD_FOR_TARGET=/kale/musl-cross-make/build/local/microblaze-linux-musl/obj_binutils/ld/ld-new NM_FOR_TARGET=/kale/musl-cross-make/build/local/microblaze-linux-musl/obj_binutils/binutils/nm-new OBJCOPY_FOR_TARGET=/kale/musl-cross-make/build/local/microblaze-linux-musl/obj_binutils/binutils/objcopy OBJDUMP_FOR_TARGET=/kale/musl-cross-make/build/local/microblaze-linux-musl/obj_binutils/binutils/objdump RANLIB_FOR_TARGET=/kale/musl-cross-make/build/local/microblaze-linux-musl/obj_binutils/binutils/ranlib READELF_FOR_TARGET=/kale/musl-cross-make/build/local/microblaze-linux-musl/obj_binutils/binutils/readelf STRIP_FOR_TARGET=/kale/musl-cross-make/build/local/microblaze-linux-musl/obj_binutils/binutils/strip-new
Thread model: posix
gcc version 8.2.0 (GCC)
COMPILER_PATH=/libexec/gcc/microblaze-linux-musl/8.2.0/:/libexec/gcc/microblaze-linux-musl/8.2.0/:/libexec/gcc/microblaze-linux-musl/:/lib/gcc/microblaze-linux-musl/8.2.0/:/lib/gcc/microblaze-linux-musl/:/lib/gcc/microblaze-linux-musl/8.2.0/../../../../microblaze-linux-musl/bin/
LIBRARY_PATH=/lib/gcc/microblaze-linux-musl/8.2.0/:/lib/gcc/microblaze-linux-musl/8.2.0/../../../../microblaze-linux-musl/lib/:/microblaze-linux-musl/lib/
COLLECT_GCC_OPTIONS='-fPIC' '-shared' '-o' 'libcmsysTestDynload.so' '-static' '-static' '-g0' '-s' '-Os' '-v'
/libexec/gcc/microblaze-linux-musl/8.2.0/collect2 --sysroot=/microblaze-linux-musl -shared -o libcmsysTestDynload.so -s /lib/gcc/microblaze-linux-musl/8.2.0/../../../../microblaze-linux-musl/lib/crti.o /lib/gcc/microblaze-linux-musl/8.2.0/crtbeginT.o -L/lib/gcc/microblaze-linux-musl/8.2.0 -L/lib/gcc/microblaze-linux-musl/8.2.0/../../../../microblaze-linux-musl/lib -L/microblaze-linux-musl/lib CMakeFiles/cmsysTestDynload.dir/testDynload.c.o --start-group -lgcc -lgcc_eh -lc --end-group /lib/gcc/microblaze-linux-musl/8.2.0/crtend.o /lib/gcc/microblaze-linux-musl/8.2.0/../../../../microblaze-linux-musl/lib/crtn.o
/lib/gcc/microblaze-linux-musl/8.2.0/../../../../microblaze-linux-musl/bin/ld: BFD (GNU Binutils) 2.31.1 assertion fail ../../src_binutils/bfd/elf32-microblaze.c:1542
/lib/gcc/microblaze-linux-musl/8.2.0/../../../../microblaze-linux-musl/bin/ld: /lib/gcc/microblaze-linux-musl/8.2.0/crtbeginT.o: probably compiled without -fPIC?
/lib/gcc/microblaze-linux-musl/8.2.0/../../../../microblaze-linux-musl/bin/ld: final link failed: bad value
collect2: error: ld returned 1 exit status
make[2]: *** [Source/kwsys/CMakeFiles/cmsysTestDynload.dir/build.make:84: Source/kwsys/libcmsysTestDynload.so] Error 1
make[1]: *** [CMakeFiles/Makefile2:1102: Source/kwsys/CMakeFiles/cmsysTestDynload.dir/all] Error 2
make: *** [Makefile:163: all] Error 2
it appears that it is trying to build a shared library, at least
libcmsysTestDynload.so
and possibly others. Searching for the
string cmsysTestDynload
within the CMake source directory says
that there is one occurrence,
$ grep -r cmsysTestDynload .
./Tests/CMakeLib/testVisualStudioSlnParser.cxx: "cmsysTestDynload",
./Tests/CMakeLib/testVisualStudioSlnParser_data/valid.sln-file:Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cmsysTestDynload", "Source\kwsys\cmsysTestDynload.vcxproj", "{A0421DCA-AC3E-42D0-94AC-379A21A1E591}"
which I am not interested in building. I even tried adding
-DBUILD_SHARED_LIBS=OFF
to my build command, but it behaved in
the exact same manner.
Searching for VisualStudioSlnParser
, I see the only occurrence
is ./Tests/
and the corresponding source file. So I disabled
building tests with -DBUILD_TESTING=OFF
and everything worked
as expected.
This issue was not encountered using binutils 2.30
and GCC
7.3.0
, however, it is believed that GCC 8.2.0
and binutils
2.3.1
correctly fault on this (rather than build an improper
.so
). I believe the "Test" is faulty.
To reproduce this, I am using CMake 2.13.2
with the following
command (the gcc
and g++
binaries are cross-compilers). Try
with -DBUILD_TESTING=ON
vs. -DBUILD_TESTING=OFF
.
CMSN=Linux
XMCM=$(gcc -dumpmachine)
cmake .. \
-DCMAKE_SYSTEM_NAME=${CMSN} \
-DCMAKE_C_COMPILER=/bin/gcc `# cross` \
-DCMAKE_CXX_COMPILER=/bin/g++ `# cross` \
-DBUILD_TESTING=OFF `# BUG: some platforms fail here` \
-DCMAKE_FIND_ROOT_PATH=/${XMCM} `# cross` \
-DCMAKE_SYSROOT=/${XMCM} `# cross` \
-DCMAKE_FIND_ROOT_PATH_MODE_PROGRAM=NEVER \
-DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=ONLY \
-DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE=ONLY \
-DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=ONLY \
-DKWSYS_LFS_WORKS=ON \
-DKWSYS_LFS_WORKS__TRYRUN_OUTPUT="" \
-DHAVE_FSETXATTR_5=ON \
-DHAVE_FSETXATTR_5__TRYRUN_OUTPUT="" \
-DHAVE_GLIBC_STRERROR_R=OFF `# because musl` \
-DHAVE_GLIBC_STRERROR_R__TRYRUN_OUTPUT="" \
-DHAVE_POSIX_STRERROR_R=ON `# because musl` \
-DHAVE_POSIX_STRERROR_R__TRYRUN_OUTPUT="" \
-DHAVE_POLL_FINE_EXITCODE=ON \
-DHAVE_POLL_FINE_EXITCODE__TRYRUN_OUTPUT=""
I am pleased to say that CMake has now been successfully built using musl, statically, on the following platforms:
aarch64-linux-musleabi/bin/cmake: ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), statically linked, stripped
aarch64_be-linux-musl/bin/cmake: ELF 64-bit MSB executable, ARM aarch64, version 1 (SYSV), statically linked, stripped
arm-linux-musleabi/bin/cmake: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), statically linked, stripped
arm-linux-musleabihf/bin/cmake: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), statically linked, stripped
armeb-linux-musleabi/bin/cmake: ELF 32-bit MSB executable, ARM, EABI5 version 1 (SYSV), statically linked, stripped
armeb-linux-musleabihf/bin/cmake: ELF 32-bit MSB executable, ARM, EABI5 version 1 (SYSV), statically linked, stripped
armel-linux-musleabi/bin/cmake: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), statically linked, stripped
armel-linux-musleabihf/bin/cmake: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), statically linked, stripped
armv5l-linux-musleabihf/bin/cmake: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), statically linked, stripped
armv7l-linux-musleabihf/bin/cmake: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), statically linked, stripped
armv7m-linux-musleabi/bin/cmake: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), statically linked, stripped
armv7r-linux-musleabihf/bin/cmake: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), statically linked, stripped
i486-linux-musl/bin/cmake: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), statically linked, stripped
i686-linux-musl/bin/cmake: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), statically linked, stripped
m68k-linux-musl/bin/cmake: ELF 32-bit MSB executable, Motorola m68k, 68020, version 1 (SYSV), statically linked, stripped
microblaze-linux-musl/bin/cmake: ELF 32-bit MSB executable, Xilinx MicroBlaze 32-bit RISC, version 1 (SYSV), statically linked, stripped
microblazeel-linux-musl/bin/cmake: ELF 32-bit LSB executable, Xilinx MicroBlaze 32-bit RISC, version 1 (SYSV), statically linked, stripped
mips-linux-musl/bin/cmake: ELF 32-bit MSB executable, MIPS, MIPS-I version 1 (SYSV), statically linked, stripped
mips-linux-musln32sf/bin/cmake: ELF 32-bit MSB executable, MIPS, MIPS-I version 1 (SYSV), statically linked, stripped
mips-linux-muslsf/bin/cmake: ELF 32-bit MSB executable, MIPS, MIPS-I version 1 (SYSV), statically linked, stripped
mips64-linux-musl/bin/cmake: ELF 64-bit MSB executable, MIPS, MIPS-III version 1 (SYSV), statically linked, stripped
mips64-linux-musln32/bin/cmake: ELF 32-bit MSB executable, MIPS, N32 MIPS-III version 1 (SYSV), statically linked, stripped
mips64-linux-musln32sf/bin/cmake: ELF 32-bit MSB executable, MIPS, N32 MIPS-III version 1 (SYSV), statically linked, stripped
mips64el-linux-musl/bin/cmake: ELF 64-bit LSB executable, MIPS, MIPS-III version 1 (SYSV), statically linked, stripped
mips64el-linux-musln32/bin/cmake: ELF 32-bit LSB executable, MIPS, N32 MIPS-III version 1 (SYSV), statically linked, stripped
mips64el-linux-musln32sf/bin/cmake: ELF 32-bit LSB executable, MIPS, N32 MIPS-III version 1 (SYSV), statically linked, stripped
mipsel-linux-musl/bin/cmake: ELF 32-bit LSB executable, MIPS, MIPS-I version 1 (SYSV), statically linked, stripped
mipsel-linux-musln32/bin/cmake: ELF 32-bit LSB executable, MIPS, MIPS-I version 1 (SYSV), statically linked, stripped
mipsel-linux-musln32sf/bin/cmake: ELF 32-bit LSB executable, MIPS, MIPS-I version 1 (SYSV), statically linked, stripped
mipsel-linux-muslsf/bin/cmake: ELF 32-bit LSB executable, MIPS, MIPS-I version 1 (SYSV), statically linked, stripped
or1k-linux-musl/bin/cmake: ELF 32-bit MSB executable, OpenRISC, version 1 (SYSV), statically linked, stripped
powerpc-linux-musl/bin/cmake: ELF 32-bit MSB executable, PowerPC or cisco 4500, version 1 (SYSV), statically linked, stripped
powerpc-linux-muslsf/bin/cmake: ELF 32-bit MSB executable, PowerPC or cisco 4500, version 1 (SYSV), statically linked, stripped
powerpc64-linux-musl/bin/cmake: ELF 64-bit MSB executable, 64-bit PowerPC or cisco 7500, version 1 (SYSV), statically linked, stripped
powerpc64le-linux-musl/bin/cmake: ELF 64-bit LSB executable, 64-bit PowerPC or cisco 7500, version 1 (SYSV), statically linked, stripped
powerpcle-linux-musl/bin/cmake: ELF 32-bit LSB executable, PowerPC or cisco 4500, version 1 (SYSV), statically linked, stripped
powerpcle-linux-muslsf/bin/cmake: ELF 32-bit LSB executable, PowerPC or cisco 4500, version 1 (SYSV), statically linked, stripped
riscv32-linux-musl/bin/cmake: ELF 32-bit LSB executable, UCB RISC-V, version 1 (SYSV), statically linked, stripped
riscv64-linux-musl/bin/cmake: ELF 64-bit LSB executable, UCB RISC-V, version 1 (SYSV), statically linked, stripped
s390x-linux-musl/bin/cmake: ELF 64-bit MSB executable, IBM S/390, version 1 (SYSV), statically linked, stripped
sh2-linux-musl/bin/cmake: ELF 32-bit LSB executable, Renesas SH, version 1 (SYSV), statically linked, stripped
sh2-linux-muslfdpic/bin/cmake: ELF 32-bit LSB executable, Renesas SH, version 1 (SYSV), statically linked, stripped
sh2eb-linux-musl/bin/cmake: ELF 32-bit MSB executable, Renesas SH, version 1 (SYSV), statically linked, stripped
sh2eb-linux-muslfdpic/bin/cmake: ELF 32-bit MSB executable, Renesas SH, version 1 (SYSV), statically linked, stripped
sh4-linux-musl/bin/cmake: ELF 32-bit LSB executable, Renesas SH, version 1 (SYSV), statically linked, stripped
sh4eb-linux-musl/bin/cmake: ELF 32-bit MSB executable, Renesas SH, version 1 (SYSV), statically linked, stripped
x86_64-linux-musl/bin/cmake: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, stripped
x86_64-linux-muslx32/bin/cmake: ELF 32-bit LSB executable, x86-64, version 1 (SYSV), statically linked, stripped
These are available immediately here for testing:
This means 48 of 48 platforms, so far excluding MinGW-based ones
due to an unrelated threading issue, build either without issue,
or with the above -DBUILD_TESTING=OFF
workaround until this
can be fixed.
ZV