This is an archive of the discontinued LLVM Phabricator instance.

[LLD] [MinGW] Implement the --no-seh flag
ClosedPublic

Authored by mstorsjo on Jul 27 2020, 1:52 PM.

Details

Summary

Previously this flag was just ignored. If set, set the IMAGE_DLL_CHARACTERISTICS_NO_SEH bit, regardless of the normal safeSEH machinery.

In mingw configurations, the safeSEH bit might not be set in e.g. object files built from handwritten assembly, making it impossible to use the normal safeseh flag. As mingw setups don't generally use SEH on 32 bit x86 at all, it should be fine to set that flag bit though - hook up the existing GNU ld flag for controlling that.

@hans - This isn't a regression fix, but a fairly safe new option, that might be important for VLC (it might fix https://code.videolan.org/videolan/vlc-winrt/-/issues/303, issues in certifying VLC built with llvm-mingw, due to this flag missing).

Diff Detail

Event Timeline

mstorsjo created this revision.Jul 27 2020, 1:52 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 27 2020, 1:52 PM
Herald added a subscriber: dang. · View Herald Transcript

Actually, this does fix a regression in one sense. Prior to LLD 9, the IMAGE_DLL_CHARACTERISTICS_NO_SEH flag did end up set even in mingw configurations, so ignoring the --no-seh option was just fine. But for LLD 9, the safeSEH mechanism implementation was improved, and this flag no longer was set in mingw configurations.

mstorsjo updated this revision to Diff 281051.Jul 27 2020, 2:09 PM

Updated the patch; the previous one was made on top of another local patch.

This is probably fine, be I have an inline comment with some questions.

lld/COFF/Writer.cpp
1396

Should setNoSEHCharacteristic and config->noSEH always agree? What happens when they don't?

setNoSEHCharacteristic is set in Writer::createSEHTable when there are no SEH handlers. Should this logical-OR happen there?

What happens if the user chooses --noSEH but there are SEH handlers?

mstorsjo added inline comments.Jul 27 2020, 10:29 PM
lld/COFF/Writer.cpp
1396

Should setNoSEHCharacteristic and config->noSEH always agree? What happens when they don't?

setNoSEHCharacteristic is set in Writer::createSEHTable when there are no SEH handlers. Should this logical-OR happen there?

We generally don't want to call createSEHTable in mingw mode. That function errors out on any input object file without the @feat marker indicating support for safe SEH (which happens for e.g. most handwritten mingw asm sources).

In practice, that doesn't happen as the safeseh option defaults to false in mingw mode, and the lld-link level /safeseh option isn't set by any mingw driver option (unless it's given -Xlink=/safeseh to manually set lld-link level options from the mingw driver).

What happens if the user chooses --noSEH but there are SEH handlers?

In that case, the image could end up lying about this aspect.

Mingw mode compilers don't use SEH at all in i386 mode at the moment though, so the mingw driver level --no-seh flag should be pretty safe for users. And it matches what GNU ld does in this case; if the option is set, the capability flag is set, without verification.

For msvc mode users, the lld-link level /noseh option that is added here is undocumented and private, and thus not meant to be used by users directly - only by the mingw driver.

hans added a comment.Jul 28 2020, 1:48 AM

Actually, this does fix a regression in one sense. Prior to LLD 9, the IMAGE_DLL_CHARACTERISTICS_NO_SEH flag did end up set even in mingw configurations, so ignoring the --no-seh option was just fine. But for LLD 9, the safeSEH mechanism implementation was improved, and this flag no longer was set in mingw configurations.

Thanks, will merge once it lands.

amccarth accepted this revision.Jul 28 2020, 8:22 AM

LGTM!

This revision is now accepted and ready to land.Jul 28 2020, 8:22 AM
This revision was automatically updated to reflect the committed changes.
hans added a comment.Jul 29 2020, 7:59 AM

Actually, this does fix a regression in one sense. Prior to LLD 9, the IMAGE_DLL_CHARACTERISTICS_NO_SEH flag did end up set even in mingw configurations, so ignoring the --no-seh option was just fine. But for LLD 9, the safeSEH mechanism implementation was improved, and this flag no longer was set in mingw configurations.

Thanks, will merge once it lands.

70b2872f4810569173c7042c51333d83deb16d88