Skip to content

Default `makepkg.conf` LTO flags causes some cargo projects to fail at link time

Description:

I was trying to build cargo-whatfeatures when the compilation failed with a link error.

link-failure.log

Interestingly the error only happens when I use makepkg and not when I use cargo directly, which leads me to figure out that it's caused by flags in makepkg.conf. Doing a basic bisection, I was able to narrow it down to LTOFLAGS="-flto=auto".

After doing some research, I found this issue which gave a solution. I set LTOFLAGS="-flto=auto -ffat-lto-objects" in makepkg.conf.d/rust.conf, and build succeeded.

From reading the description of -ffat-lto-objects in man gcc, (I'm no expert so I may very well be wrong on this) it seems like the reason for this is the linker used by cargo only supports normal linking, which necessitates this flag. Maybe specifying an alternate linker is the more idiomatic way to fix this; I'm not sure. Which is why I'm submitting an issue rather than a MR.

Additional info:

  • package version(s): 6.1.0-3
  • config and/or log files: makepkg.conf and makepkg.conf.d/rust.conf unmodified
  • link to upstream bug report, if any: N/A

This is not an isolated incident; I've also ran into the same issue with other Rust packages. The one I can recall right now is ncspot-git.

Steps to reproduce:

  1. With default makepkg.conf and makepkg.conf.d/rust.conf, build cargo-whatfeatures. Notice the link failure.
  2. Add LTOFLAGS="-flto=auto -ffat-lto-objects to /etc/makepkg.conf.d/rust.conf.
  3. Run makepkg again. It should succeed.
Edited by Sch Foo
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information