Skip to content

Commit ecb5ea6

Browse files
committed
[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
1 parent 8c2ea14 commit ecb5ea6

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

llvm/include/llvm/Object/COFF.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -379,8 +379,8 @@ class COFFSymbolRef {
379379
}
380380

381381
bool isCommon() const {
382-
return isExternal() && getSectionNumber() == COFF::IMAGE_SYM_UNDEFINED &&
383-
getValue() != 0;
382+
return (isExternal() || isSection()) &&
383+
getSectionNumber() == COFF::IMAGE_SYM_UNDEFINED && getValue() != 0;
384384
}
385385

386386
bool isUndefined() const {

llvm/test/Object/coff-sec-sym.test

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Check that section symbol (IMAGE_SYM_CLASS_SECTION) is listed as common symbol.
2+
3+
# RUN: yaml2obj %s -o %t.obj
4+
# RUN: llvm-nm %t.obj | FileCheck %s
5+
6+
# CHECK: 00000001 C foo
7+
8+
--- !COFF
9+
header:
10+
Machine: IMAGE_FILE_MACHINE_AMD64
11+
Characteristics: [ ]
12+
sections:
13+
symbols:
14+
- Name: foo
15+
Value: 1
16+
SectionNumber: 0
17+
SimpleType: IMAGE_SYM_TYPE_NULL
18+
ComplexType: IMAGE_SYM_DTYPE_NULL
19+
StorageClass: IMAGE_SYM_CLASS_SECTION
20+
...

0 commit comments

Comments
 (0)