[llvm-commits] CVS: llvm/tools/gccld/gccld.cpp

Chris Lattner lattner at cs.uiuc.edu
Tue May 13 17:15:01 PDT 2003


Changes in directory llvm/tools/gccld:

gccld.cpp updated: 1.29 -> 1.30

---
Log message:

Search LLVM_LIB_SEARCH_PATH for objects to allow it to find crtend.o
Implement minor library linking optimization.


---
Diffs of the changes:

Index: llvm/tools/gccld/gccld.cpp
diff -u llvm/tools/gccld/gccld.cpp:1.29 llvm/tools/gccld/gccld.cpp:1.30
--- llvm/tools/gccld/gccld.cpp:1.29	Thu Apr 24 14:13:02 2003
+++ llvm/tools/gccld/gccld.cpp	Tue May 13 17:14:13 2003
@@ -79,12 +79,20 @@
 
 // LoadObject - Read the specified "object file", which should not search the
 // library path to find it.
-static inline std::auto_ptr<Module> LoadObject(const std::string &FN,
+static inline std::auto_ptr<Module> LoadObject(std::string FN,
                                                std::string &OutErrorMessage) {
   if (Verbose) std::cerr << "Loading '" << FN << "'\n";
   if (!FileExists(FN)) {
-    OutErrorMessage = "could not find input file '" + FN + "'!";
-    return std::auto_ptr<Module>();
+    // Attempt to load from the LLVM_LIB_SEARCH_PATH directory... if we would
+    // otherwise fail.  This is used to locate objects like crtend.o.
+    //
+    char *SearchPath = getenv("LLVM_LIB_SEARCH_PATH");
+    if (SearchPath && FileExists(std::string(SearchPath)+"/"+FN))
+      FN = std::string(SearchPath)+"/"+FN;
+    else {
+      OutErrorMessage = "could not find input file '" + FN + "'!";
+      return std::auto_ptr<Module>();
+    }
   }
 
   std::string ErrorMessage;
@@ -224,6 +232,13 @@
 
 static bool LinkLibrary(Module *M, const std::string &LibName,
                         std::string &ErrorMessage) {
+  std::set<std::string> UndefinedSymbols;
+  GetAllUndefinedSymbols(M, UndefinedSymbols);
+  if (UndefinedSymbols.empty()) {
+    if (Verbose) std::cerr << "  No symbols undefined, don't link library!\n";
+    return false;  // No need to link anything in!
+  }
+
   std::vector<Module*> Objects;
   bool isArchive;
   if (LoadLibrary(LibName, Objects, isArchive, ErrorMessage)) return true;
@@ -233,9 +248,6 @@
   DefinedSymbols.resize(Objects.size());
   for (unsigned i = 0; i != Objects.size(); ++i)
     GetAllDefinedSymbols(Objects[i], DefinedSymbols[i]);
-
-  std::set<std::string> UndefinedSymbols;
-  GetAllUndefinedSymbols(M, UndefinedSymbols);
 
   bool Linked = true;
   while (Linked) {     // While we are linking in object files, loop.





More information about the llvm-commits mailing list