[LLVMdev] How to change the linker of clang

9,687 views
Skip to first unread message

Eric Lu

unread,
Jun 11, 2015, 9:34:50 PM6/11/15
to cfe-dev Developers, LLVM Developers Mailing List

1) Build clang with GCC-4.9.2, when compling other application s with clang/clang++, the default linker is ld, can I replace it with other linker tool, if we can, how to do it? 

I.E. can we use collect2 instead?

2) how to specify the  path, if we do not use the default vertion GCC?


Best Regards!
Eric Lew

Nathan Wilson

unread,
Jun 11, 2015, 9:58:33 PM6/11/15
to Eric Lu, cfe-dev Developers, LLVM Developers Mailing List
On Thu, Jun 11, 2015 at 8:31 PM, Eric Lu <eirc...@gmail.com> wrote:

1) Build clang with GCC-4.9.2, when compling other application s with clang/clang++, the default linker is ld, can I replace it with other linker tool, if we can, how to do it? 

I.E. can we use collect2 instead?

You could symlink ld to point to collect2.

For example I use gold and point to:
ls -la /usr/local/bin/ld:
/usr/local/bin/ld -> /usr/bin/gold
 

2) how to specify the  path, if we do not use the default vertion GCC?


You can specify which version of GCC when you run cmake by adding the flags:
-DCMAKE_C_COMPILER=<path> -DCMAKE_CXX_COMPILER=<path>



Best Regards!
Eric Lew


_______________________________________________
cfe-dev mailing list
cfe...@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev


Nikola Smiljanic

unread,
Jun 11, 2015, 10:33:59 PM6/11/15
to Nathan Wilson, cfe-dev Developers, LLVM Developers Mailing List
That's what I used to do but each Ubuntu update would revert the symlink. That's when I found about -fuse-ld=gold, I'd expect it to work with other linkers as well.

Sandeep Raju

unread,
Jun 11, 2015, 10:41:08 PM6/11/15
to Eric Lu, LLVM Developers Mailing List, cfe-dev Developers
The -B option tells clang where to look for the linker. So you could try:

clang -B /path/to/other/linker/ ...

Sandeep

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

Brian Faull

unread,
Jun 11, 2015, 10:48:27 PM6/11/15
to Nathan Wilson, cfe-dev Developers, LLVM Developers Mailing List
For #1: Consider also the -B option to specify a path prefix to consult for compiler-related sub-programs (e.g., GNU binutils) if the executables / symlinks etc. have similar names. 

Brian

Azat Khuzhin

unread,
Jun 12, 2015, 5:33:37 PM6/12/15
to Nikola Smiljanic, cfe-dev Developers, LLVM Developers Mailing List
On Fri, Jun 12, 2015 at 12:30:54PM +1000, Nikola Smiljanic wrote:
> That's what I used to do but each Ubuntu update would revert the symlink.
> That's when I found about -fuse-ld=gold, I'd expect it to work with other
> linkers as well.

Also maybe clang could support -B option like gcc have [1], that allow
you to change prefix for executables and other compiler stuff.

[1]: https://gcc.gnu.org/onlinedocs/gcc/Directory-Options.html

Joerg Sonnenberger

unread,
Jun 13, 2015, 4:47:00 PM6/13/15
to llv...@cs.uiuc.edu, cfe-dev Developers
On Fri, Jun 12, 2015 at 12:17:04PM +0300, Azat Khuzhin wrote:
> On Fri, Jun 12, 2015 at 12:30:54PM +1000, Nikola Smiljanic wrote:
> > That's what I used to do but each Ubuntu update would revert the symlink.
> > That's when I found about -fuse-ld=gold, I'd expect it to work with other
> > linkers as well.
>
> Also maybe clang could support -B option like gcc have [1], that allow
> you to change prefix for executables and other compiler stuff.

It does.

Joerg

David Chisnall

unread,
Jun 13, 2015, 5:15:39 PM6/13/15
to Nathan Wilson, cfe-dev Developers, LLVM Developers Mailing List
On 11 Jun 2015, at 21:52, Nathan Wilson <nwil...@gmail.com> wrote:
> On Thu, Jun 11, 2015 at 8:31 PM, Eric Lu <eirc...@gmail.com> wrote:
> 1) Build clang with GCC-4.9.2, when compling other application s with clang/clang++, the default linker is ld, can I replace it with other linker tool, if we can, how to do it?
>
> I.E. can we use collect2 instead?
>
> You could symlink ld to point to collect2.
>
> For example I use gold and point to:
> ls -la /usr/local/bin/ld:
> /usr/local/bin/ld -> /usr/bin/gold
>
> 2) how to specify the path, if we do not use the default vertion GCC?
>
>
> You can specify which version of GCC when you run cmake by adding the flags:
> -DCMAKE_C_COMPILER=<path> -DCMAKE_CXX_COMPILER=<path>

Didn’t we upstream the support for -fuse-ld=foo, which would use ld.foo in your default linker search path, so if you install gold as /usr/bin/ld.gold (as, I believe, is the default), it will work with -fuse-ld=gold?

David

Kim Gräsman

unread,
Jun 14, 2015, 12:10:36 PM6/14/15
to David Chisnall, cfe-dev Developers, LLVM Developers Mailing List
Hi David,

On Sat, Jun 13, 2015 at 11:05 PM, David Chisnall
<David.C...@cl.cam.ac.uk> wrote:
>
> Didn’t we upstream the support for -fuse-ld=foo, which would use ld.foo in your default linker search path, so if you install gold as /usr/bin/ld.gold (as, I believe, is the default), it will work with -fuse-ld=gold?

I think it happened relatively recently, so dated versions of Clang
might not have it.

I can't remember the details now, but when I set up my FreeBSD 10.1
box, I don't think the bundled Clang had -fuse-ld yet.

- Kim

Reply all
Reply to author
Forward
0 new messages