[Object][COFF] Allow section symbol to be common symbol
authorPengxuan Zheng <pzheng@quicinc.com>
Sat, 10 Sep 2022 00:36:16 +0000 (17:36 -0700)
committerPengxuan Zheng <pzheng@quicinc.com>
Wed, 14 Sep 2022 01:07:02 +0000 (18:07 -0700)
commitecb5ea6a266d5cc4e05252f6db4c73613b73cc3b
tree093e0d901d33409e777635d0881ed9d944738d39
parent8c2ea14436c8232fa2e496122cb1d9349b1d8737
[Object][COFF] Allow section symbol to be common symbol

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?

Reviewed By: thakis

Differential Revision: https://reviews.llvm.org/D133627
llvm/include/llvm/Object/COFF.h
llvm/test/Object/coff-sec-sym.test [new file with mode: 0644]