This is an archive of the discontinued LLVM Phabricator instance.

[LLD] [COFF] Add options for disabling auto import and runtime pseudo relocs
ClosedPublic

Authored by mstorsjo on Apr 27 2020, 6:08 AM.

Details

Summary

Allow disabling either the full auto import feature, or just forbidding the cases that require runtime fixups.

As long as all auto imported variables are referenced from separate .refptr$<name> sections, we can alias them on top of the IAT entries and don't actually need any runtime fixups via pseudo relocations. LLVM generates references to variables in .refptr stubs, if it isn't known that the variable for sure is defined in the same object module. Runtime pseudo relocs are needed if the addresses of auto imported variables are used in constant initializers though.

Fixing up runtime pseudo relocations requires the use of VirtualProtect (which is disallowed in WinStore/UWP apps) or VirtualProtectFromApp. To allow any risk of ambiguity, allow rejecting cases that would require this at the linker stage.

This adds support for the --disable-runtime-pseudo-reloc and --disable-auto-import options in the MinGW driver (matching GNU ld.bfd) with corresponding lld private options in the COFF driver.

Diff Detail

Event Timeline

mstorsjo created this revision.Apr 27 2020, 6:08 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 27 2020, 6:08 AM
mstorsjo marked an inline comment as done.Apr 27 2020, 6:15 AM
mstorsjo added inline comments.
lld/COFF/Options.td
187

It would be nice to be able to omit the HelpText for the two options here (to hide the option from the help listing), when using B<> style options for private options, but the current form of multiclass B<... doesn't allow omitting those strings and unconditionally adds HelpText, which includes it in the listing. I'm not nearly familiar enough with tablegen to know what's possible to do, though.

rnk accepted this revision.May 5 2020, 5:20 PM

lgtm

lld/COFF/Options.td
187

I suppose the best option I can think of is two def Flag variants.

This revision is now accepted and ready to land.May 5 2020, 5:20 PM
mstorsjo marked an inline comment as done.May 6 2020, 1:39 PM
In D78923#2021685, @rnk wrote:

lgtm

Thanks for the review - but I realized I'll want to revise this a bit before landing - ld.bfd actually has two different sets of options, --disable-auto-import and --disable-runtime-pseudo-relocs - and it might be good to keep the distinction. I.e. --disable-auto-import opts out of the whole process, requiring strict use of dllimports, while --disable-runtime-pseudo-relocs just makes it error out if pseudo relocs really are needed. Because thanks to .refptr$<sym> stubs, we actually don't need to create any pseudo relocs at all in most cases, as we alias the refptr stub on the IAT entry in those cases.

Also, did you specifically look at the part of the patch about allowing this lld private option in .drectve sections? I'm not entirely convinced about whether that's a good thing to do and would appreciate your opinion.

lld/COFF/Options.td
187

I realized the best might be to just make another multiclass, B_priv or something like that, without the help texts.

mstorsjo updated this revision to Diff 262591.May 7 2020, 3:48 AM
mstorsjo retitled this revision from [LLD] [COFF] Add an option for disabling runtime pseudo relocs to [LLD] [COFF] Add options for disabling auto import and runtime pseudo relocs.
mstorsjo edited the summary of this revision. (Show Details)

Split out the support for these options in .drectve to a later patch, to get that discussed separately/explicitly.

Added two separate options, one for auto import in general, and one for pseudo relocations (which auto imports may or may not require).

mstorsjo requested review of this revision.May 9 2020, 9:23 AM

@rnk - can you have another look? I changed it a bit more than just touch-ups since the first review.

Ping @rnk, can you have another look?

rnk accepted this revision.May 13 2020, 2:42 PM

Looks good.

Split out the support for these options in .drectve to a later patch, to get that discussed separately/explicitly.

Got it, I'll go look at that there. That could be interesting.

lld/COFF/Options.td
21

👍

This revision is now accepted and ready to land.May 13 2020, 2:42 PM
ruiu accepted this revision.May 13 2020, 8:31 PM

LGTM

This revision was automatically updated to reflect the committed changes.
thakis added a subscriber: thakis.May 14 2020, 3:32 AM

Looks like you need to allow a backslash too: http://45.33.8.238/win/15234/step_10.txt