This is an archive of the discontinued LLVM Phabricator instance.

[ELF] Refactor the way we handle -plugin-opt= (GCC collect2 or clang LTO related options)
ClosedPublic

Authored by MaskRay on Apr 14 2020, 2:59 PM.

Details

Summary

GCC collect2 passes several options to the linker even if LTO is not used
(note, lld does not support GCC LTO). The lto-wrapper may be a relative
path (especially during development, when gcc is in a build directory), e.g.

-plugin-opt=relative/path/to/lto-wrapper

We need to ignore such options, which are currently interpreted by
cl::ParseCommandLineOptions() and will fail with error: --plugin-opt: ld.lld: Unknown command line argument 'relative/path/to/lto-wrapper'
because the path is apparently not an option registered by an llvm::cl::opt.

See lto-plugin-ignore.s for how we interpret various -plugin-opt= options now.

Diff Detail

Event Timeline

MaskRay created this revision.Apr 14 2020, 2:59 PM
MaskRay edited the summary of this revision. (Show Details)Apr 14 2020, 3:04 PM
MaskRay updated this revision to Diff 257515.Apr 14 2020, 3:12 PM
MaskRay edited the summary of this revision. (Show Details)

Improve comments.

I'm a little concerned that options will be silently ignored, e.g. if there are any other gold-plugin options that aren't yet supported. Would it be possible to capture these options and issue warnings for all of the ones that get ignored?

MaskRay updated this revision to Diff 257543.Apr 14 2020, 3:54 PM
MaskRay edited the summary of this revision. (Show Details)

Check if '/' is in -plugin-opt=

tejohnson added inline comments.Apr 14 2020, 4:29 PM
lld/ELF/Driver.cpp
1046

This looks better to me. I suppose the ignore checking could be an even tighter, e.g. it contains either liblto_plugin.so or lto-wrapper - does that seem reasonable? Probably don't even need to check for '/' in that case.

MaskRay updated this revision to Diff 257568.Apr 14 2020, 5:22 PM

Just special case lto-wrapper

It seems that this is the only option

MaskRay updated this revision to Diff 257571.Apr 14 2020, 5:30 PM

Forgot to add -plugin path/to/liblto_plugin.so

This revision is now accepted and ready to land.Apr 14 2020, 6:05 PM
grimar accepted this revision.Apr 15 2020, 2:07 AM

LG with 2 minor nits.

lld/ELF/Options.td
573–583

Why uppercase? Seems inconsistent with: "lto_obj_path_eq", "thinlto_index_only_eq" and others.

583

The same.

MaskRay updated this revision to Diff 257717.Apr 15 2020, 7:55 AM
MaskRay marked 4 inline comments as done.

Use lowercase OPT_plugin_opt_eq_minus and OPT_plugin_opt_eq

This revision was automatically updated to reflect the committed changes.