Author: Nick Sarnie
Date: 2026-02-24T15:10:59Z
New Revision: 600919ac3259aeb9d4967c1225f192120411978c

URL: 
https://github.com/llvm/llvm-project/commit/600919ac3259aeb9d4967c1225f192120411978c
DIFF: 
https://github.com/llvm/llvm-project/commit/600919ac3259aeb9d4967c1225f192120411978c.diff

LOG: [Offload][clang-linker-wrapper][SPIRV] Tell spirv-link to not optimize out 
exported symbols (#182930)

`spirv-link` seems to internalize all symbols, which ends up causing the
OpenMP Device Environment global generated by the OMP FE to get
optimized out which causes `liboffload` to run in the wrong
parallelization mode which breaks at least one liboffload lit test.

Pass `--create-library` to tell it not to do that.

```
  --create-library
               Link the binaries into a library, keeping all exported symbols.
```

This fixes the test.

Closes: https://github.com/llvm/llvm-project/issues/182901

Signed-off-by: Nick Sarnie <[email protected]>

Added: 
    

Modified: 
    clang/lib/Driver/ToolChains/Clang.cpp
    clang/test/Driver/spirv-openmp-toolchain.c
    offload/test/offloading/info.c

Removed: 
    


################################################################################
diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 6af05130f6431..79005d97b41ee 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -9336,12 +9336,17 @@ void LinkerWrapper::ConstructJob(Compilation &C, const 
JobAction &JA,
           (TC->getTriple().isAMDGPU() || TC->getTriple().isNVPTX()))
         LinkerArgs.emplace_back("-lompdevice");
 
-      // For SPIR-V some functions will be defined by the runtime so allow
-      // unresolved symbols in `spirv-link`. `spirv-link` isn't called in LTO
-      // mode so restrict this flag to normal compilation.
+      // For SPIR-V, pass some extra flags to `spirv-link`, the out-of-tree
+      // SPIR-V linker. `spirv-link` isn't called in LTO mode so restrict these
+      // flags to normal compilation.
       if (TC->getTriple().isSPIRV() && !C.getDriver().isUsingLTO() &&
-          !C.getDriver().isUsingOffloadLTO())
+          !C.getDriver().isUsingOffloadLTO()) {
+        // For SPIR-V some functions will be defined by the runtime so allow
+        // unresolved symbols in `spirv-link`.
         LinkerArgs.emplace_back("--allow-partial-linkage");
+        // Don't optimize out exported symbols.
+        LinkerArgs.emplace_back("--create-library");
+      }
 
       // Forward all of these to the appropriate toolchain.
       for (StringRef Arg : CompilerArgs)

diff  --git a/clang/test/Driver/spirv-openmp-toolchain.c 
b/clang/test/Driver/spirv-openmp-toolchain.c
index 1a71238313901..a409ec17c0daf 100644
--- a/clang/test/Driver/spirv-openmp-toolchain.c
+++ b/clang/test/Driver/spirv-openmp-toolchain.c
@@ -65,7 +65,8 @@
 // RUN:        -nogpulib %s 2>&1 \
 // RUN: | FileCheck %s --check-prefix=CHECK-LINKER-ARG
 // CHECK-LINKER-ARG: clang-linker-wrapper
-// CHECK-LINKER: --device-linker=spirv64-intel=--allow-partial-linkage"
+// CHECK-LINKER-ARG: --device-linker=spirv64-intel=--allow-partial-linkage"
+// CHECK-LINKER-ARG-SAME: --device-linker=spirv64-intel=--create-library"
 // CHECK-LINKER-ARG-NOT: -mllvm
 // CHECK-LINKER-ARG-NOT: --spirv-ext=+SPV_INTEL_function_pointers
 // CHECK-LINKER-ARG: --linker-path

diff  --git a/offload/test/offloading/info.c b/offload/test/offloading/info.c
index 33aacc728f4ad..d86644b871e25 100644
--- a/offload/test/offloading/info.c
+++ b/offload/test/offloading/info.c
@@ -7,7 +7,6 @@
 
 // FIXME: Fails due to optimized debugging in 'ptxas'.
 // UNSUPPORTED: nvptx64-nvidia-cuda-LTO
-// XFAIL: intelgpu
 
 #include <omp.h>
 #include <stdio.h>


        
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to