Seems lld, the linker that's more or less part of llvm, is getting in
some sort of usable state.  The diff below adds code to handle the
OpenBSD shared library versioning scheme.  I intend to push this
upstream, which is likely to require some further changes.  But having
this diff out there can't hurt.

There is at least one bug in lld that currently prevents me from
successfully running binaries linked with lld.  But I have a
workaround that allows me to successfully run a "Hello, World!"
program.  And I have some ideas on how to fix this properly in the lld
codebase.

Anyway, this mail is mostly for krautcomputing reasons ;)

Cheers,

Mark


Index: tools/lld/ELF/DriverUtils.cpp
===================================================================
--- tools/lld/ELF/DriverUtils.cpp       (revision 290066)
+++ tools/lld/ELF/DriverUtils.cpp       (working copy)
@@ -153,9 +153,34 @@
     return findFromSearchPaths(Name.substr(1));
 
   for (StringRef Dir : Config->SearchPaths) {
-    if (!Config->Static)
+    if (!Config->Static) {
       if (Optional<std::string> S = findFile(Dir, "lib" + Name + ".so"))
         return S;
+
+      const StringRef LibName = (Twine("lib") + Name + ".so.").str();
+      int MaxMaj = -1, MaxMin = -1;
+      std::error_code EC;
+      for (fs::directory_iterator LI(Dir, EC), LE;
+          !EC && LI != LE; LI = LI.increment(EC)) {
+        StringRef FilePath = LI->path();
+       StringRef FileName = path::filename(FilePath);
+       if (!(FileName.startswith(LibName)))
+         continue;
+       std::pair<StringRef, StringRef> MajMin =
+         FileName.substr(LibName.size()).split('.');
+       int Maj, Min;
+       if (MajMin.first.getAsInteger(10, Maj) || Maj < 0)
+         continue;
+       if (MajMin.second.getAsInteger(10, Min) || Min < 0)
+         continue;
+       if (Maj > MaxMaj)
+         MaxMaj = Maj, MaxMin = Min;
+       if (MaxMaj == Maj && Min > MaxMin)
+         MaxMin = Min;
+      }
+      if (MaxMaj >= 0)
+       return findFile(Dir, LibName + Twine(MaxMaj) + "." + Twine(MaxMin));
+    }
     if (Optional<std::string> S = findFile(Dir, "lib" + Name + ".a"))
       return S;
   }

Reply via email to