<div dir="ltr">Did you actually confirm it's leaking?<div><br></div><div>A memory buffer of an archive file is co-owned by the archive file object and file objects create out of it using shared_ptr. Look at instantiateMember in lib/ReaderWriter/FileArchive.cpp. If you free all files, the memory buffer should be freed as well.</div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Apr 22, 2015 at 12:06 PM, Rafael Espíndola <span dir="ltr"><<a href="mailto:rafael.espindola@gmail.com" target="_blank">rafael.espindola@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Currently the lower level APIs keep track of the alignment of elf<br>
objects in memory.<br>
<br>
At some point along the layers we switch to just using 2 byte<br>
alignment because of archives.<br>
<br>
One option is to just use 2 everywhere.<br>
<br>
Another is to copy the data to make it aligned. These patches do just that.<br>
<br>
I tested them by linking an X86_64 clang in an ppc64le machine. Having<br>
aligned access seems to help on ppc64le:<br>
<br>
trunk:<br>
<br>
 <a href="tel:2.165775601" value="+12165775601" target="_blank">2.165775601</a> seconds time elapsed<br>
    ( +-  2.67% )<br>
<br>
patch:<br>
<br>
1.979675092 seconds time elapsed<br>
   ( +-  2.96% )<br>
<br>
The main missing issue is the memory leak. The reason we can't have<br>
Archive just own the buffer for the unaligned members is that in lld<br>
we have<br>
<br>
----------------------------------------<br>
FileVector loadFile(LinkingContext &ctx, StringRef path, bool wholeArchive) {<br>
  ErrorOr<std::unique_ptr<MemoryBuffer>> mb<br>
      = MemoryBuffer::getFileOrSTDIN(path);<br>
  if (std::error_code ec = mb.getError())<br>
    return makeErrorFile(path, ec);<br>
  std::vector<std::unique_ptr<File>> files;<br>
  if (std::error_code ec = ctx.registry().loadFile(std::move(mb.get()), files))<br>
    return makeErrorFile(path, ec);<br>
  if (wholeArchive)<br>
    return parseMemberFiles(files);<br>
  return files;<br>
}<br>
--------------------------------------<br>
<br>
So if --whole-archive is used, the Archive itself is freed and we then<br>
try to use the members.<br>
<br>
Should the registry have a place for putting Archives?<br>
<br>
Cheers,<br>
Rafael<br>
</blockquote></div><br></div></div>