This is an archive of the discontinued LLVM Phabricator instance.

[lld][WebAssemby] Demote LazySymbols back to undefined symbols if they are not loaded
ClosedPublic

Authored by sbc100 on Jul 28 2022, 5:04 PM.

Details

Summary

A LazySymbol is one that lives in .a archive and gets pulled in by a
strong reference. However, weak references to such symbols do not
result in them be loaded from the archive. In this case we want to
treat such symbols at undefined rather then lazy, once symbols
resolution is complete.

This fixes a crash bug in the linker when weakly referenced symbol that
lives in an archive file is live at the end of the link. In the case of
dynamic linking this is expected to turn into an import with (in the
case of a function symbol) a function index.

Diff Detail

Event Timeline

sbc100 created this revision.Jul 28 2022, 5:04 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 28 2022, 5:04 PM
Herald added subscribers: pmatos, asb, wingo. · View Herald Transcript
sbc100 requested review of this revision.Jul 28 2022, 5:04 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 28 2022, 5:04 PM
dschuff added inline comments.Jul 28 2022, 5:12 PM
lld/wasm/Driver.cpp
577

if (s->signature)
is the way to differentiate function symbols from data symbols?

1048
sbc100 updated this revision to Diff 448481.Jul 28 2022, 5:19 PM
  • feedback
sbc100 added inline comments.Jul 28 2022, 5:21 PM
lld/wasm/Driver.cpp
577

Yes see the comment in LazySymbol:

// Lazy symbols can have a signature because they can replace an               
// UndefinedFunction in which case we need to be able to preserve the          
// signature.                                                                     
// TODO(sbc): This repetition of the signature field is inelegant.  Revisit    
// the use of class hierarchy to represent symbol taxonomy.                    
const WasmSignature *signature = nullptr;
dschuff added inline comments.Jul 29 2022, 11:47 AM
lld/wasm/Symbols.h
652

these 2 places that set referenced are there so that the replaceSymbol you added above works properly?

sbc100 added inline comments.Jul 29 2022, 12:02 PM
lld/wasm/Symbols.h
652

I need to preserve the referenced of the symbol as it gets replaced.. which means I also need to initialize it correctly in insertName since all symbols start in that default state. There is some duplication between the defaults in insertName and the default ins the Symbol constructor.. its not ideal, but its the same logic that exists in the ELF linker.

dschuff accepted this revision.Jul 29 2022, 1:02 PM
This revision is now accepted and ready to land.Jul 29 2022, 1:02 PM
This revision was landed with ongoing or failed builds.Jul 29 2022, 2:05 PM
This revision was automatically updated to reflect the committed changes.