[PATCH] D15596: Add -L/path/to/cuda/lib if any of our inputs are CUDA files.

Justin Lebar via cfe-commits cfe-commits at lists.llvm.org
Wed Jan 6 14:11:27 PST 2016


jlebar added a comment.

Updated code; please have a look.


================
Comment at: include/clang/Driver/Options.td:1636
@@ -1635,1 +1635,3 @@
+def nocudalib : Flag<["-"], "nocudalib">,
+  HelpText<"Don't include libraries necessary for running CUDA (-L/path/to/cuda/lib{,64} -lcudart_static -lrt -lpthread -ldl)">;
 def nocudalibdevice : Flag<["-"], "nocudalibdevice">,
----------------
tra wrote:
> include -> link with
> 
> Perhaps less implementation details would be more appropriate for a help string.
> "Don't link with default CUDA runtime library"?
> include -> link with

Done.

> Perhaps less implementation details would be more appropriate for a help string.

I'm not sure about that?  Maybe if we were just including -lcudart_static, but given that we're pulling in other libraries and adding a library search path, I feel like we should tell users what we're doing?  I mean, we should document it somewhere, and here's where people are actually going to find it...

================
Comment at: lib/Driver/ToolChains.cpp:4129-4137
@@ +4128,11 @@
+  LDArgs.push_back("-L");
+  LDArgs.push_back(DriverArgs.MakeArgString(CudaInstallation.getLibPath()));
+  auto AddIfNotPresent = [&](const char *Flag) {
+    llvm::StringRef FlagRef(Flag);
+    if (std::find_if(LDArgs.begin(), LDArgs.end(), [FlagRef](const char *A) {
+          return llvm::StringRef(A) == FlagRef;
+        }) == LDArgs.end()) {
+      LDArgs.push_back(DriverArgs.MakeArgString(Flag));
+    }
+  };
+  AddIfNotPresent("-lcudart_static");
----------------
tra wrote:
> Does this kick in before user's arguments have been added or after?
> If user args have not been added yet, then you'll never find them and don't need this check at all.
> 
> Skipping -lFOO will also have problems if any of the libraries are static and one of preceding libraries needs extra symbols that were not linked in by this point yet.
> 
> Link with required libraries unconditionally. Make sure to add these libraries after user arguments have been added.
> 
> Does this kick in before user's arguments have been added or after?

After; I wrote tests.  :)

> Link with required libraries unconditionally.

Done.

================
Comment at: lib/Driver/ToolChains.cpp:4142
@@ +4141,3 @@
+  AddIfNotPresent("-lrt");
+  AddIfNotPresent("-pthread");
+}
----------------
tra wrote:
> -lpthread
Oh, I see, -pthread is a compile-time flag, not a link-time flag.  Thanks.


http://reviews.llvm.org/D15596





More information about the cfe-commits mailing list