# Rebuilding world + installed packages with LTO



## kpect (Apr 11, 2018)

Hello,
Recently I've tried to build my FreeBSD with LTO enabled by adding `-flto` (and tried `-flto=thin` also) to CFLAGS/COPTFLAGS in /etc/make.conf.
I've made lld my default linker by rebuilding world with 

```
WITH_LLD_IS_LD=YES
WITH_LLD_BOOTSTRAP=YES
```
in /etc/src.conf but when I try to build something with `-flto`, ports or world crash with errors every time.
Can someone help me enable LTO the proper way?
Regards.


----------



## SirDice (Apr 11, 2018)

This might be useful: https://wiki.freebsd.org/LinkTimeOptimisations


----------



## kpect (Apr 11, 2018)

SirDice said:


> This might be useful: https://wiki.freebsd.org/LinkTimeOptimisations


Yep, I saw this link a couple years ago, at that time gold also failed building the world for some reason. Now I'm trying to use lld.


----------

