Skip to content

Conversation

rocm-devops
Copy link
Contributor

Change-Id: If043762b912a0c6a82951aeed620658f016bebb5## Associated JIRA ticket number/Github issue number

SWDEV-491532 - [CLR/PAL] Allow building with clang-cl on Windows
SWDEV-545259 - Missing proper DLL entry points for a few symbols

What type of PR is this? (check all applicable)

  • Refactor
  • Feature
  • Bug Fix
  • Optimization
  • Documentation Update
  • Continuous Integration

What were the changes?

#1 - add CMakeLists.txt support for clang-cl.
#2 - add missing global functions for a few DLL entry points.

Please see the commit logs of the individual commits.

Why are these changes needed?

CMakeLists change need so we can build with clang-cl instead of MSVC.

Entry points needed because dispatch table. clang-cl fails to link unless this is done properly.

Updated CHANGELOG?

  • Yes
  • No, Does not apply to this PR.

I have no idea whether you would want to advertise support for building with clang-cl.

Added/Updated documentation?

  • Yes
  • No, Does not apply to this PR.

Ditto.

Additional Checks

  • I have added tests relevant to the introduced functionality, and the unit tests are passing locally.
  • Any dependent changes have been merged.

This depends on https://github.com/AMD-ROCm-Internal/hip/pull/280 . Without that, clang-cl notices that the declaration of hipDeviceGetTexture1DLinearMaxWidth in include/hip/hip_runtime_api.h in the hip repo does not match the definition in clr.

palves added 2 commits July 19, 2025 11:44
Tweak CMakeLists.txt to handle clang-cl.

Note that CMake does not set CMAKE_CXX_COMPILER_FRONTEND_VARIANT for
MSFT's cl.

