CMake: Gold linker detection

Hi Rafael,

I looked at the code which you pushed a while ago to check for the gold linker.

Code below:

execute_process(

COMMAND ${CMAKE_C_COMPILER} -Wl,–version

OUTPUT_VARIABLE stdout

ERROR_QUIET)

if("${stdout}" MATCHES “GNU gold”)

set(LLVM_LINKER_IS_GOLD ON)

endif()

I was trying to build runtime libraries (compiler-rt) for ARM using “clang” which includes this code.

A while ago, I saw the error message until geek4civic fixed it with “ERROR_QUIET”.

I usually specify my sysroot and tool chain(linker) through CFLAGS.

To fortify the logic, “${CMAKE_C_COMPILER} ${CMAKE_C_FLAGS} -Wl, --version” would be ideal than “${CMAKE_C_COMPILER} -Wl, --version” which works mostly for gnu compilers.

Let me know, I can push a patch

execute_process(

  • COMMAND ${CMAKE_C_COMPILER} -Wl,–version
  • COMMAND “${CMAKE_C_COMPILER} ${CMAKE_C_FLAGS}” -Wl,–version

OUTPUT_VARIABLE stdout

ERROR_QUIET)

if("${stdout}" MATCHES “GNU gold”)

set(LLVM_LINKER_IS_GOLD ON)

endif()

–Sumanth G

While this may be convenient I don't think it's strictly correct.

CFLAGS != LDFLAGS

I think if extra flags are going to be passed it should be LD specific
since that's what this is intended to check.

I reacted as per my case. You need CFLAGS in order to what linker you might be using.

In case of clang, you can use “-fuse-ld” to control the invocation of linker.

In my opinion, it is not necessary to carry forward LDFLAGS unless you want to control specific parts of the linker.

In my case, I have a cross compiler for ARM and I usually compile the code with

Clang –sysroot=<path_to_sysroot> --gcc-toolchain=<path_to_toolchain> -target= file.c

Where I pass “–sysroot=<path_to_sysroot> --gcc-toolchain=<path_to_toolchain> -target=” as CMAKE_C_FLAGS J

With out –gcc-toolchain, clang cannot find the linker and picks the system linker which is usually /usr/bin/ld on a linux system.

–Sumanth G

Unless I'm mistaken typically LDFLAGS are passed like this. (I think you
are mistaken)

${COMPILER} ${LDFLAGS}

ld ${LDFLAGS} # It doesn't mean this isn't also possible

Regardless if you're dealing with a cross compiler or whatever weird CFLAGS
you have to pass. This is a linker issue and LDFLAGS are designed to deal
precisely with that.

My bad. I agree with you.

–Sumanth G