Skip to content

[CMake] Detect properly new linker introduced in Xcode 15 #77806

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 19, 2024

Conversation

edymtt
Copy link
Contributor

@edymtt edymtt commented Jan 11, 2024

As explained in 1, this linker is functionally equivalent to the classic one (ld64)
for build system purposes -- in particular to enable the use of order files to link
clang. For this reason, in addition to fixing the detection rename
LLVM_LINKER_IS_LD64 to LLVM_LINKER_IS_APPLE to make the result of
such detection more clear -- this should not cause any issue to downstream
users, from a quick search in SourceGraph 2, only Swift uses the value of
this variable (which I will take care of updating in due time).

rdar://120740222

Copy link

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be
notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write
permissions for the repository. In which case you can instead tag reviewers by
name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review
by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate
is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@llvmbot llvmbot added cmake Build system in general and CMake in particular clang Clang issues not falling into any other category labels Jan 11, 2024
@llvmbot
Copy link
Member

llvmbot commented Jan 11, 2024

@llvm/pr-subscribers-clang

Author: Eric Miotto (edymtt)

Changes

This linker is functionally equivalent to the classic one (ld64) for build system purposes -- in particular to enable the use of order files to link clang.
For this reason, in addition to fixing the detection rename LLVM_LINKER_IS_LD64 to LLVM_LINKER_IS_APPLE to make the result of such detection more clear -- this should not cause any issue to downstream users, from a quick serch in
Sourcegraph only Swift uses the value of this variable (which I will take care of updating in due time).

rdar://120740222


Full diff: https://github.com/llvm/llvm-project/pull/77806.diff

2 Files Affected:

  • (modified) clang/tools/driver/CMakeLists.txt (+2-2)
  • (modified) llvm/cmake/modules/AddLLVM.cmake (+3-3)
diff --git a/clang/tools/driver/CMakeLists.txt b/clang/tools/driver/CMakeLists.txt
index 2182486f93a555..d70b92b0984e52 100644
--- a/clang/tools/driver/CMakeLists.txt
+++ b/clang/tools/driver/CMakeLists.txt
@@ -103,10 +103,10 @@ if (APPLE)
 endif()
 
 if(CLANG_ORDER_FILE AND
-    (LLVM_LINKER_IS_LD64 OR LLVM_LINKER_IS_GOLD OR LLVM_LINKER_IS_LLD))
+    (LLVM_LINKER_IS_APPLE OR LLVM_LINKER_IS_GOLD OR LLVM_LINKER_IS_LLD))
   include(LLVMCheckLinkerFlag)
 
-  if (LLVM_LINKER_IS_LD64 OR (LLVM_LINKER_IS_LLD AND APPLE))
+  if (LLVM_LINKER_IS_APPLE OR (LLVM_LINKER_IS_LLD AND APPLE))
     set(LINKER_ORDER_FILE_OPTION "-Wl,-order_file,${CLANG_ORDER_FILE}")
   elseif (LLVM_LINKER_IS_GOLD)
     set(LINKER_ORDER_FILE_OPTION "-Wl,--section-ordering-file,${CLANG_ORDER_FILE}")
diff --git a/llvm/cmake/modules/AddLLVM.cmake b/llvm/cmake/modules/AddLLVM.cmake
index 14c0837c35964d..5e989618552824 100644
--- a/llvm/cmake/modules/AddLLVM.cmake
+++ b/llvm/cmake/modules/AddLLVM.cmake
@@ -211,10 +211,10 @@ if (NOT DEFINED LLVM_LINKER_DETECTED AND NOT WIN32)
     )
 
   if(APPLE)
-    if("${stderr}" MATCHES "PROJECT:ld64")
+    if("${stderr}" MATCHES "PROGRAM:ld")
       set(LLVM_LINKER_DETECTED YES CACHE INTERNAL "")
-      set(LLVM_LINKER_IS_LD64 YES CACHE INTERNAL "")
-      message(STATUS "Linker detection: ld64")
+      set(LLVM_LINKER_IS_APPLE YES CACHE INTERNAL "")
+      message(STATUS "Linker detection: Apple")
     elseif("${stderr}" MATCHES "^LLD" OR
            "${stdout}" MATCHES "^LLD")
       set(LLVM_LINKER_DETECTED YES CACHE INTERNAL "")

@edymtt edymtt force-pushed the edymtt/detect-linker-xcode-15 branch from 3658468 to 7a7f803 Compare January 11, 2024 17:54
@edymtt edymtt changed the title CMake: Detect properly new linker introduced in Xcode 15 [CMake] Detect properly new linker introduced in Xcode 15 Jan 11, 2024
@edymtt
Copy link
Contributor Author

edymtt commented Jan 11, 2024

macOS testing triggered on swiftlang#7962

@edymtt
Copy link
Contributor Author

edymtt commented Jan 15, 2024

(Rebased on top of recent changes to take format changes in clang/docs/HLSL/FunctionCalls.rst)

@etcwilde etcwilde requested a review from ldionne January 16, 2024 21:24
@edymtt edymtt force-pushed the edymtt/detect-linker-xcode-15 branch from 0a0162a to c97e070 Compare January 17, 2024 20:49
@ldionne
Copy link
Member

ldionne commented Jan 18, 2024

The CI failures seem unrelated. I'll merge when the hidden e-mail address issue has been resolved.

As explained in [1], this linker is functionally equivalent to the
classic one (`ld64`) for build system purposes -- in particular to
enable the use of order files to link `clang`.
For this reason, in addition to fixing the detection rename
`LLVM_LINKER_IS_LD64` to `LLVM_LINKER_IS_APPLE` to make the result of
such detection more clear -- this should not cause any issue to
downstream users, from a quick serch in
Sourcegraph [2], only Swift uses the value of this variable (which I
will take care of updating in due time).

[1]:
https://developer.apple.com/documentation/xcode-release-notes/xcode-15-release-notes#Linking
[2]:
https://sourcegraph.com/search?q=context:global+LLVM_LINKER_IS_LD64+lang:cmake+fork:no+-file:AddLLVM.cmake+-file:clang/tools/driver/CMakeLists.txt&patternType=standard&sm=1&groupBy=repo
rdar://120740222
@edymtt edymtt force-pushed the edymtt/detect-linker-xcode-15 branch from c97e070 to 1530d4c Compare January 18, 2024 23:24
@edymtt
Copy link
Contributor Author

edymtt commented Jan 18, 2024

That issue should now be addressed in 1530d4c (for future reference, this concern is discussed in LLVM Discourse, not in the contribution documentation)

Also matched the commit message to your edits (which I forgot to thank you for, the format changes improve the overall readability)

@ldionne ldionne merged commit 9175dd9 into llvm:main Jan 19, 2024
@edymtt edymtt deleted the edymtt/detect-linker-xcode-15 branch January 30, 2024 18:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang Clang issues not falling into any other category cmake Build system in general and CMake in particular
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants