This is an archive of the discontinued LLVM Phabricator instance.

[WebAssembly] Initial support for LTO
ClosedPublic

Authored by sbc100 on May 21 2018, 2:12 PM.

Event Timeline

sbc100 created this revision.May 21 2018, 2:12 PM
sbc100 updated this revision to Diff 147871.May 21 2018, 2:17 PM
  • cleanup
sbc100 edited reviewers, added: ruiu; removed: espindola.May 21 2018, 2:18 PM
ruiu added inline comments.May 21 2018, 2:30 PM
wasm/Driver.cpp
306

ELF lld supports --thinlto-jobs=, --lto-partitions=, etc as well as --plugin-opt=jobs=, --plugin-opt=partitions=, etc for compatibility with the LTO plugin for GNU gold. Since you are creating a new linker from scratch now, I don't think that makes sense to keep --plugin-opt options. I'd use only non-"--plugin-opt=" options.

wasm/InputFiles.cpp
378

No else after return

wasm/InputFiles.h
73

nit: add a blank line before a comment.

sbc100 updated this revision to Diff 147894.May 21 2018, 3:44 PM
  • feedback
ruiu added inline comments.May 21 2018, 4:48 PM
wasm/InputFiles.cpp
374

What does Ref means? I'd name this just Name.

392

fatal is to report corrupted files. Since this case is to report a miseuse of the command, you should use error.

wasm/LTO.cpp
45

Move this to Common/Strings.cpp.

53

I'd think you should move this function to Common/ErrorHandler.cpp.

58

Move this to Common/ErrorHandler.cpp.

pcc added a subscriber: pcc.May 21 2018, 5:08 PM
pcc added inline comments.
wasm/Driver.cpp
280

Should we implement -u in the same way as in the ELF linker? With this implementation it doesn't look like it will work correctly for undefined data and globals.

wasm/InputFiles.cpp
383

I think you also want to copy the symbol's binding here and below.

wasm/SymbolTable.cpp
200

This function seems to be unused.

sbc100 updated this revision to Diff 147917.May 21 2018, 5:13 PM
sbc100 marked 4 inline comments as done.
  • feedback
sbc100 added inline comments.May 21 2018, 5:14 PM
wasm/InputFiles.cpp
374

Looks like I cargo-culted that from ELF/InputFiles.cpp. Fixed there too.

wasm/LTO.cpp
58

Is it OK for ErrorHandler.h to include llvm/IR/DiagnosticInfo.h ? I was thinking of doing some followup changes to factor out some of the common LTO code.

ruiu added inline comments.May 21 2018, 5:16 PM
wasm/LTO.cpp
58

Can't you just declare the class without including that header?

sbc100 updated this revision to Diff 147919.May 21 2018, 5:28 PM
  • feedback
ruiu added inline comments.May 22 2018, 9:14 AM
wasm/Driver.cpp
279

It feels like handle prefix implies that it's a side-effect-only function, though this function returns a new object. Perhaps addUndefined is a better name.

291

We do this not in Driver::main() but in elf::link() in the ELF linker.

wasm/InputFiles.cpp
392

Please fix.

wasm/LTO.h
52

Buff -> Buf for consistency with ELF.

wasm/SymbolTable.cpp
201

Why is this function empty?

sbc100 updated this revision to Diff 148036.May 22 2018, 10:00 AM
sbc100 marked an inline comment as done.
  • feedback and rebase onto separate change
wasm/InputFiles.cpp
392

Both COFF and ELF use fatal() when when passed bitcode of the wrong arch, but I guess that just means that they need fixing.

sbc100 edited the summary of this revision. (Show Details)May 22 2018, 10:00 AM
sbc100 updated this revision to Diff 148037.May 22 2018, 10:03 AM
sbc100 edited the summary of this revision. (Show Details)
  • revert
sbc100 updated this revision to Diff 148039.May 22 2018, 10:06 AM
  • revert ProgName
sbc100 updated this revision to Diff 148040.May 22 2018, 10:06 AM
  • addUndefined
pcc added inline comments.May 22 2018, 10:36 AM
test/wasm/lto/lto-start.ll
3

More tests please. I would expect to see a ThinLTO test as well as tests for the new flags.

wasm/Config.h
32–50

Out of these new options it looks like you are only initializing --lto-partitions and --save-temps during option parsing. You probably want to either initialize the remaining ones or remove them.

wasm/Driver.cpp
280

Please address.

wasm/InputFiles.cpp
383

Please address.

sbc100 updated this revision to Diff 148086.May 22 2018, 1:22 PM
  • handle bitcode symbol flags
sbc100 updated this revision to Diff 148087.May 22 2018, 1:22 PM
  • use flags
sbc100 marked 2 inline comments as done.May 22 2018, 1:23 PM
sbc100 added inline comments.
test/wasm/lto/lto-start.ll
3

I agree. I was thinking of landing this initial version and iterating (see the change description), but perhaps its best not to land in a half baked state. I'm happy to add more tests and make this more complete.

wasm/Driver.cpp
280

You are correct. Right now with wasm-ld -u flag only works for function symbols. This is a current limitation of the wasm linker, not something that this change introduces. I agree we should address that, but that would be a separate change I think.

pcc added inline comments.May 22 2018, 1:27 PM
wasm/Driver.cpp
280

Yes it should be a separate change, just something I noticed while reviewing this code.

sbc100 updated this revision to Diff 148981.May 29 2018, 2:37 PM
  • remove unused options
  • add more tests
sbc100 updated this revision to Diff 148982.May 29 2018, 2:39 PM
  • remove debugging
sbc100 edited the summary of this revision. (Show Details)May 29 2018, 2:40 PM
sbc100 removed a reviewer: espindola.
sbc100 edited reviewers, added: pcc; removed: espindola.May 29 2018, 2:41 PM
ruiu added a comment.May 29 2018, 3:57 PM

Generally looking good, but I'd like to wait for pcc as he knows more than me about LTO.

wasm/InputFiles.cpp
406

I think you can use toString(this) instead of toString(MB...).

wasm/LTO.h
52

nit: Buff -> Buf for consistency.

pcc added a comment.May 29 2018, 4:52 PM

I think this needs a couple more tests:

  • Test that the binding is copied correctly to the LLD symbol. You can probably do this with a test that shows that strong/weak resolution produces the correct symbol.
  • Test that VisibleToRegularObj is set correctly when building an executable. See test/ELF/lto/internalize-basic.ll for an example.
ELF/Options.td
200 ↗(On Diff #148982)

You probably want to undo this part or do it separately.

test/wasm/lto/thinlto.ll
18 ↗(On Diff #148982)

You should be able to do the same test here as in the other cases. I've updated this test in the ELF linker to do the same in r333480.

sbc100 updated this revision to Diff 149160.May 30 2018, 10:40 AM
sbc100 marked 2 inline comments as done.
  • feedback
  • more tests
sbc100 updated this revision to Diff 149161.May 30 2018, 10:48 AM
  • fix failing test
pcc accepted this revision.May 30 2018, 10:57 AM

LGTM

This revision is now accepted and ready to land.May 30 2018, 10:57 AM
This revision was automatically updated to reflect the committed changes.