Skip to content

Commit

Permalink
[driver] Allow ld as a driver alias to lld (llvm#90515)
Browse files Browse the repository at this point in the history
This adds a "hidden" alias kind that allows using LLD when symlinked as
`ld`; however, it does not install `ld` as a symlink. This is to allow
either using a mixed toolchain with both LLD and GNU ld, or a pure LLD
toolchain where LLD has been installed (or symlinked) to `ld` for
compatibility w/ older tools that expect `ld`.
  • Loading branch information
rupprecht authored Apr 29, 2024
1 parent 975eca0 commit 9d955a6
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 1 deletion.
4 changes: 4 additions & 0 deletions lld/tools/lld/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,7 @@ endif()
foreach(link ${LLD_SYMLINKS_TO_CREATE})
add_lld_symlink(${link} lld)
endforeach()

if(LLVM_TOOL_LLVM_DRIVER_BUILD)
set_property(GLOBAL APPEND PROPERTY LLVM_DRIVER_HIDDEN_TOOL_ALIASES_lld ld)
endif()
2 changes: 2 additions & 0 deletions llvm/test/tools/llvm-driver/passthrough-lld.test
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# REQUIRES: llvm-driver, lld

# RUN: %llvm ld.lld --help | FileCheck %s
# RUN: %llvm ld --help | FileCheck %s
# RUN: %llvm lld -flavor ld.lld --help | FileCheck %s
# RUN: %llvm ld -flavor ld.lld --help | FileCheck %s

# CHECK: supported targets: elf
5 changes: 5 additions & 0 deletions llvm/tools/llvm-driver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ foreach(tool ${LLVM_DRIVER_TOOLS})
string(REPLACE "llvm-" "" alias ${alias})
set(def_decl "${def_decl}LLVM_DRIVER_TOOL(\"${alias}\", ${tool_entry})\n")
endforeach()
get_property(hidden_tool_aliases GLOBAL PROPERTY LLVM_DRIVER_HIDDEN_TOOL_ALIASES_${tool})
foreach(alias ${hidden_tool_aliases})
string(REPLACE "llvm-" "" alias ${alias})
set(def_decl "${def_decl}LLVM_DRIVER_TOOL(\"${alias}\", ${tool_entry})\n")
endforeach()
endforeach()

file(WRITE
Expand Down
2 changes: 1 addition & 1 deletion utils/bazel/llvm-project-overlay/llvm/driver.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ _TOOLS = {
# aliases for a given tool.
_EXTRA_ALIASES = {
"clang": ["clang++", "clang-cl", "clang-cpp"],
"lld": ["lld-link", "ld.lld", "ld64.lld", "wasm-ld"],
"lld": ["ld", "lld-link", "ld.lld", "ld64.lld", "wasm-ld"],
"llvm-ar": ["ranlib", "lib", "dlltool"],
"llvm-objcopy": ["bitcode-strip", "install-name-tool", "strip"],
"llvm-objdump": ["otool"],
Expand Down

0 comments on commit 9d955a6

Please sign in to comment.