This is an archive of the discontinued LLVM Phabricator instance.

[lld][WebAssembly] Remove redundant check for undefined global (NFC)
ClosedPublic

Authored by aheejin on Oct 4 2021, 3:57 PM.

Diff Detail

Event Timeline

aheejin created this revision.Oct 4 2021, 3:57 PM
aheejin requested review of this revision.Oct 4 2021, 3:57 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 4 2021, 3:57 PM
sbc100 added inline comments.Oct 4 2021, 4:04 PM
lld/wasm/Relocations.cpp
45

Actually there was a recent refactor that made importName a (optional) member of the Symbol superclass.. so I think this can be written as:

if (sym->importName)
  return true;
if (isa<UndefinedFunction>(sym) && config->importUndefined)
  return true;

But if you would rather land this as is that is fine too.

aheejin added inline comments.Oct 4 2021, 4:39 PM
lld/wasm/Relocations.cpp
45

if (isa<UndefinedFunction>(sym) && config->importUndefined)

Isn't this || in the current code?

Also, if we return true unconditionally when sym->importName is defined, I think we return true for data or tables. Is that what you intended?

sbc100 added a comment.Oct 4 2021, 4:43 PM

we return true uncondition

lld/wasm/Relocations.cpp
45

Yes, any symbol with an explicit importName should always be imported and never have "undefined symbol" reported about it.

aheejin added inline comments.Oct 4 2021, 4:57 PM
lld/wasm/Relocations.cpp
45

Which one is correct?

if (isa<UndefinedFunction>(sym) && config->importUndefined)

vs.

if (isa<UndefinedFunction>(sym) || config->importUndefined)

(The current code is like the latter and you suggested the former)

Also, config->importUndefined doesn't affect UndefinedGlobal, or UndefinedTag I am going to add?

sbc100 added inline comments.Oct 4 2021, 5:37 PM
lld/wasm/Relocations.cpp
45

I think we should leave importUndefined as only effecting functions symbols for now. We could followup by extending it but that would not be NFC.

Thus I think the if (isa<UndefinedFunction>(sym) && config->importUndefined) matches the original semantics and is that we should do here for now.

aheejin added inline comments.Oct 5 2021, 12:04 AM
lld/wasm/Relocations.cpp
45
  1. You suggested to add
if (sym->importName)
  return true;

But doesn't this affect not only functions but all symbols?

I think we should leave importUndefined as only effecting functions symbols for now. We could followup by extending it but that would not be NFC.

The current code already handles globals, even twice, one of which I removed. So if we make this only handle functions that will not be NFC instead.. No?

aheejin added inline comments.Oct 5 2021, 12:07 AM
lld/wasm/Relocations.cpp
45

Ah, sorry, I misread your comment. Nevermind the comment above. I can't believe you can't delete comments from Phabricator...

aheejin updated this revision to Diff 377098.Oct 5 2021, 12:11 AM

Address comments

aheejin added inline comments.Oct 5 2021, 12:12 AM
lld/wasm/Relocations.cpp
34–35

Now that this function does not specifically target globals, is this comment correct? Can data or tables have explicit import names and return true here?

sbc100 added inline comments.Oct 5 2021, 7:32 AM
lld/wasm/Relocations.cpp
34–35

Yes, anything that has an explicit import name should return true here.

I guess we don't do much testing for those cases because the use of tables outsides of the singleton __indirect_function_table is still basically non-existent.

sbc100 added inline comments.Oct 5 2021, 7:33 AM
lld/wasm/Relocations.cpp
34–35

Maybe change the comment too: // Symbols with explicit import names are always allowed to be undefined at link time.

aheejin updated this revision to Diff 377301.Oct 5 2021, 10:59 AM
aheejin marked an inline comment as done.

Comment fix

sbc100 accepted this revision.Oct 5 2021, 11:05 AM
This revision is now accepted and ready to land.Oct 5 2021, 11:05 AM

Please confirm all the tests in lld/test/wasm still pass before landing.

aheejin updated this revision to Diff 377362.Oct 5 2021, 3:07 PM

Oops, || -> &&

This revision was landed with ongoing or failed builds.Oct 5 2021, 3:11 PM
This revision was automatically updated to reflect the committed changes.