Bug #111212 compile failed with gcc-10 when lto is enable
Submitted: 31 May 2023 8:30 Modified: 16 Jun 2023 12:41
Reporter: Xlong Li (OCA) Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Compiling Severity:S2 (Serious)
Version:8.0.30, 8.0.33 OS:Debian (10)
Assigned to: CPU Architecture:Any (x86 and arm)

[31 May 2023 8:30] Xlong Li
Description:
compile with following cmake option get core with protoc

the cmake options are:
cmake ..    -DCMAKE_BUILD_TYPE=Release -DWITH_UNIT_TESTS=OFF -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_bin \
                    -DMYSQL_TCP_PORT=3306 -DWITH_ARCHIVE_STORAGE_ENGINE=1  -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_PERFSCHEMA_STORAGE_ENGINE=0 \
                    -DWITH_INNOBASE_STORAGE_ENiGINE=1 -DWITH_MYISAM_STORAGE_ENGINE=1 -DENABLED_LOCAL_INFILE=1 -DWITH_EXTRA_CHARSETS=all  \
                    -DWITH_SEMISYNC_MASTER=ON -DWITH_SEMISYNC_SLAVE=ON -DDEFAULT_CHARSET="utf8"  -DDEFAULT_COLLATION="utf8_general_ci" \
                    -DWITH_LTO=on -DFPROFILE_DIR=./ -DFPROFILE_GENERATE=on  -DFPROFILE_USE=off

the error i got:
[ 33%] Running C++ protobuf compiler on /data00/code/hybrid_rds-mysql-server-8.0/plugin/group_replication/protobuf/replication_group_member_actions.proto - lite version
[ 33%] Built target GenDigestServerSource
terminate called after throwing an instance of 'std::system_error'
  what():  Unknown error -1

my gcc version is 
gcc (Debian 10.2.1-6) 10.2.1 20210110
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

the problem is gcc may ignore -lpthread when build protoc

How to repeat:
as I mentioned above

Suggested fix:
add STRING_APPEND(CMAKE_CXX_FLAGS " -Wl,--no-as-needed -lpthread") in extra/protobuf/CMakeLists.txt when compiled with lto
[16 Jun 2023 12:41] MySQL Verification Team
Hello Xlong Li,

Thank you for the report and feedback.
Reported issue is not observed but seen different errors in 8.0.33 source build with above cmake options.

regards,
Umesh