We have a CI pipeline that builds a bunch of projects. One of the projects uses advanced C++ features (C++20) and so we've upgraded our gcc version to gcc-9.
However, we have some target embedded systems that run debian buster and do not have the later libc versions. The images that are being built for the buster image do not rely on C++20 and their Makefiles specifically specify std=c++17.
All of these projects worked fine as-is before, however now we are getting errors like this:
./project: /usr/lib/arm-linux-gnueabihf/libstdc++.so.6: version `GLIBCXX_3.4.30' not found (required by ./project)
./project: /usr/lib/arm-linux-gnueabihf/libstdc++.so.6: version `GLIBCXX_3.4.29' not found (required by ./project)
./project: /usr/lib/arm-linux-gnueabihf/libstdc++.so.6: version `GLIBCXX_3.4.26' not found (required by ./project)
When I investigate these symbols, I find that g++ is "unnecessarily" linking to newew versions of things that really shouldn't (as far as I can tell) require newer version:
objdump -T project | egrep "GLIBC_2.3[2-6]"
00000000 DF *UND* 00000000 GLIBC_2.33 lstat
00000000 DF *UND* 00000000 GLIBC_2.34 pthread_once
00000000 DF *UND* 00000000 GLIBC_2.36 arc4random
00000000 DF *UND* 00000000 GLIBC_2.34 pthread_detach
00000000 DF *UND* 00000000 GLIBC_2.34 pthread_join
00000000 DF *UND* 00000000 GLIBC_2.34 pthread_setspecific
00000000 w DF *UND* 00000000 GLIBC_2.34 __pthread_key_create
00000000 DF *UND* 00000000 GLIBC_2.33 fstat64
00000000 DO *UND* 00000000 GLIBC_2.32 __libc_single_threaded
00000000 DF *UND* 00000000 GLIBC_2.34 pthread_key_create
00000000 DF *UND* 00000000 GLIBC_2.34 pthread_key_delete
00000000 DF *UND* 00000000 GLIBC_2.34 pthread_getspecific
00000000 DF *UND* 00000000 GLIBC_2.34 pthread_create
00000000 DF *UND* 00000000 GLIBC_2.34 __libc_start_main
Surely, I don't need to do a buster->bookworm upgrade on my edge devices so that I can get a new and improved bad_array_thrower?!
Is there a way to inform gcc to not frivolously make use of newer symbols unless they implement new features?
Once again: the projects that are being built do not use c++20 and they compile and run fine on gcc-8. It's just the new toolchain that makes it impossible to build for in the field devices.
Edit: Just so it's clear: I fully understand that toolchains do not mix and match. I would just like to be able to use C++20 features on a buster system without upgrading it to bullseye+ (because gcc-8 is the highest available package on buster).