This is an archive of the discontinued LLVM Phabricator instance.

[LLD][COFF] Reset outputSections for successive runs
ClosedPublic

Authored by baszalmstra on Aug 22 2020, 9:59 AM.

Details

Summary

The global variable outputSections in the COFF writer was not cleared between runs which caused successive calls to lld::coff::link to generate invalid binaries. These binaries when loaded would result in "invalid win32 applications" and/or "bad image" errors.

Diff Detail

Event Timeline

baszalmstra created this revision.Aug 22 2020, 9:59 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 22 2020, 9:59 AM
baszalmstra requested review of this revision.Aug 22 2020, 9:59 AM
mstorsjo accepted this revision.Aug 22 2020, 12:34 PM
mstorsjo added a reviewer: amccarth.
mstorsjo added subscribers: hans, mstorsjo.

LGTM

@hans - I think this definitely should go to the release branch after landing.

@baszalmstra - How do you want the commit credited in the git author line?

This revision is now accepted and ready to land.Aug 22 2020, 12:35 PM

@baszalmstra - How do you want the commit credited in the git author line?

Bas Zalmstra <zalmstra.bas@gmail.com> will do :)

This revision was automatically updated to reflect the committed changes.
hans added a comment.Aug 24 2020, 10:54 AM

Cherry-picked to 11.x as 0c37a9165611880b99b1f9632179864ecb3f2e13.

I'm curious about the background here, though. When would lld::coff::link be called successively? Could we have a test for this?

Cherry-picked to 11.x as 0c37a9165611880b99b1f9632179864ecb3f2e13.

I'm curious about the background here, though. When would lld::coff::link be called successively? Could we have a test for this?

That'd be when you use lld as a library from a host program, instead of using lld as a standalone executable. lld is tricky in that respect, as it fairly heavily uses global data structures (you can't have two lld linking invocations running in separate threads at the same time), and those structures need some care taken to reset them properly between each run.

aganea added a subscriber: aganea.Aug 24 2020, 12:12 PM

Cherry-picked to 11.x as 0c37a9165611880b99b1f9632179864ecb3f2e13.

I'm curious about the background here, though. When would lld::coff::link be called successively? Could we have a test for this?

D70378 covers all this, at least for the COFF driver.

hans added a comment.Aug 25 2020, 5:48 AM

I'm curious about the background here, though. When would lld::coff::link be called successively? Could we have a test for this?

D70378 covers all this, at least for the COFF driver.

Great!