<div dir="ltr">Hi Mark,<div><br></div><div>If we have to do this, or LLD doesn't work on OpenBSD, I think we need to do this. But can I ask one question? I wonder why OpenBSD systems don't have symbolic links unlike the other Unix-like systems in the first place.</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Dec 19, 2016 at 2:27 PM, Mark Kettenis via llvm-dev <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On OpenBSD we still use the "classic" SunOS 4 shared library<br>
versioning scheme where the major and minor number are part of the<br>
library name (and recorded in DT_NEEDED entries). For example the<br>
shared libc on the OpenBSD-current is named libc.so.89.2. With this<br>
scheme, linker has to pick the pick the library with the highest major<br>
and minor (within the highest major version); the symbolic links<br>
present on most other ELF-based systems don't exist on OpenBSD. The<br>
diff below implements this search algorithm. It follows the same<br>
approach of iterating over files in a directory as the implementation<br>
in the native (ld.bfd derived) toolchain.<br>
<br>
This is an RFC as I'm not sure the diff is the best way to implement<br>
this. For one thing, iterating over files is probably undesirable on<br>
non-OpenBSD systems. And the searching code should probably be moved<br>
to its own function.<br>
<br>
<br>
Index: ELF/DriverUtils.cpp<br>
==============================<wbr>==============================<wbr>=======<br>
--- ELF/DriverUtils.cpp (revision 290066)<br>
+++ ELF/DriverUtils.cpp (working copy)<br>
@@ -153,9 +153,34 @@<br>
return findFromSearchPaths(Name.<wbr>substr(1));<br>
<br>
for (StringRef Dir : Config->SearchPaths) {<br>
- if (!Config->Static)<br>
+ if (!Config->Static) {<br>
if (Optional<std::string> S = findFile(Dir, "lib" + Name + ".so"))<br>
return S;<br>
+<br>
+ const StringRef LibName = (Twine("lib") + Name + ".so.").str();<br>
+ int MaxMaj = -1, MaxMin = -1;<br>
+ std::error_code EC;<br>
+ for (fs::directory_iterator LI(Dir, EC), LE;<br>
+ !EC && LI != LE; LI = LI.increment(EC)) {<br>
+ StringRef FilePath = LI->path();<br>
+ StringRef FileName = path::filename(FilePath);<br>
+ if (!(FileName.startswith(<wbr>LibName)))<br>
+ continue;<br>
+ std::pair<StringRef, StringRef> MajMin =<br>
+ FileName.substr(LibName.size()<wbr>).split('.');<br>
+ int Maj, Min;<br>
+ if (MajMin.first.getAsInteger(10, Maj) || Maj < 0)<br>
+ continue;<br>
+ if (MajMin.second.getAsInteger(<wbr>10, Min) || Min < 0)<br>
+ continue;<br>
+ if (Maj > MaxMaj)<br>
+ MaxMaj = Maj, MaxMin = Min;<br>
+ if (MaxMaj == Maj && Min > MaxMin)<br>
+ MaxMin = Min;<br>
+ }<br>
+ if (MaxMaj >= 0)<br>
+ return findFile(Dir, LibName + Twine(MaxMaj) + "." + Twine(MaxMin));<br>
+ }<br>
if (Optional<std::string> S = findFile(Dir, "lib" + Name + ".a"))<br>
return S;<br>
}<br>
<br>
______________________________<wbr>_________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-dev</a><br>
</blockquote></div><br></div>