Recommendation on -flto & -use-gold-plugin

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 ?

Thanks for the input,
Sylvestre

[1] http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=662742

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