This is an archive of the discontinued LLVM Phabricator instance.

[LLD] [COFF] Fix wholearchive with thin archives
ClosedPublic

Authored by mstorsjo on Aug 1 2019, 2:27 AM.

Details

Summary

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.

@hans I think this should be a safe backport once it lands.

Diff Detail

Repository
rL LLVM

Event Timeline

mstorsjo created this revision.Aug 1 2019, 2:27 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 1 2019, 2:27 AM
ruiu accepted this revision.Aug 1 2019, 2:29 AM

LGTM

This revision is now accepted and ready to land.Aug 1 2019, 2:29 AM
orgads added a comment.Aug 1 2019, 5:37 AM

Seems to fix the issue. Thanks!

This revision was automatically updated to reflect the committed changes.

Seems to fix the issue. Thanks!

FYI, in case you're considering backporting this to LLD 8.0; I had to tweak the change a little bit to make it not break non-thin archives with wholearchive.

hans added a comment.Aug 2 2019, 6:34 AM

Seems to fix the issue. Thanks!

FYI, in case you're considering backporting this to LLD 8.0; I had to tweak the change a little bit to make it not break non-thin archives with wholearchive.

The commit doesn't merge cleanly to the release_90 branch.

If you think it would be useful to merge this, could you prepare a diff that applies cleanly to the branch? Doing it against the git monorepo might be easiest.

orgads added a comment.Aug 2 2019, 7:01 AM

The commit doesn't merge cleanly to the release_90 branch.

If you think it would be useful to merge this, could you prepare a diff that applies cleanly to the branch? Doing it against the git monorepo might be easiest.

The change in Driver.cpp does apply cleanly. The test file just doesn't exist in 9.0. Do you need the test?

The commit doesn't merge cleanly to the release_90 branch.

If you think it would be useful to merge this, could you prepare a diff that applies cleanly to the branch? Doing it against the git monorepo might be easiest.

The change in Driver.cpp does apply cleanly. The test file just doesn't exist in 9.0. Do you need the test?

A backport to the 9.x branch on the monorepo, including a test, is available at https://martin.st/temp/0001-COFF-Fix-wholearchive-with-thin-archives.patch. I picked the tests from the earlier commit on master, minus the tests for the new stuff in the commit that actually added them, but with the tests for wholearchive+thin instead.

hans added a comment.Aug 5 2019, 12:35 AM

The commit doesn't merge cleanly to the release_90 branch.

If you think it would be useful to merge this, could you prepare a diff that applies cleanly to the branch? Doing it against the git monorepo might be easiest.

The change in Driver.cpp does apply cleanly. The test file just doesn't exist in 9.0. Do you need the test?

A backport to the 9.x branch on the monorepo, including a test, is available at https://martin.st/temp/0001-COFF-Fix-wholearchive-with-thin-archives.patch. I picked the tests from the earlier commit on master, minus the tests for the new stuff in the commit that actually added them, but with the tests for wholearchive+thin instead.

Many thanks! Committed that to the branch in r367806.

thakis added a subscriber: thakis.Nov 20 2020, 6:18 AM

This is fairly different than D18669 which fixed the same thing for the ELF port. Any opinion on which approach is better?