Hi,

Apparently if you convert a twine to a string (using str() on the Twine)
and setting that to a StringRef variable creates a broken string.  This
means that the code never runs and thus never finds libc.so.x.y.  It
falls back to picking up the .a files instead.

Apparently you have to provide a scratch variable and use that one to
create a StringRef.  This fixes the issue that the binaries are not
linked to any shared object.

Now my lld-linked lld doesn't segfault directly but throws this.  I do
consider this progress:

# ./ld.lld
ld.lld:/usr/lib/libc++.so.0.0: undefined symbol '_ZTISt9bad_alloc'
ld.lld:/usr/lib/libc++.so.0.0: undefined symbol '_ZNSt9bad_allocD1Ev'
ld.lld:/usr/lib/libc++.so.0.0: undefined symbol '_ZNSt9bad_allocC1Ev'
./ld.lld: error: no input files
./ld.lld: error: target emulation unknown: -m or at least one .o file required

ok?

Patrick

diff --git a/gnu/llvm/tools/lld/ELF/DriverUtils.cpp 
b/gnu/llvm/tools/lld/ELF/DriverUtils.cpp
index 2c0b4405ba2..803b112120d 100644
--- a/gnu/llvm/tools/lld/ELF/DriverUtils.cpp
+++ b/gnu/llvm/tools/lld/ELF/DriverUtils.cpp
@@ -184,7 +184,8 @@ Optional<std::string> elf::searchLibrary(StringRef Name) {
       if (Optional<std::string> S = findFile(Dir, "lib" + Name + ".so"))
         return S;
 
-      const StringRef LibName = (Twine("lib") + Name + ".so.").str();
+      llvm::SmallString<128> Scratch;
+      const StringRef LibName = ("lib" + Name + ".so.").toStringRef(Scratch);
       int MaxMaj = -1, MaxMin = -1;
       std::error_code EC;
       for (fs::directory_iterator LI(Dir, EC), LE;

Reply via email to