[lld] r367599 - [COFF] Fix wholearchive with thin archives

Hans Wennborg via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 5 00:35:42 PDT 2019


Merged to release_90 in r367806 based on the patch in
https://reviews.llvm.org/D65565#1612908

On Thu, Aug 1, 2019 at 8:46 PM Martin Storsjo via llvm-commits
<llvm-commits at lists.llvm.org> wrote:
>
> Author: mstorsjo
> Date: Thu Aug  1 11:47:27 2019
> New Revision: 367599
>
> URL: http://llvm.org/viewvc/llvm-project?rev=367599&view=rev
> Log:
> [COFF] Fix wholearchive with thin archives
>
> The Archive object created when loading an archive specified with
> wholearchive got cleaned up immediately, when the owning std::unique_ptr
> went out of scope, even if persisted StringRefs pointed to memory that
> belonged to the archive, which no longer was mapped in memory.
>
> This hasn't been an issue with regular (as opposed to thin) archives,
> as references to the member objects has kept the mapping for the whole
> archive file alive - but with thin archives, all such references point
> to other files.
>
> Add the std::unique_ptr to the arena allocator, to retain it as long
> as necessary.
>
> This fixes (the last issue raised in) PR42388.
>
> Differential Revision: https://reviews.llvm.org/D65565
>
> Modified:
>     lld/trunk/COFF/Driver.cpp
>     lld/trunk/test/COFF/thin-archive.s
>
> Modified: lld/trunk/COFF/Driver.cpp
> URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Driver.cpp?rev=367599&r1=367598&r2=367599&view=diff
> ==============================================================================
> --- lld/trunk/COFF/Driver.cpp (original)
> +++ lld/trunk/COFF/Driver.cpp Thu Aug  1 11:47:27 2019
> @@ -184,8 +184,10 @@ void LinkerDriver::addBuffer(std::unique
>      if (wholeArchive) {
>        std::unique_ptr<Archive> file =
>            CHECK(Archive::create(mbref), filename + ": failed to parse archive");
> +      Archive *archive = file.get();
> +      make<std::unique_ptr<Archive>>(std::move(file)); // take ownership
>
> -      for (MemoryBufferRef m : getArchiveMembers(file.get()))
> +      for (MemoryBufferRef m : getArchiveMembers(archive))
>          addArchiveBuffer(m, "<whole-archive>", filename, 0);
>        return;
>      }
>
> Modified: lld/trunk/test/COFF/thin-archive.s
> URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/thin-archive.s?rev=367599&r1=367598&r2=367599&view=diff
> ==============================================================================
> --- lld/trunk/test/COFF/thin-archive.s (original)
> +++ lld/trunk/test/COFF/thin-archive.s Thu Aug  1 11:47:27 2019
> @@ -11,6 +11,8 @@
>  # RUN:     FileCheck --allow-empty %s
>  # RUN: lld-link /entry:main %t.main.obj %t_thin.lib /out:%t.exe 2>&1 | \
>  # RUN:     FileCheck --allow-empty %s
> +# RUN: lld-link /entry:main %t.main.obj /wholearchive:%t_thin.lib /out:%t.exe 2>&1 | \
> +# RUN:     FileCheck --allow-empty %s
>
>  # RUN: rm %t.lib.obj
>  # RUN: lld-link /entry:main %t.main.obj %t.lib /out:%t.exe 2>&1 | \
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits


More information about the llvm-commits mailing list