CMakeParseImplicitLinkInfo: Do not mistake ld.so for a linker

Our pattern meant to match `/usr/bin/ld`, `ld.exe`, etc., unfortunately also
captures `ld.so`, which happens to be the dynamic linker on x86 GNU/Hurd.
Through `linker_tool_regex`, this:

    elseif("${line}" MATCHES "${linker_tool_regex}")
      set(linker_tool "${CMAKE_MATCH_2}")
    endif()

is then assuming that:

    /.../collect2 [...] -dynamic-linker /lib/ld.so [...]

claims the linker to be `/lib/ld.so`, and stops there, without noticing
further down in the log:

    /usr/bin/ld [...] -dynamic-linker /lib/ld.so [...]

which is what should be claiming `/usr/bin/ld` is the linker.
This commit is contained in:
Samuel Thibault 2024-12-11 20:20:03 +01:00 committed by Brad King
parent a47283801e
commit c4f64cee36

View File

@ -61,7 +61,7 @@ function(cmake_parse_implicit_link_info2 text log_var obj_regex)
endif()
endif()
# Parse implicit linker arguments.
set(linker "ld[0-9]*(\\.[a-z]+)?")
set(linker "ld[0-9]*(|\\.[a-rt-z][a-z]*|\\.s[a-np-z][a-z]*|\\.so[a-z]+)")
if(is_lfortran_less_0_40)
# lfortran < 0.40 has no way to pass -v to clang/gcc driver.
string(APPEND linker "|clang|gcc")