Change-Id: If043762b912a0c6a82951aeed620658f016bebb5
When building the hip runtime with clang-cl, I see the following link
error:

 ...
 [3/3] Linking CXX shared library hipamd\src\amdhip64_6.dll
 FAILED: hipamd/src/amdhip64_6.dll hipamd/lib/amdhip64.lib
 cmd.exe /C "cd . && C:\dk\cmake\cmake-3.21.2-win64-x64\bin\cmake.exe -E vs_link_dll --intdir=hipamd\src\CMakeFiles\amdhip64.dir --rc=C:\dk\ms_wdk\e22621\bin\10.0.22621.0\x64\rc.exe --mt=C:\Users\alves\Downloads\clang+llvm-18.1.8-x86_64-pc-windows-msvc\bin\llvm-mt.exe --manifests  -- C:\Users\alves\Downloads\clang+llvm-18.1.8-x86_64-pc-windows-msvc\bin\lld-link.exe  @CMakeFiles\amdhip64.rsp  /out:hipamd\src\amdhip64_6.dll /implib:hipamd\lib\amdhip64.lib /pdb:hipamd\src\amdhip64_6.pdb /dll /version:0.0 /machine:x64 /DEBUG:FULL /debug /INCREMENTAL /DEF:C:\Users\alves\rocm\compute\drivers\drivers\compute\clr\hipamd\src\amdhip.def  /NATVIS:C:/Users/alves/rocm/compute/drivers/drivers/compute/pal/src/util/palUtil.natvis /DEF:C:\Users\alves\rocm\compute\drivers\drivers\compute\clr\hipamd\src\amdhip.def  && cmd.exe /C "cd /D C:\Users\alves\rocm\compute\drivers\drivers\compute\build\native\Debug\x64\hip\hipamd\src && C:\dk\cmake\cmake-3.21.2-win64-x64\bin\cmake.exe -E copy C:/Users/alves/rocm/compute/drivers/drivers/compute/build/native/Debug/x64/hip/hipamd/share/hip/.hipInfo C:/Users/alves/rocm/compute/drivers/drivers/compute/build/native/Debug/x64/hip/hipamd/lib/.hipInfo && cd /D C:\Users\alves\rocm\compute\drivers\drivers\compute\build\native\Debug\x64\hip\hipamd\src && C:\dk\cmake\cmake-3.21.2-win64-x64\bin\cmake.exe -E copy_directory C:/Users/alves/rocm/compute/drivers/drivers/compute/clr/hipamd/include C:/Users/alves/rocm/compute/drivers/drivers/compute/build/native/Debug/x64/hip/hipamd/include && cd /D C:\Users\alves\rocm\compute\drivers\drivers\compute\build\native\Debug\x64\hip\hipamd\src && C:\dk\cmake\cmake-3.21.2-win64-x64\bin\cmake.exe -E copy_directory C:/Users/alves/rocm/compute/drivers/drivers/compute/hip/include C:/Users/alves/rocm/compute/drivers/drivers/compute/build/native/Debug/x64/hip/hipamd/include""
 LINK Pass 1: command "C:\Users\alves\Downloads\clang+llvm-18.1.8-x86_64-pc-windows-msvc\bin\lld-link.exe @CMakeFiles\amdhip64.rsp /out:hipamd\src\amdhip64_6.dll /implib:hipamd\lib\amdhip64.lib /pdb:hipamd\src\amdhip64_6.pdb /dll /version:0.0 /machine:x64 /DEBUG:FULL /debug /INCREMENTAL /DEF:C:\Users\alves\rocm\compute\drivers\drivers\compute\clr\hipamd\src\amdhip.def /NATVIS:C:/Users/alves/rocm/compute/drivers/drivers/compute/pal/src/util/palUtil.natvis /DEF:C:\Users\alves\rocm\compute\drivers\drivers\compute\clr\hipamd\src\amdhip.def /MANIFEST /MANIFESTFILE:hipamd\src\CMakeFiles\amdhip64.dir/intermediate.manifest hipamd\src\CMakeFiles\amdhip64.dir/manifest.res" failed (exit code 1) with the following output:
 lld-link: error: <root>: undefined symbol: hipDeviceGetTexture1DLinearMaxWidth
 lld-link: error: <root>: undefined symbol: hipGraphAddExternalSemaphoresSignalNode
 lld-link: error: <root>: undefined symbol: hipGraphAddExternalSemaphoresWaitNode
 lld-link: error: <root>: undefined symbol: hipGraphExternalSemaphoresSignalNodeSetParams
 lld-link: error: <root>: undefined symbol: hipGraphExternalSemaphoresSignalNodeGetParams
 lld-link: error: <root>: undefined symbol: hipGraphExternalSemaphoresWaitNodeSetParams
 lld-link: error: <root>: undefined symbol: hipGraphExternalSemaphoresWaitNodeGetParams
 lld-link: error: <root>: undefined symbol: hipGraphExecExternalSemaphoresSignalNodeSetParams
 lld-link: error: <root>: undefined symbol: hipGraphExecExternalSemaphoresWaitNodeSetParams
 ninja: build stopped: subcommand failed.

The issue is that those symbols were added to CLR without a
corresponding global function that dispatches through the HIP dispatch
table.  This commit adds the missing functions, fixing the link.

MSVC manages to link the dll without this fix AFAICS because if
there's no function with the exact name as listed in the def file,
then it looks for a function of the same name in all namespaces, and
if it finds one (and only one), then it links against it.  In our
case, it links with the functions with the same name in the "hip"
namespace, directly.  That seems quite a dangerous "feature", as in,
it makes it easy to miss this sort of problem.  In our case, for these
entry points, the result is we are bypassing the dispatch table
mechanism.

Change-Id: I4101862633c728d73e6c191c9d515c59df7632b3
@rocm-devops
Copy link
Contributor Author

!verify

@amd-hsivasun
Copy link

Unable to import to rocm-systems due to merge conflict

@rocm-devops
Copy link
Contributor Author

Error importing due to merge conflicts – please reopen the PR on ROCm/rocm-systems

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants