This is an archive of the discontinued LLVM Phabricator instance.

COFF: Symbol resolution for common and comdat symbols defined in bitcode.
ClosedPublic

Authored by pcc on Jun 8 2015, 4:45 PM.

Details

Summary

In the case where either a bitcode file and a regular file or two bitcode
files export a common or comdat symbol with the same name, the linker needs
to pick one of them following COFF semantics. This patch implements a design
for resolving such symbols that pushes most of the work onto either LLD's
regular mechanism for resolving common or comdat symbols or the IR linker's
mechanism for doing the same.

We modify SymbolBody::compare to always prefer non-bitcode symbols, so that
during the initial phase of symbol resolution, the symbol table always contains
a regular symbol in any case where we need to choose between a regular and
a bitcode symbol. In SymbolTable::addCombinedLTOObject, we force export
any bitcode symbols that were initially pre-empted by a regular symbol,
and later use SymbolBody::compare to choose between the regular symbol in
the symbol table and the regular symbol from the combined LTO object file.

This design seems to be sound, so long as the resolution mechanism is defined
to be commutative and associative modulo arbitrary choices between symbols
(which seems to be the case for COFF).

Diff Detail

Repository
rL LLVM

Event Timeline

pcc updated this revision to Diff 27349.Jun 8 2015, 4:45 PM
pcc retitled this revision from to COFF: Symbol resolution for common and comdat symbols defined in bitcode..
pcc updated this object.
pcc edited the test plan for this revision. (Show Details)
pcc added a reviewer: ruiu.
pcc added subscribers: rafael, Unknown Object (MLST).
ruiu accepted this revision.Jun 8 2015, 8:43 PM
ruiu edited edge metadata.

LGTM

COFF/InputFiles.cpp
269 ↗(On Diff #27349)

Add parentheses after =

COFF/SymbolTable.cpp
251 ↗(On Diff #27349)

Nice. Looks like the separation of Symbol and SymbolBody works well here.

COFF/Symbols.cpp
72 ↗(On Diff #27349)
if (auto *R = ...
76 ↗(On Diff #27349)
if (auto *B = ...
82 ↗(On Diff #27349)

Remove this blank line.

This revision is now accepted and ready to land.Jun 8 2015, 8:43 PM
This revision was automatically updated to reflect the committed changes.