clang++ invoking custom built gold

Dear all,

I'm trying to compile our software (a quite large C++ codebase) using clang.

We usually build it with an own-built version of gcc 4.5.1 + gold since we do not want / cannot use the system compiler. For the record the linux distribution we use is SLC5 (https://www.scientificlinux.org/) which itself is a variant of RHEL5.

To do the port I used the same environment to build the clang suite and then changed g++ to clang++ in our build files.

While we still have some compilation issue to fix, the main problem is that any linking fails because gold, which is invoked via clang++, is not able to get the correct runtime stuff:

  /afs/cern.ch/cms/slc5_amd64_gcc451/external/gcc/4.5.1/bin/ld: error: cannot open crtbeginS.o: No such file or directory
  /afs/cern.ch/cms/slc5_amd64_gcc451/external/gcc/4.5.1/bin/ld: error: cannot open crtendS.o: No such file or directory
  /afs/cern.ch/cms/slc5_amd64_gcc451/external/gcc/4.5.1/bin/ld: error: cannot find -lstdc++
  /afs/cern.ch/cms/slc5_amd64_gcc451/external/gcc/4.5.1/bin/ld: error: cannot find -lgcc_s
  /afs/cern.ch/cms/slc5_amd64_gcc451/external/gcc/4.5.1/bin/ld: error: cannot find -lgcc_s

Googling around I found some hints on how to workaround the problem and actually managed to hammer it to a working state (see attached patch), however this is clearly a kludge and I was wondering if you had any better solution.

Ciao,
Giulio
Index: lib/Driver/Tools.cpp

You have to detect your distro and then pass the correct search path to gold.

Cheers,
Rafael

Ciao,

You have to detect your distro and then pass the correct search path to
gold.

I think I did not express myself well. We do not use the linker / compiler which comes from the distribution, but we have our own which can be even be user installed and which can be installed on a large variety of distributions (albeit we do have a reference one).

Are you saying I should detect the location of the gold binary and work the needed paths from there? Would you accept in upstream a patch which does so?

Ciao,
Giulio

Ciao,

You have to detect your distro and then pass the correct search
path to gold.

I think I did not express myself well. We do not use the linker /
compiler which comes from the distribution, but we have our own which
can be even be user installed and which can be installed on a large
variety of distributions (albeit we do have a reference one).

Are you saying I should detect the location of the gold binary and
work the needed paths from there? Would you accept in upstream a
patch which does so?

Finding gold itself should not be a problem, we search the path (starting with where clang is).

The problem you are having with crtbeginS.o not being found is because the library path being passed to the linker being wrong, not the linker not being found.

Ciao, Giulio

Cheers,
Rafael