================
@@ -1673,8 +1673,33 @@ void tools::linkSanitizerRuntimeDeps(const ToolChain &TC,
     CmdArgs.push_back("-lresolv");
 }
 
+// Host interceptor library for offload UBSan. Enabled if we are
+// offloading to a target that supports UBSan.
+static bool hostNeedsUbsanOffloadRt(Compilation &C, const ToolChain &HostTC) {
+  if (HostTC.getTriple().isGPU())
+    return false;
+
+  static constexpr Action::OffloadKind Kinds[] = {
+      Action::OFK_Cuda, Action::OFK_OpenMP, Action::OFK_HIP, Action::OFK_SYCL};
+  for (Action::OffloadKind Kind : Kinds) {
+    for (const auto &Entry : llvm::make_range(C.getOffloadToolChains(Kind))) {
+      const ToolChain *DevTC = Entry.second;
+      // FIXME: CUDA/HIPSPV copy the host mask and ignore device sanitizers.
+      if (DevTC->getTriple().isNVPTX() || DevTC->getTriple().isSPIROrSPIRV())
+        continue;
+
+      const ArgList &DevArgs = C.getArgsForToolChain(DevTC, {}, Kind);
+      SanitizerArgs DevSan = DevTC->getSanitizerArgs(DevArgs, {}, Kind);
+      if (DevSan.needsUbsanRt() && !DevSan.requiresMinimalRuntime())
----------------
yxsamliu wrote:

`hostNeedsUbsanDeviceRt()` does not check `DevSan.linkRuntimes()`. With 
device-scoped `-fno-sanitize-link-runtime`, the device runtime is not linked, 
but the host `ubsan_device` library is still added. Should the host library 
respect the same option?

https://github.com/llvm/llvm-project/pull/219973
_______________________________________________
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits

Reply via email to