This is an archive of the discontinued LLVM Phabricator instance.

[WebAssembly] Add linker options to control feature checking
ClosedPublic

Authored by tlively on Mar 12 2019, 2:45 PM.

Details

Summary

Adds --check-features and --no-check-features. The default for now is
to enable the checking, but this might change in the future.

Also adds --features=foo,bar for precisely controlling the features
used in the output binary.

Depends on D59173.

Event Timeline

tlively created this revision.Mar 12 2019, 2:45 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 12 2019, 2:45 PM
ruiu added a subscriber: ruiu.Mar 12 2019, 3:05 PM
ruiu added inline comments.
lld/wasm/Config.h
58

It seems like you can just use std::vector<std::string> instead of Optional<std::vector<std::string>>. If there's nothing, leave the vector empty.

lld/wasm/Driver.cpp
345–352

This use of using seems unusual in the lld codebase. A more common way of writing it in lld is:

if (auto *Arg = Args.getLastArg(OPT_features))
  for (StringRef S : Args.getLastArg(OPT_features))
    Config->Features.push_back(S);
lld/wasm/Options.td
162

Unless you have a plan to use C multiple times, I wouldn't define C. You can do that when you have more than one occurrence of the same pattern.

lld/wasm/Writer.cpp
873–874

This function sounds like it computes TargetFeatures, but it does more than that -- it tries to find a conflict of feature sets. Is this a good name or a design?

882

We don't use auto unless its type is obvious from the right-hand side (e.g. cast).

883
TargetFeatures = Config->Features;
884–886

Why don't you need to check features?

901

So, if --feature is given, you ignore Used but use Required and Disallowed? It seems a bit inconsistent to me. I'm not sure if it's correct.

tlively updated this revision to Diff 190369.Mar 12 2019, 6:27 PM
tlively marked 8 inline comments as done.
  • Address comments
lld/wasm/Config.h
58

This would not quite work. Currently an empty vector means "the output uses no features", which is different from an empty Optional which means "read the set of used features from the input objects."

lld/wasm/Writer.cpp
873–874

I think this is reasonable as is. Splitting this into separate functions for computing TargetFeatures and for validating the TargetFeatures would require another loop over all the individual objects' target features. I also view the validation as an important part of computing the TargetFeatures set.

882

I switched to using a loop. Hopefully auto is ok in that context?

883

This does not work. TargetFeatures is a set of strings, but Config->Features is a vector of char *.

884–886

If the user chooses to explicitly supply features on the command line (using --features=...) and also elects not to validate the used features (using --no-check-features), then there is no reason to do more work here.

901

Not quite. If --feature is given, we still compute the Used set from the input objects, then we check below that no features are Used that were not supplied on the command line by the user. If that check passes then we go on to validate against the Required and Disallowed sets.

ruiu added a comment.Mar 13 2019, 2:07 PM

Is there a PR or something that explains how these things are supposed to work?

ruiu added inline comments.Mar 13 2019, 2:10 PM
lld/wasm/Options.td
159–160

Add "(default)" to the default choice just like other options.

tlively updated this revision to Diff 190536.Mar 13 2019, 4:20 PM
tlively marked an inline comment as done.
  • Add (default) to --check-features description

Is there a PR or something that explains how these things are supposed to work?

The desired linking behavior when the user does not manually specify features is described in this PR: https://github.com/WebAssembly/tool-conventions/pull/99. Unfortunately that document does not describe the flags implemented here, because the flags are for deviating from the convention.

tlively updated this revision to Diff 190540.Mar 13 2019, 4:34 PM
  • Add more tests for empty feature sets

@sbc100 Any comments or concerns with these flags?

@sbc100 friendly ping! It would be great to start clearing this stack.

sbc100 accepted this revision.Mar 21 2019, 12:24 PM
sbc100 added inline comments.
lld/wasm/Driver.cpp
351

Is this not the default for Optional types? Can you remove this else block?

lld/wasm/Writer.cpp
920

Use single quotes around feature name to avoid escape chars?

This revision is now accepted and ready to land.Mar 21 2019, 12:24 PM
This revision was automatically updated to reflect the committed changes.
tlively marked 2 inline comments as done.