Link time optimization(LTO) segmentation fault issue

Jason Yang
Mon Dec 27 15:42:08 GMT 2021

Dear GCC developers:

If this email address is not correct for questions, please help forward 
this email. Sincerely sorry that I just find this email on 
website and hope my question can be answered.

I am currently working on building cpython with gcc. The problem is that 
after turning on lto option, such as the following

|if [[ ${_OPTIMIZED} == yes ]]; then 
_extra_opts+=(--enable-optimizations) _extra_opts+=(--with-lto) 
_MAKE_TARGET=profile-opt # To speed up build times during testing (1): # 
_PROFILE_TASK="./python -m test.regrtest --pgo test_builtin" if [[ ${CC} 
=~ .*gcc.* && ! ${c_compiler} =~ .*toolchain.* ]]; then 
LTO_CFLAGS+=(-fuse-linker-plugin) LTO_CFLAGS+=(-ffat-lto-objects) # 
-flto must come after -flto-partition due to the replacement code 
LTO_CFLAGS+=(-flto-partition=none) LTO_CFLAGS+=(-flto) else # TODO :: 
Check if -flto=thin gives better results. It is about faster # 
compilation rather than faster execution so probably not: # # 
LTO_CFLAGS+=(-flto) fi export CFLAGS="${CFLAGS} ${LTO_CFLAGS[@]}" else 

When I enabled the LTO flags and built cpython with optimization (enable 
–with-lto, -fuse-linker-plugin, -ffat-lto-objets, -flto-partition=none, 
-flto), the built python3 will encounter segmentation fault when I 
trying to run it on another host (not using Docker ,but using some 
LD_PRELOAD hacks created sandbox, which means host libc will be involved 
during the initialization), when I use Docker (isolated namespaces) with 
LTO compiled python3, there is no such segmentation fault issue.

My guess is that LTO has requirements for gcc link/compiler environments?

Though I’ve read this url 

but still could not understand whether the LTO is link/compiler 
specific? and how about its portability(compiled in one environment, and 
can be used in another environment with different link/compiler versions? )

Thanks so much for the help! And looking forward to your responses!

Best regards,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_0xDA13D7409C72F5E1.asc
Type: application/pgp-keys
Size: 3147 bytes
Desc: OpenPGP public key
URL: <>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_signature
Type: application/pgp-signature
Size: 840 bytes
Desc: OpenPGP digital signature
URL: <>

More information about the Gcc-help mailing list