This is an archive of the discontinued LLVM Phabricator instance.

[Object][COFF] Allow section symbol to be common symbol
ClosedPublic

Authored by pzheng on Sep 9 2022, 6:16 PM.

Details

Summary

I ran into an lld-link error due to a symbol named ".idata$4" coming from some
static library:

.idata$4 should not refer to special section 0.

Here is the symbol table entry for .idata$4:

Symbol {
    Name: .idata$4
    Value: 3221225536
    Section: IMAGE_SYM_UNDEFINED (0)
    BaseType: Null (0x0)
    ComplexType: Null (0x0)
    StorageClass: Section (0x68)
    AuxSymbolCount: 0
}

The symbol .idata$4 is a section symbol (IMAGE_SYM_CLASS_SECTION) and LLD
currently handles it as a regular defined symbol since isCommon() returns false
for this symbol. This results in the error ".idata$4 should not refer to special
section 0" because lld-link asserts that regular defined symbols should not
refer to section 0.

Should this symbol be handled as a common symbol instead? LLVM currently only
allows external symbols (IMAGE_SYM_CLASS_EXTERNAL) to be common
symbols. However, the PE/COFF spec (see section "Section Number Values") does
not seem to mention this restriction. Any thoughts?

Diff Detail

Event Timeline

pzheng created this revision.Sep 9 2022, 6:16 PM
Herald added a project: Restricted Project. · View Herald TranscriptSep 9 2022, 6:16 PM
pzheng requested review of this revision.Sep 9 2022, 6:16 PM
Herald added a project: Restricted Project. · View Herald TranscriptSep 9 2022, 6:16 PM
thakis added a comment.Sep 9 2022, 7:37 PM

This needs a test.

pzheng updated this revision to Diff 459625.Sep 12 2022, 7:20 PM

Add a test

thakis accepted this revision.Sep 13 2022, 7:38 AM

If this matches what link.exe does, this looks fine to me.

This revision is now accepted and ready to land.Sep 13 2022, 7:38 AM
This revision was automatically updated to reflect the committed changes.