This was originally reported here https://github.com/riscv/riscv-gnu-toolchain/issues/718 A build of gcc 10 on Ubuntu 16.04 with the libzstd-dev package installed gives multiple errors. Ubuntu 16.04 has zstd version 0.5.1 which lacks features that gcc is trying to use. The gcc configure test for zstd.h only verifies that it exists, it doesn't verify the version, or that any of the functions or macros we need are present. Ubuntu 18.04 has zstd version 1.3.3, I verified that builds. So we can maybe verify the version is 1.3.3 or greater, or maybe check for the specific functions and macros that we are trying to use. Kito did a little research that suggests that we need verfsion 1.3.0 or greater. We haven't tried to verify that. --without-zstd successfully works around the problem. build log info from the original bug report: g++ -fno-PIE -c -g -O2 -DIN_GCC -DCROSS_DIRECTORY_STRUCTURE -fno-exceptions -fno-rtti -fasynchronous-unwind-tables -W -Wall -Wno-narrowing -Wwrite-strings -Wcast-qual -Wmissing-format-attribute -Woverloaded-virtual -pedantic -Wno-long-long -Wno-variadic-macros -Wno-overlength-strings -DHAVE_CONFIG_H -I. -I. -I../.././riscv-gcc/gcc -I../.././riscv-gcc/gcc/. -I../.././riscv-gcc/gcc/../include -I../.././riscv-gcc/gcc/../libcpp/include -I../.././riscv-gcc/gcc/../libdecnumber -I../.././riscv-gcc/gcc/../libdecnumber/dpd -I../libdecnumber -I../.././riscv-gcc/gcc/../libbacktrace -o optabs-tree.o -MT optabs-tree.o -MMD -MP -MF ./.deps/optabs-tree.TPo ../.././riscv-gcc/gcc/optabs-tree.c ../.././riscv-gcc/gcc/lto-compress.c: In function ‘int lto_normalized_zstd_level()’: ../.././riscv-gcc/gcc/lto-compress.c:120:36: error: ‘ZSTD_maxCLevel’ was not declared in this scope else if (level > ZSTD_maxCLevel ()) ^ ../.././riscv-gcc/gcc/lto-compress.c: In function ‘void lto_uncompression_zstd(lto_compression_stream*)’: ../.././riscv-gcc/gcc/lto-compress.c:160:74: error: ‘ZSTD_getFrameContentSize’ was not declared in this scope unsigned long long const rsize = ZSTD_getFrameContentSize (cursor, size); ^ ../.././riscv-gcc/gcc/lto-compress.c:161:16: error: ‘ZSTD_CONTENTSIZE_ERROR’ was not declared in this scope if (rsize == ZSTD_CONTENTSIZE_ERROR) ^ ../.././riscv-gcc/gcc/lto-compress.c:163:21: error: ‘ZSTD_CONTENTSIZE_UNKNOWN’ was not declared in this scope else if (rsize == ZSTD_CONTENTSIZE_UNKNOWN) ^
I think amending the configure test for the specific macro / API uses is better than a version check.
Confirmed, can you please suggest a patch Jim?
I installed Ubuntu 16.04 on an old laptop so I can directly reproduce the build failure. Checking for the zstd version looks like the easier patch. Checking for specific macros and functions might be better, but what do we do with the info? I'm not familiar with zstd or the lto-compress.c code, and it doesn't look like we can easily change it to not use certain macros/functions when they don't exist. Checking for half a dozen macros/functions and disabling all of the code if one or more is missing seems silly. Though looking at this, as Kito pointed out, it appears that ZSTD_getFrameContentSize() is the most recently added function that we are using, so maybe we only need to check for that one. That was added in version 1.3.0. Or we can check for the 1.3.0 version which seems simpler. I do know that version 1.3.3 of zstd works as this is what Ubuntu 18.04 has. I haven't tried the versions 1.3.[012].
> Or we can check for the 1.3.0 version which seems simpler. > I do know that version 1.3.3 of zstd works as this is what Ubuntu 18.04 has. > I haven't tried the versions 1.3.[012]. Yes, I would recommend checking for a specific minimal version (in this case 1.3.0).
The master branch has been updated by Jim Wilson <wilson@gcc.gnu.org>: https://gcc.gnu.org/g:6649df18f98d5baf89b56a09b816b5eeb5f67bcb commit r11-3536-g6649df18f98d5baf89b56a09b816b5eeb5f67bcb Author: Jim Wilson <jimw@sifive.com> Date: Mon Sep 28 17:13:40 2020 -0700 Fix GCC 10+ build failure with zstd version 1.2.0 or older. Extends the configure check for zstd.h to also verify the zstd version, since gcc requires features that only exist in 1.3.0 and newer. Without this patch we get a build error for lto-compress.c when using an old zstd version. gcc/ PR bootstrap/97183 * configure.ac (gcc_cv_header_zstd_h): Check ZSTD_VERISON_NUMBER. * configure: Regenerated.
The releases/gcc-10 branch has been updated by Jim Wilson <wilson@gcc.gnu.org>: https://gcc.gnu.org/g:9d85b9880e1772ead961c7b5a2bd8caab57815bf commit r10-8831-g9d85b9880e1772ead961c7b5a2bd8caab57815bf Author: Jim Wilson <jimw@sifive.com> Date: Wed Sep 30 13:06:28 2020 -0700 Fix build failure with zstd versio9n 1.2.0 or older. Extends the configure check for zstd.h to also verify the zstd version, since gcc requires features that only exist in 1.3.0 and newer. Without this patch we get a build error for lto-compress.c when using an old zstd version. Backported from master: 2020-09-29 Jim Wilson <jimw@sifive.com> gcc/ PR bootstrap/97183 * configure.ac (gcc_cv_header_zstd_h): Check ZSTD_VERISON_NUMBER. * configure: Regenerated.
Fixed on mainline and the gcc-10 branch.
Remember to set it to resolved/fixed this tine,