[clang] [HIP] search fatbin symbols for libs passed by -l (PR #104638)

Yaxun Liu via cfe-commits cfe-commits at lists.llvm.org
Sun Aug 18 06:35:49 PDT 2024


================
@@ -76,8 +79,75 @@ class HIPUndefinedFatBinSymbols {
     return GPUBinHandleSymbols;
   }
 
+  // Collect symbols from static libraries specified by -l options.
+  void processStaticLibraries() {
+    llvm::SmallVector<llvm::StringRef, 16> LibNames;
+    llvm::SmallVector<llvm::StringRef, 16> LibPaths;
+    llvm::SmallVector<llvm::StringRef, 16> ExactLibNames;
+    llvm::Triple Triple(C.getDriver().getTargetTriple());
+    bool IsMSVC = Triple.isWindowsMSVCEnvironment();
+    llvm::StringRef Ext = IsMSVC ? ".lib" : ".a";
+
+    for (const auto *Arg : Args.filtered(options::OPT_l)) {
+      llvm::StringRef Value = Arg->getValue();
+      if (Value.starts_with(":"))
+        ExactLibNames.push_back(Value.drop_front());
+      else
+        LibNames.push_back(Value);
+    }
+    for (const auto *Arg : Args.filtered(options::OPT_L)) {
+      auto Path = Arg->getValue();
+      LibPaths.push_back(Path);
+      if (Verbose)
+        llvm::errs() << "HIP fatbin symbol search uses library path:  " << Path
+                     << "\n";
+    }
+
+    auto ProcessLib = [&](llvm::StringRef LibName, bool IsExact) {
+      llvm::SmallString<256> FullLibName;
+      if (IsExact)
+        FullLibName = LibName;
+      else {
+        if (IsMSVC)
+          (llvm::Twine(LibName) + Ext).toVector(FullLibName);
+        else
+          (llvm::Twine("lib") + LibName + Ext).toVector(FullLibName);
+      }
----------------
yxsamliu wrote:

will use the first suggestion. with minor change Twine("lib") for it to work

https://github.com/llvm/llvm-project/pull/104638


More information about the cfe-commits mailing list