[LLVMdev] Enabling the gold linker on freebsd

107 views
Skip to first unread message

Aditya Verma

unread,
Jun 22, 2015, 4:05:48 AM6/22/15
to llv...@cs.uiuc.edu

I have been trying to enable the gold linker on FreeBSD to use the link time optimizations. I made gold from the binutils under /usr/ports. After building binutils using make -k install clean i got ld under /usr/bin and in the directory /usr/local/bin i got ld, ld.gold and ld.bfd.

Now while trying to use link time optimization for the simple example programs herehttp://llvm.org/docs/GoldPlugin.html (a.c and b.c under the heading 'Examples of Link Time Optimization') i entered the four commands as follows:

clang -flto a.c -c -o a.o 
ar q a.a a.o 
clang b.c -c -o b.o 
clang -flto a.a b.o -o main

I got the following error:

usr/bin/ld: unrecogonized option '-plugin'
usr/bin/ld: use the --help option for usage information
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Is there the problem with the linker that ld.gold is not being called. Should I replace the ld with ld.gold? Does the linker looks in the right directiry for the .so plugins?

The LLVMgold.so and libLTO.so shared objects are in the directory /usr/local/llvm-devel/lib/. I cannot find the directory where clang is installed. I am not sure where to make the bfd-plugins directory and add the symlinks to LLVMgold.so and libLTO.so.

I am using freebsd 10.1 release. How to enable the gold linker for link time optimizations? also how can I enable it to be the default linker?

Rafael Espíndola

unread,
Jun 22, 2015, 8:30:26 AM6/22/15
to Aditya Verma, LLVM Developers Mailing List
Two options:

* Try passing -fuse-ld=gold to clang.
* have 'ld' be a symlink to ld.gold.

Cheers,
Rafael
> _______________________________________________
> LLVM Developers mailing list
> LLV...@cs.uiuc.edu http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>
_______________________________________________
LLVM Developers mailing list
LLV...@cs.uiuc.edu http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev

Aditya Verma

unread,
Jun 23, 2015, 2:51:07 AM6/23/15
to Rafael Espíndola, LLVM Developers Mailing List
the symlink ld is already pointing to /usr/bin/ld. Also -fuse-ld=gold does not works on clang in freebsd. I am not sure where is the problem?should I remove /usr/bin/ld and create a new symlink to /usr/local/bin/ld.gold?

Regards
Aditya Verma
Junior Undergraduate
IDD Computer Sc & Engg
IIT(BHU), Varanasi(UP)

David Chisnall

unread,
Jun 23, 2015, 5:16:59 AM6/23/15
to Aditya Verma, LLVM Developers Mailing List
On 23 Jun 2015, at 07:45, Aditya Verma <aditya.ve...@iitbhu.ac.in> wrote:
>
> Also -fuse-ld=gold does not works on clang in freebsd

Are you sure? We were carrying that one as a patch set on the clang that FreeBSD distributes before it was upstreamed.

David

John Criswell

unread,
Jun 23, 2015, 11:48:14 AM6/23/15
to Aditya Verma, Rafael Espíndola, LLVM Developers Mailing List
On 6/23/15 1:45 AM, Aditya Verma wrote:
the symlink ld is already pointing to /usr/bin/ld. Also -fuse-ld=gold does not works on clang in freebsd. I am not sure where is the problem?should I remove /usr/bin/ld and create a new symlink to /usr/local/bin/ld.gold?

Aditya:

I would think that /usr/bin/ld would be BSD ld.  Can you verify whether /usr/bin/ld is ld.bfd or ld.gold?  If it's not ld.gold, it won't use the Gold plugin.

Rafael:

Does -fuse-ld=gold cause Clang to look for ld.gold, or does it just cause Clang to pass the need command-line options to ld to get it to use the gold plugin?  Ideally, I'd like to not have to manually modify things in /usr/bin to get the Gold plugin working on FreeBSD.  I would think that it makes systems upgrades a nightmare.

Regards,

John Criswell
-- 
John Criswell
Assistant Professor
Department of Computer Science, University of Rochester
http://www.cs.rochester.edu/u/criswell

Rafael Espíndola

unread,
Jun 23, 2015, 11:57:43 AM6/23/15
to John Criswell, Aditya Verma, LLVM Developers Mailing List
> Rafael:
>
> Does -fuse-ld=gold cause Clang to look for ld.gold, or does it just cause
> Clang to pass the need command-line options to ld to get it to use the gold
> plugin? Ideally, I'd like to not have to manually modify things in /usr/bin
> to get the Gold plugin working on FreeBSD. I would think that it makes
> systems upgrades a nightmare.

It causes clang to use ld.gold:

$ clang test.o -o test.so -shared -fuse-ld=gold -v
...
"/home/espindola/inst/binutils/bin/ld.gold" ....

Cheers,
Rafael
Reply all
Reply to author
Forward
0 new messages