<div dir="ltr">
<span style="color:rgb(34,34,34);font-family:sans-serif;font-size:13px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">If you move the buffer to the class definition of SharedFile, you can </span>remove the last call of Saver.save() as well.<br></div><br><div class="gmail_quote"><div dir="ltr">On Fri, Apr 6, 2018 at 1:56 PM Rafael Espindola via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: rafael<br>
Date: Fri Apr 6 13:53:06 2018<br>
New Revision: 329453<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=329453&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=329453&view=rev</a><br>
Log:<br>
Avoid some temporary allocations.<br>
<br>
Some system libraries have a lot of versioned symbols. When linking<br>
scylla this brings the number of malloc calls from 49154 to 37944.<br>
<br>
Modified:<br>
lld/trunk/ELF/InputFiles.cpp<br>
<br>
Modified: lld/trunk/ELF/InputFiles.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.cpp?rev=329453&r1=329452&r2=329453&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.cpp?rev=329453&r1=329452&r2=329453&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/ELF/InputFiles.cpp (original)<br>
+++ lld/trunk/ELF/InputFiles.cpp Fri Apr 6 13:53:06 2018<br>
@@ -906,6 +906,11 @@ template <class ELFT> void SharedFile<EL<br>
std::vector<uint32_t> Versyms = parseVersyms(); // parse .gnu.version<br>
ArrayRef<Elf_Shdr> Sections = CHECK(this->getObj().sections(), this);<br>
<br>
+ // System libraries can have a lot of symbols with versions. Using a<br>
+ // fixed buffer for computing the versions name (foo@ver) can save a<br>
+ // lot of allocations.<br>
+ SmallString<0> VersionedNameBuffer;<br>
+<br>
// Add symbols to the symbol table.<br>
ArrayRef<Elf_Sym> Syms = this->getGlobalELFSyms();<br>
for (size_t I = 0; I < Syms.size(); ++I) {<br>
@@ -956,8 +961,9 @@ template <class ELFT> void SharedFile<EL<br>
<br>
StringRef VerName =<br>
this->StringTable.data() + Verdefs[Idx]->getAux()->vda_name;<br>
- Name = Saver.save(Name + "@" + VerName);<br>
- Symtab->addShared(Name, *this, Sym, Alignment, Idx);<br>
+ VersionedNameBuffer.clear();<br>
+ Name = (Name + "@" + VerName).toStringRef(VersionedNameBuffer);<br>
+ Symtab->addShared(Saver.save(Name), *this, Sym, Alignment, Idx);<br>
}<br>
}<br>
<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
</blockquote></div>