What to do about alignment of ELF objects

Rafael EspĂ­ndola rafael.espindola at gmail.com
Thu Apr 23 12:26:13 PDT 2015


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

:-)

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.

Cheers,
Rafael



More information about the llvm-commits mailing list