1

I would like to try the LLVM linker (lld) on our project. We use gcc 6, so apparently the -fuse-ld=lld flag is not available yet. I don't control the ld executable used by default, so I can't replace it with a symlink. Are there any other options?

The build system we use is make, and linking is done by the compiler, not a direct call to ld.

Innot Kauker
  • 1,333
  • 1
  • 18
  • 30
  • To be pedantic, linking is never done by the compiler (it has no idea how to do it). The `gcc` executable you are using is called the compiler driver. – Vladislav Ivanishin Apr 11 '19 at 12:40

2 Answers2

2

Given the path to the ld executable you want is /path/to/custom/ld, passing -B/path/to/custom/ to the compiler driver (gcc) should do it. From the GCC manual:

-Bprefix This option specifies where to find the executables, libraries, include files, and data files of the compiler itself. The compiler driver program runs one or more of the subprograms cpp, cc1, as and ld. It tries prefix as a prefix for each program it tries to run, both with and without machine/version/ for the corresponding target machine and compiler version. For each subprogram to be run, the compiler driver first tries the -B prefix, if any.

Vladislav Ivanishin
  • 2,092
  • 16
  • 22
1

One easy workaround is to modify PATH environment variable to point to custom ld executable (see the example here).

yugr
  • 19,769
  • 3
  • 51
  • 96
  • According to collect2 docs (https://gcc.gnu.org/onlinedocs/gccint/Collect2.html), this only works if ld is not hardcoded in gcc during the build, which was the case in my scenario. However, I was able to specify a different compiler and there it worked fine. – Innot Kauker Apr 11 '19 at 10:52