[cfe-dev] Recommendation on -flto & -use-gold-plugin

Rafael Espíndola rafael.espindola at gmail.com
Sun Apr 15 18:13:03 PDT 2012


On 15 March 2012 18:06, Sylvestre Ledru <sylvestre at debian.org> wrote:
> Hi,
>
> Reported as bug #662742 in the Debian bug tracker [1], the following
> code fails:
>  echo 'int main () { return 0; }' > foo.cc
>  clang++ -c -flto -O2 foo.cc -o foo.o
>  clang++ -flto -use-gold-plugin -O2 foo.o -o foo
> with:
> /usr/bin/ld: error: foo.o:1:3: invalid character
> /usr/bin/ld: error: foo.o:1:3: syntax error, unexpected $end
> /usr/bin/ld: error: foo.o: not an object or archive
> /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crt1.o(.text
> +0x20): error: undefined reference to 'main'
>
> With binutils-gold (contains ld gold), adding "-use-gold-plugin" to the
> last line fixes the issue.
>
> In order to simplify the usage of the -flto to any user of the clang
> Debian packages, I have two questions:
> * does it make sense to force the installation binutils-gold with clang
> or it is too risky ?
> * should I automagically/transparently add -use-gold-plugin when using
> -flto ?

Newer versions of clang do that. If you pass -flto or -O4 they will
pass the plugin to the linker on linux.

> Thanks for the input,
> Sylvestre
>

Cheers,
Rafael




More information about the cfe-dev mailing list