What to do about alignment of ELF objects

Rui Ueyama ruiu at google.com
Thu Apr 23 12:34:04 PDT 2015


On Thu, Apr 23, 2015 at 12:26 PM, Rafael EspĂ­ndola <
rafael.espindola at gmail.com> wrote:

> On 23 April 2015 at 15:17, Rui Ueyama <ruiu at google.com> wrote:
> > Did you actually confirm it's leaking?
> >
> > 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.
>
> My patch makes it leak. Note the
>
> +      Copy.release(); //leak
>
> :-)
>

Ah, I was looking only at the patch for LLD. Sorry. Yeah it leaks memory.


> The idea from the llvm side is simple. Delete that release and have
> AlignedMemberData own the data.
>
> From lld it complicates --whole-archive a bit. Right now what happens is:
>
> * The Archive is created.
> * The members are read (with my patch any unaligned members are copied
> to anonymous memory).
> * The Archive is discarded.
> * Link continues using the members.
>
> One way to handle it would be to change
>
>   if (wholeArchive)
>     return parseMemberFiles(files);
>
> into
>
>   if (wholeArchive) {
>     ctx.registry().saveArchive....
>     return parseMemberFiles(files);
>    }
>
> I will try coding it to see exactly what it looks like.
>

The other idea would be to copy a memory buffer if it's unaligned in LLD,
not in LLVM, and gives the ownership of the new memory buffer to a
newly-created file. But I don't know which is better (at least your idea
looks more generic).

If we go with your idea, we should remove code to make member files
co-owners of the original memory buffer because it's useless.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150423/92668538/attachment.html>


More information about the llvm-commits mailing list